Hi,
[Sorry seems this was waiting a few days in the Google groups spam filter]
Lepl is a recursive descent parser (like pyparsing, I think) and, as such, has
a well defined ordering when parsing grammar. So it will resolve ambiguities
according to the order implicit in the way the matchers are defined. The only
errors it will flag are left recursion and, by default, the failure to match
the entire input.
You ask how Lepl can be made to reject the grammar. It cannot.
However, you can, with care, define the grammar so that the ordering resolves
ambiguities in the way you feel most appropriate. For example,
Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lepl import *
>>> def build():
... stmt = Delayed()
... with DroppedSpace():
... expr = Literal('EXPR')
... end = Literal ('endif')
... cond = stmt | end
... stmt += ('if' & expr & 'then' & cond & Optional('else' & cond) > list)
... line = Trace(stmt) & Eos()
... return line.get_parse()
...
>>> parser = build()
>>> print parser('if EXPR then if EXPR then endif else endif')
[['if', 'EXPR', 'then', ['if', 'EXPR', 'then', 'endif', 'else', 'endif']]]
where the nesting shows how the ambiguity was resolved.
Andrew
> --
> You received this message because you are subscribed to the Google Groups "lepl" group.
> To post to this group, send email to
le...@googlegroups.com.
> To unsubscribe from this group, send email to
lepl+uns...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/lepl?hl=en.
>