Debian Codegraph @

lib/prism/inspect_visitor.rb

raw symbols SCIP
1 # frozen_string_literal: true
2 # :markup: markdown
3
4 =begin
5 --
6 This file is generated by the templates/template.rb script and should not be
7 modified manually. See templates/lib/prism/inspect_visitor.rb.erb
8 if you are looking to modify the template
9 ++
10 =end
11
12 module Prism
13 # This visitor is responsible for composing the strings that get returned by
14 # the various #inspect methods defined on each of the nodes.
15 class InspectVisitor < Visitor
16 # Most of the time, we can simply pass down the indent to the next node.
17 # However, when we are inside a list we want some extra special formatting
18 # when we hit an element in that list. In this case, we have a special
19 # command that replaces the subsequent indent with the given value.
20 class Replace # :nodoc:
21 attr_reader :value
22
23 def initialize(value)
24 @value = value
25 end
26 end
27
28 private_constant :Replace
29
30 # The current prefix string.
31 attr_reader :indent
32
33 # The list of commands that we need to execute in order to compose the
34 # final string.
35 attr_reader :commands
36
37 # Initializes a new instance of the InspectVisitor.
38 def initialize(indent = +"")
39 @indent = indent
40 @commands = []
41 end
42
43 # Compose an inspect string for the given node.
44 def self.compose(node)
45 visitor = new
46 node.accept(visitor)
47 visitor.compose
48 end
49
50 # Compose the final string.
51 def compose
52 buffer = +""
53 replace = nil
54
55 until commands.empty?
56 # @type var command: String | node | Replace
57 # @type var indent: String
58 command, indent = *commands.shift
59
60 case command
61 when String
62 buffer << (replace || indent)
63 buffer << command
64 replace = nil
65 when Node
66 visitor = InspectVisitor.new(indent)
67 command.accept(visitor)
68 @commands = [*visitor.commands, *@commands]
69 when Replace
70 replace = command.value
71 else
72 raise "Unknown command: #{command.inspect}"
73 end
74 end
75
76 buffer
77 end
78
79 # Inspect a AliasGlobalVariableNode node.
80 def visit_alias_global_variable_node(node)
81 commands << [inspect_node("AliasGlobalVariableNode", node), indent]
82 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
83 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
84 commands << ["├── new_name:\n", indent]
85 commands << [node.new_name, "#{indent}│ "]
86 commands << ["├── old_name:\n", indent]
87 commands << [node.old_name, "#{indent}│ "]
88 commands << ["└── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
89 end
90
91 # Inspect a AliasMethodNode node.
92 def visit_alias_method_node(node)
93 commands << [inspect_node("AliasMethodNode", node), indent]
94 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
95 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
96 commands << ["├── new_name:\n", indent]
97 commands << [node.new_name, "#{indent}│ "]
98 commands << ["├── old_name:\n", indent]
99 commands << [node.old_name, "#{indent}│ "]
100 commands << ["└── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
101 end
102
103 # Inspect a AlternationPatternNode node.
104 def visit_alternation_pattern_node(node)
105 commands << [inspect_node("AlternationPatternNode", node), indent]
106 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
107 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
108 commands << ["├── left:\n", indent]
109 commands << [node.left, "#{indent}│ "]
110 commands << ["├── right:\n", indent]
111 commands << [node.right, "#{indent}│ "]
112 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
113 end
114
115 # Inspect a AndNode node.
116 def visit_and_node(node)
117 commands << [inspect_node("AndNode", node), indent]
118 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
119 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
120 commands << ["├── left:\n", indent]
121 commands << [node.left, "#{indent}│ "]
122 commands << ["├── right:\n", indent]
123 commands << [node.right, "#{indent}│ "]
124 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
125 end
126
127 # Inspect a ArgumentsNode node.
128 def visit_arguments_node(node)
129 commands << [inspect_node("ArgumentsNode", node), indent]
130 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("contains_forwarding" if node.contains_forwarding?), ("contains_keywords" if node.contains_keywords?), ("contains_keyword_splat" if node.contains_keyword_splat?), ("contains_splat" if node.contains_splat?), ("contains_multiple_splats" if node.contains_multiple_splats?)].compact
131 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
132 commands << ["└── arguments: (length: #{(arguments = node.arguments).length})\n", indent]
133 if arguments.any?
134 arguments[0...-1].each do |child|
135 commands << [Replace.new("#{indent} ├── "), indent]
136 commands << [child, "#{indent} │ "]
137 end
138 commands << [Replace.new("#{indent} └── "), indent]
139 commands << [arguments[-1], "#{indent} "]
140 end
141 end
142
143 # Inspect a ArrayNode node.
144 def visit_array_node(node)
145 commands << [inspect_node("ArrayNode", node), indent]
146 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("contains_splat" if node.contains_splat?)].compact
147 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
148 commands << ["├── elements: (length: #{(elements = node.elements).length})\n", indent]
149 if elements.any?
150 elements[0...-1].each do |child|
151 commands << [Replace.new("#{indent}│ ├── "), indent]
152 commands << [child, "#{indent}│ │ "]
153 end
154 commands << [Replace.new("#{indent}│ └── "), indent]
155 commands << [elements[-1], "#{indent}│ "]
156 end
157 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
158 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
159 end
160
161 # Inspect a ArrayPatternNode node.
162 def visit_array_pattern_node(node)
163 commands << [inspect_node("ArrayPatternNode", node), indent]
164 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
165 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
166 if (constant = node.constant).nil?
167 commands << ["├── constant: ∅\n", indent]
168 else
169 commands << ["├── constant:\n", indent]
170 commands << [constant, "#{indent}│ "]
171 end
172 commands << ["├── requireds: (length: #{(requireds = node.requireds).length})\n", indent]
173 if requireds.any?
174 requireds[0...-1].each do |child|
175 commands << [Replace.new("#{indent}│ ├── "), indent]
176 commands << [child, "#{indent}│ │ "]
177 end
178 commands << [Replace.new("#{indent}│ └── "), indent]
179 commands << [requireds[-1], "#{indent}│ "]
180 end
181 if (rest = node.rest).nil?
182 commands << ["├── rest: ∅\n", indent]
183 else
184 commands << ["├── rest:\n", indent]
185 commands << [rest, "#{indent}│ "]
186 end
187 commands << ["├── posts: (length: #{(posts = node.posts).length})\n", indent]
188 if posts.any?
189 posts[0...-1].each do |child|
190 commands << [Replace.new("#{indent}│ ├── "), indent]
191 commands << [child, "#{indent}│ │ "]
192 end
193 commands << [Replace.new("#{indent}│ └── "), indent]
194 commands << [posts[-1], "#{indent}│ "]
195 end
196 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
197 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
198 end
199
200 # Inspect a AssocNode node.
201 def visit_assoc_node(node)
202 commands << [inspect_node("AssocNode", node), indent]
203 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
204 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
205 commands << ["├── key:\n", indent]
206 commands << [node.key, "#{indent}│ "]
207 commands << ["├── value:\n", indent]
208 commands << [node.value, "#{indent}│ "]
209 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
210 end
211
212 # Inspect a AssocSplatNode node.
213 def visit_assoc_splat_node(node)
214 commands << [inspect_node("AssocSplatNode", node), indent]
215 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
216 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
217 if (value = node.value).nil?
218 commands << ["├── value: ∅\n", indent]
219 else
220 commands << ["├── value:\n", indent]
221 commands << [value, "#{indent}│ "]
222 end
223 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
224 end
225
226 # Inspect a BackReferenceReadNode node.
227 def visit_back_reference_read_node(node)
228 commands << [inspect_node("BackReferenceReadNode", node), indent]
229 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
230 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
231 commands << ["└── name: #{node.name.inspect}\n", indent]
232 end
233
234 # Inspect a BeginNode node.
235 def visit_begin_node(node)
236 commands << [inspect_node("BeginNode", node), indent]
237 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
238 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
239 commands << ["├── begin_keyword_loc: #{inspect_location(node.begin_keyword_loc)}\n", indent]
240 if (statements = node.statements).nil?
241 commands << ["├── statements: ∅\n", indent]
242 else
243 commands << ["├── statements:\n", indent]
244 commands << [statements, "#{indent}│ "]
245 end
246 if (rescue_clause = node.rescue_clause).nil?
247 commands << ["├── rescue_clause: ∅\n", indent]
248 else
249 commands << ["├── rescue_clause:\n", indent]
250 commands << [rescue_clause, "#{indent}│ "]
251 end
252 if (else_clause = node.else_clause).nil?
253 commands << ["├── else_clause: ∅\n", indent]
254 else
255 commands << ["├── else_clause:\n", indent]
256 commands << [else_clause, "#{indent}│ "]
257 end
258 if (ensure_clause = node.ensure_clause).nil?
259 commands << ["├── ensure_clause: ∅\n", indent]
260 else
261 commands << ["├── ensure_clause:\n", indent]
262 commands << [ensure_clause, "#{indent}│ "]
263 end
264 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
265 end
266
267 # Inspect a BlockArgumentNode node.
268 def visit_block_argument_node(node)
269 commands << [inspect_node("BlockArgumentNode", node), indent]
270 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
271 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
272 if (expression = node.expression).nil?
273 commands << ["├── expression: ∅\n", indent]
274 else
275 commands << ["├── expression:\n", indent]
276 commands << [expression, "#{indent}│ "]
277 end
278 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
279 end
280
281 # Inspect a BlockLocalVariableNode node.
282 def visit_block_local_variable_node(node)
283 commands << [inspect_node("BlockLocalVariableNode", node), indent]
284 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("repeated_parameter" if node.repeated_parameter?)].compact
285 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
286 commands << ["└── name: #{node.name.inspect}\n", indent]
287 end
288
289 # Inspect a BlockNode node.
290 def visit_block_node(node)
291 commands << [inspect_node("BlockNode", node), indent]
292 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
293 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
294 commands << ["├── locals: #{node.locals.inspect}\n", indent]
295 if (parameters = node.parameters).nil?
296 commands << ["├── parameters: ∅\n", indent]
297 else
298 commands << ["├── parameters:\n", indent]
299 commands << [parameters, "#{indent}│ "]
300 end
301 if (body = node.body).nil?
302 commands << ["├── body: ∅\n", indent]
303 else
304 commands << ["├── body:\n", indent]
305 commands << [body, "#{indent}│ "]
306 end
307 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
308 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
309 end
310
311 # Inspect a BlockParameterNode node.
312 def visit_block_parameter_node(node)
313 commands << [inspect_node("BlockParameterNode", node), indent]
314 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("repeated_parameter" if node.repeated_parameter?)].compact
315 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
316 if (name = node.name).nil?
317 commands << ["├── name: ∅\n", indent]
318 else
319 commands << ["├── name: #{name.inspect}\n", indent]
320 end
321 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
322 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
323 end
324
325 # Inspect a BlockParametersNode node.
326 def visit_block_parameters_node(node)
327 commands << [inspect_node("BlockParametersNode", node), indent]
328 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
329 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
330 if (parameters = node.parameters).nil?
331 commands << ["├── parameters: ∅\n", indent]
332 else
333 commands << ["├── parameters:\n", indent]
334 commands << [parameters, "#{indent}│ "]
335 end
336 commands << ["├── locals: (length: #{(locals = node.locals).length})\n", indent]
337 if locals.any?
338 locals[0...-1].each do |child|
339 commands << [Replace.new("#{indent}│ ├── "), indent]
340 commands << [child, "#{indent}│ │ "]
341 end
342 commands << [Replace.new("#{indent}│ └── "), indent]
343 commands << [locals[-1], "#{indent}│ "]
344 end
345 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
346 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
347 end
348
349 # Inspect a BreakNode node.
350 def visit_break_node(node)
351 commands << [inspect_node("BreakNode", node), indent]
352 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
353 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
354 if (arguments = node.arguments).nil?
355 commands << ["├── arguments: ∅\n", indent]
356 else
357 commands << ["├── arguments:\n", indent]
358 commands << [arguments, "#{indent}│ "]
359 end
360 commands << ["└── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
361 end
362
363 # Inspect a CallAndWriteNode node.
364 def visit_call_and_write_node(node)
365 commands << [inspect_node("CallAndWriteNode", node), indent]
366 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
367 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
368 if (receiver = node.receiver).nil?
369 commands << ["├── receiver: ∅\n", indent]
370 else
371 commands << ["├── receiver:\n", indent]
372 commands << [receiver, "#{indent}│ "]
373 end
374 commands << ["├── call_operator_loc: #{inspect_location(node.call_operator_loc)}\n", indent]
375 commands << ["├── message_loc: #{inspect_location(node.message_loc)}\n", indent]
376 commands << ["├── read_name: #{node.read_name.inspect}\n", indent]
377 commands << ["├── write_name: #{node.write_name.inspect}\n", indent]
378 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
379 commands << ["└── value:\n", indent]
380 commands << [node.value, "#{indent} "]
381 end
382
383 # Inspect a CallNode node.
384 def visit_call_node(node)
385 commands << [inspect_node("CallNode", node), indent]
386 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
387 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
388 if (receiver = node.receiver).nil?
389 commands << ["├── receiver: ∅\n", indent]
390 else
391 commands << ["├── receiver:\n", indent]
392 commands << [receiver, "#{indent}│ "]
393 end
394 commands << ["├── call_operator_loc: #{inspect_location(node.call_operator_loc)}\n", indent]
395 commands << ["├── name: #{node.name.inspect}\n", indent]
396 commands << ["├── message_loc: #{inspect_location(node.message_loc)}\n", indent]
397 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
398 if (arguments = node.arguments).nil?
399 commands << ["├── arguments: ∅\n", indent]
400 else
401 commands << ["├── arguments:\n", indent]
402 commands << [arguments, "#{indent}│ "]
403 end
404 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
405 commands << ["├── equal_loc: #{inspect_location(node.equal_loc)}\n", indent]
406 if (block = node.block).nil?
407 commands << ["└── block: ∅\n", indent]
408 else
409 commands << ["└── block:\n", indent]
410 commands << [block, "#{indent} "]
411 end
412 end
413
414 # Inspect a CallOperatorWriteNode node.
415 def visit_call_operator_write_node(node)
416 commands << [inspect_node("CallOperatorWriteNode", node), indent]
417 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
418 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
419 if (receiver = node.receiver).nil?
420 commands << ["├── receiver: ∅\n", indent]
421 else
422 commands << ["├── receiver:\n", indent]
423 commands << [receiver, "#{indent}│ "]
424 end
425 commands << ["├── call_operator_loc: #{inspect_location(node.call_operator_loc)}\n", indent]
426 commands << ["├── message_loc: #{inspect_location(node.message_loc)}\n", indent]
427 commands << ["├── read_name: #{node.read_name.inspect}\n", indent]
428 commands << ["├── write_name: #{node.write_name.inspect}\n", indent]
429 commands << ["├── binary_operator: #{node.binary_operator.inspect}\n", indent]
430 commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
431 commands << ["└── value:\n", indent]
432 commands << [node.value, "#{indent} "]
433 end
434
435 # Inspect a CallOrWriteNode node.
436 def visit_call_or_write_node(node)
437 commands << [inspect_node("CallOrWriteNode", node), indent]
438 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
439 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
440 if (receiver = node.receiver).nil?
441 commands << ["├── receiver: ∅\n", indent]
442 else
443 commands << ["├── receiver:\n", indent]
444 commands << [receiver, "#{indent}│ "]
445 end
446 commands << ["├── call_operator_loc: #{inspect_location(node.call_operator_loc)}\n", indent]
447 commands << ["├── message_loc: #{inspect_location(node.message_loc)}\n", indent]
448 commands << ["├── read_name: #{node.read_name.inspect}\n", indent]
449 commands << ["├── write_name: #{node.write_name.inspect}\n", indent]
450 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
451 commands << ["└── value:\n", indent]
452 commands << [node.value, "#{indent} "]
453 end
454
455 # Inspect a CallTargetNode node.
456 def visit_call_target_node(node)
457 commands << [inspect_node("CallTargetNode", node), indent]
458 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
459 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
460 commands << ["├── receiver:\n", indent]
461 commands << [node.receiver, "#{indent}│ "]
462 commands << ["├── call_operator_loc: #{inspect_location(node.call_operator_loc)}\n", indent]
463 commands << ["├── name: #{node.name.inspect}\n", indent]
464 commands << ["└── message_loc: #{inspect_location(node.message_loc)}\n", indent]
465 end
466
467 # Inspect a CapturePatternNode node.
468 def visit_capture_pattern_node(node)
469 commands << [inspect_node("CapturePatternNode", node), indent]
470 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
471 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
472 commands << ["├── value:\n", indent]
473 commands << [node.value, "#{indent}│ "]
474 commands << ["├── target:\n", indent]
475 commands << [node.target, "#{indent}│ "]
476 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
477 end
478
479 # Inspect a CaseMatchNode node.
480 def visit_case_match_node(node)
481 commands << [inspect_node("CaseMatchNode", node), indent]
482 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
483 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
484 if (predicate = node.predicate).nil?
485 commands << ["├── predicate: ∅\n", indent]
486 else
487 commands << ["├── predicate:\n", indent]
488 commands << [predicate, "#{indent}│ "]
489 end
490 commands << ["├── conditions: (length: #{(conditions = node.conditions).length})\n", indent]
491 if conditions.any?
492 conditions[0...-1].each do |child|
493 commands << [Replace.new("#{indent}│ ├── "), indent]
494 commands << [child, "#{indent}│ │ "]
495 end
496 commands << [Replace.new("#{indent}│ └── "), indent]
497 commands << [conditions[-1], "#{indent}│ "]
498 end
499 if (else_clause = node.else_clause).nil?
500 commands << ["├── else_clause: ∅\n", indent]
501 else
502 commands << ["├── else_clause:\n", indent]
503 commands << [else_clause, "#{indent}│ "]
504 end
505 commands << ["├── case_keyword_loc: #{inspect_location(node.case_keyword_loc)}\n", indent]
506 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
507 end
508
509 # Inspect a CaseNode node.
510 def visit_case_node(node)
511 commands << [inspect_node("CaseNode", node), indent]
512 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
513 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
514 if (predicate = node.predicate).nil?
515 commands << ["├── predicate: ∅\n", indent]
516 else
517 commands << ["├── predicate:\n", indent]
518 commands << [predicate, "#{indent}│ "]
519 end
520 commands << ["├── conditions: (length: #{(conditions = node.conditions).length})\n", indent]
521 if conditions.any?
522 conditions[0...-1].each do |child|
523 commands << [Replace.new("#{indent}│ ├── "), indent]
524 commands << [child, "#{indent}│ │ "]
525 end
526 commands << [Replace.new("#{indent}│ └── "), indent]
527 commands << [conditions[-1], "#{indent}│ "]
528 end
529 if (else_clause = node.else_clause).nil?
530 commands << ["├── else_clause: ∅\n", indent]
531 else
532 commands << ["├── else_clause:\n", indent]
533 commands << [else_clause, "#{indent}│ "]
534 end
535 commands << ["├── case_keyword_loc: #{inspect_location(node.case_keyword_loc)}\n", indent]
536 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
537 end
538
539 # Inspect a ClassNode node.
540 def visit_class_node(node)
541 commands << [inspect_node("ClassNode", node), indent]
542 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
543 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
544 commands << ["├── locals: #{node.locals.inspect}\n", indent]
545 commands << ["├── class_keyword_loc: #{inspect_location(node.class_keyword_loc)}\n", indent]
546 commands << ["├── constant_path:\n", indent]
547 commands << [node.constant_path, "#{indent}│ "]
548 commands << ["├── inheritance_operator_loc: #{inspect_location(node.inheritance_operator_loc)}\n", indent]
549 if (superclass = node.superclass).nil?
550 commands << ["├── superclass: ∅\n", indent]
551 else
552 commands << ["├── superclass:\n", indent]
553 commands << [superclass, "#{indent}│ "]
554 end
555 if (body = node.body).nil?
556 commands << ["├── body: ∅\n", indent]
557 else
558 commands << ["├── body:\n", indent]
559 commands << [body, "#{indent}│ "]
560 end
561 commands << ["├── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
562 commands << ["└── name: #{node.name.inspect}\n", indent]
563 end
564
565 # Inspect a ClassVariableAndWriteNode node.
566 def visit_class_variable_and_write_node(node)
567 commands << [inspect_node("ClassVariableAndWriteNode", node), indent]
568 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
569 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
570 commands << ["├── name: #{node.name.inspect}\n", indent]
571 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
572 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
573 commands << ["└── value:\n", indent]
574 commands << [node.value, "#{indent} "]
575 end
576
577 # Inspect a ClassVariableOperatorWriteNode node.
578 def visit_class_variable_operator_write_node(node)
579 commands << [inspect_node("ClassVariableOperatorWriteNode", node), indent]
580 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
581 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
582 commands << ["├── name: #{node.name.inspect}\n", indent]
583 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
584 commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
585 commands << ["├── value:\n", indent]
586 commands << [node.value, "#{indent}│ "]
587 commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
588 end
589
590 # Inspect a ClassVariableOrWriteNode node.
591 def visit_class_variable_or_write_node(node)
592 commands << [inspect_node("ClassVariableOrWriteNode", node), indent]
593 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
594 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
595 commands << ["├── name: #{node.name.inspect}\n", indent]
596 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
597 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
598 commands << ["└── value:\n", indent]
599 commands << [node.value, "#{indent} "]
600 end
601
602 # Inspect a ClassVariableReadNode node.
603 def visit_class_variable_read_node(node)
604 commands << [inspect_node("ClassVariableReadNode", node), indent]
605 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
606 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
607 commands << ["└── name: #{node.name.inspect}\n", indent]
608 end
609
610 # Inspect a ClassVariableTargetNode node.
611 def visit_class_variable_target_node(node)
612 commands << [inspect_node("ClassVariableTargetNode", node), indent]
613 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
614 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
615 commands << ["└── name: #{node.name.inspect}\n", indent]
616 end
617
618 # Inspect a ClassVariableWriteNode node.
619 def visit_class_variable_write_node(node)
620 commands << [inspect_node("ClassVariableWriteNode", node), indent]
621 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
622 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
623 commands << ["├── name: #{node.name.inspect}\n", indent]
624 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
625 commands << ["├── value:\n", indent]
626 commands << [node.value, "#{indent}│ "]
627 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
628 end
629
630 # Inspect a ConstantAndWriteNode node.
631 def visit_constant_and_write_node(node)
632 commands << [inspect_node("ConstantAndWriteNode", node), indent]
633 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
634 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
635 commands << ["├── name: #{node.name.inspect}\n", indent]
636 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
637 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
638 commands << ["└── value:\n", indent]
639 commands << [node.value, "#{indent} "]
640 end
641
642 # Inspect a ConstantOperatorWriteNode node.
643 def visit_constant_operator_write_node(node)
644 commands << [inspect_node("ConstantOperatorWriteNode", node), indent]
645 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
646 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
647 commands << ["├── name: #{node.name.inspect}\n", indent]
648 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
649 commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
650 commands << ["├── value:\n", indent]
651 commands << [node.value, "#{indent}│ "]
652 commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
653 end
654
655 # Inspect a ConstantOrWriteNode node.
656 def visit_constant_or_write_node(node)
657 commands << [inspect_node("ConstantOrWriteNode", node), indent]
658 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
659 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
660 commands << ["├── name: #{node.name.inspect}\n", indent]
661 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
662 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
663 commands << ["└── value:\n", indent]
664 commands << [node.value, "#{indent} "]
665 end
666
667 # Inspect a ConstantPathAndWriteNode node.
668 def visit_constant_path_and_write_node(node)
669 commands << [inspect_node("ConstantPathAndWriteNode", node), indent]
670 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
671 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
672 commands << ["├── target:\n", indent]
673 commands << [node.target, "#{indent}│ "]
674 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
675 commands << ["└── value:\n", indent]
676 commands << [node.value, "#{indent} "]
677 end
678
679 # Inspect a ConstantPathNode node.
680 def visit_constant_path_node(node)
681 commands << [inspect_node("ConstantPathNode", node), indent]
682 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
683 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
684 if (parent = node.parent).nil?
685 commands << ["├── parent: ∅\n", indent]
686 else
687 commands << ["├── parent:\n", indent]
688 commands << [parent, "#{indent}│ "]
689 end
690 if (name = node.name).nil?
691 commands << ["├── name: ∅\n", indent]
692 else
693 commands << ["├── name: #{name.inspect}\n", indent]
694 end
695 commands << ["├── delimiter_loc: #{inspect_location(node.delimiter_loc)}\n", indent]
696 commands << ["└── name_loc: #{inspect_location(node.name_loc)}\n", indent]
697 end
698
699 # Inspect a ConstantPathOperatorWriteNode node.
700 def visit_constant_path_operator_write_node(node)
701 commands << [inspect_node("ConstantPathOperatorWriteNode", node), indent]
702 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
703 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
704 commands << ["├── target:\n", indent]
705 commands << [node.target, "#{indent}│ "]
706 commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
707 commands << ["├── value:\n", indent]
708 commands << [node.value, "#{indent}│ "]
709 commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
710 end
711
712 # Inspect a ConstantPathOrWriteNode node.
713 def visit_constant_path_or_write_node(node)
714 commands << [inspect_node("ConstantPathOrWriteNode", node), indent]
715 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
716 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
717 commands << ["├── target:\n", indent]
718 commands << [node.target, "#{indent}│ "]
719 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
720 commands << ["└── value:\n", indent]
721 commands << [node.value, "#{indent} "]
722 end
723
724 # Inspect a ConstantPathTargetNode node.
725 def visit_constant_path_target_node(node)
726 commands << [inspect_node("ConstantPathTargetNode", node), indent]
727 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
728 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
729 if (parent = node.parent).nil?
730 commands << ["├── parent: ∅\n", indent]
731 else
732 commands << ["├── parent:\n", indent]
733 commands << [parent, "#{indent}│ "]
734 end
735 if (name = node.name).nil?
736 commands << ["├── name: ∅\n", indent]
737 else
738 commands << ["├── name: #{name.inspect}\n", indent]
739 end
740 commands << ["├── delimiter_loc: #{inspect_location(node.delimiter_loc)}\n", indent]
741 commands << ["└── name_loc: #{inspect_location(node.name_loc)}\n", indent]
742 end
743
744 # Inspect a ConstantPathWriteNode node.
745 def visit_constant_path_write_node(node)
746 commands << [inspect_node("ConstantPathWriteNode", node), indent]
747 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
748 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
749 commands << ["├── target:\n", indent]
750 commands << [node.target, "#{indent}│ "]
751 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
752 commands << ["└── value:\n", indent]
753 commands << [node.value, "#{indent} "]
754 end
755
756 # Inspect a ConstantReadNode node.
757 def visit_constant_read_node(node)
758 commands << [inspect_node("ConstantReadNode", node), indent]
759 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
760 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
761 commands << ["└── name: #{node.name.inspect}\n", indent]
762 end
763
764 # Inspect a ConstantTargetNode node.
765 def visit_constant_target_node(node)
766 commands << [inspect_node("ConstantTargetNode", node), indent]
767 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
768 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
769 commands << ["└── name: #{node.name.inspect}\n", indent]
770 end
771
772 # Inspect a ConstantWriteNode node.
773 def visit_constant_write_node(node)
774 commands << [inspect_node("ConstantWriteNode", node), indent]
775 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
776 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
777 commands << ["├── name: #{node.name.inspect}\n", indent]
778 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
779 commands << ["├── value:\n", indent]
780 commands << [node.value, "#{indent}│ "]
781 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
782 end
783
784 # Inspect a DefNode node.
785 def visit_def_node(node)
786 commands << [inspect_node("DefNode", node), indent]
787 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
788 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
789 commands << ["├── name: #{node.name.inspect}\n", indent]
790 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
791 if (receiver = node.receiver).nil?
792 commands << ["├── receiver: ∅\n", indent]
793 else
794 commands << ["├── receiver:\n", indent]
795 commands << [receiver, "#{indent}│ "]
796 end
797 if (parameters = node.parameters).nil?
798 commands << ["├── parameters: ∅\n", indent]
799 else
800 commands << ["├── parameters:\n", indent]
801 commands << [parameters, "#{indent}│ "]
802 end
803 if (body = node.body).nil?
804 commands << ["├── body: ∅\n", indent]
805 else
806 commands << ["├── body:\n", indent]
807 commands << [body, "#{indent}│ "]
808 end
809 commands << ["├── locals: #{node.locals.inspect}\n", indent]
810 commands << ["├── def_keyword_loc: #{inspect_location(node.def_keyword_loc)}\n", indent]
811 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
812 commands << ["├── lparen_loc: #{inspect_location(node.lparen_loc)}\n", indent]
813 commands << ["├── rparen_loc: #{inspect_location(node.rparen_loc)}\n", indent]
814 commands << ["├── equal_loc: #{inspect_location(node.equal_loc)}\n", indent]
815 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
816 end
817
818 # Inspect a DefinedNode node.
819 def visit_defined_node(node)
820 commands << [inspect_node("DefinedNode", node), indent]
821 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
822 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
823 commands << ["├── lparen_loc: #{inspect_location(node.lparen_loc)}\n", indent]
824 commands << ["├── value:\n", indent]
825 commands << [node.value, "#{indent}│ "]
826 commands << ["├── rparen_loc: #{inspect_location(node.rparen_loc)}\n", indent]
827 commands << ["└── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
828 end
829
830 # Inspect a ElseNode node.
831 def visit_else_node(node)
832 commands << [inspect_node("ElseNode", node), indent]
833 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
834 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
835 commands << ["├── else_keyword_loc: #{inspect_location(node.else_keyword_loc)}\n", indent]
836 if (statements = node.statements).nil?
837 commands << ["├── statements: ∅\n", indent]
838 else
839 commands << ["├── statements:\n", indent]
840 commands << [statements, "#{indent}│ "]
841 end
842 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
843 end
844
845 # Inspect a EmbeddedStatementsNode node.
846 def visit_embedded_statements_node(node)
847 commands << [inspect_node("EmbeddedStatementsNode", node), indent]
848 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
849 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
850 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
851 if (statements = node.statements).nil?
852 commands << ["├── statements: ∅\n", indent]
853 else
854 commands << ["├── statements:\n", indent]
855 commands << [statements, "#{indent}│ "]
856 end
857 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
858 end
859
860 # Inspect a EmbeddedVariableNode node.
861 def visit_embedded_variable_node(node)
862 commands << [inspect_node("EmbeddedVariableNode", node), indent]
863 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
864 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
865 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
866 commands << ["└── variable:\n", indent]
867 commands << [node.variable, "#{indent} "]
868 end
869
870 # Inspect a EnsureNode node.
871 def visit_ensure_node(node)
872 commands << [inspect_node("EnsureNode", node), indent]
873 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
874 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
875 commands << ["├── ensure_keyword_loc: #{inspect_location(node.ensure_keyword_loc)}\n", indent]
876 if (statements = node.statements).nil?
877 commands << ["├── statements: ∅\n", indent]
878 else
879 commands << ["├── statements:\n", indent]
880 commands << [statements, "#{indent}│ "]
881 end
882 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
883 end
884
885 # Inspect a FalseNode node.
886 def visit_false_node(node)
887 commands << [inspect_node("FalseNode", node), indent]
888 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
889 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
890 end
891
892 # Inspect a FindPatternNode node.
893 def visit_find_pattern_node(node)
894 commands << [inspect_node("FindPatternNode", node), indent]
895 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
896 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
897 if (constant = node.constant).nil?
898 commands << ["├── constant: ∅\n", indent]
899 else
900 commands << ["├── constant:\n", indent]
901 commands << [constant, "#{indent}│ "]
902 end
903 commands << ["├── left:\n", indent]
904 commands << [node.left, "#{indent}│ "]
905 commands << ["├── requireds: (length: #{(requireds = node.requireds).length})\n", indent]
906 if requireds.any?
907 requireds[0...-1].each do |child|
908 commands << [Replace.new("#{indent}│ ├── "), indent]
909 commands << [child, "#{indent}│ │ "]
910 end
911 commands << [Replace.new("#{indent}│ └── "), indent]
912 commands << [requireds[-1], "#{indent}│ "]
913 end
914 commands << ["├── right:\n", indent]
915 commands << [node.right, "#{indent}│ "]
916 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
917 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
918 end
919
920 # Inspect a FlipFlopNode node.
921 def visit_flip_flop_node(node)
922 commands << [inspect_node("FlipFlopNode", node), indent]
923 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("exclude_end" if node.exclude_end?)].compact
924 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
925 if (left = node.left).nil?
926 commands << ["├── left: ∅\n", indent]
927 else
928 commands << ["├── left:\n", indent]
929 commands << [left, "#{indent}│ "]
930 end
931 if (right = node.right).nil?
932 commands << ["├── right: ∅\n", indent]
933 else
934 commands << ["├── right:\n", indent]
935 commands << [right, "#{indent}│ "]
936 end
937 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
938 end
939
940 # Inspect a FloatNode node.
941 def visit_float_node(node)
942 commands << [inspect_node("FloatNode", node), indent]
943 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
944 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
945 commands << ["└── value: #{node.value.inspect}\n", indent]
946 end
947
948 # Inspect a ForNode node.
949 def visit_for_node(node)
950 commands << [inspect_node("ForNode", node), indent]
951 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
952 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
953 commands << ["├── index:\n", indent]
954 commands << [node.index, "#{indent}│ "]
955 commands << ["├── collection:\n", indent]
956 commands << [node.collection, "#{indent}│ "]
957 if (statements = node.statements).nil?
958 commands << ["├── statements: ∅\n", indent]
959 else
960 commands << ["├── statements:\n", indent]
961 commands << [statements, "#{indent}│ "]
962 end
963 commands << ["├── for_keyword_loc: #{inspect_location(node.for_keyword_loc)}\n", indent]
964 commands << ["├── in_keyword_loc: #{inspect_location(node.in_keyword_loc)}\n", indent]
965 commands << ["├── do_keyword_loc: #{inspect_location(node.do_keyword_loc)}\n", indent]
966 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
967 end
968
969 # Inspect a ForwardingArgumentsNode node.
970 def visit_forwarding_arguments_node(node)
971 commands << [inspect_node("ForwardingArgumentsNode", node), indent]
972 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
973 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
974 end
975
976 # Inspect a ForwardingParameterNode node.
977 def visit_forwarding_parameter_node(node)
978 commands << [inspect_node("ForwardingParameterNode", node), indent]
979 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
980 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
981 end
982
983 # Inspect a ForwardingSuperNode node.
984 def visit_forwarding_super_node(node)
985 commands << [inspect_node("ForwardingSuperNode", node), indent]
986 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
987 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
988 if (block = node.block).nil?
989 commands << ["└── block: ∅\n", indent]
990 else
991 commands << ["└── block:\n", indent]
992 commands << [block, "#{indent} "]
993 end
994 end
995
996 # Inspect a GlobalVariableAndWriteNode node.
997 def visit_global_variable_and_write_node(node)
998 commands << [inspect_node("GlobalVariableAndWriteNode", node), indent]
999 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1000 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1001 commands << ["├── name: #{node.name.inspect}\n", indent]
1002 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1003 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1004 commands << ["└── value:\n", indent]
1005 commands << [node.value, "#{indent} "]
1006 end
1007
1008 # Inspect a GlobalVariableOperatorWriteNode node.
1009 def visit_global_variable_operator_write_node(node)
1010 commands << [inspect_node("GlobalVariableOperatorWriteNode", node), indent]
1011 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1012 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1013 commands << ["├── name: #{node.name.inspect}\n", indent]
1014 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1015 commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
1016 commands << ["├── value:\n", indent]
1017 commands << [node.value, "#{indent}│ "]
1018 commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
1019 end
1020
1021 # Inspect a GlobalVariableOrWriteNode node.
1022 def visit_global_variable_or_write_node(node)
1023 commands << [inspect_node("GlobalVariableOrWriteNode", node), indent]
1024 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1025 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1026 commands << ["├── name: #{node.name.inspect}\n", indent]
1027 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1028 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1029 commands << ["└── value:\n", indent]
1030 commands << [node.value, "#{indent} "]
1031 end
1032
1033 # Inspect a GlobalVariableReadNode node.
1034 def visit_global_variable_read_node(node)
1035 commands << [inspect_node("GlobalVariableReadNode", node), indent]
1036 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1037 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1038 commands << ["└── name: #{node.name.inspect}\n", indent]
1039 end
1040
1041 # Inspect a GlobalVariableTargetNode node.
1042 def visit_global_variable_target_node(node)
1043 commands << [inspect_node("GlobalVariableTargetNode", node), indent]
1044 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1045 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1046 commands << ["└── name: #{node.name.inspect}\n", indent]
1047 end
1048
1049 # Inspect a GlobalVariableWriteNode node.
1050 def visit_global_variable_write_node(node)
1051 commands << [inspect_node("GlobalVariableWriteNode", node), indent]
1052 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1053 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1054 commands << ["├── name: #{node.name.inspect}\n", indent]
1055 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1056 commands << ["├── value:\n", indent]
1057 commands << [node.value, "#{indent}│ "]
1058 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1059 end
1060
1061 # Inspect a HashNode node.
1062 def visit_hash_node(node)
1063 commands << [inspect_node("HashNode", node), indent]
1064 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1065 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1066 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1067 commands << ["├── elements: (length: #{(elements = node.elements).length})\n", indent]
1068 if elements.any?
1069 elements[0...-1].each do |child|
1070 commands << [Replace.new("#{indent}│ ├── "), indent]
1071 commands << [child, "#{indent}│ │ "]
1072 end
1073 commands << [Replace.new("#{indent}│ └── "), indent]
1074 commands << [elements[-1], "#{indent}│ "]
1075 end
1076 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1077 end
1078
1079 # Inspect a HashPatternNode node.
1080 def visit_hash_pattern_node(node)
1081 commands << [inspect_node("HashPatternNode", node), indent]
1082 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1083 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1084 if (constant = node.constant).nil?
1085 commands << ["├── constant: ∅\n", indent]
1086 else
1087 commands << ["├── constant:\n", indent]
1088 commands << [constant, "#{indent}│ "]
1089 end
1090 commands << ["├── elements: (length: #{(elements = node.elements).length})\n", indent]
1091 if elements.any?
1092 elements[0...-1].each do |child|
1093 commands << [Replace.new("#{indent}│ ├── "), indent]
1094 commands << [child, "#{indent}│ │ "]
1095 end
1096 commands << [Replace.new("#{indent}│ └── "), indent]
1097 commands << [elements[-1], "#{indent}│ "]
1098 end
1099 if (rest = node.rest).nil?
1100 commands << ["├── rest: ∅\n", indent]
1101 else
1102 commands << ["├── rest:\n", indent]
1103 commands << [rest, "#{indent}│ "]
1104 end
1105 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1106 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1107 end
1108
1109 # Inspect a IfNode node.
1110 def visit_if_node(node)
1111 commands << [inspect_node("IfNode", node), indent]
1112 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1113 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1114 commands << ["├── if_keyword_loc: #{inspect_location(node.if_keyword_loc)}\n", indent]
1115 commands << ["├── predicate:\n", indent]
1116 commands << [node.predicate, "#{indent}│ "]
1117 commands << ["├── then_keyword_loc: #{inspect_location(node.then_keyword_loc)}\n", indent]
1118 if (statements = node.statements).nil?
1119 commands << ["├── statements: ∅\n", indent]
1120 else
1121 commands << ["├── statements:\n", indent]
1122 commands << [statements, "#{indent}│ "]
1123 end
1124 if (subsequent = node.subsequent).nil?
1125 commands << ["├── subsequent: ∅\n", indent]
1126 else
1127 commands << ["├── subsequent:\n", indent]
1128 commands << [subsequent, "#{indent}│ "]
1129 end
1130 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
1131 end
1132
1133 # Inspect a ImaginaryNode node.
1134 def visit_imaginary_node(node)
1135 commands << [inspect_node("ImaginaryNode", node), indent]
1136 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1137 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1138 commands << ["└── numeric:\n", indent]
1139 commands << [node.numeric, "#{indent} "]
1140 end
1141
1142 # Inspect a ImplicitNode node.
1143 def visit_implicit_node(node)
1144 commands << [inspect_node("ImplicitNode", node), indent]
1145 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1146 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1147 commands << ["└── value:\n", indent]
1148 commands << [node.value, "#{indent} "]
1149 end
1150
1151 # Inspect a ImplicitRestNode node.
1152 def visit_implicit_rest_node(node)
1153 commands << [inspect_node("ImplicitRestNode", node), indent]
1154 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1155 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1156 end
1157
1158 # Inspect a InNode node.
1159 def visit_in_node(node)
1160 commands << [inspect_node("InNode", node), indent]
1161 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1162 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1163 commands << ["├── pattern:\n", indent]
1164 commands << [node.pattern, "#{indent}│ "]
1165 if (statements = node.statements).nil?
1166 commands << ["├── statements: ∅\n", indent]
1167 else
1168 commands << ["├── statements:\n", indent]
1169 commands << [statements, "#{indent}│ "]
1170 end
1171 commands << ["├── in_loc: #{inspect_location(node.in_loc)}\n", indent]
1172 commands << ["└── then_loc: #{inspect_location(node.then_loc)}\n", indent]
1173 end
1174
1175 # Inspect a IndexAndWriteNode node.
1176 def visit_index_and_write_node(node)
1177 commands << [inspect_node("IndexAndWriteNode", node), indent]
1178 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
1179 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1180 if (receiver = node.receiver).nil?
1181 commands << ["├── receiver: ∅\n", indent]
1182 else
1183 commands << ["├── receiver:\n", indent]
1184 commands << [receiver, "#{indent}│ "]
1185 end
1186 commands << ["├── call_operator_loc: #{inspect_location(node.call_operator_loc)}\n", indent]
1187 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1188 if (arguments = node.arguments).nil?
1189 commands << ["├── arguments: ∅\n", indent]
1190 else
1191 commands << ["├── arguments:\n", indent]
1192 commands << [arguments, "#{indent}│ "]
1193 end
1194 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1195 if (block = node.block).nil?
1196 commands << ["├── block: ∅\n", indent]
1197 else
1198 commands << ["├── block:\n", indent]
1199 commands << [block, "#{indent}│ "]
1200 end
1201 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1202 commands << ["└── value:\n", indent]
1203 commands << [node.value, "#{indent} "]
1204 end
1205
1206 # Inspect a IndexOperatorWriteNode node.
1207 def visit_index_operator_write_node(node)
1208 commands << [inspect_node("IndexOperatorWriteNode", node), indent]
1209 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
1210 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1211 if (receiver = node.receiver).nil?
1212 commands << ["├── receiver: ∅\n", indent]
1213 else
1214 commands << ["├── receiver:\n", indent]
1215 commands << [receiver, "#{indent}│ "]
1216 end
1217 commands << ["├── call_operator_loc: #{inspect_location(node.call_operator_loc)}\n", indent]
1218 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1219 if (arguments = node.arguments).nil?
1220 commands << ["├── arguments: ∅\n", indent]
1221 else
1222 commands << ["├── arguments:\n", indent]
1223 commands << [arguments, "#{indent}│ "]
1224 end
1225 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1226 if (block = node.block).nil?
1227 commands << ["├── block: ∅\n", indent]
1228 else
1229 commands << ["├── block:\n", indent]
1230 commands << [block, "#{indent}│ "]
1231 end
1232 commands << ["├── binary_operator: #{node.binary_operator.inspect}\n", indent]
1233 commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
1234 commands << ["└── value:\n", indent]
1235 commands << [node.value, "#{indent} "]
1236 end
1237
1238 # Inspect a IndexOrWriteNode node.
1239 def visit_index_or_write_node(node)
1240 commands << [inspect_node("IndexOrWriteNode", node), indent]
1241 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
1242 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1243 if (receiver = node.receiver).nil?
1244 commands << ["├── receiver: ∅\n", indent]
1245 else
1246 commands << ["├── receiver:\n", indent]
1247 commands << [receiver, "#{indent}│ "]
1248 end
1249 commands << ["├── call_operator_loc: #{inspect_location(node.call_operator_loc)}\n", indent]
1250 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1251 if (arguments = node.arguments).nil?
1252 commands << ["├── arguments: ∅\n", indent]
1253 else
1254 commands << ["├── arguments:\n", indent]
1255 commands << [arguments, "#{indent}│ "]
1256 end
1257 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1258 if (block = node.block).nil?
1259 commands << ["├── block: ∅\n", indent]
1260 else
1261 commands << ["├── block:\n", indent]
1262 commands << [block, "#{indent}│ "]
1263 end
1264 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1265 commands << ["└── value:\n", indent]
1266 commands << [node.value, "#{indent} "]
1267 end
1268
1269 # Inspect a IndexTargetNode node.
1270 def visit_index_target_node(node)
1271 commands << [inspect_node("IndexTargetNode", node), indent]
1272 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("safe_navigation" if node.safe_navigation?), ("variable_call" if node.variable_call?), ("attribute_write" if node.attribute_write?), ("ignore_visibility" if node.ignore_visibility?)].compact
1273 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1274 commands << ["├── receiver:\n", indent]
1275 commands << [node.receiver, "#{indent}│ "]
1276 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1277 if (arguments = node.arguments).nil?
1278 commands << ["├── arguments: ∅\n", indent]
1279 else
1280 commands << ["├── arguments:\n", indent]
1281 commands << [arguments, "#{indent}│ "]
1282 end
1283 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1284 if (block = node.block).nil?
1285 commands << ["└── block: ∅\n", indent]
1286 else
1287 commands << ["└── block:\n", indent]
1288 commands << [block, "#{indent} "]
1289 end
1290 end
1291
1292 # Inspect a InstanceVariableAndWriteNode node.
1293 def visit_instance_variable_and_write_node(node)
1294 commands << [inspect_node("InstanceVariableAndWriteNode", node), indent]
1295 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1296 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1297 commands << ["├── name: #{node.name.inspect}\n", indent]
1298 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1299 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1300 commands << ["└── value:\n", indent]
1301 commands << [node.value, "#{indent} "]
1302 end
1303
1304 # Inspect a InstanceVariableOperatorWriteNode node.
1305 def visit_instance_variable_operator_write_node(node)
1306 commands << [inspect_node("InstanceVariableOperatorWriteNode", node), indent]
1307 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1308 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1309 commands << ["├── name: #{node.name.inspect}\n", indent]
1310 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1311 commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
1312 commands << ["├── value:\n", indent]
1313 commands << [node.value, "#{indent}│ "]
1314 commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
1315 end
1316
1317 # Inspect a InstanceVariableOrWriteNode node.
1318 def visit_instance_variable_or_write_node(node)
1319 commands << [inspect_node("InstanceVariableOrWriteNode", node), indent]
1320 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1321 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1322 commands << ["├── name: #{node.name.inspect}\n", indent]
1323 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1324 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1325 commands << ["└── value:\n", indent]
1326 commands << [node.value, "#{indent} "]
1327 end
1328
1329 # Inspect a InstanceVariableReadNode node.
1330 def visit_instance_variable_read_node(node)
1331 commands << [inspect_node("InstanceVariableReadNode", node), indent]
1332 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1333 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1334 commands << ["└── name: #{node.name.inspect}\n", indent]
1335 end
1336
1337 # Inspect a InstanceVariableTargetNode node.
1338 def visit_instance_variable_target_node(node)
1339 commands << [inspect_node("InstanceVariableTargetNode", node), indent]
1340 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1341 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1342 commands << ["└── name: #{node.name.inspect}\n", indent]
1343 end
1344
1345 # Inspect a InstanceVariableWriteNode node.
1346 def visit_instance_variable_write_node(node)
1347 commands << [inspect_node("InstanceVariableWriteNode", node), indent]
1348 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1349 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1350 commands << ["├── name: #{node.name.inspect}\n", indent]
1351 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1352 commands << ["├── value:\n", indent]
1353 commands << [node.value, "#{indent}│ "]
1354 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1355 end
1356
1357 # Inspect a IntegerNode node.
1358 def visit_integer_node(node)
1359 commands << [inspect_node("IntegerNode", node), indent]
1360 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("binary" if node.binary?), ("decimal" if node.decimal?), ("octal" if node.octal?), ("hexadecimal" if node.hexadecimal?)].compact
1361 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1362 commands << ["└── value: #{node.value.inspect}\n", indent]
1363 end
1364
1365 # Inspect a InterpolatedMatchLastLineNode node.
1366 def visit_interpolated_match_last_line_node(node)
1367 commands << [inspect_node("InterpolatedMatchLastLineNode", node), indent]
1368 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("ignore_case" if node.ignore_case?), ("extended" if node.extended?), ("multi_line" if node.multi_line?), ("once" if node.once?), ("euc_jp" if node.euc_jp?), ("ascii_8bit" if node.ascii_8bit?), ("windows_31j" if node.windows_31j?), ("utf_8" if node.utf_8?), ("forced_utf8_encoding" if node.forced_utf8_encoding?), ("forced_binary_encoding" if node.forced_binary_encoding?), ("forced_us_ascii_encoding" if node.forced_us_ascii_encoding?)].compact
1369 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1370 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1371 commands << ["├── parts: (length: #{(parts = node.parts).length})\n", indent]
1372 if parts.any?
1373 parts[0...-1].each do |child|
1374 commands << [Replace.new("#{indent}│ ├── "), indent]
1375 commands << [child, "#{indent}│ │ "]
1376 end
1377 commands << [Replace.new("#{indent}│ └── "), indent]
1378 commands << [parts[-1], "#{indent}│ "]
1379 end
1380 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1381 end
1382
1383 # Inspect a InterpolatedRegularExpressionNode node.
1384 def visit_interpolated_regular_expression_node(node)
1385 commands << [inspect_node("InterpolatedRegularExpressionNode", node), indent]
1386 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("ignore_case" if node.ignore_case?), ("extended" if node.extended?), ("multi_line" if node.multi_line?), ("once" if node.once?), ("euc_jp" if node.euc_jp?), ("ascii_8bit" if node.ascii_8bit?), ("windows_31j" if node.windows_31j?), ("utf_8" if node.utf_8?), ("forced_utf8_encoding" if node.forced_utf8_encoding?), ("forced_binary_encoding" if node.forced_binary_encoding?), ("forced_us_ascii_encoding" if node.forced_us_ascii_encoding?)].compact
1387 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1388 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1389 commands << ["├── parts: (length: #{(parts = node.parts).length})\n", indent]
1390 if parts.any?
1391 parts[0...-1].each do |child|
1392 commands << [Replace.new("#{indent}│ ├── "), indent]
1393 commands << [child, "#{indent}│ │ "]
1394 end
1395 commands << [Replace.new("#{indent}│ └── "), indent]
1396 commands << [parts[-1], "#{indent}│ "]
1397 end
1398 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1399 end
1400
1401 # Inspect a InterpolatedStringNode node.
1402 def visit_interpolated_string_node(node)
1403 commands << [inspect_node("InterpolatedStringNode", node), indent]
1404 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("frozen" if node.frozen?), ("mutable" if node.mutable?)].compact
1405 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1406 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1407 commands << ["├── parts: (length: #{(parts = node.parts).length})\n", indent]
1408 if parts.any?
1409 parts[0...-1].each do |child|
1410 commands << [Replace.new("#{indent}│ ├── "), indent]
1411 commands << [child, "#{indent}│ │ "]
1412 end
1413 commands << [Replace.new("#{indent}│ └── "), indent]
1414 commands << [parts[-1], "#{indent}│ "]
1415 end
1416 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1417 end
1418
1419 # Inspect a InterpolatedSymbolNode node.
1420 def visit_interpolated_symbol_node(node)
1421 commands << [inspect_node("InterpolatedSymbolNode", node), indent]
1422 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1423 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1424 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1425 commands << ["├── parts: (length: #{(parts = node.parts).length})\n", indent]
1426 if parts.any?
1427 parts[0...-1].each do |child|
1428 commands << [Replace.new("#{indent}│ ├── "), indent]
1429 commands << [child, "#{indent}│ │ "]
1430 end
1431 commands << [Replace.new("#{indent}│ └── "), indent]
1432 commands << [parts[-1], "#{indent}│ "]
1433 end
1434 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1435 end
1436
1437 # Inspect a InterpolatedXStringNode node.
1438 def visit_interpolated_x_string_node(node)
1439 commands << [inspect_node("InterpolatedXStringNode", node), indent]
1440 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1441 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1442 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1443 commands << ["├── parts: (length: #{(parts = node.parts).length})\n", indent]
1444 if parts.any?
1445 parts[0...-1].each do |child|
1446 commands << [Replace.new("#{indent}│ ├── "), indent]
1447 commands << [child, "#{indent}│ │ "]
1448 end
1449 commands << [Replace.new("#{indent}│ └── "), indent]
1450 commands << [parts[-1], "#{indent}│ "]
1451 end
1452 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1453 end
1454
1455 # Inspect a ItLocalVariableReadNode node.
1456 def visit_it_local_variable_read_node(node)
1457 commands << [inspect_node("ItLocalVariableReadNode", node), indent]
1458 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1459 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1460 end
1461
1462 # Inspect a ItParametersNode node.
1463 def visit_it_parameters_node(node)
1464 commands << [inspect_node("ItParametersNode", node), indent]
1465 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1466 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1467 end
1468
1469 # Inspect a KeywordHashNode node.
1470 def visit_keyword_hash_node(node)
1471 commands << [inspect_node("KeywordHashNode", node), indent]
1472 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("symbol_keys" if node.symbol_keys?)].compact
1473 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1474 commands << ["└── elements: (length: #{(elements = node.elements).length})\n", indent]
1475 if elements.any?
1476 elements[0...-1].each do |child|
1477 commands << [Replace.new("#{indent} ├── "), indent]
1478 commands << [child, "#{indent} │ "]
1479 end
1480 commands << [Replace.new("#{indent} └── "), indent]
1481 commands << [elements[-1], "#{indent} "]
1482 end
1483 end
1484
1485 # Inspect a KeywordRestParameterNode node.
1486 def visit_keyword_rest_parameter_node(node)
1487 commands << [inspect_node("KeywordRestParameterNode", node), indent]
1488 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("repeated_parameter" if node.repeated_parameter?)].compact
1489 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1490 if (name = node.name).nil?
1491 commands << ["├── name: ∅\n", indent]
1492 else
1493 commands << ["├── name: #{name.inspect}\n", indent]
1494 end
1495 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1496 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1497 end
1498
1499 # Inspect a LambdaNode node.
1500 def visit_lambda_node(node)
1501 commands << [inspect_node("LambdaNode", node), indent]
1502 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1503 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1504 commands << ["├── locals: #{node.locals.inspect}\n", indent]
1505 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1506 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1507 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1508 if (parameters = node.parameters).nil?
1509 commands << ["├── parameters: ∅\n", indent]
1510 else
1511 commands << ["├── parameters:\n", indent]
1512 commands << [parameters, "#{indent}│ "]
1513 end
1514 if (body = node.body).nil?
1515 commands << ["└── body: ∅\n", indent]
1516 else
1517 commands << ["└── body:\n", indent]
1518 commands << [body, "#{indent} "]
1519 end
1520 end
1521
1522 # Inspect a LocalVariableAndWriteNode node.
1523 def visit_local_variable_and_write_node(node)
1524 commands << [inspect_node("LocalVariableAndWriteNode", node), indent]
1525 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1526 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1527 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1528 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1529 commands << ["├── value:\n", indent]
1530 commands << [node.value, "#{indent}│ "]
1531 commands << ["├── name: #{node.name.inspect}\n", indent]
1532 commands << ["└── depth: #{node.depth.inspect}\n", indent]
1533 end
1534
1535 # Inspect a LocalVariableOperatorWriteNode node.
1536 def visit_local_variable_operator_write_node(node)
1537 commands << [inspect_node("LocalVariableOperatorWriteNode", node), indent]
1538 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1539 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1540 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1541 commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
1542 commands << ["├── value:\n", indent]
1543 commands << [node.value, "#{indent}│ "]
1544 commands << ["├── name: #{node.name.inspect}\n", indent]
1545 commands << ["├── binary_operator: #{node.binary_operator.inspect}\n", indent]
1546 commands << ["└── depth: #{node.depth.inspect}\n", indent]
1547 end
1548
1549 # Inspect a LocalVariableOrWriteNode node.
1550 def visit_local_variable_or_write_node(node)
1551 commands << [inspect_node("LocalVariableOrWriteNode", node), indent]
1552 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1553 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1554 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1555 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1556 commands << ["├── value:\n", indent]
1557 commands << [node.value, "#{indent}│ "]
1558 commands << ["├── name: #{node.name.inspect}\n", indent]
1559 commands << ["└── depth: #{node.depth.inspect}\n", indent]
1560 end
1561
1562 # Inspect a LocalVariableReadNode node.
1563 def visit_local_variable_read_node(node)
1564 commands << [inspect_node("LocalVariableReadNode", node), indent]
1565 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1566 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1567 commands << ["├── name: #{node.name.inspect}\n", indent]
1568 commands << ["└── depth: #{node.depth.inspect}\n", indent]
1569 end
1570
1571 # Inspect a LocalVariableTargetNode node.
1572 def visit_local_variable_target_node(node)
1573 commands << [inspect_node("LocalVariableTargetNode", node), indent]
1574 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1575 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1576 commands << ["├── name: #{node.name.inspect}\n", indent]
1577 commands << ["└── depth: #{node.depth.inspect}\n", indent]
1578 end
1579
1580 # Inspect a LocalVariableWriteNode node.
1581 def visit_local_variable_write_node(node)
1582 commands << [inspect_node("LocalVariableWriteNode", node), indent]
1583 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1584 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1585 commands << ["├── name: #{node.name.inspect}\n", indent]
1586 commands << ["├── depth: #{node.depth.inspect}\n", indent]
1587 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1588 commands << ["├── value:\n", indent]
1589 commands << [node.value, "#{indent}│ "]
1590 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1591 end
1592
1593 # Inspect a MatchLastLineNode node.
1594 def visit_match_last_line_node(node)
1595 commands << [inspect_node("MatchLastLineNode", node), indent]
1596 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("ignore_case" if node.ignore_case?), ("extended" if node.extended?), ("multi_line" if node.multi_line?), ("once" if node.once?), ("euc_jp" if node.euc_jp?), ("ascii_8bit" if node.ascii_8bit?), ("windows_31j" if node.windows_31j?), ("utf_8" if node.utf_8?), ("forced_utf8_encoding" if node.forced_utf8_encoding?), ("forced_binary_encoding" if node.forced_binary_encoding?), ("forced_us_ascii_encoding" if node.forced_us_ascii_encoding?)].compact
1597 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1598 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1599 commands << ["├── content_loc: #{inspect_location(node.content_loc)}\n", indent]
1600 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1601 commands << ["└── unescaped: #{node.unescaped.inspect}\n", indent]
1602 end
1603
1604 # Inspect a MatchPredicateNode node.
1605 def visit_match_predicate_node(node)
1606 commands << [inspect_node("MatchPredicateNode", node), indent]
1607 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1608 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1609 commands << ["├── value:\n", indent]
1610 commands << [node.value, "#{indent}│ "]
1611 commands << ["├── pattern:\n", indent]
1612 commands << [node.pattern, "#{indent}│ "]
1613 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1614 end
1615
1616 # Inspect a MatchRequiredNode node.
1617 def visit_match_required_node(node)
1618 commands << [inspect_node("MatchRequiredNode", node), indent]
1619 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1620 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1621 commands << ["├── value:\n", indent]
1622 commands << [node.value, "#{indent}│ "]
1623 commands << ["├── pattern:\n", indent]
1624 commands << [node.pattern, "#{indent}│ "]
1625 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1626 end
1627
1628 # Inspect a MatchWriteNode node.
1629 def visit_match_write_node(node)
1630 commands << [inspect_node("MatchWriteNode", node), indent]
1631 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1632 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1633 commands << ["├── call:\n", indent]
1634 commands << [node.call, "#{indent}│ "]
1635 commands << ["└── targets: (length: #{(targets = node.targets).length})\n", indent]
1636 if targets.any?
1637 targets[0...-1].each do |child|
1638 commands << [Replace.new("#{indent} ├── "), indent]
1639 commands << [child, "#{indent} │ "]
1640 end
1641 commands << [Replace.new("#{indent} └── "), indent]
1642 commands << [targets[-1], "#{indent} "]
1643 end
1644 end
1645
1646 # Inspect a MissingNode node.
1647 def visit_missing_node(node)
1648 commands << [inspect_node("MissingNode", node), indent]
1649 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1650 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1651 end
1652
1653 # Inspect a ModuleNode node.
1654 def visit_module_node(node)
1655 commands << [inspect_node("ModuleNode", node), indent]
1656 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1657 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1658 commands << ["├── locals: #{node.locals.inspect}\n", indent]
1659 commands << ["├── module_keyword_loc: #{inspect_location(node.module_keyword_loc)}\n", indent]
1660 commands << ["├── constant_path:\n", indent]
1661 commands << [node.constant_path, "#{indent}│ "]
1662 if (body = node.body).nil?
1663 commands << ["├── body: ∅\n", indent]
1664 else
1665 commands << ["├── body:\n", indent]
1666 commands << [body, "#{indent}│ "]
1667 end
1668 commands << ["├── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
1669 commands << ["└── name: #{node.name.inspect}\n", indent]
1670 end
1671
1672 # Inspect a MultiTargetNode node.
1673 def visit_multi_target_node(node)
1674 commands << [inspect_node("MultiTargetNode", node), indent]
1675 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1676 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1677 commands << ["├── lefts: (length: #{(lefts = node.lefts).length})\n", indent]
1678 if lefts.any?
1679 lefts[0...-1].each do |child|
1680 commands << [Replace.new("#{indent}│ ├── "), indent]
1681 commands << [child, "#{indent}│ │ "]
1682 end
1683 commands << [Replace.new("#{indent}│ └── "), indent]
1684 commands << [lefts[-1], "#{indent}│ "]
1685 end
1686 if (rest = node.rest).nil?
1687 commands << ["├── rest: ∅\n", indent]
1688 else
1689 commands << ["├── rest:\n", indent]
1690 commands << [rest, "#{indent}│ "]
1691 end
1692 commands << ["├── rights: (length: #{(rights = node.rights).length})\n", indent]
1693 if rights.any?
1694 rights[0...-1].each do |child|
1695 commands << [Replace.new("#{indent}│ ├── "), indent]
1696 commands << [child, "#{indent}│ │ "]
1697 end
1698 commands << [Replace.new("#{indent}│ └── "), indent]
1699 commands << [rights[-1], "#{indent}│ "]
1700 end
1701 commands << ["├── lparen_loc: #{inspect_location(node.lparen_loc)}\n", indent]
1702 commands << ["└── rparen_loc: #{inspect_location(node.rparen_loc)}\n", indent]
1703 end
1704
1705 # Inspect a MultiWriteNode node.
1706 def visit_multi_write_node(node)
1707 commands << [inspect_node("MultiWriteNode", node), indent]
1708 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1709 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1710 commands << ["├── lefts: (length: #{(lefts = node.lefts).length})\n", indent]
1711 if lefts.any?
1712 lefts[0...-1].each do |child|
1713 commands << [Replace.new("#{indent}│ ├── "), indent]
1714 commands << [child, "#{indent}│ │ "]
1715 end
1716 commands << [Replace.new("#{indent}│ └── "), indent]
1717 commands << [lefts[-1], "#{indent}│ "]
1718 end
1719 if (rest = node.rest).nil?
1720 commands << ["├── rest: ∅\n", indent]
1721 else
1722 commands << ["├── rest:\n", indent]
1723 commands << [rest, "#{indent}│ "]
1724 end
1725 commands << ["├── rights: (length: #{(rights = node.rights).length})\n", indent]
1726 if rights.any?
1727 rights[0...-1].each do |child|
1728 commands << [Replace.new("#{indent}│ ├── "), indent]
1729 commands << [child, "#{indent}│ │ "]
1730 end
1731 commands << [Replace.new("#{indent}│ └── "), indent]
1732 commands << [rights[-1], "#{indent}│ "]
1733 end
1734 commands << ["├── lparen_loc: #{inspect_location(node.lparen_loc)}\n", indent]
1735 commands << ["├── rparen_loc: #{inspect_location(node.rparen_loc)}\n", indent]
1736 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1737 commands << ["└── value:\n", indent]
1738 commands << [node.value, "#{indent} "]
1739 end
1740
1741 # Inspect a NextNode node.
1742 def visit_next_node(node)
1743 commands << [inspect_node("NextNode", node), indent]
1744 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1745 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1746 if (arguments = node.arguments).nil?
1747 commands << ["├── arguments: ∅\n", indent]
1748 else
1749 commands << ["├── arguments:\n", indent]
1750 commands << [arguments, "#{indent}│ "]
1751 end
1752 commands << ["└── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
1753 end
1754
1755 # Inspect a NilNode node.
1756 def visit_nil_node(node)
1757 commands << [inspect_node("NilNode", node), indent]
1758 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1759 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1760 end
1761
1762 # Inspect a NoKeywordsParameterNode node.
1763 def visit_no_keywords_parameter_node(node)
1764 commands << [inspect_node("NoKeywordsParameterNode", node), indent]
1765 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1766 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1767 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1768 commands << ["└── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
1769 end
1770
1771 # Inspect a NumberedParametersNode node.
1772 def visit_numbered_parameters_node(node)
1773 commands << [inspect_node("NumberedParametersNode", node), indent]
1774 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1775 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1776 commands << ["└── maximum: #{node.maximum.inspect}\n", indent]
1777 end
1778
1779 # Inspect a NumberedReferenceReadNode node.
1780 def visit_numbered_reference_read_node(node)
1781 commands << [inspect_node("NumberedReferenceReadNode", node), indent]
1782 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1783 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1784 commands << ["└── number: #{node.number.inspect}\n", indent]
1785 end
1786
1787 # Inspect a OptionalKeywordParameterNode node.
1788 def visit_optional_keyword_parameter_node(node)
1789 commands << [inspect_node("OptionalKeywordParameterNode", node), indent]
1790 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("repeated_parameter" if node.repeated_parameter?)].compact
1791 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1792 commands << ["├── name: #{node.name.inspect}\n", indent]
1793 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1794 commands << ["└── value:\n", indent]
1795 commands << [node.value, "#{indent} "]
1796 end
1797
1798 # Inspect a OptionalParameterNode node.
1799 def visit_optional_parameter_node(node)
1800 commands << [inspect_node("OptionalParameterNode", node), indent]
1801 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("repeated_parameter" if node.repeated_parameter?)].compact
1802 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1803 commands << ["├── name: #{node.name.inspect}\n", indent]
1804 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
1805 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1806 commands << ["└── value:\n", indent]
1807 commands << [node.value, "#{indent} "]
1808 end
1809
1810 # Inspect a OrNode node.
1811 def visit_or_node(node)
1812 commands << [inspect_node("OrNode", node), indent]
1813 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1814 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1815 commands << ["├── left:\n", indent]
1816 commands << [node.left, "#{indent}│ "]
1817 commands << ["├── right:\n", indent]
1818 commands << [node.right, "#{indent}│ "]
1819 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1820 end
1821
1822 # Inspect a ParametersNode node.
1823 def visit_parameters_node(node)
1824 commands << [inspect_node("ParametersNode", node), indent]
1825 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1826 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1827 commands << ["├── requireds: (length: #{(requireds = node.requireds).length})\n", indent]
1828 if requireds.any?
1829 requireds[0...-1].each do |child|
1830 commands << [Replace.new("#{indent}│ ├── "), indent]
1831 commands << [child, "#{indent}│ │ "]
1832 end
1833 commands << [Replace.new("#{indent}│ └── "), indent]
1834 commands << [requireds[-1], "#{indent}│ "]
1835 end
1836 commands << ["├── optionals: (length: #{(optionals = node.optionals).length})\n", indent]
1837 if optionals.any?
1838 optionals[0...-1].each do |child|
1839 commands << [Replace.new("#{indent}│ ├── "), indent]
1840 commands << [child, "#{indent}│ │ "]
1841 end
1842 commands << [Replace.new("#{indent}│ └── "), indent]
1843 commands << [optionals[-1], "#{indent}│ "]
1844 end
1845 if (rest = node.rest).nil?
1846 commands << ["├── rest: ∅\n", indent]
1847 else
1848 commands << ["├── rest:\n", indent]
1849 commands << [rest, "#{indent}│ "]
1850 end
1851 commands << ["├── posts: (length: #{(posts = node.posts).length})\n", indent]
1852 if posts.any?
1853 posts[0...-1].each do |child|
1854 commands << [Replace.new("#{indent}│ ├── "), indent]
1855 commands << [child, "#{indent}│ │ "]
1856 end
1857 commands << [Replace.new("#{indent}│ └── "), indent]
1858 commands << [posts[-1], "#{indent}│ "]
1859 end
1860 commands << ["├── keywords: (length: #{(keywords = node.keywords).length})\n", indent]
1861 if keywords.any?
1862 keywords[0...-1].each do |child|
1863 commands << [Replace.new("#{indent}│ ├── "), indent]
1864 commands << [child, "#{indent}│ │ "]
1865 end
1866 commands << [Replace.new("#{indent}│ └── "), indent]
1867 commands << [keywords[-1], "#{indent}│ "]
1868 end
1869 if (keyword_rest = node.keyword_rest).nil?
1870 commands << ["├── keyword_rest: ∅\n", indent]
1871 else
1872 commands << ["├── keyword_rest:\n", indent]
1873 commands << [keyword_rest, "#{indent}│ "]
1874 end
1875 if (block = node.block).nil?
1876 commands << ["└── block: ∅\n", indent]
1877 else
1878 commands << ["└── block:\n", indent]
1879 commands << [block, "#{indent} "]
1880 end
1881 end
1882
1883 # Inspect a ParenthesesNode node.
1884 def visit_parentheses_node(node)
1885 commands << [inspect_node("ParenthesesNode", node), indent]
1886 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("multiple_statements" if node.multiple_statements?)].compact
1887 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1888 if (body = node.body).nil?
1889 commands << ["├── body: ∅\n", indent]
1890 else
1891 commands << ["├── body:\n", indent]
1892 commands << [body, "#{indent}│ "]
1893 end
1894 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1895 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1896 end
1897
1898 # Inspect a PinnedExpressionNode node.
1899 def visit_pinned_expression_node(node)
1900 commands << [inspect_node("PinnedExpressionNode", node), indent]
1901 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1902 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1903 commands << ["├── expression:\n", indent]
1904 commands << [node.expression, "#{indent}│ "]
1905 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1906 commands << ["├── lparen_loc: #{inspect_location(node.lparen_loc)}\n", indent]
1907 commands << ["└── rparen_loc: #{inspect_location(node.rparen_loc)}\n", indent]
1908 end
1909
1910 # Inspect a PinnedVariableNode node.
1911 def visit_pinned_variable_node(node)
1912 commands << [inspect_node("PinnedVariableNode", node), indent]
1913 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1914 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1915 commands << ["├── variable:\n", indent]
1916 commands << [node.variable, "#{indent}│ "]
1917 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1918 end
1919
1920 # Inspect a PostExecutionNode node.
1921 def visit_post_execution_node(node)
1922 commands << [inspect_node("PostExecutionNode", node), indent]
1923 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1924 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1925 if (statements = node.statements).nil?
1926 commands << ["├── statements: ∅\n", indent]
1927 else
1928 commands << ["├── statements:\n", indent]
1929 commands << [statements, "#{indent}│ "]
1930 end
1931 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
1932 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1933 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1934 end
1935
1936 # Inspect a PreExecutionNode node.
1937 def visit_pre_execution_node(node)
1938 commands << [inspect_node("PreExecutionNode", node), indent]
1939 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1940 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1941 if (statements = node.statements).nil?
1942 commands << ["├── statements: ∅\n", indent]
1943 else
1944 commands << ["├── statements:\n", indent]
1945 commands << [statements, "#{indent}│ "]
1946 end
1947 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
1948 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
1949 commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
1950 end
1951
1952 # Inspect a ProgramNode node.
1953 def visit_program_node(node)
1954 commands << [inspect_node("ProgramNode", node), indent]
1955 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1956 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1957 commands << ["├── locals: #{node.locals.inspect}\n", indent]
1958 commands << ["└── statements:\n", indent]
1959 commands << [node.statements, "#{indent} "]
1960 end
1961
1962 # Inspect a RangeNode node.
1963 def visit_range_node(node)
1964 commands << [inspect_node("RangeNode", node), indent]
1965 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("exclude_end" if node.exclude_end?)].compact
1966 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1967 if (left = node.left).nil?
1968 commands << ["├── left: ∅\n", indent]
1969 else
1970 commands << ["├── left:\n", indent]
1971 commands << [left, "#{indent}│ "]
1972 end
1973 if (right = node.right).nil?
1974 commands << ["├── right: ∅\n", indent]
1975 else
1976 commands << ["├── right:\n", indent]
1977 commands << [right, "#{indent}│ "]
1978 end
1979 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
1980 end
1981
1982 # Inspect a RationalNode node.
1983 def visit_rational_node(node)
1984 commands << [inspect_node("RationalNode", node), indent]
1985 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("binary" if node.binary?), ("decimal" if node.decimal?), ("octal" if node.octal?), ("hexadecimal" if node.hexadecimal?)].compact
1986 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1987 commands << ["├── numerator: #{node.numerator.inspect}\n", indent]
1988 commands << ["└── denominator: #{node.denominator.inspect}\n", indent]
1989 end
1990
1991 # Inspect a RedoNode node.
1992 def visit_redo_node(node)
1993 commands << [inspect_node("RedoNode", node), indent]
1994 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
1995 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
1996 end
1997
1998 # Inspect a RegularExpressionNode node.
1999 def visit_regular_expression_node(node)
2000 commands << [inspect_node("RegularExpressionNode", node), indent]
2001 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("ignore_case" if node.ignore_case?), ("extended" if node.extended?), ("multi_line" if node.multi_line?), ("once" if node.once?), ("euc_jp" if node.euc_jp?), ("ascii_8bit" if node.ascii_8bit?), ("windows_31j" if node.windows_31j?), ("utf_8" if node.utf_8?), ("forced_utf8_encoding" if node.forced_utf8_encoding?), ("forced_binary_encoding" if node.forced_binary_encoding?), ("forced_us_ascii_encoding" if node.forced_us_ascii_encoding?)].compact
2002 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2003 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
2004 commands << ["├── content_loc: #{inspect_location(node.content_loc)}\n", indent]
2005 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
2006 commands << ["└── unescaped: #{node.unescaped.inspect}\n", indent]
2007 end
2008
2009 # Inspect a RequiredKeywordParameterNode node.
2010 def visit_required_keyword_parameter_node(node)
2011 commands << [inspect_node("RequiredKeywordParameterNode", node), indent]
2012 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("repeated_parameter" if node.repeated_parameter?)].compact
2013 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2014 commands << ["├── name: #{node.name.inspect}\n", indent]
2015 commands << ["└── name_loc: #{inspect_location(node.name_loc)}\n", indent]
2016 end
2017
2018 # Inspect a RequiredParameterNode node.
2019 def visit_required_parameter_node(node)
2020 commands << [inspect_node("RequiredParameterNode", node), indent]
2021 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("repeated_parameter" if node.repeated_parameter?)].compact
2022 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2023 commands << ["└── name: #{node.name.inspect}\n", indent]
2024 end
2025
2026 # Inspect a RescueModifierNode node.
2027 def visit_rescue_modifier_node(node)
2028 commands << [inspect_node("RescueModifierNode", node), indent]
2029 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2030 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2031 commands << ["├── expression:\n", indent]
2032 commands << [node.expression, "#{indent}│ "]
2033 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2034 commands << ["└── rescue_expression:\n", indent]
2035 commands << [node.rescue_expression, "#{indent} "]
2036 end
2037
2038 # Inspect a RescueNode node.
2039 def visit_rescue_node(node)
2040 commands << [inspect_node("RescueNode", node), indent]
2041 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2042 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2043 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2044 commands << ["├── exceptions: (length: #{(exceptions = node.exceptions).length})\n", indent]
2045 if exceptions.any?
2046 exceptions[0...-1].each do |child|
2047 commands << [Replace.new("#{indent}│ ├── "), indent]
2048 commands << [child, "#{indent}│ │ "]
2049 end
2050 commands << [Replace.new("#{indent}│ └── "), indent]
2051 commands << [exceptions[-1], "#{indent}│ "]
2052 end
2053 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
2054 if (reference = node.reference).nil?
2055 commands << ["├── reference: ∅\n", indent]
2056 else
2057 commands << ["├── reference:\n", indent]
2058 commands << [reference, "#{indent}│ "]
2059 end
2060 commands << ["├── then_keyword_loc: #{inspect_location(node.then_keyword_loc)}\n", indent]
2061 if (statements = node.statements).nil?
2062 commands << ["├── statements: ∅\n", indent]
2063 else
2064 commands << ["├── statements:\n", indent]
2065 commands << [statements, "#{indent}│ "]
2066 end
2067 if (subsequent = node.subsequent).nil?
2068 commands << ["└── subsequent: ∅\n", indent]
2069 else
2070 commands << ["└── subsequent:\n", indent]
2071 commands << [subsequent, "#{indent} "]
2072 end
2073 end
2074
2075 # Inspect a RestParameterNode node.
2076 def visit_rest_parameter_node(node)
2077 commands << [inspect_node("RestParameterNode", node), indent]
2078 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("repeated_parameter" if node.repeated_parameter?)].compact
2079 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2080 if (name = node.name).nil?
2081 commands << ["├── name: ∅\n", indent]
2082 else
2083 commands << ["├── name: #{name.inspect}\n", indent]
2084 end
2085 commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
2086 commands << ["└── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
2087 end
2088
2089 # Inspect a RetryNode node.
2090 def visit_retry_node(node)
2091 commands << [inspect_node("RetryNode", node), indent]
2092 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2093 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2094 end
2095
2096 # Inspect a ReturnNode node.
2097 def visit_return_node(node)
2098 commands << [inspect_node("ReturnNode", node), indent]
2099 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2100 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2101 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2102 if (arguments = node.arguments).nil?
2103 commands << ["└── arguments: ∅\n", indent]
2104 else
2105 commands << ["└── arguments:\n", indent]
2106 commands << [arguments, "#{indent} "]
2107 end
2108 end
2109
2110 # Inspect a SelfNode node.
2111 def visit_self_node(node)
2112 commands << [inspect_node("SelfNode", node), indent]
2113 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2114 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2115 end
2116
2117 # Inspect a ShareableConstantNode node.
2118 def visit_shareable_constant_node(node)
2119 commands << [inspect_node("ShareableConstantNode", node), indent]
2120 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("literal" if node.literal?), ("experimental_everything" if node.experimental_everything?), ("experimental_copy" if node.experimental_copy?)].compact
2121 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2122 commands << ["└── write:\n", indent]
2123 commands << [node.write, "#{indent} "]
2124 end
2125
2126 # Inspect a SingletonClassNode node.
2127 def visit_singleton_class_node(node)
2128 commands << [inspect_node("SingletonClassNode", node), indent]
2129 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2130 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2131 commands << ["├── locals: #{node.locals.inspect}\n", indent]
2132 commands << ["├── class_keyword_loc: #{inspect_location(node.class_keyword_loc)}\n", indent]
2133 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
2134 commands << ["├── expression:\n", indent]
2135 commands << [node.expression, "#{indent}│ "]
2136 if (body = node.body).nil?
2137 commands << ["├── body: ∅\n", indent]
2138 else
2139 commands << ["├── body:\n", indent]
2140 commands << [body, "#{indent}│ "]
2141 end
2142 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
2143 end
2144
2145 # Inspect a SourceEncodingNode node.
2146 def visit_source_encoding_node(node)
2147 commands << [inspect_node("SourceEncodingNode", node), indent]
2148 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2149 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2150 end
2151
2152 # Inspect a SourceFileNode node.
2153 def visit_source_file_node(node)
2154 commands << [inspect_node("SourceFileNode", node), indent]
2155 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("forced_utf8_encoding" if node.forced_utf8_encoding?), ("forced_binary_encoding" if node.forced_binary_encoding?), ("frozen" if node.frozen?), ("mutable" if node.mutable?)].compact
2156 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2157 commands << ["└── filepath: #{node.filepath.inspect}\n", indent]
2158 end
2159
2160 # Inspect a SourceLineNode node.
2161 def visit_source_line_node(node)
2162 commands << [inspect_node("SourceLineNode", node), indent]
2163 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2164 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2165 end
2166
2167 # Inspect a SplatNode node.
2168 def visit_splat_node(node)
2169 commands << [inspect_node("SplatNode", node), indent]
2170 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2171 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2172 commands << ["├── operator_loc: #{inspect_location(node.operator_loc)}\n", indent]
2173 if (expression = node.expression).nil?
2174 commands << ["└── expression: ∅\n", indent]
2175 else
2176 commands << ["└── expression:\n", indent]
2177 commands << [expression, "#{indent} "]
2178 end
2179 end
2180
2181 # Inspect a StatementsNode node.
2182 def visit_statements_node(node)
2183 commands << [inspect_node("StatementsNode", node), indent]
2184 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2185 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2186 commands << ["└── body: (length: #{(body = node.body).length})\n", indent]
2187 if body.any?
2188 body[0...-1].each do |child|
2189 commands << [Replace.new("#{indent} ├── "), indent]
2190 commands << [child, "#{indent} │ "]
2191 end
2192 commands << [Replace.new("#{indent} └── "), indent]
2193 commands << [body[-1], "#{indent} "]
2194 end
2195 end
2196
2197 # Inspect a StringNode node.
2198 def visit_string_node(node)
2199 commands << [inspect_node("StringNode", node), indent]
2200 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("forced_utf8_encoding" if node.forced_utf8_encoding?), ("forced_binary_encoding" if node.forced_binary_encoding?), ("frozen" if node.frozen?), ("mutable" if node.mutable?)].compact
2201 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2202 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
2203 commands << ["├── content_loc: #{inspect_location(node.content_loc)}\n", indent]
2204 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
2205 commands << ["└── unescaped: #{node.unescaped.inspect}\n", indent]
2206 end
2207
2208 # Inspect a SuperNode node.
2209 def visit_super_node(node)
2210 commands << [inspect_node("SuperNode", node), indent]
2211 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2212 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2213 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2214 commands << ["├── lparen_loc: #{inspect_location(node.lparen_loc)}\n", indent]
2215 if (arguments = node.arguments).nil?
2216 commands << ["├── arguments: ∅\n", indent]
2217 else
2218 commands << ["├── arguments:\n", indent]
2219 commands << [arguments, "#{indent}│ "]
2220 end
2221 commands << ["├── rparen_loc: #{inspect_location(node.rparen_loc)}\n", indent]
2222 if (block = node.block).nil?
2223 commands << ["└── block: ∅\n", indent]
2224 else
2225 commands << ["└── block:\n", indent]
2226 commands << [block, "#{indent} "]
2227 end
2228 end
2229
2230 # Inspect a SymbolNode node.
2231 def visit_symbol_node(node)
2232 commands << [inspect_node("SymbolNode", node), indent]
2233 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("forced_utf8_encoding" if node.forced_utf8_encoding?), ("forced_binary_encoding" if node.forced_binary_encoding?), ("forced_us_ascii_encoding" if node.forced_us_ascii_encoding?)].compact
2234 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2235 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
2236 commands << ["├── value_loc: #{inspect_location(node.value_loc)}\n", indent]
2237 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
2238 commands << ["└── unescaped: #{node.unescaped.inspect}\n", indent]
2239 end
2240
2241 # Inspect a TrueNode node.
2242 def visit_true_node(node)
2243 commands << [inspect_node("TrueNode", node), indent]
2244 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2245 commands << ["└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2246 end
2247
2248 # Inspect a UndefNode node.
2249 def visit_undef_node(node)
2250 commands << [inspect_node("UndefNode", node), indent]
2251 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2252 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2253 commands << ["├── names: (length: #{(names = node.names).length})\n", indent]
2254 if names.any?
2255 names[0...-1].each do |child|
2256 commands << [Replace.new("#{indent}│ ├── "), indent]
2257 commands << [child, "#{indent}│ │ "]
2258 end
2259 commands << [Replace.new("#{indent}│ └── "), indent]
2260 commands << [names[-1], "#{indent}│ "]
2261 end
2262 commands << ["└── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2263 end
2264
2265 # Inspect a UnlessNode node.
2266 def visit_unless_node(node)
2267 commands << [inspect_node("UnlessNode", node), indent]
2268 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2269 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2270 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2271 commands << ["├── predicate:\n", indent]
2272 commands << [node.predicate, "#{indent}│ "]
2273 commands << ["├── then_keyword_loc: #{inspect_location(node.then_keyword_loc)}\n", indent]
2274 if (statements = node.statements).nil?
2275 commands << ["├── statements: ∅\n", indent]
2276 else
2277 commands << ["├── statements:\n", indent]
2278 commands << [statements, "#{indent}│ "]
2279 end
2280 if (else_clause = node.else_clause).nil?
2281 commands << ["├── else_clause: ∅\n", indent]
2282 else
2283 commands << ["├── else_clause:\n", indent]
2284 commands << [else_clause, "#{indent}│ "]
2285 end
2286 commands << ["└── end_keyword_loc: #{inspect_location(node.end_keyword_loc)}\n", indent]
2287 end
2288
2289 # Inspect a UntilNode node.
2290 def visit_until_node(node)
2291 commands << [inspect_node("UntilNode", node), indent]
2292 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("begin_modifier" if node.begin_modifier?)].compact
2293 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2294 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2295 commands << ["├── do_keyword_loc: #{inspect_location(node.do_keyword_loc)}\n", indent]
2296 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
2297 commands << ["├── predicate:\n", indent]
2298 commands << [node.predicate, "#{indent}│ "]
2299 if (statements = node.statements).nil?
2300 commands << ["└── statements: ∅\n", indent]
2301 else
2302 commands << ["└── statements:\n", indent]
2303 commands << [statements, "#{indent} "]
2304 end
2305 end
2306
2307 # Inspect a WhenNode node.
2308 def visit_when_node(node)
2309 commands << [inspect_node("WhenNode", node), indent]
2310 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2311 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2312 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2313 commands << ["├── conditions: (length: #{(conditions = node.conditions).length})\n", indent]
2314 if conditions.any?
2315 conditions[0...-1].each do |child|
2316 commands << [Replace.new("#{indent}│ ├── "), indent]
2317 commands << [child, "#{indent}│ │ "]
2318 end
2319 commands << [Replace.new("#{indent}│ └── "), indent]
2320 commands << [conditions[-1], "#{indent}│ "]
2321 end
2322 commands << ["├── then_keyword_loc: #{inspect_location(node.then_keyword_loc)}\n", indent]
2323 if (statements = node.statements).nil?
2324 commands << ["└── statements: ∅\n", indent]
2325 else
2326 commands << ["└── statements:\n", indent]
2327 commands << [statements, "#{indent} "]
2328 end
2329 end
2330
2331 # Inspect a WhileNode node.
2332 def visit_while_node(node)
2333 commands << [inspect_node("WhileNode", node), indent]
2334 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("begin_modifier" if node.begin_modifier?)].compact
2335 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2336 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2337 commands << ["├── do_keyword_loc: #{inspect_location(node.do_keyword_loc)}\n", indent]
2338 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
2339 commands << ["├── predicate:\n", indent]
2340 commands << [node.predicate, "#{indent}│ "]
2341 if (statements = node.statements).nil?
2342 commands << ["└── statements: ∅\n", indent]
2343 else
2344 commands << ["└── statements:\n", indent]
2345 commands << [statements, "#{indent} "]
2346 end
2347 end
2348
2349 # Inspect a XStringNode node.
2350 def visit_x_string_node(node)
2351 commands << [inspect_node("XStringNode", node), indent]
2352 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ("forced_utf8_encoding" if node.forced_utf8_encoding?), ("forced_binary_encoding" if node.forced_binary_encoding?)].compact
2353 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2354 commands << ["├── opening_loc: #{inspect_location(node.opening_loc)}\n", indent]
2355 commands << ["├── content_loc: #{inspect_location(node.content_loc)}\n", indent]
2356 commands << ["├── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
2357 commands << ["└── unescaped: #{node.unescaped.inspect}\n", indent]
2358 end
2359
2360 # Inspect a YieldNode node.
2361 def visit_yield_node(node)
2362 commands << [inspect_node("YieldNode", node), indent]
2363 flags = [("newline" if node.newline?), ("static_literal" if node.static_literal?), ].compact
2364 commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
2365 commands << ["├── keyword_loc: #{inspect_location(node.keyword_loc)}\n", indent]
2366 commands << ["├── lparen_loc: #{inspect_location(node.lparen_loc)}\n", indent]
2367 if (arguments = node.arguments).nil?
2368 commands << ["├── arguments: ∅\n", indent]
2369 else
2370 commands << ["├── arguments:\n", indent]
2371 commands << [arguments, "#{indent}│ "]
2372 end
2373 commands << ["└── rparen_loc: #{inspect_location(node.rparen_loc)}\n", indent]
2374 end
2375
2376 private
2377
2378 # Compose a header for the given node.
2379 def inspect_node(name, node)
2380 location = node.location
2381 "@ #{name} (location: (#{location.start_line},#{location.start_column})-(#{location.end_line},#{location.end_column}))\n"
2382 end
2383
2384 # Compose a string representing the given inner location field.
2385 def inspect_location(location)
2386 if location
2387 "(#{location.start_line},#{location.start_column})-(#{location.end_line},#{location.end_column}) = #{location.slice.inspect}"
2388 else
2389 "∅"
2390 end
2391 end
2392 end
2393 end