summaryrefslogtreecommitdiff
path: root/lib/prism/pattern.rb
diff options
context:
space:
mode:
authorGopal Patel <[email protected]>2024-01-08 10:31:37 -0800
committergit <[email protected]>2024-02-24 03:39:22 +0000
commit7556fd937cfedbee9775b92124fcdce5c416dd50 ()
tree55bca2cd9e0dce4543c8e086bda52d3c2158e1a6 /lib/prism/pattern.rb
parente03e9c3644c3c5a8713e1fed547da0c0becf36de (diff)
[ruby/prism] Split private types
https://.com/ruby/prism/commit/0209d093ec
-rw-r--r--lib/prism/pattern.rb22
1 files changed, 18 insertions, 4 deletions
@@ -69,7 +69,14 @@ module Prism
# nodes.
def compile
result = Prism.parse("case nil\nin #{query}\nend")
- compile_node(result.value.statements.body.last.conditions.last.pattern)
end
# Scan the given node and all of its children for nodes that match the
@@ -77,13 +84,14 @@ module Prism
# matches the pattern. If no block is given, an enumerator will be returned
# that will yield each node that matches the pattern.
def scan(root)
- return to_enum(__method__, root) unless block_given?
@compiled ||= compile
queue = [root]
while (node = queue.shift)
- yield node if @compiled.call(node)
queue.concat(node.compact_child_nodes)
end
end
@@ -174,7 +182,13 @@ module Prism
preprocessed =
node.elements.to_h do |element|
- [element.key.unescaped.to_sym, compile_node(element.value)]
end
compiled_keywords = ->(other) do