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


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

Re: help with pypeg2?

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

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: help with pypeg2? Neal Becker <ndbecker2@gmail.com> - 2015-02-06 13:26 -0500

#85299 — Re: help with pypeg2?

FromNeal Becker <ndbecker2@gmail.com>
Date2015-02-06 13:26 -0500
SubjectRe: help with pypeg2?
Message-ID<mailman.18512.1423247212.18130.python-list@python.org>
Ian Kelly wrote:

> On Fri, Feb 6, 2015 at 7:55 AM, Neal Becker <ndbecker2@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).

It didn't work without [list..] (even trivial examples did not work without it).
I don't know if it's broken, I though csl (*args) should mean a comma-sep-list 
of _any_ of the *args, but it doesn't work.  [list] means alternatives, and does 
seem to work (for simple examples).

-- 
-- Those who don't understand recursion are doomed to repeat it

[toc] | [standalone]


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


csiph-web