14

私は ANTLR4 が初めてで、v4 用の Eclipse プラグインがないようです。したがって、.g4 文法から Java ソースを自動的に構築するとよいでしょう。src/main/java、src/test/java を使用した単純な空の Maven プロジェクトがあります。.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>

エクリプス 言います:

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
4

2 に答える 2

17

私は、Eclipse ビルド中に ANTLR 4 文法からの自動コード生成をサポートするためだけpom.xmlに設計された以下の Gist を作成しました。これには、m2e がコード生成が必要であることを知るために必要なライフサイクル情報が含まれており、Eclipse が別の方法で見つけるのに問題があるように見えたため、 を使用してコード生成フォルダーを明示的に追加します。build-helper-maven-plugin

この構成では、文法ファイル ( *.g4) が他の Java ソース ファイルと一緒に配置されます。Maven プラグインは、生成されたファイルに適切なステートメントを自動的に追加するため、文法自体に行をpackage ...含めないでください。@header{package ...}

https://gist.github.com/sharwell/4979017

于 2013-02-18T17:31:07.377 に答える
1

Eclipse用のこのAntlr4プラグインをチェックしてください

https://github.com/jknack/antlr4ide

于 2014-01-13T19:29:06.557 に答える