无法使用Eclipse Kepler在组合语法中导入antlr4词法分析器语法

时间:2014-03-07 14:32:06

标签: java maven antlr4 eclipse-kepler

假设:

Simple.g4

grammar Simple;

import SimpleLexer;

prog : entry+ EOF;
entry : a semi tail;
semi : ':';
tail : TAIL;
a : 'a';
W:;

SimpleLexer.g4

lexer grammar SimpleLexer;

TAIL : [a-z]+;

它们都位于'src / main / antlr4'下的同一个包中。

Maven插件:

 <plugins>
  ...
             <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>target/generated-sources/antlr4</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

     <plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>4.2</version>          
            <executions>
                <execution>
                    <goals>
                        <goal>antlr4</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>

    <pluginManagement>
        <plugins>
            <!--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.2,)</versionRange>
                                    <goals>
                                        <goal>antlr4</goal>                                         
                                    </goals>                                        
                                </pluginExecutionFilter>
                                <action>
                                    <execute>
                                        <runOnIncremental>true</runOnIncremental>
                                    </execute>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

antlr eclipse插件的版本:

ANTLR 4 SDK Feature 0.1.1.201401151138  antlr4ide.sdk.feature.group

Eclipse版本:

Version: Kepler Service Release 2
Build id: 20140224-0627

eclipse提供的Simple.g4中import语句的错误是:

 can't find or load grammar 'SimpleLexer' from 'Simple.g4'

环境适用于单个文件语法。

0 个答案:

没有答案