diff options
author | Kevin Newton <[email protected]> | 2023-09-27 12:24:48 -0400 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2023-09-27 13:57:38 -0400 |
commit | 4f73a7c2f7ff16aa78cf0dec2d4c7f90a2c41c9b () | |
tree | 3b6f0cedc858d46d30a28c6d03439d653884a915 /lib/prism/pattern.rb | |
parent | 8ab56869a64fdccc094f4a83c6367fb23b72d38b (diff) |
Sync to prism rename commits
-rw-r--r-- | lib/prism/pattern.rb | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -1,24 +1,24 @@ # frozen_string_literal: true -module YARP # A pattern is an object that wraps a Ruby pattern matching expression. The # expression would normally be passed to an `in` clause within a `case` # expression or a rightward assignment expression. For example, in the # following snippet: # # case node - # in ConstantPathNode[ConstantReadNode[name: :YARP], ConstantReadNode[name: :Pattern]] # end # # the pattern is the `ConstantPathNode[...]` expression. # # The pattern gets compiled into an object that responds to #call by running - # the #compile method. This method itself will run back through YARP to # parse the expression into a tree, then walk the tree to generate the # necessary callable objects. For example, if you wanted to compile the # expression above into a callable, you would: # - # callable = YARP::Pattern.new("ConstantPathNode[ConstantReadNode[name: :YARP], ConstantReadNode[name: :Pattern]]").compile # callable.call(node) # # The callable object returned by #compile is guaranteed to respond to #call @@ -32,7 +32,7 @@ module YARP # # If the query given to the initializer cannot be compiled into a valid # matcher (either because of a syntax error or because it is using syntax we - # do not yet support) then a YARP::Pattern::CompilationError will be # raised. class Pattern # Raised when the query given to a pattern is either invalid Ruby syntax or @@ -40,15 +40,15 @@ module YARP class CompilationError < StandardError def initialize(repr) super(<<~ERROR) - YARP was unable to compile the pattern you provided into a usable expression. It failed on to understand the node represented by: #{repr} Note that not all syntax supported by Ruby's pattern matching syntax - is also supported by YARP's patterns. If you're using some syntax that you believe should be supported, please open an issue on - at https://.com/ruby/yarp/issues/new. ERROR end end @@ -61,7 +61,7 @@ module YARP end def compile - result = YARP.parse("case nil\nin #{query}\nend") compile_node(result.value.statements.body.last.conditions.last.pattern) end @@ -126,11 +126,11 @@ module YARP combine_or(compile_node(node.left), compile_node(node.right)) end - # in YARP::ConstantReadNode def compile_constant_path_node(node) parent = node.parent - if parent.is_a?(ConstantReadNode) && parent.slice == "YARP" compile_node(node.child) else compile_error(node) @@ -142,8 +142,8 @@ module YARP def compile_constant_read_node(node) value = node.slice - if YARP.const_defined?(value, false) - clazz = YARP.const_get(value) ->(other) { clazz === other } elsif Object.const_defined?(value, false) |