Class: Prism::AlternationPatternNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::AlternationPatternNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents an alternation pattern in pattern matching.
foo => bar | baz
^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :alternation_pattern_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc) ⇒ AlternationPatternNode
:call-seq: copy(**fields) -> AlternationPatternNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, left, right, operator_loc) ⇒ AlternationPatternNode
constructor
Initialize a new AlternationPatternNode node.
-
#inspect ⇒ String
: () -> String.
-
#left ⇒ Prism::node
:call-seq: left -> Node.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#right ⇒ Prism::node
:call-seq: right -> Node.
-
#save_operator_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :alternation_pattern_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, left, right, operator_loc) ⇒ AlternationPatternNode
Initialize a new AlternationPatternNode node.
: (Source source, Integer node_id, Location location, Integer flags, Prism::node left, Prism::node right, Location operator_loc) -> void
853 854 855 856 857 858 859 860 861 |
# File 'lib/prism/node.rb', line 853 def initialize(source, node_id, location, flags, left, right, operator_loc) @source = source @node_id = node_id @location = location @flags = flags @left = left @right = right @operator_loc = operator_loc end |
Class Method Details
.type ⇒ :alternation_pattern_node
See Node.type.
: () -> :alternation_pattern_node
944 945 946 |
# File 'lib/prism/node.rb', line 944 def self.type :alternation_pattern_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
1033 1034 1035 1036 1037 1038 |
# File 'lib/prism/node.rb', line 1033 def ===(other) # :nodoc: other.is_a?(AlternationPatternNode) && (left === other.left) && (right === other.right) && (operator_loc.nil? == other.operator_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
877 878 879 |
# File 'lib/prism/node.rb', line 877 def accept(visitor) visitor.visit_alternation_pattern_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
884 885 886 |
# File 'lib/prism/node.rb', line 884 def child_nodes [left, right] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
902 903 904 |
# File 'lib/prism/node.rb', line 902 def compact_child_nodes [left, right] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc) ⇒ AlternationPatternNode
:call-seq:
copy(**fields) -> AlternationPatternNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node, ?right: Prism::node, ?operator_loc: Location) -> AlternationPatternNode
912 913 914 |
# File 'lib/prism/node.rb', line 912 def copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc) AlternationPatternNode.new(source, node_id, location, flags, left, right, operator_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
919 920 921 922 923 924 925 926 927 928 929 930 931 932 |
# File 'lib/prism/node.rb', line 919 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location left right operator_loc operator]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :left then deconstructed[:left] = self.left when :right then deconstructed[:right] = self.right when :operator_loc then deconstructed[:operator_loc] = self.operator_loc when :operator then deconstructed[:operator] = self.operator end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
892 893 894 895 896 897 |
# File 'lib/prism/node.rb', line 892 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield left yield right end |
#inspect ⇒ String
: () -> String
949 950 951 |
# File 'lib/prism/node.rb', line 949 def inspect # :nodoc: InspectVisitor.compose(self) end |
#left ⇒ Prism::node
:call-seq:
left -> Node
Represents the left side of the expression.
foo => bar | baz
^^^
: () -> Prism::node
968 969 970 |
# File 'lib/prism/node.rb', line 968 def left @left end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
1026 1027 1028 |
# File 'lib/prism/node.rb', line 1026 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
Represents the alternation operator Location.
foo => bar | baz
^
: () -> Location
1003 1004 1005 1006 1007 |
# File 'lib/prism/node.rb', line 1003 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#right ⇒ Prism::node
:call-seq:
right -> Node
Represents the right side of the expression.
foo => bar | baz
^^^
: () -> Prism::node
985 986 987 |
# File 'lib/prism/node.rb', line 985 def right @right end |
#save_operator_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the operator_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
1014 1015 1016 |
# File 'lib/prism/node.rb', line 1014 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :alternation_pattern_node
See Node#type.
: () -> :alternation_pattern_node
937 938 939 |
# File 'lib/prism/node.rb', line 937 def type :alternation_pattern_node end |