eclipse-langium / langium

Next-gen language engineering / DSL framework
https://langium.org/
MIT License
725 stars 65 forks source link

Parse error, but still yields a correct AST #1297

Closed rolandzwaga closed 10 months ago

rolandzwaga commented 10 months ago

Langium version: 2.1.2 Package name: langium

Steps To Reproduce

  1. Check this playground url

Link to code example:

playground url

The current behavior

Check the red squiglies underneath '=#main-title', when mouse-overing it reports the error 'expecting the token EQUALS but found #main-title'. Then check the AST column, the NamedArgument instance has a value of '#main-title'

The expected behavior

I would expect no parsing error to occur, because the AST is exactly what I expect. Of course, I might do something very, very wrong in my grammar, in which case I would really appreciate some guidance.

Thank you in advance!

spoenemann commented 10 months ago

The error is likely due to the way how you defined EQUALS (with positive lookahead). Changing to a simple '=' keyword fixes it:

NamedArgument:
    name=NAME '=' value=Value;

Value returns string:
    STRING | NUMBER | NAME | SELECTOR | BOOL_TRUE | BOOL_FALSE;

Here I also extracted the value to a string typed rule.

msujew commented 10 months ago

Note that there are actually two red squiggles (right after another):

image

The first one indicates that the = sign couldn't be lexed (due to the issue outlined above by @spoenemann), while the other indicates that EQUALS had to be skipped in order to parse the input.

rolandzwaga commented 10 months ago

Argh, thank you gentlemen, the problem was indeed the defintion of my terminal. The grammar I posted was a simplified version of my real grammar. I now see that I ordered some terminals wrong there. In an effort to try and fix the problem I was trying out all sorts of things and had added the look-aheads. Not realising this actually just made matters worse...

Thank you for your time!