【发布时间】:2014-12-22 21:11:53
【问题描述】:
我在 Eclipse 中使用 antlr-4.4-complete.jar 在 v4 语法中嵌入动作时遇到问题。
当使用 4.4 jar 从 ant 生成识别器时,生成器会发出消息“unknown attribute 'text' for rule ...”
动作可以像{System.out.println($rule.text);}一样简单
如果我使用 antlr-4.0-complete.jar,我的 ant 构建工作正常。
当我发现这条评论最近发布到 Antlr 4 book errata:
#77534: When I run antlr4 on Simple.g4 I get the error message:
error(65): Simple.g4:18:52: unknown attribute text for rule stat in $stat.text
error(65): Simple.g4:20:54: unknown attribute text for rule stat in $stat.text
寻找一种方法来验证问题并改进工作流程,我想我会尝试使用 maven。
如果antlr4-maven-plugin版本设置为4.3,下面的片段会报告“unknown attribute 'text'”消息如果antlr4-maven-plugin版本设置为4.2,它将成功构建代码。
另一个问题:
.tokens 不是在目标包目录中生成的,而是在 generate-sources/antlr4 目录中创建的,但是插件文档指出(在 using library 目录下):
任何语法的 .tokens 文件都在与 .java 文件相同的输出目录结构中生成。
和
插件将...在输出目录 target/generated-sources/antlr4/org/foo/bar 中生成 .java 和 .tokens 文件。
我是否缺少配置参数?
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>6</source>
<target>6</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArguments>
<Xlint />
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.2</version>
<configuration>
<sourceDirectory>src/antlr4</sourceDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.3</version>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<versionRange>[4.0,)</versionRange>
<goals>
<goal>antlr4</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<versionRange>[1.7,)</versionRange>
<goals>
<goal>add-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
【问题讨论】:
标签: eclipse maven-plugin antlr4