-
Notifications
You must be signed in to change notification settings - Fork 588
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
[JavaScript] Division incorrectly highlighted as regex. A general fix is known, but nontrivial and could use feedback. #885
Comments
This looks like it might be a bigger project than I'd realized. A roadmap might look like this:
Questions:
Also, an additional note. Rather than keeping both
|
In working on this, I have noticed that a number of the tests are incorrect. Example: 'aabbcc'.replace(/b+/, 'd')
// ^^^^ string.regexp
// ^ keyword.operator.quantifier.regexp
/a+(?:bc)/
// <- string.regexp
// ^^ punctuation.definition.group.no-capture.regexp The second line of code is not a regular expression; the slash is a division operator. To correct the test, a semicolon should be added to the first line of code. There are a handful of similar examples where a missing comma or semicolon results in a faulty test. |
This has been completely resolved. |
Examples (note that GitHub gets the second example wrong):
The root cause seems to be the architecture of
expressions
. Theafter-operator
andafter-identifier
contexts work to differentiate uses of the/
characters in common cases, but they aren't really a general solution. The same architectural issue also holds back #324; the suggested solution there suffers from exactly the same bug.The third example also suffers from a lack of distinction between statements and expressions.
The general solution I've worked out for this sort of issue is to have separate
expression-head
andexpression-tail
contexts. I've included a minimal example:The following are scoped correctly:
The
expression-head
context should:(
or/
) and set.The
expression-tail
context should:expression-head
.As written, this will match one expression and pop everything when the next character is not part of an expression. Slight modification will yield contexts that can parse a list of expressions or gracefully skip invalid input.
This might seem like an odd architecture, but I've used it quite a bit (including in an unpublished JavaScript syntax). It should gracefully solve this bug and any similar bugs and allow for an easy solution to #324. I welcome feedback on the approach; if there are no objections, I'll write up a patch.
The text was updated successfully, but these errors were encountered: