mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 11:33:58 +02:00
[ruby/yarp] Move node ext and parse result to their own files
916828767c
This commit is contained in:
parent
7d11f58b6e
commit
5f905026bc
5 changed files with 358 additions and 350 deletions
55
lib/yarp/node_ext.rb
Normal file
55
lib/yarp/node_ext.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue