1// Turn something like {a,b{c,d},}x{e,f} into2// ["axe", "axf", "bcxe", "bcxf", "bdxe", "bdxf", "xe", "xf"]3// Only {,} groups are expanded. While in many cases {x,y} is4// functionally equivalent to @(x|y), for the purpose of globbing5// files, only {x,y} gets expanded as multiple patterns.6minimatch.patternSet = patternSet7function patternSet (pattern) {8if (!pattern.match(/{/) || !pattern.match(/}/)) {9// shortcut - no sets.10return [pattern]11}1213// a{b,c{d,e},{f,g}h}x{y,z}14//15// t=[before set, set, after set]16// t=["a", ["b", "c{d,e}", "{f,g}h"], "x{y,z}"]1718// start walking, and note the position of the first {19// and the corresponding }20var p = pattern.indexOf("{")21, l = pattern.length22, d = 023, escaping = false24, inClass = false25while (++ p < l) {26switch (pattern.charAt(p)) {27case "{":28d ++29continue30case "}":31323334// t[2] = patternSet(t[2])35// t = [t[0]].concat([t[1].map(patternSet)]).concat([t[2]])36//37// t=["a",[["b"],[["cd","ce"]],[["fh","gh"]]],["xy","xz"]]38//39// // first turn into40// // [["ab"], ["acd", "ace"], ["afh", "agh"]]41// return t[1].map(function (p) {42// return p.map(function (p) {43// return t[0] + p44// })45// })46// // flatten into ["ab", "acd", "ace", "afh", "agh"]47// .reduce(function (l, r) {48// return l.concat(r)49// }, [])50// // tack all the endings onto each one51// .map(function (p) {52// return t[2].map(function (e) {53// return p + e54// })55// })56// // flatten again57// .reduce(function (l, r) {58// return l.concat(r)59// }, [])60}61626364