Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(even': 0.05; 'args': 0.07; 'subject:help': 0.08; '*args,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '__future__': 0.16; 'alphanum': 0.16; 'args.': 0.16; 'expecting': 0.16; 'optional': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'syntaxerror:': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'examples': 0.20; 'feb': 0.22; 'import': 0.22; 'tests': 0.22; 'header:User-Agent:1': 0.23; 'looks': 0.24; '(for': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; "i'm": 0.30; 'work.': 0.31; 'fine,': 0.31; 'produces': 0.31; 'trivial': 0.31; 'class': 0.32; 'fri,': 0.33; 'subject:with': 0.35; 'but': 0.35; "didn't": 0.36; 'subject:?': 0.36; 'should': 0.36; 'list': 0.37; 'lists.': 0.38; 'to:addr :python-list': 0.38; 'list,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'ian': 0.60; 'simple': 0.61; 'more': 0.64; 'repeat': 0.74; '2015': 0.84; 'received:139': 0.84; 'recursive.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Neal Becker Subject: Re: help with pypeg2? Date: Fri, 06 Feb 2015 13:26:44 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: exa2-in-fw-01-epn.hns.com User-Agent: KNode/4.14.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423247212 news.xs4all.nl 2859 [2001:888:2000:d::a6]:43453 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85299 Ian Kelly wrote: > On Fri, Feb 6, 2015 at 7:55 AM, Neal Becker 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