[antlr-interest] antlr2, maven2 plugin and importvocab

Jim Idle jimi at temporal-wave.com
Tue Nov 25 08:11:02 PST 2008


On Tue, 2008-11-25 at 11:44 +0000, James Cowan wrote:
> Hi
>  
> I am struggling to get the antlrv2 maven plugin to find the vocabulary
> of a grammar.
>  
> If I put the grammar in src/main/antlr it finds the grammar ok but the
> importVocab command fails.
>  
> If I put the vocabulary in the base directory of the maven project, it
> will find the vocabulary.
>  
> However, if I build the project as part of a modular maven project
> (i.e it is a sub module of another module) it cannot find the
> vocabulary.
>  
> I have fiddled with sourceDirectory and the grammar localtion in the
> plugin. For example below I have tried to make the sourceDirectory the
> basedir of the submodule.
>  
> plugin>
>      <groupId>org.codehaus.mojo</groupId>
>      <artifactId>antlr-maven-plugin</artifactId>
>      <configuration>
>       <sourceDirectory>${basedir}</sourceDirectory>
>       <grammars>src/main/antlr/MySqlParser.g</grammars>
>      </configuration>
>      <executions>
>       <execution>
>        <goals>
>         <goal>generate</goal>
>        </goals>
>       </execution>
>      </executions>
> </plugin>
>  
> Anyone else found a way around this problem? I guess changing maven2's
> working directory to that of the grammar would work but it is not
> clear to me how to do this.


The v2 plugin basically expects all the grammars (at least those that
import), to be in the one directory. It is a reasonable expectation
given that v2 does not allow you to import vocab.txt files from
directories other than the current directory, but it is a bit annoying.
As you can see from the v3 source, I decided to basically collect all
the v2 grammars together in one directory and all the v3 grammars in
another. The plugin then works perfectly. 

However, your configuration is not quite right. From the antlr v3
source:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>antlr-maven-plugin</artifactId>
                <configuration>

<sourceDirectory>src/org/antlr/grammar/v2</sourceDirectory>
                    <grammars>antlr.g codegen.g, antlr.print.g,
assign.types.g, buildnfa.g, define.g</grammars>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Note the specification of the <sourceDirectory>, which contains the
whole directory path, with the .g files specified without paths.

Jim


>  
> James
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 


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


More information about the antlr-interest mailing list