help with pypeg2?
Neal Becker
ndbecker2 at gmail.com
Fri Feb 6 09:55:53 EST 2015
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]))
class Gen (List):
grammar = attr ('type', ident), '(', attr ('args', args), ')'
p = parse ('abc,123', args)
p2 = parse ('abc(123,456)', Gen)
p3 = parse ('abc(123,def(456))', Gen)
--
-- Those who don't understand recursion are doomed to repeat it
More information about the Python-list
mailing list