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


Groups > comp.lang.python > #85294 > unrolled thread

help with pypeg2?

Started byNeal Becker <ndbecker2@gmail.com>
First post2015-02-06 09:55 -0500
Last post2015-02-06 09:55 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#85294 — help with pypeg2?

FromNeal Becker <ndbecker2@gmail.com>
Date2015-02-06 09:55 -0500
Subjecthelp with pypeg2?
Message-ID<mailman.18508.1423234568.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web