Skip to content

Conversation

@alexcrocha
Copy link

@alexcrocha alexcrocha commented Nov 28, 2025

Enable walking the AST by generating a Visit trait with per-node visitor methods. It uses double dispatch to route each node type to its corresponding visitor method. This avoids consumers needing to manually match on Node variants and allows overriding specific visits while inheriting default behaviour for others.

  • Updates build.rs to generate a Visit trait with methods for every node type (e.g., visit_class_node, visit_method_definition_node).
  • Implements a central visit(&mut self, node: &Node) dispatch method that matches on the Node enum.
  • Generates default (empty) implementations for all visitor methods, allowing implementers to override only the nodes they care about.

This lays the groundwork for implementing AST traversals in Rust.

Copy link
Author

alexcrocha commented Nov 28, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@alexcrocha alexcrocha force-pushed the 11-28-add_generated_visit_trait branch from 2c6b902 to acd7de9 Compare November 28, 2025 23:39
@alexcrocha alexcrocha marked this pull request as ready for review November 28, 2025 23:44
Enable walking the AST by generating a Visit trait with per-node visitor
methods. It uses double dispatch to route each node type to its
corresponding visitor method. This avoids consumers needing to manually
match on Node variants and allows overriding specific visits while
inheriting default behavior for others.
@alexcrocha alexcrocha force-pushed the 11-28-add_generated_visit_trait branch from acd7de9 to 403f139 Compare December 1, 2025 17:43
@alexcrocha alexcrocha requested a review from vinistock December 1, 2025 17:48
@alexcrocha alexcrocha merged commit f62c13c into ar-rust-rbs-build Dec 1, 2025
15 of 27 checks passed
alexcrocha added a commit that referenced this pull request Dec 18, 2025
The Visit trait added in #69 provided the scaffolding for AST traversal,
but the visitor functions were empty stubs that didn't recurse into
children nodes. Without this, the visitor pattern is incomplete as we'd
have to manually write traversal logic every time we want to walk the
tree.

This commit adds the generation of visitor functions for child node
traversal. We handle four field types:
- `rbs_node`: single child node
- `rbs_node_list`: list of child nodes
- `rbs_hash`: key-value pairs of nodes
- Wrapper types (`rbs_type_name`, `rbs_namespace`, etc): each with its
own visitor method

Each case handles optional fields to safely skip NULL pointers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants