Class: SwiftAST::Node
- Inherits:
-
Object
- Object
- SwiftAST::Node
- Defined in:
- lib/swift-ast-dump/swift_ast_parser.rb
Instance Method Summary collapse
- #children ⇒ Object
- #dump(level = 0) ⇒ Object
- #find_nodes(type) ⇒ Object
-
#initialize(name, parameters = [], children = []) ⇒ Node
constructor
A new instance of Node.
- #name ⇒ Object
- #on_node(type, &block) ⇒ Object
- #parameters ⇒ Object
Constructor Details
#initialize(name, parameters = [], children = []) ⇒ Node
Returns a new instance of Node.
170 171 172 173 174 |
# File 'lib/swift-ast-dump/swift_ast_parser.rb', line 170 def initialize(name, parameters = [], children = []) @name = name @parameters = parameters @children = children end |
Instance Method Details
#children ⇒ Object
184 185 186 |
# File 'lib/swift-ast-dump/swift_ast_parser.rb', line 184 def children @children end |
#dump(level = 0) ⇒ Object
188 189 190 191 192 193 194 |
# File 'lib/swift-ast-dump/swift_ast_parser.rb', line 188 def dump(level = 0) @@line = 0 if level == 0 puts "\n" if level == 0 puts " " * level + "[#{@@line}][#{@name} #{@parameters}" @@line = @@line + 1 @children.each { |child| child.dump(level + 1) } end |
#find_nodes(type) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/swift-ast-dump/swift_ast_parser.rb', line 196 def find_nodes(type) found_nodes = [] @children.each { |child| if child.name == type found_nodes << child else found_nodes += child.find_nodes(type) end } found_nodes end |
#name ⇒ Object
176 177 178 |
# File 'lib/swift-ast-dump/swift_ast_parser.rb', line 176 def name @name end |
#on_node(type, &block) ⇒ Object
208 209 210 211 212 213 |
# File 'lib/swift-ast-dump/swift_ast_parser.rb', line 208 def on_node(type, &block) @children.each { |child| yield child if child.name == type child.on_node(type, &block) } end |
#parameters ⇒ Object
180 181 182 |
# File 'lib/swift-ast-dump/swift_ast_parser.rb', line 180 def parameters @parameters end |