rrevenantt / antlr4rust

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

BaseLexer deref / superClass #6

Closed dfrankland closed 3 years ago

dfrankland commented 4 years ago

I am trying to use antlr4rust with a stateful lexer that is already implemented in C++ and TypeScript.

It seems the best way to do this is to add to the lexer fields / members, but there's no way to reference them from from the BaseLexer. BaseParser seems to deref to its inner ext, so I thought that BaseLexer should probably be doing something similar by derefing to its inner recog.

Here's the change I am thinking of: https://github.com/dfrankland/antlr4rust/commit/6f3ac161da1defa06560eea12ab3dd243bcfaf31

Does that seem correct?

dfrankland commented 4 years ago

I've also run into the case that I need to extend the functionality of BaseLexer to emit more tokens. It seems that BaseLexer should be a trait that other traits have a constraint on so that user-provided functionality is possible.

dfrankland commented 4 years ago

I was able to get superClass to be supported by fixing up the antlr4 repo's rust-target branch's Rust template and fixing the LexerRecog trait to be generic.

Fix for antlr4 template: https://github.com/rrevenantt/antlr4/compare/rust-target...dfrankland:rust-target-fix-superClass

Fix for antlr4rust: https://github.com/dfrankland/antlr4rust/compare/6f3ac16...9c1557c

You can see the full changes and the tests for antlr4 here: https://github.com/rrevenantt/antlr4rust/compare/master...dfrankland:fix_base_lexer_deref