rrevenantt / antlr4rust

ANTLR4 parser generator runtime for Rust programming laguage
Other
398 stars 70 forks source link

NullPointerException #82

Open wizardxz opened 1 year ago

wizardxz commented 1 year ago

Hi I am building antlr binary and use it to generate my parser and I saw a NPE in the runtime Here is what I did

git clone -b rust-target https://github.com/rrevenantt/antlr4
git submodule update --init --recursive --remote
mvn -DskipTests install

Then I get

tool/target/antlr4-4.8-2-SNAPSHOT-complete.jar

Run it to against Expr.g4

grammar Expr;
prog:   (expr NEWLINE)* ;
expr:   expr ('*'|'/') expr
    |   expr ('+'|'-') expr
    |   INT
    |   '(' expr ')'
    ;
NEWLINE : [\r\n]+ ;
INT     : [0-9]+ ;
java -jar antlr4-4.8-2-SNAPSHOT-complete.jar -Dlanguage=Rust Expr.g4 -o generated/expr -visitor
error(31):  ANTLR cannot generate Rust code as of version 4.8
Exception in thread "main" java.lang.NullPointerException
        at org.antlr.v4.analysis.LeftRecursiveRuleAnalyzer.getArtificialOpPrecRule(LeftRecursiveRuleAnalyzer.java:211)
        at org.antlr.v4.analysis.LeftRecursiveRuleTransformer.translateLeftRecursiveRule(LeftRecursiveRuleTransformer.java:116)
        at org.antlr.v4.analysis.LeftRecursiveRuleTransformer.translateLeftRecursiveRules(LeftRecursiveRuleTransformer.java:71)
        at org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:71)
        at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:382)
        at org.antlr.v4.Tool.process(Tool.java:369)
        at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:328)
        at org.antlr.v4.Tool.main(Tool.java:172)
wizardxz commented 1 year ago

I investigated the code a little bit, found the RustTarget does not exist here https://github.com/rrevenantt/antlr4/blob/rust-target/tool/src/org/antlr/v4/codegen/CodeGenerator.java#L78

Do you have an idea about why the RustTarget is not loaded? Thanks

newca12 commented 1 year ago

It simply mean that your fat jar was not built with the Rust target. Ensure you did the git submodule update in the antlr4 directory and that your Reactor Summary for your fat jar build is a full green SUCCESS.

git clone -b rust-target https://github.com/rrevenantt/antlr4
cd antlr4
git submodule update --init --recursive --remote
mvn -DskipTests install