Skip to content

Conversation

@sakuro
Copy link
Owner

@sakuro sakuro commented Jan 13, 2026

Summary

Add Visitor pattern support to foxtail-tools AST for reusable tree traversal without ad-hoc case statements.

Changes

  • Add Foxtail::Syntax::Visitor module with visit_* hooks for all 23 AST node types
  • Add accept(visitor) and children methods to AST nodes
  • Default visit_* methods auto-traverse children; omit super to stop traversal
  • Refactor example to demonstrate Visitor pattern usage

Test Plan

bundle exec rake spec:tools
bundle exec rake rubocop:tools
cd foxtail-tools && bundle exec ruby examples/01_prefix_message_ids.rb

Closes #155

- Add Visitor module with visit_* hooks for all 23 AST node types
- Add accept(visitor) and children methods to AST nodes
- Enable reusable tree traversal without ad-hoc case statements
- Default visit_* methods now call visit_children(node)
- Use super to continue traversal, omit to stop
- Simplify example by removing boilerplate visitor methods
@sakuro sakuro merged commit c6fd30d into main Jan 13, 2026
5 checks passed
@sakuro sakuro deleted the feature/support-visitor-pattern branch January 13, 2026 07:51
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.

Support Visitor pattern

2 participants