[antlr-interest] StringTemplate approach applied to ANTLR?
Jose San Leandro
jose.sanleandro at ventura24.es
Fri Jan 5 04:11:15 PST 2007
Hi,
One thing that could be cleaned up in ANTLR (in my opinion), is mixing grammar
definition with custom parsing logic. I mean, in ANTLR you can write code to
execute whenever a rule, an alternative or a pattern matches the input. Such
logic can be used to direct the parser or to do anything else.
That makes the .g itself coupled with the language the custom code is and the
output of antlr.Tool.
There's no clean separation between the rules describing the grammar and the
custom parsing logic.
Also, it makes reusing grammars more difficult than it should. You start from
a grammar and modify it to suit your needs, but whenever the grammar you
started from changes you need to apply the changes to your branched grammar.
Shouldn't be better to separate the ANTLR flow into two steps?
1) You provide a .g file and the desired language the parser will be
implemented in. ANTLR would then generate the lexer and/or parser in the
target language, as it does currently.
2) From the .g file, ANTLR also generates an interface and an no-op
implementation declaring all the hooks the grammar accepts. The generated API
would support an optional parameter allowing a different implementation of
the interface.
I haven't thought too deep in this. I wouldn't like a Context object back and
forth, but the potential interests me: get a standard set of official ANTLR
grammars ready-to-use with no source-level changes.
It makes ANTLR less coupled to Java as well.
More information about the antlr-interest
mailing list