langium
langium copied to clipboard
Strange Parser Error with Langium 1.0.0
Langium version: 1.0.0 Package name: langium
Chevrotain version; 10.4.2
Steps To Reproduce
- Create Hello World Example
- Replace Grammar with the following grammar
grammar HelloWorld
entry Model: GroupContent;
Person: 'person' name=ID;
fragment SimpleGroupContent:
(persons+=Person | greetings+=Greeting )*;
fragment GroupContent:
(persons+=Person | greetings+=Greeting | groups+=Group)*;
Group: 'group' name=ID ('(' 'info' '=' info=STRING ')')? (
('{'
GroupContent
'}')|
( // ';' // <.. this line seems to fix the effect
SimpleGroupContent
)
);
Greeting:
'Hello' person=[Person:ID] '!';
hidden terminal WS: /\s+/;
terminal ID: /[_a-zA-Z][\w_]*/;
terminal INT returns number: /[0-9]+/;
terminal STRING: /"[^"]*"|'[^']*'/;
hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//;
hidden terminal SL_COMMENT: /\/\/[^\n\r]*/;
- Compile and run the IDE, enter the following model
person Pi
Hello Pi!
group G1 ( info="Hello") {
person Tim1
Hello Tim1!
}
group G2 ( info="Hello") { // resulting error indicated here: "Expecting end of file but found `{`."
p_ERROR_erson Pi // <--- Error entered here, expecting something like: "Expecting token of type '}' but found `p_ERROR_erson`."
Hello Pi!
}
The current behavior
- The IDE indicates the error at "{"
- Completion does not work properly
The expected behavior
- Correct error message in the line of the error
- Better completion performance
The strange thing is, that if a ';' is added to the grammar (sketched above), the problem gets fixed. Also I did not observe this with my Langium 0.0.5 version of hello-world.
Maybe the following Chevrotain issue is related https://github.com/Chevrotain/chevrotain/issues/1868
This is likely related to https://github.com/langium/langium/pull/755. Do you mind adding the chevrotainParserConfig.maxLookahead property to the langium config? Similar to here.
Thank you, @msujew ! This helped... Adding the property - like you suggested - solved the issue.
{
"projectName": "HelloWorld",
"languages": [{
"id": "hello-world",
"grammar": "src/language-server/hello-world.langium",
"fileExtensions": [".hello"],
"chevrotainParserConfig": {
"maxLookahead": 3
},
"textMate": {
"out": "syntaxes/hello-world.tmLanguage.json"
}
}],
"out": "src/language-server/generated"
}
It remains unclear to me, if this is a bug or not. Or if my grammar was some kind of "sub-optimal"? If you prefer I can copy the issue to the discussion section... (other people might have similar issues.) What do you think?
It's a bug, though I thought I fixed all of them in https://github.com/langium/chevrotain-allstar. I'll look into it once my vacation ends.