Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
StuartReavley opened this issue Dec 2, 2020 · 4 comments

Comments

@StuartReavley
Copy link

To repro:

  • use grammars here: https://github.com/sepp2k/antlr4-string-interpolation-examples/tree/master/with-duplication

  • run commands

    • java -jar ./antlr4-4.8-2-SNAPSHOT-complete.jar -Dlanguage=Rust StringLexer.g4
    • java -jar ./antlr4-4.8-2-SNAPSHOT-complete.jar -Dlanguage=Rust StringParser.g4
  • Observe errors, e.g:
    error[E0412]: cannot find type `StringParserParserContextType` in this scope --> src/parsing/jasm/gen/stringparser.rs:532:49 | 156 | pub struct StringParserContextType; | ----------------------------------- similarly named struct `StringParserContextType` defined here ... 532 | fn RPAR(&self) -> Option<Rc<TerminalNode<'input,StringParserParserContextType>>> where Self:Sized{ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |

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
Copy link
Contributor

@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
Copy link

mh182 commented Mar 28, 2022

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
Copy link

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".

@derrley
Copy link

derrley commented Oct 10, 2024

Did anyone ever figure out what causes this? I just hit it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants