Ah OK :o)
> Enabled level=DEBUG. Now I am getting
>
> DEBUG:lepl.context.Global:Getting operators/<class
> 'lepl.operators.DefaultNamespace'>
> INFO:lepl.lexer.rewriters.lexer_rewriter:Lexer rewriter used, but no
> tokens found.
These can be ignored.
> WARNING:lepl.memo.PerCallCache:A view completed before the cache was
> complete: Or(Line(u'sys.func()')[0:]). This typically means that the
> grammar contains a matcher that does not consume input within a loop
> and is usually an error.
>
> It looks like an infinite loop. I guess I screwed up my grammar with
> cross references, right?
Oh, that's a nasty one. Yes, the most likely explanation is that your
grammar is wrong. For example, something like this might trigger that
error:
a = Delayed()
b = a | Word()
a += b | Integer()
Because trying to match a will try to match b, which will try to match
a, all without consuming any input.
Looking at the error in more detail I would be suspicious of the [0:]
you have there. If that's inside a loop then you will get the kind of
problem I describe because each time it is called it will first try to
match zero instances (ie match nothing). You might need to change it
to [1:] and then make the whole loop optional (for example).
So, expanding on that, this will fail:
a = Delayed()
a += Foo()[0:] & a
b = a & ....
Because it will match zero Foo's and then call a, which will match
zero Foo's and call a which... You could avoid that with, for exaple:
a = Delayed()
a += Foo()[1:] & a
b = Optional(a)
where the Optional() handles the case of matching nothing, making the
loop always consume something.
It's also possible that there's a bug in the code, but to be convinced
of that I'd need to see a grammar that's compact, easily
understandable, and still fails.
So I'd suggest trying to isolate the few rules in your grammar that
are causing a problem, and simplifying them. You will hopefully find
the loop as above or end up with code that obviously should work, in
which case I'll (try to) fix the bug...
Good luck,
Andrew
PS Similar topics are covered in the tutorial - see
http://www.acooke.org/lepl/intro-4.html#ambiguity-and-left-recursion
PPS It seems to me I should be able to handle this automatically and
simply "break the loop". I will look at that sometime in the future,
but it won;t be for some time.
So if you have
a = Delayed()
b = Delayed()
c = Delayed()
...
blah
c += ....
blah
a += ...
blah
b += ...
You cannot (currently) use c or a as the source of your parser,
because "b" was "tied up" after them.
I can see how to fix this (I need to sort the graph rather than make
assumptions about it), but the fix is non-trivial, so it really won't
be until this weekend earliest.
Sorry,
Andrew
2009/9/1 andrew cooke <acook...@gmail.com>:
So Nick if you want to grab this from mercurial, it should fix the
issue with "None".
I am continuing to work on this (I will add a separate rewriter that
removes Delayed instances from a graph) and then release a new version
of LEPL - hopefully this weekend, but it could be later in the month.
I wouldn't suggest people use the subversion code unless they need to
fix this same issue as it's not well-tested and also contains other
changes related to (incomplete) offside rule parsing.
Cheers,
Andrew
A fix should be possible, but I can't give a good estimate as it's
taken me "all weekend" (ie the time I had free) just to work out what
the problem was... this was one really obscure bug :o(
Andrew