I just got left recursion working. It was more complex than I
suspected (the final code is quite simple, but for a long time I had a
bug that I didn't understand). The following test now succeeds (on a
naive recursive descent parser it would exhaust the stack because seq
would repeatedly call itself).
def test_left(self):
basicConfig(level=DEBUG)
seq = Delayed()
letter = Any()
seq += Optional(seq) & letter
p = string_matcher(seq,
Configuration(memoizers=[LMemo], monitors=[TraceResults
(True)]))
results = list(p('ab'))
print(results)
assert len(results) == 2, len(results)
assert results[0][0] == ['a', 'b'], results[0][0]
assert results[1][0] == ['a'], results[1][0]
Note the new Configuration object - necessary as the library becomes
more complex.
I now need to add more tests and document the new features. Apart
from bug fixing I don't expect to add more code (except to improve
support for parsing raw strings/lists - the Stream class is now less
critical as resource management is done during trampolining).
(The trampolining is described in a comment here -
http://knol.google.com/k/davy-wybiral/trampolining-in-python (please
ignore the response - computer science is not a game to avoid the use
of certain abstract data types...))
Work is busy and I have some (non-programming!) vacations coming up,
so I don't expect a release until March (World of Goo on Linux is also
using some of my free time!).
This will probably version 2.0, since there are several API changes
(the basic matchers remain the same). For 2.1 I will look at
performance (ignored in this release).
Andrew