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

Wrong backtracking algorithm #181

Closed
62 opened this issue Jun 11, 2013 · 4 comments
Closed

Wrong backtracking algorithm #181

62 opened this issue Jun 11, 2013 · 4 comments

Comments

@62
Copy link

62 commented Jun 11, 2013

Hello! I'm find that expression like:

start = (term? term)? term
term = [0-9]

don't correct work with nested optional terminals. It cannot recognize two digit string (11). One and three digit is ok.

Analogous regular expression work fine:
([0-9]?[0-9])?[0-9]

I think you use "possessive quantifiers" backtracking algorithm for optimize performance, like:
([0-9]?+[0-9])?+[0-9]
but in common case it is not correct.

How can I switch to classic "greedy"?

Thank you very much for your work!

@otac0n
Copy link

otac0n commented Jun 11, 2013

This is not how PEG grammars work. PEG grammars are a short hand for recursive descent parsers, which do not backtrack in the same way that regular expressions do.

This is intentional.

@otac0n
Copy link

otac0n commented Jun 11, 2013

Also, see #105 and #57.

@62
Copy link
Author

62 commented Jun 11, 2013

Sorry, name PEG misleading me (and switch BNF alternative "|" to PEG ordered choice "/") This is common for "parsing strings" grammars unlike BNF "constructing string" (context free).

@dmajda
Copy link
Contributor

dmajda commented Jan 18, 2014

As explained above, this is not a bug. Closing.

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