lib/yarp.rb in yarp-0.11.0 vs lib/yarp.rb in yarp-0.12.0
- old
+ new
@@ -305,24 +305,11 @@
def slice
location.slice
end
def pretty_print(q)
- q.group do
- q.text(self.class.name.split("::").last)
- location.pretty_print(q)
- q.text("[Li:#{location.start_line}]") if newline?
- q.text("(")
- q.nest(2) do
- deconstructed = deconstruct_keys([])
- deconstructed.delete(:location)
- q.breakable("")
- q.seplist(deconstructed, lambda { q.comma_breakable }, :each_value) { |value| q.pp(value) }
- end
- q.breakable("")
- q.text(")")
- end
+ q.text(inspect.chomp)
end
end
# This object is responsible for generating the output for the inspect method
# implementations of child nodes.
@@ -387,34 +374,10 @@
def to_str
output
end
end
- class FloatNode < Node
- def value
- Float(slice)
- end
- end
-
- class ImaginaryNode < Node
- def value
- Complex(0, numeric.value)
- end
- end
-
- class IntegerNode < Node
- def value
- Integer(slice)
- end
- end
-
- class RationalNode < Node
- def value
- Rational(slice.chomp("r"))
- end
- end
-
# Load the serialized AST using the source as a reference into a tree.
def self.load(source, serialized)
Serialize.load(source, serialized)
end
@@ -475,14 +438,10 @@
# CRuby will push on a special local variable when there are keyword
# arguments. We get rid of that here.
names = names.grep_v(Integer)
- # TODO: We don't support numbered local variables yet, so we get rid
- # of those here.
- names = names.grep_v(/^_\d$/)
-
# For some reason, CRuby occasionally pushes this special local
# variable when there are splat arguments. We get rid of that here.
names = names.grep_v(:"#arg_rest")
# Now push them onto the list of locals.
@@ -596,6 +555,62 @@
if RUBY_ENGINE == "ruby" and !ENV["YARP_FFI_BACKEND"]
require "yarp/yarp"
else
require_relative "yarp/ffi"
+end
+
+# Reopening the YARP module after yarp/node is required so that constant
+# reflection APIs will find the constants defined in the node file before these.
+# This block is meant to contain extra APIs we define on YARP nodes that aren't
+# templated and are meant as convenience methods.
+module YARP
+ class FloatNode < Node
+ # Returns the value of the node as a Ruby Float.
+ def value
+ Float(slice)
+ end
+ end
+
+ class ImaginaryNode < Node
+ # Returns the value of the node as a Ruby Complex.
+ def value
+ Complex(0, numeric.value)
+ end
+ end
+
+ class IntegerNode < Node
+ # Returns the value of the node as a Ruby Integer.
+ def value
+ Integer(slice)
+ end
+ end
+
+ class InterpolatedRegularExpressionNode < Node
+ # Returns a numeric value that represents the flags that were used to create
+ # the regular expression.
+ def options
+ o = flags & 0b111
+ o |= Regexp::FIXEDENCODING if flags.anybits?(RegularExpressionFlags::EUC_JP | RegularExpressionFlags::WINDOWS_31J | RegularExpressionFlags::UTF_8)
+ o |= Regexp::NOENCODING if flags.anybits?(RegularExpressionFlags::ASCII_8BIT)
+ o
+ end
+ end
+
+ class RationalNode < Node
+ # Returns the value of the node as a Ruby Rational.
+ def value
+ Rational(slice.chomp("r"))
+ end
+ end
+
+ class RegularExpressionNode < Node
+ # Returns a numeric value that represents the flags that were used to create
+ # the regular expression.
+ def options
+ o = flags & 0b111
+ o |= Regexp::FIXEDENCODING if flags.anybits?(RegularExpressionFlags::EUC_JP | RegularExpressionFlags::WINDOWS_31J | RegularExpressionFlags::UTF_8)
+ o |= Regexp::NOENCODING if flags.anybits?(RegularExpressionFlags::ASCII_8BIT)
+ o
+ end
+ end
end