[ruby/yarp] Move node ext and parse result to their own files

916828767c
This commit is contained in:
Kevin Newton 2023-09-22 11:57:13 -04:00
parent 7d11f58b6e
commit 5f905026bc
5 changed files with 358 additions and 350 deletions

55
lib/yarp/node_ext.rb Normal file
View file

@ -0,0 +1,55 @@
# frozen_string_literal: true
# Here we are reopening the YARP module to provide methods on 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 & (RegularExpressionFlags::IGNORE_CASE | RegularExpressionFlags::EXTENDED | RegularExpressionFlags::MULTI_LINE)
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 & (RegularExpressionFlags::IGNORE_CASE | RegularExpressionFlags::EXTENDED | RegularExpressionFlags::MULTI_LINE)
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