End grammar rules using EOL? #1510
-
Hi, I want to write a grammar for the following type of structure,
I want to terminate ever 'line' in 'Comamnds' by EOL but how. I found somewhere that I can use:
I have this grammar (fragment) so far:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @PatrikN-work, I've adjusted your language to work as expected with regards to EOL markers. See this playground link. You can see what kind of AST the input produces by toggling the syntax tree viewer. Note that I would generally recommend against employing newline-delimited languages, as they don't behave very well when it comes to error recovery behavior in Langium. Unless you're reimplementing an existing language in Langium, you're almost always better suited using a different delimiter like |
Beta Was this translation helpful? Give feedback.
Hey @PatrikN-work,
I've adjusted your language to work as expected with regards to EOL markers. See this playground link. You can see what kind of AST the input produces by toggling the syntax tree viewer.
Note that I would generally recommend against employing newline-delimited languages, as they don't behave very well when it comes to error recovery behavior in Langium. Unless you're reimplementing an existing language in Langium, you're almost always better suited using a different delimiter like
;
. Generic parsers are generally pretty bad at handling unexpected input in whitespace-aware languages. It also makes maintenance on the grammar pretty difficult, as you always need to keep tr…