Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #85294

help with pypeg2?

From Neal Becker <ndbecker2@gmail.com>
Subject help with pypeg2?
Date 2015-02-06 09:55 -0500
Newsgroups comp.lang.python
Message-ID <mailman.18508.1423234568.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

help with pypeg2? Neal Becker <ndbecker2@gmail.com> - 2015-02-06 09:55 -0500

csiph-web