eclipse - 如何使用 ANTLR4 和 Maven 自动生成词法分析器+解析器?

标签 eclipse maven antlr4

我是 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/

相关文章:

java - 尝试使用 JAVA 自定义注释构建 Maven 项目(其中定义了 ENUM 变量)时出现编译错误

java - org.osgi.framework.BundleException : Unable to resolve: missing requirement: osgi. wiring.package; (osgi.wiring.package=org.json)

regex - ANTLR4 RegEx 词法分析器模式

java - 如何忽略 ANTLR4 中的某些文本?

java - 如何正确使用另一个类的方法? (基本计算器)(Java)

c++ - Eclipse CDT 中的项目依赖关系

maven - java.lang.ClassNotFoundException : javax. 企业.event.Event

eclipse - 将 JUnit 与 App Engine 和 Eclipse 结合使用

java - 为什么在 eclipse 中出现 NoClassDefFound 错误是可以接受的?解决办法是什么?

parsing - ANTLR4 中上下文相关的空白处理