Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser throws error if text to parse doesn't end with a new line. #139

Closed
RobRoseKnows opened this issue May 9, 2018 · 4 comments
Closed

Comments

@RobRoseKnows
Copy link
Member

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?

@erezsh
Copy link
Member

erezsh commented May 9, 2018

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:

rule: RULE priority? ":" expansions (_NL|$)

@RobRoseKnows
Copy link
Member Author

Yeah, I think adding an EOF symbol would be a good idea. Especially since Windows is now using Unix line endings in Notepad by default.

@nomorepanic
Copy link

I can see the usefulness of an EOF token too, so you should definitely consider adding it

@erezsh
Copy link
Member

erezsh commented Sep 18, 2018

Closing. This idea of adding EOF continues in issue #237

@erezsh erezsh closed this as completed Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants