Is there a way to avoid token/ID conflicts? #1032
Replies: 1 comment 1 reply
-
Hi @rpedrosanto, Langium's parser (chevrotain) is using a typical two-phase approach to parsing: The text is first tokenized by a lexer and then these tokens are parsed the actual parser. This has a few benefits, mostly performance related. On the other hand, it has the disadvantage of not being able to easily decide between tokens using context. Generally, lexers work without any context. This is the issue you're encountering. Fortunately, it can be relatively easily addressed. You can declare a data type rule that includes these keywords:
The |
Beta Was this translation helpful? Give feedback.
-
Take the following grammar as an example:
It works fine for the following:
But if I define a new type for which the ID conflicts with any of the tokens in the language, e.g.:
I get the error
Expecting token of type 'ID' but found 'text'.
Is this supposed to work? Doesn't it know from context that
text
aftertype
andas
should be an ID?Is there a way to fix this without changing the language? I could wrap the IDs in single quotes for instance but I'd really like to avoid it.
Thanks in advance. I appreciate it.
Beta Was this translation helpful? Give feedback.
All reactions