I am trying to create a parser using antlr3 and I have problems using java classes from the same project.
I have built a second project, added the maven dependency and the import in the header and lexer:::header of my grammar and everything works OK.
But I want to be able to have everything in one project.
Do I have to include something in my .pom or my grammar headers to get that to work? I tried putting the import in the headers but that did not work. Any ideas?
Currently I have these in my pom:
<dependencies><dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
<version>3.3</version>
<type>jar</type>
<scope>compile</scope>
</dependency></dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>run antlr</id>
<phase>generate-sources</phase>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources/antlr3</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I also include the first line of my grammar. The lines in comments are the ones that I use when I get it to work with a second project containing my custom classes:
grammar GCQLParser;
@header {
package gr.uoa.di.madgik.search.parser.gcqlparser;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import gr.uoa.di.madgik.search.parser.gcqlparser.tree.*;
//import search.library.util.cql.query.tree.*;
}
@lexer::header {
package gr.uoa.di.madgik.search.parser.gcqlparser;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import gr.uoa.di.madgik.search.parser.gcqlparser.tree.*;
//import search.library.util.cql.query.tree.*;
}
And here is a rule that uses custom classes:
booleanOp returns[GCQLBooleanNode node]
: AND { $node = new GCQLAndNode(); }
| OR { $node = new GCQLOrNode(); }
| NOT { $node = new GCQLNotNode(); }
| PROX { $node = new GCQLProxNode(); }
;
mvn compile
? – Absurd-Mind