I'm new to parsing (obviously). I am using LEPL library to parse some markup language.
I have a problem with this code (I've omitted details for the sake of clarity).
from lepl import *
a = Literal('a')[0:,...] # 0 or more, join the result
b = Literal('b')
c = (a | b)[0:]
print c.parse("abaabaaab")
The last line should give me ['a','b','aa','b','aaa','b']
There is no error but it hangs (infinite recursion maybe?). Could anyone point me in the right direction?
Edit
I could do this like this
from lepl import *
a = Literal('a')
b = Literal('b')
c = (a | b)[0:]
print c.pa开发者_JAVA百科rse("abaabaaab")
But the a will not be grouped.
I am pretty sure that, in your first example, you want
a = Literal('a')[1:]
With two [0:]
repeats in your grammar, the parser will indeed run into effectively infinite backtracking.
精彩评论