rrevenantt / antlr4rust

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

Return Types for Visitors #23

Closed aferr closed 2 years ago

aferr commented 3 years ago

I was wondering if there is any plan to support parse tree visitors that return something as in the Java implementation of antlr. I find this is a convenient way to write a visitor that constructs AST node objects. Concretely, the current implementation of visit_terminal has signature: fn visit_terminal(self, TerminalNode<...>) {},

but if it were instead

fn visit_terminal<T>(self, TerminalNode<...>) -> T {} (and similar for the other functions in the ParseTreeVisitor trait)

then it would be possible to write a visitor that builds an AST by returning the AST nodes with each of these calls.

aferr commented 2 years ago

Thanks :)