aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pp.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pp.rb')
-rw-r--r--lib/pp.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/pp.rb b/lib/pp.rb
index 85401c8aa6..bb504bc1b4 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -514,6 +514,36 @@ class MatchData # :nodoc:
end
end
+class RubyVM::AbstractSyntaxTree::Node
+ def pretty_print_children(q, names = [])
+ children.zip(names) do |c, n|
+ if n
+ q.breakable
+ q.text "#{n}:"
+ end
+ q.group(2) do
+ q.breakable
+ q.pp c
+ end
+ end
+ end
+
+ def pretty_print(q)
+ q.group(1, "(#{type.sub(/\ANODE_/,'')}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
+ case type
+ when "NODE_SCOPE"
+ pretty_print_children(q, %w"tbl args body")
+ when "NODE_ARGS"
+ pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
+ when "NODE_DEFN"
+ pretty_print_children(q, %w[mid body])
+ else
+ pretty_print_children(q)
+ end
+ }
+ end
+end
+
class Object < BasicObject # :nodoc:
include PP::ObjectMixin
end