Discussion:
[Pyparsing] Bringing together ANTLR and PyParsing
Athanasios Anastasiou
2014-05-06 17:07:01 UTC
Permalink
Hello everybody

I have been using PyParsing for some time now and after i came across
ANTLR, i thought about bringing the two together. That is, specify a parser
in ANTLR's meta-language and then have that translated to a set of
PyParsing objects.

If you have not seen ANTLR before, it looks like this:

input: list+;
list: SYM_SBL atom (SYM_COMA atom)* SYM_SBR; //Tokens and rules separated
by comas effectively means concatenation.
atom:number|string; //The usual OR
number:NUM; //number is a rule, NUM is a token (Anything that starts with a
capital letter is a token else is a rule)
string:STR;

SYM_SBL:'[';
SYM_RBL:']';
SYM_COMA:',';
NUM:[0-9]+;
STR:'\'' .*? '\'';

A preliminary attempt at this transformation can be found at:
https://bitbucket.org/aanastasiou/antlr2pyparsing

The relevant discussion over at ANTLR's group is available at:
https://groups.google.com/forum/#!topic/antlr-discussion/feRPZhfMcpU

ANTLR will be generating parsers in Python soon as it seems. The relevant
discussion is available at:
https://groups.google.com/forum/#!topic/antlr-discussion/sFH5Y0QO4HA But in
any case, this transformation would be very useful to have for PyParsing
too.

I am just wondering if we could perhaps even augment ANTLR's syntax to
accommodate PyParsing features (like Group or Suppress) that ANTLR does not
know about.

What do you think?

All the best
AA
Paul McGuire
2014-05-06 17:47:32 UTC
Permalink
Athanasios Anastasiou [mailto:]
1970-01-01 00:00:00 UTC
Permalink
Did you check out the ANTLR grammar parser in the pyparsing examples? (You
have to download either the source zip or tarball.)

-- Paul


-----Original Message-----
From: Athanasios Anastasiou [mailto:***@gmail.com]
Sent: Tuesday, May 06, 2014 12:07 PM
To: pyparsing-***@lists.sourceforge.net
Subject: [Pyparsing] Bringing together ANTLR and PyParsing

Hello everybody

I have been using PyParsing for some time now and after i came across ANTLR,
i thought about bringing the two together. That is, specify a parser in
ANTLR's meta-language and then have that translated to a set of PyParsing
objects.

If you have not seen ANTLR before, it looks like this:

input: list+;
list: SYM_SBL atom (SYM_COMA atom)* SYM_SBR; //Tokens and rules separated by
comas effectively means concatenation.
atom:number|string; //The usual OR
number:NUM; //number is a rule, NUM is a token (Anything that starts with a
capital letter is a token else is a rule) string:STR;

SYM_SBL:'[';
SYM_RBL:']';
SYM_COMA:',';
NUM:[0-9]+;
STR:'\'' .*? '\'';

A preliminary attempt at this transformation can be found at:
https://bitbucket.org/aanastasiou/antlr2pyparsing

The relevant discussion over at ANTLR's group is available at:
https://groups.google.com/forum/#!topic/antlr-discussion/feRPZhfMcpU

ANTLR will be generating parsers in Python soon as it seems. The relevant
discussion is available at:
https://groups.google.com/forum/#!topic/antlr-discussion/sFH5Y0QO4HA But in
any case, this transformation would be very useful to have for PyParsing
too.

I am just wondering if we could perhaps even augment ANTLR's syntax to
accommodate PyParsing features (like Group or Suppress) that ANTLR does not
know about.

What do you think?

All the best
AA
----------------------------------------------------------------------------
--
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
• 3 signs your SCM is hindering your productivity • Requirements
for releasing software faster • Expert tips and advice for migrating
your SCM now http://p.sf.net/sfu/perforce

Loading...