parsley parsing question, how to make a variable grammar

E

Eric S. Johansson

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)
"""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,836
Messages
2,569,747
Members
45,545
Latest member
rapter____0

Latest Threads

Top