2009年5月19日火曜日

antlr3-maven-plugin

ANTLRWorksが便利なんだけど、grammarファイルが大きいのか、ソースのジェネレートがうまく動作してくれない。

error(10): internal error: org.antlr.tool.Grammar.createLookaheadDFA(Grammar.java:1242): could not even do k=1 for decision XXX; reason timed out(>1000ms)

上記のようなメッセージがいくつか出て、cpuをひとつ使い切ったまま処理が返ってこなくなってしまい、強制終了するしかなくなる(少なくとも分単位では落ち着いてくれない)。$ java -cp antlr-3.1.3.jar ...とやってもいいんだけど、せっかくだからmavenでできないか?と思ったら、mavenのプラグインも提供されていた。知らなかった。

antlr3-maven-plugin

<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.1.3-1</version>
<executions>
<execution>
<configuration>
<goals>
<goal>antlr</goal>
</goals>
<conversionTimeout>10000</conversionTimeout>
<debug>true</debug>
<dfa>false</dfa>
<nfa>false</nfa>
<libDirectory>src/main/antlr3/imports</libDirectory>
<messageFormat>antlr</messageFormat>
<outputDirectory>target/generated-sources/antlr3</outputDirectory>
<printGrammar>true</printGrammar>
<profile>false</profile>
<report>true</report>
<sourceDirectory>src/main/antlr3</sourceDirectory>
<trace>false</trace>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
view raw gistfile1.xsl hosted with ❤ by GitHub

grammarファイルは"src/main/antlr3"配下に配置するのがお約束のようだ。ただし、src/main/antlr3直下に置くとマズイようで、適当なフォルダ(Lexer,Parserが出力されるべきパッケージ構成を作成する)に配置するのが良いみたい。

Mavenでは問題無くソースがジェネレートできているので、ANTLRWorksは編集用にしか使っていないカンジ。

0 件のコメント: