summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-10-17 13:02:53 -0400
committergit <svn-admin@ruby-lang.org>2023-10-26 13:58:40 +0000
commit51ea82a7701afea79f5137445a28e8dfdf832e46 (patch)
tree5aa563879c6de48ee1898490a4232ae7c8418714
parent3ed317a441d5a66a56a41bc28399137d0012f3ae (diff)
[ruby/prism] Expose options on match last line nodes
https://github.com/ruby/prism/commit/0284b38861
-rw-r--r--lib/prism/node_ext.rb39
1 files changed, 23 insertions, 16 deletions
diff --git a/lib/prism/node_ext.rb b/lib/prism/node_ext.rb
index 264d3a5c1e..2ed3913fb4 100644
--- a/lib/prism/node_ext.rb
+++ b/lib/prism/node_ext.rb
@@ -3,6 +3,19 @@
# Here we are reopening the prism module to provide methods on nodes that aren't
# templated and are meant as convenience methods.
module Prism
+ module RegularExpressionOptions
+ # 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
+
+ private_constant :RegularExpressionOptions
+
class FloatNode < Node
# Returns the value of the node as a Ruby Float.
def value
@@ -24,15 +37,16 @@ module Prism
end
end
+ class InterpolatedMatchLastLineNode < Node
+ include RegularExpressionOptions
+ 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
+ include RegularExpressionOptions
+ end
+
+ class MatchLastLineNode < Node
+ include RegularExpressionOptions
end
class RationalNode < Node
@@ -43,14 +57,7 @@ module Prism
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
+ include RegularExpressionOptions
end
class ConstantReadNode < Node