Token for EOF #1041
-
How can i specify the end of the code in my grammar? I would like to make a line either statements with a newline at the end, or statements and the end of file. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
There is a branch of Lark the implements the end symbol as We haven't merged it in, because for some grammars, which are hard to detect automatically, the parser might go into an infinite loop. But it's pretty stable per grammar, so if you get it working for yours, it's probably fine. However, In practice I think the easiest choice is to only check for newlines, and always add a newline at the end of your input, before sending it to the parser. |
Beta Was this translation helpful? Give feedback.
-
I tried specifying lalr as a parser and it started doing what i wanted |
Beta Was this translation helpful? Give feedback.
There is a branch of Lark the implements the end symbol as
$
: https://github.com/lark-parser/lark/tree/end_symbol_2021We haven't merged it in, because for some grammars, which are hard to detect automatically, the parser might go into an infinite loop. But it's pretty stable per grammar, so if you get it working for yours, it's probably fine.
However,
In practice I think the easiest choice is to only check for newlines, and always add a newline at the end of your input, before sending it to the parser.