What is the difference between importing a langium grammar and just putting that grammar into your file? #1602
-
So if I have a common file with this inside of it:
and I have a langium file with this:
what is the difference between just doing this and having the common file directly inside of the grammer gitGraph file. Because for whatever reason it seems to create different rules. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @Austin-Fulbright, the only real difference is that there no guarantee that the order of terminals is preserved. Generally, Terminals are lexed in the order they appear in the grammar. I.e. if a word could be tokenized as two different terminals, the first terminal that appears in the grammar receives precedence. However, when importing a grammar, all imported terminal rules get put to the back of the list, and consequently get the lowest precedence. What kind of different behavior are you seeing with the import compared to the inlined grammar? |
Beta Was this translation helpful? Give feedback.
-
So the grammer rules that involve collecting
inputed into the language with the imports would throw an error such as expecting EOF but found 'accTitle' However if in the playground or my langium project I use all of the code in the same file, it will work just fine. There is also some services that I am using from my common. This is probably a misunderstanding on my part how the modules work. Here are some examples from my project: Thanks for taking the time to answer my question :) |
Beta Was this translation helpful? Give feedback.
I've put your grammar into the playground and simulated what happens when using grammar imports here. I've mentioned this in my earlier comment:
Since terminals that appear later in the grammar get a lower precedence, the lexer and consequently the parser behave differently. Note that you can adjust the
TokenBuilder
instance to modify that behavior.