Class: RBI::TreeBuilder
- Inherits:
-
ASTVisitor
- Object
- ASTVisitor
- RBI::TreeBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/rbi/parser.rb
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
-
#initialize(file:, comments: [], nodes_comments_assoc: {}) ⇒ TreeBuilder
constructor
A new instance of TreeBuilder.
- #post_process ⇒ Object
- #visit(node) ⇒ Object
Methods inherited from ASTVisitor
Constructor Details
#initialize(file:, comments: [], nodes_comments_assoc: {}) ⇒ TreeBuilder
Returns a new instance of TreeBuilder.
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rbi/parser.rb', line 123 def initialize(file:, comments: [], nodes_comments_assoc: {}) super() @file = file @comments = comments @nodes_comments_assoc = nodes_comments_assoc @tree = T.let(Tree.new, Tree) @scopes_stack = T.let([@tree], T::Array[Tree]) @last_sigs = T.let([], T::Array[RBI::Sig]) separate_header_comments end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
114 115 116 |
# File 'lib/rbi/parser.rb', line 114 def tree @tree end |
Instance Method Details
#post_process ⇒ Object
136 137 138 139 |
# File 'lib/rbi/parser.rb', line 136 def post_process assoc_dangling_comments set_root_tree_loc end |
#visit(node) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/rbi/parser.rb', line 142 def visit(node) return unless node.is_a?(AST::Node) case node.type when :module, :class, :sclass scope = parse_scope(node) current_scope << scope @scopes_stack << scope visit_all(node.children) @scopes_stack.pop when :casgn current_scope << parse_const_assign(node) when :def, :defs current_scope << parse_def(node) when :send node = parse_send(node) current_scope << node if node when :block node = parse_block(node) if node.is_a?(Sig) @last_sigs << node elsif node current_scope << node end else visit_all(node.children) end end |