mikesamuel / regexp-make-js

ES6 string template tag for creating dynamic regular expressions
Apache License 2.0
51 stars 9 forks source link

Is the Expressions table complete? #13

Open bergus opened 9 years ago

bergus commented 9 years ago

I'm not sure I understand the Expressions table. Does it mean that interpolation values may only appear in these parts of a regex, and everything else is a syntax error?

If that was not the intended meaning, there seem to be a lot possible occurences that are not discussed:

Also I think the table should use the offical grammar production names. I assume the "context Block" does mean that we consider the "interpolation hole" to produce an Atom?

slevithan commented 4 months ago

Alternative library Regex.make takes a more exhaustive approach to this, and might be instructive.

ClassAtom as Range delimiters: RegExp.make`[${"a"}-${"z"}]` - is anything but a single-codepoint string valid here?

Regex.make says no. Any single code point matching token is okay on a range boundary (phrased that way because it supports interpolating both escaped strings and regex patterns as strings) but interpolating a set of code point matching tokens is an error in this context.

Unicode Escape Sequences: RegExp.make`\u${2503}` - what does this do?

Regex.make says it's an error in v mode, because it's considered to be incomplete token \u followed by tokens 2, 5, 0, 3. But Regex.make`\u{${2503}}` is valid and outputs /\u{2503}/.