[antlr-interest] ANTLR error in Ant for multiple super grammars

Christian Bering cb at acrolinx.com
Wed Feb 1 07:36:22 PST 2006


Hi everybody,

 

we are experiencing a strange problem when calling ANTLR from Ant for a
grammar which has two super grammars. The scenario is as follows: We
have three grammars Grammar1, 2, 3, where Grammar1 and Grammar2 reside
at path1, and Grammar3 resides at path2. Grammar2 inherits from
Grammar1, and Grammar3 inherits from both Grammar1 and Grammar2. The
following code snippet should IMHO (and AFAIK according to
<http://ant.apache.org/manual/OptionalTasks/antlr.html>) render this
situation:

 

-- 8< ---

            <target name="antlr" description="Compiles the ANTLR grammar
files">

                        <antlr target="path1/Grammar1.g">

                                   <classpath>

                                               <pathelement
location="${utils.root.dir}/lib/antlr.jar"/>

                                               <pathelement
path="${classpath}"/>                                          

                                   </classpath>

                        </antlr>

                        <antlr target="path1/Grammar2.g"

                                   glib="path1/Grammar1.g">

                                   <classpath>

                                               <pathelement
location="${utils.root.dir}/lib/antlr.jar"/>

                                               <pathelement
path="${classpath}"/>                                          

                                   </classpath>

                        </antlr>

                        <antlr target="path2/Grammar3.g"

 
glib="path1/Grammar1.g;path1/Grammar2.g">

                                   <classpath>

                                               <pathelement
location="${utils.root.dir}/lib/antlr.jar"/>

                <pathelement path="${classpath}"/>

                                   </classpath>

                        </antlr>

            </target>

-- 8< ---

 

Of the three <antlr target ...> blocks, the first two (for Grammar1 and
2) work fine, but for the third one we get an ANTLR error in ant:

 

C:\buildTemp\[...]\build.xml:97: ANTLR signaled an error: ANTLR Parser
Generator   Version 2.7.5 (20050128)   1989-2005 jGuru.com

error: file Grammar2.g not found

 

When we switch the order of Grammar1.g and Grammar2.g in the glib-line
(i.e., make it glib="path1/Grammar2.g;path1/Grammar1.g"), we get the
same error, but for "Grammar1.g", i.e., it always reports the second one
as being missing. I had found (but unfortunately do not re-find) a bug
discussion from the ant context in which it was discussed that glib list
arguments would not be checked in any way by ant, but passed directly to
ANTLR (which is apparently what happens here, since the error is an
ANTLR error). The file reported missing is present in the build
directory (the strange thing is that, if ANTLR doesn't check the
argument list backwards, it apparently finds Grammar1.g in the same
directory). A workaround which works (since Grammar2.g inherits from
Grammar1.g anyway) is to make Grammar3.g inherit from the expanded
version of Grammar2.g, i.e., use glib="path1/expandedGrammar2.g".
However, since this relies on what one might want to treat as internal
ANTLR expansion processes, we regard this somewhat as a hack.

 

Has anybody experienced anything similar and/or found a solution? Any
help or hint is greatly appreciated.

 

Cheers

Christian Bering

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060201/c537533f/attachment.html


More information about the antlr-interest mailing list