help with pypeg2?

Ian Kelly ian.g.kelly at gmail.com
Fri Feb 6 11:40:10 EST 2015


On Fri, Feb 6, 2015 at 7:55 AM, Neal Becker <ndbecker2 at gmail.com> wrote:
> Trying out pypeg2.  The below grammar is recursive.  A 'Gen' is an ident
> followed by parenthesized args.  args is a csl of alphanum or Gen.
>
> The tests 'p' and 'p2' are fine, but 'p3' fails
> SyntaxError: expecting u')'
>
>
> from __future__ import unicode_literals, print_function
> from pypeg2 import *
>
> ident = re.compile (r'[a-z]+')
> alphanum = re.compile (r'[a-z0-9]+')
> num = re.compile (r'[0-9]+')
>
> class args (List):
>     grammar = maybe_some ( csl ([alphanum, Gen]))

I'm not familiar with pypeg2, but should this use optional instead of
maybe_some? The csl function already produces a list, so the result of
maybe_some on that would be one or more consecutive lists.

Also, it looks from the docs like it should just be "csi(alphanum,
Gen)" (no list in the arguments).



More information about the Python-list mailing list