rrevenantt / antlr4rust

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

Generator is incompatible with runtime #67

Closed wprzytula closed 1 year ago

wprzytula commented 1 year ago

After I download the generator release 0.3.0-beta, generate parser using it and try to run it using master branch of this repo (or crate 0.3.0-beta from crates.io), then I encounter a lot of incompatibility errors:

error[E0433]: failed to resolve: could not find `impl_tid` in `antlr_rust`
   --> src/frontend/parser/latteparser.rs:206:15
    |
206 | #[antlr_rust::impl_tid]
    |               ^^^^^^^^ could not find `impl_tid` in `antlr_rust`

error[E0433]: failed to resolve: could not find `type_id` in `antlr_rust`
   --> src/frontend/parser/latteparser.rs:210:13
    |
210 | antlr_rust::type_id!{LatteParserContextType}
    |             ^^^^^^^ could not find `type_id` in `antlr_rust`
...    
error: cannot find derive macro `Tid` in this scope
   --> src/frontend/parser/lattelexer.rs:118:10
    |
118 | #[derive(Tid)]
    |          ^^^
    |
...
error[E0200]: the trait `TidAble<'input>` requires an `unsafe impl` declaration
   --> src/frontend/parser/latteparser.rs:204:1
    |
204 | impl<'input> antlr_rust::TidAble<'input> for dyn LatteParserContext<'input> + 'input{}
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the trait `TidAble<'input>` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
    |
204 | unsafe impl<'input> antlr_rust::TidAble<'input> for dyn LatteParserContext<'input> + 'input{}
    | ++++++

all of which, I believe, originate from better_any crate. So far, I haven't managed to solve it myself.

As I need to use your great crate ASAP, I'd be very grateful for quick help. @rrevenantt

rrevenantt commented 1 year ago

Are you absolutely sure that you have used the version of generator that you have linked? because such code was generated only in previous versions

wprzytula commented 1 year ago

Yes, I've tried both downloading the prebuilt release and building it from your fork - the result is the same.

rrevenantt commented 1 year ago

Well i have just downloaded generator right from that link and it works as expected so i have no idea what is going wrong in your case. Are you executing generator from terminal or from build.rs or some other script? Also can you share your grammar?

wprzytula commented 1 year ago

I'm so sorry. I've messed with two directories, and files that actually caused the compilation problem were left from generation with older generator. Everything does work. Thank you very much for your instant response!

rrevenantt commented 1 year ago

Yeah. antlr tool uses some weird path selection mechanism, for whatever reason it generated code in src/parser/src instead of expected src/parser when i tried to reproduce your issue