-
Notifications
You must be signed in to change notification settings - Fork 592
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] Improved identifier and number lexing. #1427
[JavaScript] Improved identifier and number lexing. #1427
Conversation
Ruby may need this sort of thing, too. |
identifier: '{{identifier_start}}{{identifier_part}}*{{identifier_break}}' | ||
constant_identifier: '[[:upper:]]{{identifier_part}}*{{identifier_break}}' | ||
dollar_only_identifier: '\${{identifier_break}}' | ||
dollar_identifier: '(\$){{identifier_part}}*{{identifier_break}}+' |
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.
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.
It's valid but redundant. I don't know why syntect doesn't handle this, but if you open up a PR to remove the +
I'll endorse 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.
…tifiers [JavaScript] Improved identifier and number lexing.
Implemented the identifier rules from the spec.
The syntax previously used
\b
in a lot of rules. This is not quite right, and it leads to some bugs:function$NotAFunction
Where
\b
followed identifier characters, I replaced it with a negative lookahead. (Testing showed that there was no effect on performance.) Where\b
preceded identifier characters, we would need a lookbehind, which the fast regexp engine does not support. However, we don't actually need assertions at the beginning of matches if we maintain the invariant that the "cursor" should never pause with identifier characters on both sides. This is guaranteed if every match that ends with an identifier character ends with the negative lookahead.Implementing this correctly required changing the implementation of numeric literals. I added more tests and improved the behavior of numbers in some corner cases.