Class: SwiftAST::Node
- Inherits:
-
Object
- Object
- SwiftAST::Node
- Defined in:
- lib/swift_ast_dump_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.
178 179 180 181 182 |
# File 'lib/swift_ast_dump_parser.rb', line 178 def initialize(name, parameters = [], children = []) @name = name @parameters = parameters @children = children end |
Instance Method Details
#children ⇒ Object
192 193 194 |
# File 'lib/swift_ast_dump_parser.rb', line 192 def children @children end |
#dump(level = 0) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/swift_ast_dump_parser.rb', line 196 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
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/swift_ast_dump_parser.rb', line 204 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
184 185 186 |
# File 'lib/swift_ast_dump_parser.rb', line 184 def name @name end |
#on_node(type, &block) ⇒ Object
216 217 218 219 220 221 |
# File 'lib/swift_ast_dump_parser.rb', line 216 def on_node(type, &block) @children.each { |child| yield child if child.name == type child.on_node(type, &block) } end |
#parameters ⇒ Object
188 189 190 |
# File 'lib/swift_ast_dump_parser.rb', line 188 def parameters @parameters end |