Brace expansion: Difference between revisions
Content deleted Content added
Line 1,225: | Line 1,225: | ||
<lang JavaScript>(function () { |
<lang JavaScript>(function () { |
||
'use strict' |
'use strict' |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
]; |
|||
⚫ | |||
function (s) { |
|||
⚫ | |||
⚫ | |||
tokens(s) |
|||
)[0]; |
|||
⚫ | |||
⚫ | |||
); |
|||
⚫ | |||
dctParse |
|||
).map(function (x) { |
|||
return ' ' + x; |
|||
⚫ | |||
} |
|||
⚫ | |||
} |
|||
// Index of any closing brace matching the opening brace at iPosn |
// Index of any closing brace matching the opening brace at iPosn |
||
Line 1,265: | Line 1,232: | ||
var t = tkns[iPosn], |
var t = tkns[iPosn], |
||
n = (t === '{') ? iNest + 1 : ( |
n = (t === '{') ? iNest + 1 : (t === '}' ? iNest - 1 : iNest), |
||
t === ' |
lst = (t === ',' && iNest === 1) ? lstCommas.concat(iPosn) : lstCommas; |
||
), |
|||
lst = (t === ',' && iNest === 1) ? |
|||
lstCommas.concat(iPosn) : lstCommas; |
|||
return n ? bracePair(tkns, iPosn + 1, n, lst) : { |
return n ? bracePair(tkns, iPosn + 1, n, lst) : { |
||
Line 1,347: | Line 1,311: | ||
return lng ? ( |
return lng ? ( |
||
1 < lng ? lstHead.reduce(function (a, h) { |
1 < lng ? lstHead.reduce(function (a, h) { |
||
return a.concat( |
return a.concat(and(args.slice(1)).map(function (t) { |
||
return h + t; |
|||
})); |
|||
}) |
|||
); |
|||
}, []) : lstHead |
}, []) : lstHead |
||
) : []; |
) : []; |
||
Line 1,366: | Line 1,328: | ||
// One list split into two (first sublist length n) |
// One list split into two (first sublist length n) |
||
function splitAt(n, lst) { |
function splitAt(n, lst) { |
||
return n < lst.length + 1 ? ( |
return n < lst.length + 1 ? [lst.slice(0, n), lst.slice(n)] : [lst, []]; |
||
[lst.slice(0, n), lst.slice(n)] |
|||
) : [lst, []]; |
|||
} |
} |
||
Line 1,380: | Line 1,340: | ||
// Value of the parse tree |
// Value of the parse tree |
||
function evaluated(e) { |
function evaluated(e) { |
||
return typeof e === 'string' ? e : |
return typeof e === 'string' ? e : |
||
e.args.map(evaluated) |
e.fn(e.args.map(evaluated)); |
||
); |
|||
} |
} |
||
Line 1,394: | Line 1,353: | ||
} |
} |
||
return main(); |
|||
// MAIN |
|||
// s -> [s] |
|||
⚫ | |||
// BRACE EXPRESSION PARSED |
|||
⚫ | |||
// ABSTRACT SYNTAX TREE LOGGED |
|||
⚫ | |||
// AST EVALUATED TO LIST OF STRINGS |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
})();</lang> |
})();</lang> |
||