我是 ANTLR4 的新手,似乎没有适用于 v4 的 Eclipse-Plug-In。因此,从 .g4 语法自动构建 Java 源代码会很好。我有一个简单的空 Maven 项目,其中包含 src/main/java、src/test/java。将 .g4 文件放在哪里?如何使用 Maven 自动构建语法?
我自己的 POM 测试失败了:
<repository>
<id>mvn-public</id>
<name>MVNRepository</name>
<url>http://mvnrepository.com</url>
</repository>
...
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Eclipse 说:
Failure to find org.antlr:antlr4-maven-plugin:pom:4.0.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of
central has elapsed or updates are forced
最佳答案
我用 pom.xml
创建了以下 Gist专为支持在 Eclipse 构建期间从 ANTLR 4 语法自动生成代码而设计。它包括m2e知道代码生成是必要的必要生命周期信息,并使用build-helper-maven-plugin
显式添加代码生成文件夹。因为 Eclipse 似乎在其他情况下很难找到它。
在此配置中,语法文件 ( *.g4
) 与其他 Java 源文件放在一起。 Maven 插件会自动添加正确的 package ...
声明到生成的文件,所以你不应该包含 @header{package ...}
语法本身中的行。
https://gist.github.com/sharwell/4979017
关于eclipse - 如何使用 ANTLR4 和 Maven 自动生成词法分析器+解析器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14926060/