[antlr-interest] How to come up with catch-all rules?
Geoffrey Zhu
gzhu at peak6.com
Fri Nov 17 13:49:47 PST 2006
Thanks for the quick reply, Dave.
This is pretty good but still makes assumptions on the structure of the
hand-written code. For example, the number of { and } within the outmost
{ and } need to match. It also makes assumptions on the syntax of
string, comments, and char literals. If I use perl style comments in the
hand-written code and write:
# This will break ANTLR {{{
It will cause syntax errors in ANTLR.
Is there any even more general ways?
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of David Holroyd
Sent: Friday, November 17, 2006 2:03 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] How to come up with catch-all rules?
On Fri, Nov 17, 2006 at 01:27:02PM -0600, Geoffrey Zhu wrote:
> Hi All,
>
> I am writing a code generator with ANTLR 2.x. Like ANTLR itself, the
> program is going to generate a framework and fill in handwritten code
> in the right places. For example, in the following code:
>
> handler abc_name (x, y, z)
> {
> //hand-written code here
> }
>
> I'd like my code generator to dump the handwritten code between the {
> and } to an output file, without the code generator caring about the
> syntax of those code. But I cannot seem to be able to come up with a
> rule that can match arbitrary text between { and }. One thing I can
> come up with is { #include "file_name"} and have my code in a separate
> file, but this is extremely awkward.
>
> Does anyone know how to best solve this problem?
This 'parrt' guy does:
http://fisheye2.cenqua.com/browse/antlr/src/org/antlr/tool/antlr.g?r=324
4#l1186
;)
dave
--
http://david.holroyd.me.uk/
More information about the antlr-interest
mailing list