rrevenantt / antlr4rust

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

Splitting lexer and parser grammar into separate files causes error #15

Open StuartReavley opened 3 years ago

StuartReavley commented 3 years ago

To repro:

As I understand, there is no way to use lexer modes (e.g. in that example) without separate files. Any way to get this to work?

Thank you! Stuart

rbuckland commented 3 years ago

@StuartReavley - did you try adding both files to the command line ?

eg:

cd grammars && java -jar /home/rbuckland/.m2/repository/org/antlr/antlr4/4.8-2-SNAPSHOT/antlr4-4.8-2-SNAPSHOT-complete.jar -Dlanguage=Rust -o ../src/gen PhpParser.g4 PhpLexer.g4 

image

image

mh182 commented 2 years ago

I hit the same problem with the generated code of a PL/SQL grammar even if I used the lexer and parser grammar together.

antlr4 -Dlanguage=Rust -o src -Xexact-output-dir grammars/PlSqlLexer.g4 grammars/PlSqlParser.g4

Compiling the generated code

        error[E0405]: cannot find trait `PlSqlParserParserContext` in this scope
              --> src/plsqlparser.rs:106025:14
               |
        4098   | / pub trait PlSqlParserContext<'input>:
        4099   | |     for<'x> Listenable<dyn PlSqlParserListener<'input> + 'x > + 
        4100   | |     ParserRuleContext<'input, TF=LocalTokenFactory<'input>, Ctx=PlSqlParserContextType>
        4101   | | {}
               | |__- similarly named trait `PlSqlParserContext` defined here
        ...
        106025 |   impl<'input> PlSqlParserParserContext<'input> for Table_ref_aux_internalContextAll<'input>{}
               |                ^^^^^^^^^^^^^^^^^^^^^^^^ help: a trait with a similar name exists: `PlSqlParserContext`

        Some errors have detailed explanations: E0405, E0424.
        For more information about an error, try `rustc --explain E0405`.

Renaming the generated trait to PLSqlParserContext fixed it

sed -i s/PlSqlParserParserContext/PlSqlParserContext/g src/plsqlparser.rs
ndimiduk commented 3 months ago

Same for me working with https://github.com/p-org/P/tree/bec256f/Src/PCompiler/CompilerCore/Parser

I'm using antlr4-4.8-2-Rust0.3.0-beta and antlr-rust = "0.3.0-beta".