You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This was a problem I came across in a grammar I was writing, but I was able to reproduce it with some of the examples. I don't know if this is Lark working as designed and just grammars are defined incorrectly, or if this is a problem with Lark.
If you start a grammar with a line like: start: (_item | _NL)* and then try to read a file that doesn't end with a new line, it will throw a bad parse error. Reproduce by using lark.lark as the grammar and then try to parse it without a \n at the end of the file.
The easy solution to this is, of course, just add a newline at the end of any string you want to parse. But this doesn't feel like a very good solution. Any thoughts of how to fix?
The text was updated successfully, but these errors were encountered:
The reason that lark.lark requires files to end in a newline is because of the way its rules are written: You can see that rule, token and statement all require _NL at the end. The reason I wrote it like this is that making _NL optional would make it harder to parse with LALR(1).
But now that you mention it, I have a different idea. I can add an EOF symbol, something like:
This was a problem I came across in a grammar I was writing, but I was able to reproduce it with some of the examples. I don't know if this is Lark working as designed and just grammars are defined incorrectly, or if this is a problem with Lark.
If you start a grammar with a line like:
start: (_item | _NL)*
and then try to read a file that doesn't end with a new line, it will throw a bad parse error. Reproduce by using lark.lark as the grammar and then try to parse it without a\n
at the end of the file.The easy solution to this is, of course, just add a newline at the end of any string you want to parse. But this doesn't feel like a very good solution. Any thoughts of how to fix?
The text was updated successfully, but these errors were encountered: