[antlr-interest] Lexer.java output in wrong directory

Jared Bunting jared.bunting at peachjean.com
Sun Sep 13 11:35:42 PDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It's been awhile since I messed with this, and I don't remember the
exact sytnax, but I believe that the "@header" section in X.g only
applies to the parser.  This means that the Lexer is created in the
default package.  Adding something like:

@lexer::header {
  package x;
}

to X.g might get you closer to your solution...

You might also consider putting L in the same package - I always seemed
to have more luck that way.

Hilco Wijbenga wrote:
> Hi all,
> 
> (I couldn't find an issue tracker so I'm just sending this problem to
> the mailing list. I'm not sure whether it is an ANTLR issue or an
> antlr3-maven-plugin issue.)
> 
> I have the setup below. If I run it I get the following result:
> 
> hilco at centaur ~/workspaces/default/JavaParser $ mvn clean compile ; tree
> [INFO] Scanning for projects...
> [INFO] ------------------------------------------------------------------------
> [INFO] Building Unnamed - org.example:x:jar:0.0.1-SNAPSHOT
> [INFO]    task-segment: [clean, compile]
> [INFO] ------------------------------------------------------------------------
> [INFO] [clean:clean]
> [INFO] Deleting directory /home/hilco/workspaces/default/JavaParser/target
> [INFO] [antlr3:antlr {execution: default}]
> [INFO] ANTLR: Processing source directory
> /home/hilco/workspaces/default/JavaParser/src/main/antlr3
> ANTLR Parser Generator  Version 3.1.3 Mar 17, 2009 19:23:44
> x/X.g
> [INFO] [resources:resources]
> [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
> resources, i.e. build is platform dependent!
> [INFO] skip non existing resourceDirectory
> /home/hilco/workspaces/default/JavaParser/src/main/resources
> [INFO] [compiler:compile]
> [INFO] Compiling 3 source files to
> /home/hilco/workspaces/default/JavaParser/target/classes
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD SUCCESSFUL
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 5 seconds
> [INFO] Finished at: Sat Sep 12 23:30:56 PDT 2009
> [INFO] Final Memory: 13M/126M
> [INFO] ------------------------------------------------------------------------
> .
> |-- pom.xml
> |-- src
> |   `-- main
> |       `-- antlr3
> |           |-- imports
> |           |   `-- L.g
> |           `-- x
> |               `-- X.g
> `-- target
>     |-- classes
>     |   |-- XLexer.class
>     |   |-- X_L.class
>     |   `-- x
>     |       `-- XParser.class
>     `-- generated-sources
>         `-- antlr3
>             |-- L.tokens
>             |-- X.tokens
>             |-- home
>             |   `-- hilco
>             |       `-- workspaces
>             |           `-- default
>             |               `-- JavaParser
>             |                   `-- src
>             |                       `-- main
>             |                           `-- antlr3
>             |                               `-- XLexer.java
>             `-- x
>                 |-- XParser.java
>                 `-- X_L.java
> 
> Note the strange location of XLexer.java. If I comment out "import L;"
> and uncomment "LETTER : 'X' ;" everything works as expected and
> XLexer.java ends up next to XParser.java.
> 
> How do I get "import" to work properly?
> 
> Cheers,
> Hilco
> 
> .
> |-- pom.xml
> `-- src
>     `-- main
>         `-- antlr3
>             |-- imports
>             |   `-- L.g
>             `-- x
>                 `-- X.g
> 
> X.g:
> grammar X;
> import L;
> @header {
> package x;
> }
> //LETTER : 'X' ;
> x : 'x' LETTER ;
> 
> L.g:
> lexer grammar L;
> LETTER : 'X' ;
> 
> pom.xml:
> <project
>   xmlns="http://maven.apache.org/POM/4.0.0"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd"
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>org.example</groupId>
>   <artifactId>x</artifactId>
>   <version>0.0.1-SNAPSHOT</version>
>   <dependencies>
>     <dependency>
>       <groupId>org.antlr</groupId>
>       <artifactId>antlr-runtime</artifactId>
>       <version>3.1.3</version>
>     </dependency>
>   </dependencies>
>   <build>
>     <plugins>
>       <plugin>
>         <groupId>org.antlr</groupId>
>         <artifactId>antlr3-maven-plugin</artifactId>
>         <version>3.1.3-1</version>
>         <executions>
>           <execution>
>             <goals>
>               <goal>antlr</goal>
>             </goals>
>           </execution>
>         </executions>
>       </plugin>
>     </plugins>
>   </build>
> </project>
> 
> My environment:
> Apache Maven 2.1.0 (r755702; 2009-03-18 12:10:27-0700)
> Java version: 1.5.0_19
> Java home: /opt/sun-jdk-1.5.0.19/jre
> Default locale: en_CA, platform encoding: UTF-8
> OS name: "linux" version: "2.6.30-gentoo-r6" arch: "i386" Family: "unix"
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkqtO3oACgkQIEGZQEcPs5gjjgCff8qqItjD41I7sUmWHk/lp1kf
zS4AnilbzDcNSrW6iC02ckQ1B7C4gkpq
=GIiy
-----END PGP SIGNATURE-----


More information about the antlr-interest mailing list