-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How are backreferences adjusted? #16
Comments
Ah, I just came across this by chance: They are octal escape sequences, just like the ones in string literals. |
Are you satisfied with the handling of back-references? Would more tests or changes to documentation help others avoid your intitial confusion? What are your thoughts about the semantic gap between /\1/.exec('\u0001') and RegExp.make`()${/\1/}`.exec('\u0001') |
Closing. I don't think there's a point of disagreement or change requested here. |
OK, I'd like to request a change for the tests to match the draft goals. RegExp.make `^(#+)([^#\r\n]*)${ /\1/ }` /* should imo
become */ /^(#+)([^#\r\n]*)(?:\x01)/ /*
not */ /^(#+)([^#\r\n]*)(?:\1)/
RegExp.make `(fo(o))${ /(x)\1(?:\2)/ }bar${ /\1/ }(baz)` /* should imo
become */ /(fo(o))(?:(x)\3(?:\x02))bar(?:\x01)(baz)/ /*
not */ /(fo(o))(?:(x)\3(?:\2))bar(?:\1)(baz)/
RegExp.make `${ /\1/ }` /* should imo
become */ /(?:\x01)/ /*
not */ /(?:(?:))/ In short: capturing groups and backreferences should only refer to each other within the same regex or template, and not clash with interpolation. |
Fair enough. I'll not it in the doc. I think I probably agree with you, but there's no other way of specifying capturing groups right now in strict mode code since `\1` is an octal escape. |
Oh, I didn't realize this was done because I'd guess that |
That wasn't the original reason I did it. I didn't read the spec closely enough to realize that |
When regex instances are interpolated in blocks, the comment mentions "With back-references adjusted". What does that mean?
The tests don't really help me to understand this:
First of all, I don't understand what
/\1/
is. If I read the spec (ES6, ES5) right, then this should throw aSyntaxError
, as there are not enough NcapturingParens in the regex. If I test it in my browser (old Opera, FF), this is a valid expression however, which happily matches"\1"
(yes, that'sString.fromCharCode(1)
).Neither of these behaviours is reflected in the tests, though. Instead, they do expect
(?:)
which imo both collide with the goal that
The rewriting of backreferences (both from the template, when "interrupted", and from the interpolation value, to reference the same group as before) seem to reasonable in contrast.
The text was updated successfully, but these errors were encountered: