[antlr-interest] antlr based data parser frameworks

Vladimir Olenin volenin at gmail.com
Tue Feb 14 04:52:23 PST 2006


Hi,

I wonder if there are any antlr powered data parser frameworks which
would facilitate most common tasks of parsing arbitrary flat data files
(eg, delimited lists, etc). The key here is SIMPLE, meaning there is a
way to setup parsing 'parameters' through simple config file, eg XML.
The Lexer&Parser would also be generic enough to allow reasonably
flexible behavior for these use cases (data files with no looping, etc).

Just to illustrate the idea, here what config file might look like:
...
  <data file="xxx" listener="com.myproject.CSVParserListener">
    <delim>;,/t</delim>
    <field name="alias" order="1" />
    <field name="name"  order="2" />
    <field name="email" order="3" />
  </data>
...
with sample input file

JACK, JACK LAYTON, jack at canada.com
PAUL, Paul Martin, paul at canada.com

The intermediate step would be to generate Lexer&Parser from a template
on the fly, transforming XML definitions (above) into Lexer tokens and
Parser rules, compiling them and parsing the defined input file. The
also should be some way to hook up an event listener which would listen
for the tokens/data structures spit out by the parser.

I realize it might be a bit of a long shot, but I don't see any major
technical obstacles which might prevent such or similar framework. (The
example above is quite primitive. It should also be possible to describe
more complex _structured_ data through xml, similar to the way arbitrary
XML file structure can be described through DTD or XSD)

I've seen ANTLR provides an example of 'simple parser' (CSV list). I've
also ran into a commercial ANTLR powered CSV parser. But there seems to
be no framework like the one I've tried to describe above.


PS: I realize there is not enough information here to even sketch the
draft of the framework, so if there is no such framework yet and there
is interest in discussing the idea, I can put together something more
coherent.




More information about the antlr-interest mailing list