Skip to content

Rust bindings for P Protocol Language generate code which fails builds #32

Description

@christow-aws

Dupe of rrevenantt/antlr4rust#92; which is a confusing repo... because it has the name of the crate https://docs.rs/antlr4rust/latest/antlr4rust/; If I'm in the wrong place again, please let me know!


This line of the ANTLR parser for P generates Rust bindings which do not compile due to the word "base".

Also, the name of the P Parser file seems to confuse the codegen; below is the diff log for my changes to fix the generated code:

What is the recommended approach for dealing with this kind of issue?

the errors:

error[E0405]: cannot find trait `PParserParserContext` in this scope
   --> pparser.rs:854:14
    |
396 | / pub trait PParserContext<'input>:
397 | |     for<'x> Listenable<dyn PParserListener<'input> + 'x > + 
398 | |     ParserRuleContext<'input, TF=LocalTokenFactory<'input>, Ctx=PParserContextType>
399 | | {}
    | |__- similarly named trait `PParserContext` defined here
...
854 |   impl<'input> PParserParserContext<'input> for TypeContextAll<'input>{}
    |                ^^^^^^^^^^^^^^^^^^^^ help: a trait with a similar name exists: `PParserContext`

and

error[E0124]: field `base` is already declared
     --> pparser.rs:15229:2
      |
15228 |     base:FloatLiteralContextExt<'input>,
      |     ----------------------------------- `base` first declared here
15229 |     pub base: Option<TokenType<'input>>,
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field already declared

Followed by my hand-jammed fixes:

@@ -851,7 +851,7 @@ antlr4rust::tid!{TypeContextAll<'a>}
 
 impl<'input> antlr4rust::parser_rule_context::DerefSeal for TypeContextAll<'input>{}
 
-impl<'input> PParserParserContext<'input> for TypeContextAll<'input>{}
+impl<'input> PParserContext<'input> for TypeContextAll<'input>{}
 
 impl<'input> Deref for TypeContextAll<'input>{
        type Target = dyn TypeContextAttrs<'input> + 'input;
@@ -2743,7 +2743,7 @@ antlr4rust::tid!{ProofBlockDeclContextAll<'a>}

...................................................................
... truncated a bunch more of the same ...
...................................................................

@@ -15226,7 +15226,7 @@ impl<'input> ExpFloatContextAttrs<'input> for ExpFloatContext<'input>{}
 
 pub struct ExpFloatContextExt<'input>{
        base:FloatLiteralContextExt<'input>,
-       pub base: Option<TokenType<'input>>,
+       pub float_base: Option<TokenType<'input>>,
        pub exp: Option<TokenType<'input>>,
        ph:PhantomData<&'input str>
 }
@@ -15264,7 +15264,7 @@ impl<'input> ExpFloatContextExt<'input>{
                Rc::new(
                        FloatLiteralContextAll::ExpFloatContext(
                                BaseParserRuleContext::copy_from(ctx,ExpFloatContextExt{
-                                       base:None, exp:None, 
+                                       float_base:None, exp:None, 
                                base: ctx.borrow().clone(),
                                ph:PhantomData
                                })
@@ -15405,7 +15405,7 @@ where
                                        recog.base.set_state(1012);
                                        let tmp = recog.base.match_token(PParser_IntLiteral,&mut recog.err_handler)?;
                                        if let FloatLiteralContextAll::ExpFloatContext(ctx) = cast_mut::<_,FloatLiteralContextAll >(&mut _localctx){
-                                       ctx.base = Some(tmp.clone()); } else {unreachable!("cant cast");}  
+                                       ctx.float_base = Some(tmp.clone()); } else {unreachable!("cant cast");}  
 
                                        recog.base.set_state(1013);
                                        recog.base.match_token(PParser_COMMA,&mut recog.err_handler)?;
@@ -16064,7 +16064,7 @@ antlr4rust::tid!{ModExprContextAll<'a>}

...................................................................
... removed unnecessary git diff output ...
...................................................................

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions