Closed mspoulsen closed 3 years ago
You can just write a template function that interpolates RegExps, e.g.:
function reg(strings, ...pieces) {
return new RegExp(strings.raw.map((r, i) => r + (pieces[i] === undefined ? '' : '(?:' + pieces[i].source + ')')).join(''))
}
const AMOUNT = /\d+([\d,]*\d+)?(.\d+)?/
const CHIPS = reg`\(\s*(\W)(${AMOUNT})\s+\w+\s*\)`
Hi,
In jison you can compose rules from other rules like this:
Is there a way to do this in moo so I can re-use complicated rules like in this case amount?
Thanks!