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


Groups > comp.lang.python > #73271

parsley parsing question, how to make a variable grammar

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <esj@harvee.org>
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; '"""': 0.07; 'element': 0.07; 'elements.': 0.07; 'failing': 0.07; 'append': 0.09; 'interpreted': 0.09; 'parsers': 0.09; 'statements': 0.09; 'subject:parsing': 0.09; 'subject:question': 0.10; 'python': 0.11; "':'": 0.16; 'aggregates': 0.16; 'notation,': 0.16; 'parentheses': 0.16; 'postfix.': 0.16; 'prefix,': 0.16; 'quest': 0.16; 'r"""': 0.16; 'splitting': 0.16; 'statements,': 0.16; 'subject:make': 0.16; 'subject:variable': 0.16; 'track.': 0.16; 'elements': 0.16; 'extensions': 0.16; 'trying': 0.19; 'pieces': 0.19; 'seems': 0.21; 'to:name:python-list@python.org': 0.22; 'header:User-Agent:1': 0.23; 'accommodate': 0.24; 'section.': 0.24; '---': 0.24; "i've": 0.25; 'second': 0.26; 'expansion': 0.30; 'statement': 0.30; 'especially': 0.30; "i'm": 0.30; 'included': 0.31; 'figure': 0.32; 'skip:d 20': 0.34; 'could': 0.34; 'problem': 0.35; 'tool': 0.35; 'done,': 0.36; 'received:10.43': 0.36; 'possible': 0.36; 'should': 0.36; 'too': 0.37; 'list': 0.37; 'received:10': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'expression': 0.60; 'simple': 0.61; 'first': 0.61; 'making': 0.63; 'developed': 0.63; 'more': 0.64; 'great': 0.65; 'between': 0.67; 'insight': 0.68; 'friendly': 0.72; "'returns'": 0.84; 'bot': 0.84; 'extensions.': 0.84; 'speech': 0.84
X-Virus-Scanned amavisd-new at harvee.org
Date Fri, 13 Jun 2014 17:05:32 -0400
From "Eric S. Johansson" <esj@harvee.org>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
MIME-Version 1.0
To "python-list@python.org" <python-list@python.org>
Subject parsley parsing question, how to make a variable grammar
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11060.1402695110.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402695110 news.xs4all.nl 2892 [2001:888:2000:d::a6]:50008
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73271

Show key headers only | View raw


In my quest for making speech friendly applications, I've developed a 
very simple domain specific language/notation that works well. I'm using 
parsley which is a great tool for writing parsers especially simple ones 
like the one I need. However, I've come across a problem that I don't 
know how to solve.

Below is my grammar. The problem is the last element which aggregates 
all individual grammar elements. In my domain specific notation, it's 
possible for a user to create extensions and I'm trying to figure out 
how to make the grammar accommodate those extensions.

The first Issue is adding more statements. I can handle that easy enough 
by splitting the existing grammar into a prefix, statements, and 
postfix. I could append more statements to the end of the statement 
section. When I'm done, I can then join all of the pieces together into 
a single grammar.

The second issue is adding more elements between parentheses of bot so 
the additional statements can be included in the grammar. Seems to me, I 
should be able to create a Python expression which returns the OR list 
and it is interpreted as part of the grammar. Failing that, I'm just 
going to do a %s expansion when I create the grammar.

I appreciate any insight before I go too far off track.
--- eric

TF_grammar = r"""
kwToken = (letter|digit|'_')+
uses_statement = 'uses' ws kwToken:kwT ':' <anything*>:roL -> do_uses 
("".join(kwT), "".join(roL))
returns_statement = 'returns' ws kwToken:kwT -> do_returns("".join(kwT))
template_statement = 'template' ws kwToken:kwT -> do_template("".join(kwT))
remembers_statement = 'remembers' ws kwToken:kwT -> 
do_remembers("".join(kwT))
everything_else = <anything*>:roL '\n'{0,1} -> do_everything_else 
("".join(roL))
bot = (uses_statement | returns_statement | template_statement | 
everything_else)
"""

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


Thread

parsley parsing question, how to make a variable grammar "Eric S. Johansson" <esj@harvee.org> - 2014-06-13 17:05 -0400

csiph-web