-
Firstly, my compliments for this amazing project. Langium will be really useful for me to migrate my eclipse/xtext-based DSLs to VSCode extensions. In some of my xtext grammars, I needed to use syntactic predicates => and -> to help the parser to choose between initially ambiguous alternatives. I see the Langium grammar language allows me to write these also, but they do not seem to have an effect on the parser behaviour. Are they not supported yet? As an example, I have a javascript-like language in which expressions can reference variables and functions using qualified names, and they can also be post-fixed with member calls. Below a simplified excerpt from my grammar. Note the colon in the qualified name to disambiguate it from subsequent member calls.
Now, if I offer an expression like Any hints on resolving this ambiguity in any other way than with syntactic predicates is also welcome, of course. Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi @mrtnstn, thanks for the compliment :) You're right in your assumption that Langium doesn't respect syntactic predicates. They are only in there for the purpose of Xtext "backwards compatibility". The issue here is based on our underlying parser library Chevrotain and is twofold:
Although we can fix most issues with syntactic predicates due to 1. by simply reordering alternatives, I don't think that this special case can the represented in Langium due to 2. In theory, Chevrotain is capable of resolving this by using backtracking, but Langium doesn't expose that much of the Chevrotain API to actually do this. We probably have to wait until the mentioned PR is merged, then it should work out-of-the-box (even without the syntactic predicate). Unfortunately the maintainer of Chevrotain is quite busy at the moment, so it might take some time until this is done. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the explanation @msujew . Good to know a solution is coming in the hopefully not too distant future. Keep up the good work. |
Beta Was this translation helpful? Give feedback.
Hi @mrtnstn,
thanks for the compliment :)
You're right in your assumption that Langium doesn't respect syntactic predicates. They are only in there for the purpose of Xtext "backwards compatibility". The issue here is based on our underlying parser library Chevrotain and is twofold:
ID =>(('.' ID)* ':' ID)?;
at all, a more powerful approach (ANTLR3/4 style LL(*)) is needed.