fracpete / jcamp-dx

Reference implemention of the IUPAC JCAMP-DX spectroscopy data standard. Fork of https://sourceforge.net/projects/jcamp-dx/
Other
7 stars 7 forks source link

nondeterminism warning in grammar, maven plugin does not compile #10

Open laeubi opened 5 years ago

laeubi commented 5 years ago

Running mvn antlr:generate produce the following output:

[INFO] ------------------------------------------------------------------------
[INFO] Building jcamp-dx 
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- antlr-maven-plugin:2.2:generate (default-cli) @ jcamp-dx ---
[INFO] performing grammar generation [ASDFLexer.g]
ANTLR Parser Generator   Version 2.7.2   1989-2003 jGuru.com
src/main/antlr/ASDFLexer.g: warning:lexical nondeterminism between rules XCHECK and PAC upon
src/main/antlr/ASDFLexer.g:     k==1:'+','-','0'..'9'
src/main/antlr/ASDFLexer.g:     k==2:<end-of-token>,'0'..'9'
src/main/antlr/ASDFLexer.g:39: warning:lexical nondeterminism upon
src/main/antlr/ASDFLexer.g:39:     k==1:'0'..'9'
src/main/antlr/ASDFLexer.g:39:     k==2:'0'..'9'
src/main/antlr/ASDFLexer.g:39:     between alt 1 and exit branch of block

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
fracpete commented 5 years ago

Never had to compile the grammar before. Using the maven plugin didn't work for me at all. However, using antlr2 directly from command-line worked:

runantlr -o target/generated-sources/antlr/org/jcamp/parser src/main/antlr/ASDFLexer.g
runantlr -o target/generated-sources/antlr/org/jcamp/parser src/main/antlr/ASDFParser.g

NB: You will end up with duplicate classes, namely ASDFLexer, ASDFLexerTokenTypes, ASDFParser, ASDFParserTokenTypes. The original authors must have moved these classes manually into src/main/java.

laeubi commented 5 years ago

Yeah my goal was to configure the plugin so it places the classes into src/main/generated or something and remove them from src/main/java and let them compile on every run. Do you think it is worth to try upgrading the antlr plugin to antlr4?

laeubi commented 5 years ago

I also noticed that antlr seem to generate the required source into the directory (in fact it is only a warning) but since the build is marked as a failure this does not help much. Do you get any warnings on the commandline? What version of antlr are you using?

fracpete commented 5 years ago

I get the same warnings like you do. However, I don't consider warnings a failure. ;-)

laeubi commented 5 years ago

For these kind of things I like to treat warnings as errors :-) Because exactly the ASDF is causing problems here #3 with parsing failed expecting EOL, found '-7' and the parser complains about an nondeterminism of k==1:'+','-','0'..'9' and k==2:<end-of-token>,'0'..'9'