On 11/12/2011 04:41 PM, andrew cooke wrote:
> > > you need to use [...] to join together the fragments, but you > >
> only want to joint together the text, not the comments, so need > > >
to break things open a little. > > > > > > instead of nested_comment =
Delayed() contents = (nested_comment > > > | ~Lookahead(both) &
Any())[:] comment = start & contents & end > > > > Comment
nested_comment += comment > > > > > > try something more like:
nested_comment = Delayed() word = > > > (~Lookahead(both) &
Any())[:,...] contents = (nested_comment | > > > word)[:] comment =
start & contents & end > Comment > > > nested_comment += comment > > > >
> > (i haven't tried it out, but that shoulf give you the right > > >
idea). > > > > This is what I tried initially but the parser then
becomes very > > inefficient... to the point where I kill it before it's
done > > parsing a file. >
> is it slow parsing the tiny test case, or slow parsing some larger >
file? if the latter, can you show me the file that it is having >
problems with? > > more generally, it could be that it contains an error
(in which case > lepl is backtracking like crazy because it is stuck) or
some problem > with the grammar that i can't see, but which might be
fixed by > appropriate use of First().
Well, it had problems with all test files,
Here is a simplified version of a parser that uses lookahead but shows
the same problem.
#! /usr/bin/env python
from lepl import *
start = Literal('(*')
end = Literal('*)')
# collect (as many as possible) symbols other than '(*' or '*)'
word = (~Lookahead(start|end) & Any()) #[:,...]
parser = (start|end|word)[:].get_parse()
If you uncomment the #[:,...] bit, the parser hangs with 100% cpu.
I'm probably doing something stupid here, but I don't see what...