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

Infinite loop (or similar) in parser #17

Open
boxed opened this issue Apr 30, 2013 · 6 comments
Open

Infinite loop (or similar) in parser #17

boxed opened this issue Apr 30, 2013 · 6 comments

Comments

@boxed
Copy link

boxed commented Apr 30, 2013

The following code will make parsley take 100% CPU and slowly growing in memory for a long long time. This is an incorrect grammar because the rule "output" is referencing "one" directly AND indirectly via the rule "number". It would be better if parsley detected this and threw a helpful error.

from parsley import makeGrammar, termMaker
from itertools import chain

x = makeGrammar("""
one = '1'
two = '2'
number = (one | two)*
output = (number | one)*
""", {})
print x("1122121").output()
@washort
Copy link
Contributor

washort commented May 7, 2013

yep, using a rule that can match the empty string inside a star expression will do that.

more succinctly:

output = ('1'*)*

@boxed
Copy link
Author

boxed commented May 8, 2013

Shouldn't this be caught? I mean, isn't part of the point of parsley to have nice error messages... an infinite loop isn't very nice.

@washort
Copy link
Contributor

washort commented May 8, 2013

That'd be nice. There's probably even a way to detect some cases of this statically.

@johtso
Copy link

johtso commented Jul 5, 2013

This also causes an infinite loop: ('foo'?)*

@washort
Copy link
Contributor

washort commented Jul 5, 2013

Yes. Repeating any rule that will match an empty string will loop forever.

@SuperDoxin
Copy link

so wouldn't it be possible to check a rule to see if it matches the empty string before building it into a star expression? seems like a relatively cheap operation which'd prevent a common error.

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

4 participants