@@ -293,71 +293,6 @@ def pretty_print(q)
293
293
end
294
294
end
295
295
296
- # This object is responsible for generating the output for the inspect method
297
- # implementations of child nodes.
298
- class NodeInspector
299
- attr_reader :prefix , :output
300
-
301
- def initialize ( prefix = "" )
302
- @prefix = prefix
303
- @output = +""
304
- end
305
-
306
- # Appends a line to the output with the current prefix.
307
- def <<( line )
308
- output << "#{ prefix } #{ line } "
309
- end
310
-
311
- # This generates a string that is used as the header of the inspect output
312
- # for any given node.
313
- def header ( node )
314
- output = +"@ #{ node . class . name . split ( "::" ) . last } ("
315
- output << "location: (#{ node . location . start_line } ,#{ node . location . start_column } )-(#{ node . location . end_line } ,#{ node . location . end_column } )"
316
- output << ", newline: true" if node . newline?
317
- output << ")\n "
318
- output
319
- end
320
-
321
- # Generates a string that represents a list of nodes. It handles properly
322
- # using the box drawing characters to make the output look nice.
323
- def list ( prefix , nodes )
324
- output = +"(length: #{ nodes . length } )\n "
325
- last_index = nodes . length - 1
326
-
327
- nodes . each_with_index do |node , index |
328
- pointer , preadd = ( index == last_index ) ? [ "└── " , " " ] : [ "├── " , "│ " ]
329
- node_prefix = "#{ prefix } #{ preadd } "
330
- output << node . inspect ( NodeInspector . new ( node_prefix ) ) . sub ( node_prefix , "#{ prefix } #{ pointer } " )
331
- end
332
-
333
- output
334
- end
335
-
336
- # Generates a string that represents a location field on a node.
337
- def location ( value )
338
- if value
339
- "(#{ value . start_line } ,#{ value . start_column } )-(#{ value . end_line } ,#{ value . end_column } ) = #{ value . slice . inspect } "
340
- else
341
- "∅"
342
- end
343
- end
344
-
345
- # Generates a string that represents a child node.
346
- def child_node ( node , append )
347
- node . inspect ( child_inspector ( append ) ) . delete_prefix ( prefix )
348
- end
349
-
350
- # Returns a new inspector that can be used to inspect a child node.
351
- def child_inspector ( append )
352
- NodeInspector . new ( "#{ prefix } #{ append } " )
353
- end
354
-
355
- # Returns the output as a string.
356
- def to_str
357
- output
358
- end
359
- end
360
-
361
296
# There are many files in YARP that are templated to handle every node type,
362
297
# which means the files can end up being quite large. We autoload them to make
363
298
# our require speed faster since consuming libraries are unlikely to use all
@@ -369,6 +304,7 @@ def to_str
369
304
autoload :Dispatcher , "yarp/dispatcher"
370
305
autoload :DSL , "yarp/dsl"
371
306
autoload :MutationCompiler , "yarp/mutation_compiler"
307
+ autoload :NodeInspector , "yarp/node_inspector"
372
308
autoload :RipperCompat , "yarp/ripper_compat"
373
309
autoload :Pack , "yarp/pack"
374
310
autoload :Pattern , "yarp/pattern"
0 commit comments