-
Notifications
You must be signed in to change notification settings - Fork 75
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
Support terminal lookbehind #1356
Conversation
Yay - this cleans up my request from #591! |
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.
Looks pretty good to me! 🚀
@@ -49,7 +49,7 @@ export class DefaultTokenBuilder implements TokenBuilder { | |||
|
|||
protected buildTerminalToken(terminal: TerminalRule): TokenType { | |||
const regex = terminalRegex(terminal); | |||
const pattern = regex.flags.includes('u') ? this.regexPatternFunction(regex) : regex; | |||
const pattern = this.requiresCustomPattern(regex) ? this.regexPatternFunction(regex) : regex; |
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.
Am I right that this distinction and the corresponding RegExp
wrapping in regexPatternFunction
is just there to prevent Chevrotain from applying validation rules to the given regex pattern?
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 does have something to do with Chevrotain, yes. Basically, Chevrotain will apply a few optimizations on token types based on the regex you pass. If you pass a non-trivial regex (usually those with the /u
flag or lookbehind), those optimizations cannot be performed. Instead of ignoring optimizations, it will instead throw an error. To disable those errors, we wrap the regex inside of an custom pattern function.
Do you plan to filter code completion based on the look-behind patterns, too? |
@szarnekow Can you give an example? I don't think the completion takes the specific token pattern into account at all right now. |
I see. The completion engine doesn't use the terminal rules to check inserted tokens for validity at all. |
Yes, it will currently just insert whatever the scope provider returns, ignoring any potential parser/lexer error that this might result in. |
Model with cursor positions
I wouldn't expect B to show up at |
I see, thanks for the example. I have created a separate issue, see #1368 👍 |
9a2d1ad
to
dca2ee3
Compare
Closes #1355
Allows adopters to write positive/negative lookbehind in both EBNF and Regex notation, with full support in the lexer/parser phase.