summaryrefslogtreecommitdiff
path: root/lib/prism
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-07-02 15:43:01 -0400
committerKevin Newton <[email protected]>2024-07-11 14:25:54 -0400
commit687be43c79a6fb119e52b09ea561cf958a9aabf2 (patch)
treedffa61a0172886f091571c73340926a70fe69340 /lib/prism
parentca48fb76fb0669ca0666a7aa129e1f5d2b7468da (diff)
[ruby/prism] Expose flags on every node type
https://github.com/ruby/prism/commit/9f12a56fd6
Diffstat (limited to 'lib/prism')
-rw-r--r--lib/prism/node_ext.rb12
-rw-r--r--lib/prism/parse_result/newlines.rb56
2 files changed, 36 insertions, 32 deletions
diff --git a/lib/prism/node_ext.rb b/lib/prism/node_ext.rb
index fe36be8541..30ab652384 100644
--- a/lib/prism/node_ext.rb
+++ b/lib/prism/node_ext.rb
@@ -21,7 +21,10 @@ module Prism
# 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 = 0
+ o |= Regexp::IGNORECASE if flags.anybits?(RegularExpressionFlags::IGNORE_CASE)
+ o |= Regexp::EXTENDED if flags.anybits?(RegularExpressionFlags::EXTENDED)
+ o |= Regexp::MULTILINE if flags.anybits?(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
@@ -87,6 +90,7 @@ module Prism
InterpolatedXStringNode.new(
source,
location,
+ flags,
opening_loc,
[StringNode.new(source, content_loc, 0, nil, content_loc, nil, unescaped)],
closing_loc
@@ -117,7 +121,7 @@ module Prism
if denominator == 1
IntegerNode.new(source, location.chop, flags, numerator)
else
- FloatNode.new(source, location.chop, numerator.to_f / denominator)
+ FloatNode.new(source, location.chop, 0, numerator.to_f / denominator)
end
end
end
@@ -195,7 +199,7 @@ module Prism
# continue to supply that API.
def child
deprecated("name", "name_loc")
- name ? ConstantReadNode.new(source, name_loc, name) : MissingNode.new(source, location)
+ name ? ConstantReadNode.new(source, name_loc, 0, name) : MissingNode.new(source, location, 0)
end
end
@@ -231,7 +235,7 @@ module Prism
# continue to supply that API.
def child
deprecated("name", "name_loc")
- name ? ConstantReadNode.new(source, name_loc, name) : MissingNode.new(source, location)
+ name ? ConstantReadNode.new(source, name_loc, 0, name) : MissingNode.new(source, location, 0)
end
end
diff --git a/lib/prism/parse_result/newlines.rb b/lib/prism/parse_result/newlines.rb
index 808a129a6b..a04fa78a75 100644
--- a/lib/prism/parse_result/newlines.rb
+++ b/lib/prism/parse_result/newlines.rb
@@ -45,7 +45,7 @@ module Prism
# Mark if/unless nodes as newlines.
def visit_if_node(node)
- node.newline!(@lines)
+ node.newline_flag!(@lines)
super(node)
end
@@ -54,7 +54,7 @@ module Prism
# Permit statements lists to mark newlines within themselves.
def visit_statements_node(node)
node.body.each do |child|
- child.newline!(@lines)
+ child.newline_flag!(@lines)
end
super(node)
end
@@ -62,93 +62,93 @@ module Prism
end
class Node
- def newline? # :nodoc:
- @newline ? true : false
+ def newline_flag? # :nodoc:
+ @newline_flag ? true : false
end
- def newline!(lines) # :nodoc:
+ def newline_flag!(lines) # :nodoc:
line = location.start_line
unless lines[line]
lines[line] = true
- @newline = true
+ @newline_flag = true
end
end
end
class BeginNode < Node
- def newline!(lines) # :nodoc:
+ def newline_flag!(lines) # :nodoc:
# Never mark BeginNode with a newline flag, mark children instead.
end
end
class ParenthesesNode < Node
- def newline!(lines) # :nodoc:
+ def newline_flag!(lines) # :nodoc:
# Never mark ParenthesesNode with a newline flag, mark children instead.
end
end
class IfNode < Node
- def newline!(lines) # :nodoc:
- predicate.newline!(lines)
+ def newline_flag!(lines) # :nodoc:
+ predicate.newline_flag!(lines)
end
end
class UnlessNode < Node
- def newline!(lines) # :nodoc:
- predicate.newline!(lines)
+ def newline_flag!(lines) # :nodoc:
+ predicate.newline_flag!(lines)
end
end
class UntilNode < Node
- def newline!(lines) # :nodoc:
- predicate.newline!(lines)
+ def newline_flag!(lines) # :nodoc:
+ predicate.newline_flag!(lines)
end
end
class WhileNode < Node
- def newline!(lines) # :nodoc:
- predicate.newline!(lines)
+ def newline_flag!(lines) # :nodoc:
+ predicate.newline_flag!(lines)
end
end
class RescueModifierNode < Node
- def newline!(lines) # :nodoc:
- expression.newline!(lines)
+ def newline_flag!(lines) # :nodoc:
+ expression.newline_flag!(lines)
end
end
class InterpolatedMatchLastLineNode < Node
- def newline!(lines) # :nodoc:
+ def newline_flag!(lines) # :nodoc:
first = parts.first
- first.newline!(lines) if first
+ first.newline_flag!(lines) if first
end
end
class InterpolatedRegularExpressionNode < Node
- def newline!(lines) # :nodoc:
+ def newline_flag!(lines) # :nodoc:
first = parts.first
- first.newline!(lines) if first
+ first.newline_flag!(lines) if first
end
end
class InterpolatedStringNode < Node
- def newline!(lines) # :nodoc:
+ def newline_flag!(lines) # :nodoc:
first = parts.first
- first.newline!(lines) if first
+ first.newline_flag!(lines) if first
end
end
class InterpolatedSymbolNode < Node
- def newline!(lines) # :nodoc:
+ def newline_flag!(lines) # :nodoc:
first = parts.first
- first.newline!(lines) if first
+ first.newline_flag!(lines) if first
end
end
class InterpolatedXStringNode < Node
- def newline!(lines) # :nodoc:
+ def newline_flag!(lines) # :nodoc:
first = parts.first
- first.newline!(lines) if first
+ first.newline_flag!(lines) if first
end
end
end