mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/pp] Only do RubyVM patches if class exists
This class does not exist in any implementation except CRuby. I would recommend moving this code somewhere else, like a separate file loaded only on CRuby or into CRuby itself. For now this change is sufficient to load the library on other implementations. https://github.com/ruby/pp/commit/7d5a220f64
This commit is contained in:
parent
de6ef2ca71
commit
5a6baaba38
1 changed files with 30 additions and 28 deletions
58
lib/pp.rb
58
lib/pp.rb
|
@ -539,37 +539,39 @@ class MatchData # :nodoc:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RubyVM::AbstractSyntaxTree::Node
|
if defined?(RubyVM::AbstractSyntaxTree)
|
||||||
def pretty_print_children(q, names = [])
|
class RubyVM::AbstractSyntaxTree::Node
|
||||||
children.zip(names) do |c, n|
|
def pretty_print_children(q, names = [])
|
||||||
if n
|
children.zip(names) do |c, n|
|
||||||
q.breakable
|
if n
|
||||||
q.text "#{n}:"
|
q.breakable
|
||||||
end
|
q.text "#{n}:"
|
||||||
q.group(2) do
|
end
|
||||||
q.breakable
|
q.group(2) do
|
||||||
q.pp c
|
q.breakable
|
||||||
|
q.pp c
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def pretty_print(q)
|
def pretty_print(q)
|
||||||
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
|
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
|
||||||
case type
|
case type
|
||||||
when :SCOPE
|
when :SCOPE
|
||||||
pretty_print_children(q, %w"tbl args body")
|
pretty_print_children(q, %w"tbl args body")
|
||||||
when :ARGS
|
when :ARGS
|
||||||
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
|
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
|
||||||
when :DEFN
|
when :DEFN
|
||||||
pretty_print_children(q, %w[mid body])
|
pretty_print_children(q, %w[mid body])
|
||||||
when :ARYPTN
|
when :ARYPTN
|
||||||
pretty_print_children(q, %w[const pre rest post])
|
pretty_print_children(q, %w[const pre rest post])
|
||||||
when :HSHPTN
|
when :HSHPTN
|
||||||
pretty_print_children(q, %w[const kw kwrest])
|
pretty_print_children(q, %w[const kw kwrest])
|
||||||
else
|
else
|
||||||
pretty_print_children(q)
|
pretty_print_children(q)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue