[antlr-interest] antlr2, maven2 plugin and importvocab

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


On Tue, 2008-11-25 at 16:39 +0000, James Cowan wrote:

>  
> 
> Hi Jim
>  
> thanks for the reply
>  
> The only solution to the problem I can find is to have the vocabulary
> in the sub module and the parent module so that they can both compile.
>  
> Is there any way that one can change the working directory of a maven
> plugin (i.e. to src/main/antlr) while it is executing a plugin?


No - I have been through all possible attempts, but the way it all hangs
together does not lend itself to this because v2 doesn't allow you to
import from other directories. Your only practical choice is to relocate
the grammar files into the same directory. 

Practically speaking, if they are interdependent at the vocabulary
level, then they are not really parent and sub module anyway, as you
can't recompile one without recompiling the other.

There probably is some way to hack it all to death, but I don't think
that is wise.

Jim

>  
> James
> 
> 
>         ----- Original Message ----- 
>         From: Jim Idle 
>         Cc: antlr-interest at antlr.org 
>         Sent: Tuesday, November 25, 2008 4:11 PM
>         Subject: Re: [antlr-interest] antlr2, maven2 plugin and
>         importvocab
>         
>         
>         
>         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
>         > 
>         
>         
>         
>         
>         
>         ______________________________________________________________
>         
>         List:
>         http://www.antlr.org/mailman/listinfo/antlr-interest
>         Unsubscribe:
>         http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>         
>         
>         
>         
>         ______________________________________________________________
>         
>         
>         No virus found in this incoming message.
>         Checked by AVG - http://www.avg.com 
>         Version: 8.0.175 / Virus Database: 270.9.10/1810 - Release
>         Date: 24/11/2008 14:36


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


More information about the antlr-interest mailing list