首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用ANTLR4 IDE外接程序的Eclipse使用ANTLR 4.4自动构建

使用ANTLR4 IDE外接程序的Eclipse使用ANTLR 4.4自动构建
EN

Stack Overflow用户
提问于 2022-10-22 18:31:09
回答 2查看 39关注 0票数 1

我正在尝试使用Eclipse和Maven开发一个ANTLR 4.9.2项目。我已经将我的pom.xml配置为使用运行时和构建工具的正确版本:

代码语言:javascript
运行
复制
<properties>
    <maven.compiler.target>18</maven.compiler.target>
    <maven.compiler.source>18</maven.compiler.source>
    <antlr4.plugin.version>4.9.2</antlr4.plugin.version>
    <antlr4.version>4.9.2</antlr4.version>
</properties>

<dependencies>
    <!-- ANTLR 4 parser runtime -->
    <dependency>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-runtime</artifactId>
        <version>${antlr4.version}</version>
    </dependency>

    <!-- ANTLR 4 parser generator tools -->
    <dependency>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <version>${antlr4.plugin.version}</version>
    </dependency>
    <!-- other irrelevant dependencies redacted -->
</dependencies>
<build>
    <plugins>
        <!-- build antlr4 grammars -->
        <plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>${antlr4.plugin.version}</version>
            <configuration>
                <arguments>
                    <argument>-visitor</argument>
                    <!-- <argument>-Dlanguage=JavaScript</argument> -->
                </arguments>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>antlr4</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <!-- ensure antlr4 generated source is added to the build path -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated-sources/antlr4/</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我还安装了ANTLR4IDE eclipse外接程序(在安装细节屏幕中报告为ANTLR 4 SDK 0.3.6.201611052310 antlr4ide.sdk.feature.group Edgar Espina ),以便在编辑.g4文件时提供语法突出显示。

我遇到的问题是,每次修改文件时,都会出现在控制台窗口中:

代码语言:javascript
运行
复制
ANTLR Tool v4.4 (C:\Users\user\AppData\Local\Temp\antlr-4.4-complete.jar)
KindModule.g4 -o C:\Users\user\git\kindtest3\target\generated-sources\antlr4\org\kindlang\kindtest3\grammar -listener -no-visitor -package org.kindlang.kindtest3.grammar -encoding UTF-8

BUILD SUCCESSFUL
Total time: 4 second(s)

运行项目测试时,错误消息ANTLR Tool version 4.4 used for code generation does not match the current runtime version 4.9.2失败。

我试图在“properties / ANTLR4 / Tool”下禁用"Tool is activated“设置,但这似乎只会在当前会话中禁用它。当我重新启动Eclipse时,它又开始发生了。

(更新--实际上,属性对话框中似乎有一个bug :当我单击"apply & close“时,标题为"Error”的消息框将被简要显示,但在读取其内容之前消失)

如何永久防止使用错误版本的ANTLR的自动生成运行?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-10-22 21:19:11

通过直接编辑项目根目录下的com.github.jknack.antlr4ide.Antlr4.prefs目录中的.settings文件并将autobuilding=true行更改为autobuilding=false,我已经能够解决这个问题。

票数 0
EN

Stack Overflow用户

发布于 2022-10-22 20:13:50

不幸的是,我不能说一些关于Eclipse的事情。

我建议以正确的方式使用antlr4 4 maven-plugin,如下所示:

代码语言:javascript
运行
复制
  <build>
    <plugins>
      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>antlr4</goal>
            </goals>
            <configuration>
              <visitor>true</visitor>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

此外,使用build-helper-maven-plugin的配置非常简单,因为antlr4-maven-plugin正确地添加了要编译的信息。这意味着删除build-helper-maven-plugin的整个配置和定义,因为根本不需要它。

另外,我建议升级到最新版本的antlr4-maven-plugin /运行时,目前的版本是4.11.1 .

我会在普通命令行上检查编译等。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74166147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档