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

Incomplete parse is not working as expected #64

Closed
igordejanovic opened this issue Oct 22, 2018 · 8 comments
Closed

Incomplete parse is not working as expected #64

igordejanovic opened this issue Oct 22, 2018 · 8 comments
Assignees
Labels

Comments

@igordejanovic
Copy link
Owner

Reported on the related issue #16.

This parse should succeed where the input string should be consumed incompletely:

g = Grammar.from_string('T: NL* L+ NL* | NL*; L: /.+/; NL: "\n";', re_flags=re.MULTILINE)
print(Parser(g, ws=False).parse('\nL1\nL2\n\n'))
# ParseError: Error at 3:0:"\nL1\n*L2\n\n" => Expected: STOP but found <L(L2)>

Relevant docs is here.

@igordejanovic igordejanovic self-assigned this Oct 22, 2018
@amerlyq
Copy link

amerlyq commented Oct 22, 2018

By the way, what about changing defaults to "always parse till the end with errors" and only by explicitly requesting allow_partial_input=True in parser() user will get continous parsing?
I feel like it's more intuitive due to incomplete parsing being not that frequent.
Or do you have your own point on using "continuous" as default?

grammar allow_partial behavior
S False(default) error
S True OK, partial
S EOF False error
S EOF True error

@igordejanovic
Copy link
Owner Author

I prefer this to be explicitly specified trough the grammar instead of introducing a new parser config flag. It's more a matter of preference but if it can be specified by the grammar I think it is always better that way. In my view using EOF in the grammar has a clean semantics.

@amerlyq
Copy link

amerlyq commented Oct 23, 2018 via email

@igordejanovic
Copy link
Owner Author

I understand your line of reasoning and it sound perfectly valid. The rule of least surprise greatly depends on your previous experiences I would say :)
Thanks for sharing your thinking and standpoint. When I get back to resolving this I'll reconsider different approaches again.

@amerlyq
Copy link

amerlyq commented Oct 23, 2018 via email

@igordejanovic
Copy link
Owner Author

@amerlyq I've been rethinking this idea lately and I think that you are right. Several users have been sidetracked by this issue so it would definitely be better to make complete parse the default and have a parser option to allow incomplete parse. I'm planning to address this issue in the following days. Thanks for bringing this issue and discussing.

igordejanovic added a commit that referenced this issue Nov 28, 2019
igordejanovic added a commit that referenced this issue Nov 28, 2019
igordejanovic added a commit that referenced this issue Nov 28, 2019
igordejanovic added a commit that referenced this issue Nov 28, 2019
@igordejanovic
Copy link
Owner Author

Implementation is finished on the remove-eof branch. You can check out the tests and docs changes. Will test more in the following days and if all goes well this is going to be released in the next version.

@igordejanovic
Copy link
Owner Author

Everything seems fine so far. Merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants