-
Notifications
You must be signed in to change notification settings - Fork 77
Whitespace terminal rules are always matched first #1828
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
Comments
Hey @dsogari, This is actually working as intended, although we might want to refactor parts of that code anyway soon. Adopters of Langium can always override the Note that I'm not entirely sure that even with this adjustment that your language will parse as expected. We use an LL parser that features a separate lexing and parsing phase (see chevrotain). The lexing phase is not context aware, and therefore will likely lead to unintended behavior when it comes to the |
Oh, I see it now. Thanks for the response! I guess I was biased from having used Jison in the past, in which we could push and pop lexer states. So in that case the grammar actually |
This is also possible, but again through the |
@msujew I think what I'm looking for is the Lexer Modes feature of Chevrotain. Is there a way to use that within Langium? If so, could you point me to a tutorial or example code that demonstrates it? |
Sorry for the noise, but for anyone who might follow this discussion, here are some notes from Chevrotain's tutorial summarizing the issues I've been facing:
|
See here (from eclipse-langium/langium-website#132), we simply expose the Chevrotain API directly. |
Thanks a lot! I'll take a look at it. EDIT: that is exactly what I was looking for. :) |
Langium version: latest
Package name: langium
Steps To Reproduce
Open the playground page.
Copy and paste the following grammar into the Grammar pane:
Copy and paste the following content into the Content pane (notice the trailing spaces):
Link to code example: playground example
The current behavior
The expected behavior
The content should be parsed and the following syntax tree should appear in the Syntax tree pane:
Additional notes
I think this behaviour is caused by the following piece of code in token-builder.ts:
In other words, whitespace-matching lexer rules are being given priority, thus changing the order specified in the grammar and altering the expected behavior. This is espeically frustrating, for instance, when we need a single whitespace as a delimiter/separator for specific parser rules.
The text was updated successfully, but these errors were encountered: