Introduce a new `Visitor` and `Traverser` API
ryangjchandler opened this issue · 0 comments
There used to be a Node
trait that all Statement
and Expression
structures had to implement. This allowed us to have a very small traversal API and cast Node
values into a specific Statement
or Expression
.
The performance of this system wasn't great though and I removed the code that handled it all.
I want to instead introduce a more verbose and performant API for traversing an AST.
The first step is going to be having some sort of Visitor
trait that can be implemented on a structure. By default, the trait will have a default set of method implementations for handling all StatementKind
and ExpressionKind
values.
Visitors will be called by a Traverser
where the Traverser
is responsible for processing the nodes correctly, i.e. traverse_statement()
will match on the kind
and call the corresponding visit_X()
method.