Class: RBS::AST::Visitor
- Inherits:
-
Object
- Object
- RBS::AST::Visitor
- Defined in:
- lib/rbs/ast/visitor.rb
Overview
The Visitor class implements the Visitor pattern for traversing the RBS Abstract Syntax Tree (AST).
It provides methods to visit each type of node in the AST, allowing for custom processing of each node type.
This class is designed to be subclassed, with specific visit methods overridden to implement custom behavior for different node types.
Example usage:
~~~rb class MyVisitor < RBS::AST::Visitor
def visit_declaration_class(node)
puts "Visiting class: #{node.name}"
super # call `super` to run the default visiting behavior
end
end
visitor = MyVisitor.new visitor.visit(ast_node) ~~~
Instance Method Summary collapse
- #visit(node) ⇒ Object
- #visit_all(nodes) ⇒ Object
- #visit_declaration_class(node) ⇒ Object
- #visit_declaration_constant(node) ⇒ Object
- #visit_declaration_global(node) ⇒ Object
- #visit_declaration_interface(node) ⇒ Object
- #visit_declaration_module(node) ⇒ Object
- #visit_declaration_type_alias(node) ⇒ Object
- #visit_member_alias(node) ⇒ Object
- #visit_member_attr_accessor(node) ⇒ Object
- #visit_member_attr_reader(node) ⇒ Object
- #visit_member_attr_writer(node) ⇒ Object
- #visit_member_class_instance_variable(node) ⇒ Object
- #visit_member_class_variable(node) ⇒ Object
- #visit_member_extend(node) ⇒ Object
- #visit_member_include(node) ⇒ Object
- #visit_member_instance_variable(node) ⇒ Object
- #visit_member_method_definition(node) ⇒ Object
- #visit_member_prepend(node) ⇒ Object
- #visit_member_private(node) ⇒ Object
- #visit_member_public(node) ⇒ Object
Instance Method Details
#visit(node) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rbs/ast/visitor.rb', line 27 def visit(node) case node when Declarations::Global visit_declaration_global(node) when Declarations::Class visit_declaration_class(node) when Declarations::Module visit_declaration_module(node) when Declarations::Constant visit_declaration_constant(node) when Declarations::TypeAlias visit_declaration_type_alias(node) when Declarations::Interface visit_declaration_interface(node) when Members::Alias visit_member_alias(node) when Members::ClassInstanceVariable visit_member_class_instance_variable(node) when Members::ClassVariable visit_member_class_variable(node) when Members::InstanceVariable visit_member_instance_variable(node) when Members::Private visit_member_private(node) when Members::Public visit_member_public(node) when Members::MethodDefinition visit_member_method_definition(node) when Members::AttrReader visit_member_attr_reader(node) when Members::AttrWriter visit_member_attr_writer(node) when Members::AttrAccessor visit_member_attr_accessor(node) when Members::Include visit_member_include(node) when Members::Prepend visit_member_prepend(node) when Members::Extend visit_member_extend(node) end end |
#visit_all(nodes) ⇒ Object
70 71 72 73 74 |
# File 'lib/rbs/ast/visitor.rb', line 70 def visit_all(nodes) nodes.each do |node| visit(node) end end |
#visit_declaration_class(node) ⇒ Object
79 80 81 |
# File 'lib/rbs/ast/visitor.rb', line 79 def visit_declaration_class(node) visit_all(node.members) end |
#visit_declaration_constant(node) ⇒ Object
87 88 |
# File 'lib/rbs/ast/visitor.rb', line 87 def visit_declaration_constant(node) end |
#visit_declaration_global(node) ⇒ Object
76 77 |
# File 'lib/rbs/ast/visitor.rb', line 76 def visit_declaration_global(node) end |
#visit_declaration_interface(node) ⇒ Object
93 94 95 |
# File 'lib/rbs/ast/visitor.rb', line 93 def visit_declaration_interface(node) visit_all(node.members) end |
#visit_declaration_module(node) ⇒ Object
83 84 85 |
# File 'lib/rbs/ast/visitor.rb', line 83 def visit_declaration_module(node) visit_all(node.members) end |
#visit_declaration_type_alias(node) ⇒ Object
90 91 |
# File 'lib/rbs/ast/visitor.rb', line 90 def visit_declaration_type_alias(node) end |
#visit_member_alias(node) ⇒ Object
97 98 |
# File 'lib/rbs/ast/visitor.rb', line 97 def visit_member_alias(node) end |
#visit_member_attr_accessor(node) ⇒ Object
124 125 |
# File 'lib/rbs/ast/visitor.rb', line 124 def visit_member_attr_accessor(node) end |
#visit_member_attr_reader(node) ⇒ Object
118 119 |
# File 'lib/rbs/ast/visitor.rb', line 118 def visit_member_attr_reader(node) end |
#visit_member_attr_writer(node) ⇒ Object
121 122 |
# File 'lib/rbs/ast/visitor.rb', line 121 def visit_member_attr_writer(node) end |
#visit_member_class_instance_variable(node) ⇒ Object
100 101 |
# File 'lib/rbs/ast/visitor.rb', line 100 def visit_member_class_instance_variable(node) end |
#visit_member_class_variable(node) ⇒ Object
103 104 |
# File 'lib/rbs/ast/visitor.rb', line 103 def visit_member_class_variable(node) end |
#visit_member_extend(node) ⇒ Object
133 134 |
# File 'lib/rbs/ast/visitor.rb', line 133 def visit_member_extend(node) end |
#visit_member_include(node) ⇒ Object
127 128 |
# File 'lib/rbs/ast/visitor.rb', line 127 def visit_member_include(node) end |
#visit_member_instance_variable(node) ⇒ Object
106 107 |
# File 'lib/rbs/ast/visitor.rb', line 106 def visit_member_instance_variable(node) end |
#visit_member_method_definition(node) ⇒ Object
115 116 |
# File 'lib/rbs/ast/visitor.rb', line 115 def visit_member_method_definition(node) end |
#visit_member_prepend(node) ⇒ Object
130 131 |
# File 'lib/rbs/ast/visitor.rb', line 130 def visit_member_prepend(node) end |
#visit_member_private(node) ⇒ Object
109 110 |
# File 'lib/rbs/ast/visitor.rb', line 109 def visit_member_private(node) end |
#visit_member_public(node) ⇒ Object
112 113 |
# File 'lib/rbs/ast/visitor.rb', line 112 def visit_member_public(node) end |