Replies: 7 comments 3 replies
-
This is working as intended, the terminals Where does the documentation say that data type rules parse context dependent text? That's definitely not correct. Langium can only parse context free grammars, with some exceptions, depending on your changes to the lexer. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick response! Here's where the document states it: https://langium.org/docs/reference/grammar-language/#data-type-rules If you don't mind, I have 2 questions:
|
Beta Was this translation helpful? Give feedback.
-
One more thing... What are the exceptions? Is it possible to, embed a grammar inside another? Or to parse different segments of a document using different grammars? |
Beta Was this translation helpful? Give feedback.
-
I see, it probably makes sense to change that, since this is not correct - the existence of a parser rule doesn't make the lexer suddenly create different kinds of tokens (this is impossible, since the parser cannot have this kind of feedback effect on the lexer).
See this WIP guide on multi-mode lexing, which explains how to add state to lexers and also how to override the token builder in general. |
Beta Was this translation helpful? Give feedback.
-
Thanks, @msujew ! I'm also going to allow embedding another language I'm also creating inside code blocks. I was checking the multi-language setup like explained here: https://eclipse-langium.github.io/langium-previews/pr-previews/pr-132/guides/multiple-languages/ Would It be possible to combine the grammars in different parts of the document instead of different files? |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I can follow. What is the difference between having multiple grammars or one big grammar for this purpose? |
Beta Was this translation helpful? Give feedback.
-
Think about how we can embed other languages inside markdown. Except, in my case, the outer scope would provide context for autocomplete of the language in the inner scope. I'm creating two languages: Rcl and RclScript. They will be used to create RCS (the new SMS) agents and message flows. The first is similar to yaml, indentation sensitive and focused on defining data objects. The second allows writing logical conditions for the message flow. They are really different and having them in separate grammar would make them more manageable |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I read in the documentation that data rules are context-dependent but that does not seem to be the case.
Langium version: 3.5 (I also tested locally
Link to code example:
https://langium.org/playground/
Grammar
Content:
The current behavior
The parser seems to try all rules and in an order I cannot control
See image
The expected behavior
I would the parser behavior for the rule
Command returns string: 'cmd' Word (YES|NO);
to either match the entire rule at once them break it down into tokens, or to match and tag the tokens respecting the rule I created. If it matches a 'cmd' string, it then tries to match a singleWord
, then it tries to match eitherYES
orNO
and sets the appropriate token types at each stepBeta Was this translation helpful? Give feedback.
All reactions