class RBS::AST::Visitor

Visitor 类实现了遍历 RBS 抽象语法树 (AST) 的 Visitor 模式。

它提供了访问 AST 中每种类型节点的方法,允许对每种节点类型进行自定义处理。

此类设计为被子类化,通过重写特定的 visit 方法来实现不同节点类型的自定义行为。

用法示例

~~~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) ~~~

公共实例方法

visit(node) 点击切换源码
# File rbs-3.8.0/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) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 70
def visit_all(nodes)
  nodes.each do |node|
    visit(node)
  end
end
visit_declaration_class(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 79
def visit_declaration_class(node)
  visit_all(node.members)
end
visit_declaration_constant(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 87
def visit_declaration_constant(node)
end
visit_declaration_global(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 76
def visit_declaration_global(node)
end
visit_declaration_interface(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 93
def visit_declaration_interface(node)
  visit_all(node.members)
end
visit_declaration_module(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 83
def visit_declaration_module(node)
  visit_all(node.members)
end
visit_declaration_type_alias(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 90
def visit_declaration_type_alias(node)
end
visit_member_alias(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 97
def visit_member_alias(node)
end
visit_member_attr_accessor(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 124
def visit_member_attr_accessor(node)
end
visit_member_attr_reader(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 118
def visit_member_attr_reader(node)
end
visit_member_attr_writer(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 121
def visit_member_attr_writer(node)
end
visit_member_class_instance_variable(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 100
def visit_member_class_instance_variable(node)
end
visit_member_class_variable(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 103
def visit_member_class_variable(node)
end
visit_member_extend(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 133
def visit_member_extend(node)
end
visit_member_include(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 127
def visit_member_include(node)
end
visit_member_instance_variable(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 106
def visit_member_instance_variable(node)
end
visit_member_method_definition(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 115
def visit_member_method_definition(node)
end
visit_member_prepend(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 130
def visit_member_prepend(node)
end
visit_member_private(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 109
def visit_member_private(node)
end
visit_member_public(node) 点击切换源码
# File rbs-3.8.0/lib/rbs/ast/visitor.rb, line 112
def visit_member_public(node)
end