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

Support for infinite loops detection and reporting #23

Open
igordejanovic opened this issue Oct 27, 2015 · 4 comments
Open

Support for infinite loops detection and reporting #23

igordejanovic opened this issue Oct 27, 2015 · 4 comments

Comments

@igordejanovic
Copy link
Member

In the case of left recursive grammar Arpeggio will end with RecursionError.
It would be nice to have a detailed report why that happen and where in the grammar is the left recursive loop.

@igordejanovic
Copy link
Member Author

This is in relation with the idea to fully support left recursive grammars #5

@igordejanovic igordejanovic changed the title Support for left recusion detection and reporting Support for infinite loops detection and reporting May 31, 2016
@igordejanovic
Copy link
Member Author

Another example of infinite loop is using expression that could succeed without consuming any input in repetition. For example, using Optional inside ZeroOrMore.

@Ygg01
Copy link
Contributor

Ygg01 commented May 31, 2016

Interesting problem. Any ideas how to solve this issue?

Best I've found were:
https://github.com/orlandohill/peg-left-recursion

Alternatively, you could limit nesting within a AST via some kind of decrementing counter.

@igordejanovic
Copy link
Member Author

Thanks for the link. There are several papers published on the subject. I had plans to support left recursive grammars (there is still issue registered) but I'm not so sure anymore that it is the right way to go.

PEGs have a nice property that they are representation of recursive descent parser and thus are easy to reason about and debug. Introducing support for left recursion would break that simplicity.

For the time being I think that detection of infinite loops on the grammar level is good enough.
Idea is to run those checks during grammar design so there should be no run-time overhead. I have some vague idea of how that can be done but I still must find some more time to investigate.

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

No branches or pull requests

2 participants