-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Normative: Add RegExp Modifiers #3221
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we use the RegularExpressionFlags
production and restrict it with an early error instead of introducing a new, more restricted production?
Is there a reason not to? Modifiers are a strict subset of |
I believe |
How would you propose it be written so as not to require early errors? Modifiers can appear in any order, cannot be duplicated within one or both of the modifier locations, and I do plan to extend the set of allowed modifiers over time with things like
The more modifiers we add, the more production parameters we need, and the more complex the production becomes. Plus, this doesn't avoid the need for an early error to forbid |
@rbuckton I'm not saying we can't use any early errors at all on the production, just that we don't need to use early errors to enforce the allowed flag characters when an alternative grammar could do the job. I'm happy to continue using early errors to check for duplicates. |
Now that both V8 and SpiderMonkey are shipping regex modifiers, I'm hoping to request Stage 4 at the October plenary. As such I'm working on updating this PR so that it is in a mergeable state. @michaelficarra do you still want me to refactor modifiers to something other than |
@michaelficarra I went ahead and added a |
spec.html
Outdated
<emu-grammar>Atom :: `(?` RegularExpressionModifiers `-` RegularExpressionModifiers `:` Disjunction `)`</emu-grammar> | ||
<ul> | ||
<li> | ||
It is a Syntax Error if the source text matched by the first |RegularExpressionModifiers| and the source text matched by the second |RegularExpressionModifiers| are both empty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just throw the early error when the second |RegularExpressionModifiers|
is empty regardless of whether the first modifiers are empty? For example, currently the spec allows /(?i-:foo)/
, but the implementation differs: V8 accepts this production while Babel rejects it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly? We only error here because we decided to be more pedantic about modifiers than other languages. C#, for example, seems to parse (?-:)
just fine. Any change here would need consensus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remembered that I was wondering the same (why the start
constant is placed here) when I was reviewing my RegExp check implementation for TypeScript.
I believe that Huáng’s expectation is actually more ergonomic, otherwise it would not be so easy for the current behavior to be misimplemented.
spec.html
Outdated
<emu-grammar>Atom :: `(?` RegularExpressionModifiers `:` Disjunction `)`</emu-grammar> | ||
<ul> | ||
<li> | ||
It is a Syntax Error if the source text matched by |RegularExpressionModifiers| contains the same code point more than once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess technically we could accomplish this entirely within the grammar, but this is a fine use of early errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Outside of updating from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm % question about strings
478b815
to
f55b180
Compare
This adds the specification text for the Stage 3 RegExp Modifiers proposal.
Test262 tests can be found at tc39/test262#3960.