Debian Codegraph @

lib/prism/node.rb

raw symbols SCIP
1 # frozen_string_literal: true
2 # :markup: markdown
3
4 =begin
5 --
6 This file is generated by the templates/template.rb script and should not be
7 modified manually. See templates/lib/prism/node.rb.erb
8 if you are looking to modify the template
9 ++
10 =end
11
12 module Prism
13 # This represents a node in the tree. It is the parent class of all of the
14 # various node types.
15 class Node
16 # A pointer to the source that this node was created from.
17 attr_reader :source
18 private :source
19
20 # A unique identifier for this node. This is used in a very specific
21 # use case where you want to keep around a reference to a node without
22 # having to keep around the syntax tree in memory. This unique identifier
23 # will be consistent across multiple parses of the same source code.
24 attr_reader :node_id
25
26 # Save this node using a saved source so that it can be retrieved later.
27 def save(repository)
28 repository.enter(node_id, :itself)
29 end
30
31 # A Location instance that represents the location of this node in the
32 # source.
33 def location
34 location = @location
35 return location if location.is_a?(Location)
36 @location = Location.new(source, location >> 32, location & 0xFFFFFFFF)
37 end
38
39 # Save the location using a saved source so that it can be retrieved later.
40 def save_location(repository)
41 repository.enter(node_id, :location)
42 end
43
44 # Delegates to the start_line of the associated location object.
45 def start_line
46 location.start_line
47 end
48
49 # Delegates to the end_line of the associated location object.
50 def end_line
51 location.end_line
52 end
53
54 # The start offset of the node in the source. This method is effectively a
55 # delegate method to the location object.
56 def start_offset
57 location = @location
58 location.is_a?(Location) ? location.start_offset : location >> 32
59 end
60
61 # The end offset of the node in the source. This method is effectively a
62 # delegate method to the location object.
63 def end_offset
64 location = @location
65 location.is_a?(Location) ? location.end_offset : ((location >> 32) + (location & 0xFFFFFFFF))
66 end
67
68 # Delegates to the start_character_offset of the associated location object.
69 def start_character_offset
70 location.start_character_offset
71 end
72
73 # Delegates to the end_character_offset of the associated location object.
74 def end_character_offset
75 location.end_character_offset
76 end
77
78 # Delegates to the cached_start_code_units_offset of the associated location
79 # object.
80 def cached_start_code_units_offset(cache)
81 location.cached_start_code_units_offset(cache)
82 end
83
84 # Delegates to the cached_end_code_units_offset of the associated location
85 # object.
86 def cached_end_code_units_offset(cache)
87 location.cached_end_code_units_offset(cache)
88 end
89
90 # Delegates to the start_column of the associated location object.
91 def start_column
92 location.start_column
93 end
94
95 # Delegates to the end_column of the associated location object.
96 def end_column
97 location.end_column
98 end
99
100 # Delegates to the start_character_column of the associated location object.
101 def start_character_column
102 location.start_character_column
103 end
104
105 # Delegates to the end_character_column of the associated location object.
106 def end_character_column
107 location.end_character_column
108 end
109
110 # Delegates to the cached_start_code_units_column of the associated location
111 # object.
112 def cached_start_code_units_column(cache)
113 location.cached_start_code_units_column(cache)
114 end
115
116 # Delegates to the cached_end_code_units_column of the associated location
117 # object.
118 def cached_end_code_units_column(cache)
119 location.cached_end_code_units_column(cache)
120 end
121
122 # Delegates to the leading_comments of the associated location object.
123 def leading_comments
124 location.leading_comments
125 end
126
127 # Delegates to the trailing_comments of the associated location object.
128 def trailing_comments
129 location.trailing_comments
130 end
131
132 # Delegates to the comments of the associated location object.
133 def comments
134 location.comments
135 end
136
137 # Returns all of the lines of the source code associated with this node.
138 def source_lines
139 location.source_lines
140 end
141
142 # An alias for source_lines, used to mimic the API from
143 # RubyVM::AbstractSyntaxTree to make it easier to migrate.
144 alias script_lines source_lines
145
146 # Slice the location of the node from the source.
147 def slice
148 location.slice
149 end
150
151 # Slice the location of the node from the source, starting at the beginning
152 # of the line that the location starts on, ending at the end of the line
153 # that the location ends on.
154 def slice_lines
155 location.slice_lines
156 end
157
158 # An bitset of flags for this node. There are certain flags that are common
159 # for all nodes, and then some nodes have specific flags.
160 attr_reader :flags
161 protected :flags
162
163 # Returns true if the node has the newline flag set.
164 def newline?
165 flags.anybits?(NodeFlags::NEWLINE)
166 end
167
168 # Returns true if the node has the static literal flag set.
169 def static_literal?
170 flags.anybits?(NodeFlags::STATIC_LITERAL)
171 end
172
173 # Similar to inspect, but respects the current level of indentation given by
174 # the pretty print object.
175 def pretty_print(q)
176 q.seplist(inspect.chomp.each_line, -> { q.breakable }) do |line|
177 q.text(line.chomp)
178 end
179 q.current_group.break
180 end
181
182 # Convert this node into a graphviz dot graph string.
183 def to_dot
184 # @type self: node
185 DotVisitor.new.tap { |visitor| accept(visitor) }.to_dot
186 end
187
188 # Returns a list of nodes that are descendants of this node that contain the
189 # given line and column. This is useful for locating a node that is selected
190 # based on the line and column of the source code.
191 #
192 # Important to note is that the column given to this method should be in
193 # bytes, as opposed to characters or code units.
194 def tunnel(line, column)
195 queue = [self] #: Array[Prism::node]
196 result = [] #: Array[Prism::node]
197 offset = source.byte_offset(line, column)
198
199 while (node = queue.shift)
200 result << node
201
202 node.each_child_node do |child_node|
203 if child_node.start_offset <= offset && offset < child_node.end_offset
204 queue << child_node
205 break
206 end
207 end
208 end
209
210 result
211 end
212
213 # Returns the first node that matches the given block when visited in a
214 # breadth-first search. This is useful for finding a node that matches a
215 # particular condition.
216 #
217 # node.breadth_first_search { |node| node.node_id == node_id }
218 #
219 def breadth_first_search(&block)
220 queue = [self] #: Array[Prism::node]
221
222 while (node = queue.shift)
223 return node if yield node
224 queue.concat(node.compact_child_nodes)
225 end
226
227 nil
228 end
229 alias find breadth_first_search
230
231 # Returns all of the nodes that match the given block when visited in a
232 # breadth-first search. This is useful for finding all nodes that match a
233 # particular condition.
234 #
235 # node.breadth_first_search_all { |node| node.is_a?(Prism::CallNode) }
236 #
237 def breadth_first_search_all(&block)
238 queue = [self] #: Array[Prism::node]
239 results = [] #: Array[Prism::node]
240
241 while (node = queue.shift)
242 results << node if yield node
243 queue.concat(node.compact_child_nodes)
244 end
245
246 results
247 end
248 alias find_all breadth_first_search_all
249
250 # Returns a list of the fields that exist for this node class. Fields
251 # describe the structure of the node. This kind of reflection is useful for
252 # things like recursively visiting each node _and_ field in the tree.
253 def self.fields
254 # This method should only be called on subclasses of Node, not Node
255 # itself.
256 raise NoMethodError, "undefined method `fields' for #{inspect}" if self == Node
257
258 Reflection.fields_for(self)
259 end
260
261 # --------------------------------------------------------------------------
262 # :section: Node interface
263 # These methods are effectively abstract methods that must be implemented by
264 # the various subclasses of Node. They are here to make it easier to work
265 # with typecheckers.
266 # --------------------------------------------------------------------------
267
268 # Accepts a visitor and calls back into the specialized visit function.
269 def accept(visitor)
270 raise NoMethodError, "undefined method `accept' for #{inspect}"
271 end
272
273 # Returns an array of child nodes, including `nil`s in the place of optional
274 # nodes that were not present.
275 def child_nodes
276 raise NoMethodError, "undefined method `child_nodes' for #{inspect}"
277 end
278
279 alias deconstruct child_nodes
280
281 # With a block given, yields each child node. Without a block, returns
282 # an enumerator that contains each child node. Excludes any `nil`s in
283 # the place of optional nodes that were not present.
284 def each_child_node
285 raise NoMethodError, "undefined method `each_child_node' for #{inspect}"
286 end
287
288 # Returns an array of child nodes, excluding any `nil`s in the place of
289 # optional nodes that were not present.
290 def compact_child_nodes
291 raise NoMethodError, "undefined method `compact_child_nodes' for #{inspect}"
292 end
293
294 # Returns an array of child nodes and locations that could potentially have
295 # comments attached to them.
296 def comment_targets
297 raise NoMethodError, "undefined method `comment_targets' for #{inspect}"
298 end
299
300 # Returns a string representation of the node.
301 def inspect
302 raise NoMethodError, "undefined method `inspect' for #{inspect}"
303 end
304
305 # Sometimes you want to check an instance of a node against a list of
306 # classes to see what kind of behavior to perform. Usually this is done by
307 # calling `[cls1, cls2].include?(node.class)` or putting the node into a
308 # case statement and doing `case node; when cls1; when cls2; end`. Both of
309 # these approaches are relatively slow because of the constant lookups,
310 # method calls, and/or array allocations.
311 #
312 # Instead, you can call #type, which will return to you a symbol that you
313 # can use for comparison. This is faster than the other approaches because
314 # it uses a single integer comparison, but also because if you're on CRuby
315 # you can take advantage of the fact that case statements with all symbol
316 # keys will use a jump table.
317 def type
318 raise NoMethodError, "undefined method `type' for #{inspect}"
319 end
320
321 # Similar to #type, this method returns a symbol that you can use for
322 # splitting on the type of the node without having to do a long === chain.
323 # Note that like #type, it will still be slower than using == for a single
324 # class, but should be faster in a case statement or an array comparison.
325 def self.type
326 raise NoMethodError, "undefined method `type' for #{inspect}"
327 end
328 end
329
330 # Represents the use of the `alias` keyword to alias a global variable.
331 #
332 # alias $foo $bar
333 # ^^^^^^^^^^^^^^^
334 class AliasGlobalVariableNode < Node
335 # Initialize a new AliasGlobalVariableNode node.
336 def initialize(source, node_id, location, flags, new_name, old_name, keyword_loc)
337 @source = source
338 @node_id = node_id
339 @location = location
340 @flags = flags
341 @new_name = new_name
342 @old_name = old_name
343 @keyword_loc = keyword_loc
344 end
345
346 # def accept: (Visitor visitor) -> void
347 def accept(visitor)
348 visitor.visit_alias_global_variable_node(self)
349 end
350
351 # def child_nodes: () -> Array[Node?]
352 def child_nodes
353 [new_name, old_name]
354 end
355
356 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
357 def each_child_node
358 return to_enum(:each_child_node) unless block_given?
359
360 yield new_name
361 yield old_name
362 end
363
364 # def compact_child_nodes: () -> Array[Node]
365 def compact_child_nodes
366 [new_name, old_name]
367 end
368
369 # def comment_targets: () -> Array[Node | Location]
370 def comment_targets
371 [new_name, old_name, keyword_loc] #: Array[Prism::node | Location]
372 end
373
374 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?new_name: GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode, ?old_name: GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | SymbolNode | MissingNode, ?keyword_loc: Location) -> AliasGlobalVariableNode
375 def copy(node_id: self.node_id, location: self.location, flags: self.flags, new_name: self.new_name, old_name: self.old_name, keyword_loc: self.keyword_loc)
376 AliasGlobalVariableNode.new(source, node_id, location, flags, new_name, old_name, keyword_loc)
377 end
378
379 # def deconstruct: () -> Array[Node?]
380 alias deconstruct child_nodes
381
382 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, new_name: GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode, old_name: GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | SymbolNode | MissingNode, keyword_loc: Location }
383 def deconstruct_keys(keys)
384 { node_id: node_id, location: location, new_name: new_name, old_name: old_name, keyword_loc: keyword_loc }
385 end
386
387 # Represents the new name of the global variable that can be used after aliasing.
388 #
389 # alias $foo $bar
390 # ^^^^
391 attr_reader :new_name
392
393 # Represents the old name of the global variable that can be used before aliasing.
394 #
395 # alias $foo $bar
396 # ^^^^
397 attr_reader :old_name
398
399 # The location of the `alias` keyword.
400 #
401 # alias $foo $bar
402 # ^^^^^
403 def keyword_loc
404 location = @keyword_loc
405 return location if location.is_a?(Location)
406 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
407 end
408
409 # Save the keyword_loc location using the given saved source so that
410 # it can be retrieved later.
411 def save_keyword_loc(repository)
412 repository.enter(node_id, :keyword_loc)
413 end
414
415 # def keyword: () -> String
416 def keyword
417 keyword_loc.slice
418 end
419
420 # def inspect -> String
421 def inspect
422 InspectVisitor.compose(self)
423 end
424
425 # Return a symbol representation of this node type. See `Node#type`.
426 def type
427 :alias_global_variable_node
428 end
429
430 # Return a symbol representation of this node type. See `Node::type`.
431 def self.type
432 :alias_global_variable_node
433 end
434
435 # Implements case-equality for the node. This is effectively == but without
436 # comparing the value of locations. Locations are checked only for presence.
437 def ===(other)
438 other.is_a?(AliasGlobalVariableNode) &&
439 (new_name === other.new_name) &&
440 (old_name === other.old_name) &&
441 (keyword_loc.nil? == other.keyword_loc.nil?)
442 end
443 end
444
445 # Represents the use of the `alias` keyword to alias a method.
446 #
447 # alias foo bar
448 # ^^^^^^^^^^^^^
449 class AliasMethodNode < Node
450 # Initialize a new AliasMethodNode node.
451 def initialize(source, node_id, location, flags, new_name, old_name, keyword_loc)
452 @source = source
453 @node_id = node_id
454 @location = location
455 @flags = flags
456 @new_name = new_name
457 @old_name = old_name
458 @keyword_loc = keyword_loc
459 end
460
461 # def accept: (Visitor visitor) -> void
462 def accept(visitor)
463 visitor.visit_alias_method_node(self)
464 end
465
466 # def child_nodes: () -> Array[Node?]
467 def child_nodes
468 [new_name, old_name]
469 end
470
471 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
472 def each_child_node
473 return to_enum(:each_child_node) unless block_given?
474
475 yield new_name
476 yield old_name
477 end
478
479 # def compact_child_nodes: () -> Array[Node]
480 def compact_child_nodes
481 [new_name, old_name]
482 end
483
484 # def comment_targets: () -> Array[Node | Location]
485 def comment_targets
486 [new_name, old_name, keyword_loc] #: Array[Prism::node | Location]
487 end
488
489 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?new_name: SymbolNode | InterpolatedSymbolNode, ?old_name: SymbolNode | InterpolatedSymbolNode | GlobalVariableReadNode | MissingNode, ?keyword_loc: Location) -> AliasMethodNode
490 def copy(node_id: self.node_id, location: self.location, flags: self.flags, new_name: self.new_name, old_name: self.old_name, keyword_loc: self.keyword_loc)
491 AliasMethodNode.new(source, node_id, location, flags, new_name, old_name, keyword_loc)
492 end
493
494 # def deconstruct: () -> Array[Node?]
495 alias deconstruct child_nodes
496
497 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, new_name: SymbolNode | InterpolatedSymbolNode, old_name: SymbolNode | InterpolatedSymbolNode | GlobalVariableReadNode | MissingNode, keyword_loc: Location }
498 def deconstruct_keys(keys)
499 { node_id: node_id, location: location, new_name: new_name, old_name: old_name, keyword_loc: keyword_loc }
500 end
501
502 # Represents the new name of the method that will be aliased.
503 #
504 # alias foo bar
505 # ^^^
506 #
507 # alias :foo :bar
508 # ^^^^
509 #
510 # alias :"#{foo}" :"#{bar}"
511 # ^^^^^^^^^
512 attr_reader :new_name
513
514 # Represents the old name of the method that will be aliased.
515 #
516 # alias foo bar
517 # ^^^
518 #
519 # alias :foo :bar
520 # ^^^^
521 #
522 # alias :"#{foo}" :"#{bar}"
523 # ^^^^^^^^^
524 attr_reader :old_name
525
526 # Represents the location of the `alias` keyword.
527 #
528 # alias foo bar
529 # ^^^^^
530 def keyword_loc
531 location = @keyword_loc
532 return location if location.is_a?(Location)
533 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
534 end
535
536 # Save the keyword_loc location using the given saved source so that
537 # it can be retrieved later.
538 def save_keyword_loc(repository)
539 repository.enter(node_id, :keyword_loc)
540 end
541
542 # def keyword: () -> String
543 def keyword
544 keyword_loc.slice
545 end
546
547 # def inspect -> String
548 def inspect
549 InspectVisitor.compose(self)
550 end
551
552 # Return a symbol representation of this node type. See `Node#type`.
553 def type
554 :alias_method_node
555 end
556
557 # Return a symbol representation of this node type. See `Node::type`.
558 def self.type
559 :alias_method_node
560 end
561
562 # Implements case-equality for the node. This is effectively == but without
563 # comparing the value of locations. Locations are checked only for presence.
564 def ===(other)
565 other.is_a?(AliasMethodNode) &&
566 (new_name === other.new_name) &&
567 (old_name === other.old_name) &&
568 (keyword_loc.nil? == other.keyword_loc.nil?)
569 end
570 end
571
572 # Represents an alternation pattern in pattern matching.
573 #
574 # foo => bar | baz
575 # ^^^^^^^^^
576 class AlternationPatternNode < Node
577 # Initialize a new AlternationPatternNode node.
578 def initialize(source, node_id, location, flags, left, right, operator_loc)
579 @source = source
580 @node_id = node_id
581 @location = location
582 @flags = flags
583 @left = left
584 @right = right
585 @operator_loc = operator_loc
586 end
587
588 # def accept: (Visitor visitor) -> void
589 def accept(visitor)
590 visitor.visit_alternation_pattern_node(self)
591 end
592
593 # def child_nodes: () -> Array[Node?]
594 def child_nodes
595 [left, right]
596 end
597
598 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
599 def each_child_node
600 return to_enum(:each_child_node) unless block_given?
601
602 yield left
603 yield right
604 end
605
606 # def compact_child_nodes: () -> Array[Node]
607 def compact_child_nodes
608 [left, right]
609 end
610
611 # def comment_targets: () -> Array[Node | Location]
612 def comment_targets
613 [left, right, operator_loc] #: Array[Prism::node | Location]
614 end
615
616 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node, ?right: Prism::node, ?operator_loc: Location) -> AlternationPatternNode
617 def copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc)
618 AlternationPatternNode.new(source, node_id, location, flags, left, right, operator_loc)
619 end
620
621 # def deconstruct: () -> Array[Node?]
622 alias deconstruct child_nodes
623
624 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, left: Prism::node, right: Prism::node, operator_loc: Location }
625 def deconstruct_keys(keys)
626 { node_id: node_id, location: location, left: left, right: right, operator_loc: operator_loc }
627 end
628
629 # Represents the left side of the expression.
630 #
631 # foo => bar | baz
632 # ^^^
633 attr_reader :left
634
635 # Represents the right side of the expression.
636 #
637 # foo => bar | baz
638 # ^^^
639 attr_reader :right
640
641 # Represents the alternation operator location.
642 #
643 # foo => bar | baz
644 # ^
645 def operator_loc
646 location = @operator_loc
647 return location if location.is_a?(Location)
648 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
649 end
650
651 # Save the operator_loc location using the given saved source so that
652 # it can be retrieved later.
653 def save_operator_loc(repository)
654 repository.enter(node_id, :operator_loc)
655 end
656
657 # def operator: () -> String
658 def operator
659 operator_loc.slice
660 end
661
662 # def inspect -> String
663 def inspect
664 InspectVisitor.compose(self)
665 end
666
667 # Return a symbol representation of this node type. See `Node#type`.
668 def type
669 :alternation_pattern_node
670 end
671
672 # Return a symbol representation of this node type. See `Node::type`.
673 def self.type
674 :alternation_pattern_node
675 end
676
677 # Implements case-equality for the node. This is effectively == but without
678 # comparing the value of locations. Locations are checked only for presence.
679 def ===(other)
680 other.is_a?(AlternationPatternNode) &&
681 (left === other.left) &&
682 (right === other.right) &&
683 (operator_loc.nil? == other.operator_loc.nil?)
684 end
685 end
686
687 # Represents the use of the `&&` operator or the `and` keyword.
688 #
689 # left and right
690 # ^^^^^^^^^^^^^^
691 class AndNode < Node
692 # Initialize a new AndNode node.
693 def initialize(source, node_id, location, flags, left, right, operator_loc)
694 @source = source
695 @node_id = node_id
696 @location = location
697 @flags = flags
698 @left = left
699 @right = right
700 @operator_loc = operator_loc
701 end
702
703 # def accept: (Visitor visitor) -> void
704 def accept(visitor)
705 visitor.visit_and_node(self)
706 end
707
708 # def child_nodes: () -> Array[Node?]
709 def child_nodes
710 [left, right]
711 end
712
713 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
714 def each_child_node
715 return to_enum(:each_child_node) unless block_given?
716
717 yield left
718 yield right
719 end
720
721 # def compact_child_nodes: () -> Array[Node]
722 def compact_child_nodes
723 [left, right]
724 end
725
726 # def comment_targets: () -> Array[Node | Location]
727 def comment_targets
728 [left, right, operator_loc] #: Array[Prism::node | Location]
729 end
730
731 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node, ?right: Prism::node, ?operator_loc: Location) -> AndNode
732 def copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc)
733 AndNode.new(source, node_id, location, flags, left, right, operator_loc)
734 end
735
736 # def deconstruct: () -> Array[Node?]
737 alias deconstruct child_nodes
738
739 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, left: Prism::node, right: Prism::node, operator_loc: Location }
740 def deconstruct_keys(keys)
741 { node_id: node_id, location: location, left: left, right: right, operator_loc: operator_loc }
742 end
743
744 # Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
745 #
746 # left and right
747 # ^^^^
748 #
749 # 1 && 2
750 # ^
751 attr_reader :left
752
753 # Represents the right side of the expression.
754 #
755 # left && right
756 # ^^^^^
757 #
758 # 1 and 2
759 # ^
760 attr_reader :right
761
762 # The location of the `and` keyword or the `&&` operator.
763 #
764 # left and right
765 # ^^^
766 def operator_loc
767 location = @operator_loc
768 return location if location.is_a?(Location)
769 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
770 end
771
772 # Save the operator_loc location using the given saved source so that
773 # it can be retrieved later.
774 def save_operator_loc(repository)
775 repository.enter(node_id, :operator_loc)
776 end
777
778 # def operator: () -> String
779 def operator
780 operator_loc.slice
781 end
782
783 # def inspect -> String
784 def inspect
785 InspectVisitor.compose(self)
786 end
787
788 # Return a symbol representation of this node type. See `Node#type`.
789 def type
790 :and_node
791 end
792
793 # Return a symbol representation of this node type. See `Node::type`.
794 def self.type
795 :and_node
796 end
797
798 # Implements case-equality for the node. This is effectively == but without
799 # comparing the value of locations. Locations are checked only for presence.
800 def ===(other)
801 other.is_a?(AndNode) &&
802 (left === other.left) &&
803 (right === other.right) &&
804 (operator_loc.nil? == other.operator_loc.nil?)
805 end
806 end
807
808 # Represents a set of arguments to a method or a keyword.
809 #
810 # return foo, bar, baz
811 # ^^^^^^^^^^^^^
812 class ArgumentsNode < Node
813 # Initialize a new ArgumentsNode node.
814 def initialize(source, node_id, location, flags, arguments)
815 @source = source
816 @node_id = node_id
817 @location = location
818 @flags = flags
819 @arguments = arguments
820 end
821
822 # def accept: (Visitor visitor) -> void
823 def accept(visitor)
824 visitor.visit_arguments_node(self)
825 end
826
827 # def child_nodes: () -> Array[Node?]
828 def child_nodes
829 [*arguments]
830 end
831
832 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
833 def each_child_node
834 return to_enum(:each_child_node) unless block_given?
835
836 arguments.each { |node| yield node }
837 end
838
839 # def compact_child_nodes: () -> Array[Node]
840 def compact_child_nodes
841 [*arguments]
842 end
843
844 # def comment_targets: () -> Array[Node | Location]
845 def comment_targets
846 [*arguments] #: Array[Prism::node | Location]
847 end
848
849 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?arguments: Array[Prism::node]) -> ArgumentsNode
850 def copy(node_id: self.node_id, location: self.location, flags: self.flags, arguments: self.arguments)
851 ArgumentsNode.new(source, node_id, location, flags, arguments)
852 end
853
854 # def deconstruct: () -> Array[Node?]
855 alias deconstruct child_nodes
856
857 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, arguments: Array[Prism::node] }
858 def deconstruct_keys(keys)
859 { node_id: node_id, location: location, arguments: arguments }
860 end
861
862 # def contains_forwarding?: () -> bool
863 def contains_forwarding?
864 flags.anybits?(ArgumentsNodeFlags::CONTAINS_FORWARDING)
865 end
866
867 # def contains_keywords?: () -> bool
868 def contains_keywords?
869 flags.anybits?(ArgumentsNodeFlags::CONTAINS_KEYWORDS)
870 end
871
872 # def contains_keyword_splat?: () -> bool
873 def contains_keyword_splat?
874 flags.anybits?(ArgumentsNodeFlags::CONTAINS_KEYWORD_SPLAT)
875 end
876
877 # def contains_splat?: () -> bool
878 def contains_splat?
879 flags.anybits?(ArgumentsNodeFlags::CONTAINS_SPLAT)
880 end
881
882 # def contains_multiple_splats?: () -> bool
883 def contains_multiple_splats?
884 flags.anybits?(ArgumentsNodeFlags::CONTAINS_MULTIPLE_SPLATS)
885 end
886
887 # The list of arguments, if present. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
888 #
889 # foo(bar, baz)
890 # ^^^^^^^^
891 attr_reader :arguments
892
893 # def inspect -> String
894 def inspect
895 InspectVisitor.compose(self)
896 end
897
898 # Return a symbol representation of this node type. See `Node#type`.
899 def type
900 :arguments_node
901 end
902
903 # Return a symbol representation of this node type. See `Node::type`.
904 def self.type
905 :arguments_node
906 end
907
908 # Implements case-equality for the node. This is effectively == but without
909 # comparing the value of locations. Locations are checked only for presence.
910 def ===(other)
911 other.is_a?(ArgumentsNode) &&
912 (flags === other.flags) &&
913 (arguments.length == other.arguments.length) &&
914 arguments.zip(other.arguments).all? { |left, right| left === right }
915 end
916 end
917
918 # Represents an array literal. This can be a regular array using brackets or a special array using % like %w or %i.
919 #
920 # [1, 2, 3]
921 # ^^^^^^^^^
922 class ArrayNode < Node
923 # Initialize a new ArrayNode node.
924 def initialize(source, node_id, location, flags, elements, opening_loc, closing_loc)
925 @source = source
926 @node_id = node_id
927 @location = location
928 @flags = flags
929 @elements = elements
930 @opening_loc = opening_loc
931 @closing_loc = closing_loc
932 end
933
934 # def accept: (Visitor visitor) -> void
935 def accept(visitor)
936 visitor.visit_array_node(self)
937 end
938
939 # def child_nodes: () -> Array[Node?]
940 def child_nodes
941 [*elements]
942 end
943
944 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
945 def each_child_node
946 return to_enum(:each_child_node) unless block_given?
947
948 elements.each { |node| yield node }
949 end
950
951 # def compact_child_nodes: () -> Array[Node]
952 def compact_child_nodes
953 [*elements]
954 end
955
956 # def comment_targets: () -> Array[Node | Location]
957 def comment_targets
958 [*elements, *opening_loc, *closing_loc] #: Array[Prism::node | Location]
959 end
960
961 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?elements: Array[Prism::node], ?opening_loc: Location?, ?closing_loc: Location?) -> ArrayNode
962 def copy(node_id: self.node_id, location: self.location, flags: self.flags, elements: self.elements, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
963 ArrayNode.new(source, node_id, location, flags, elements, opening_loc, closing_loc)
964 end
965
966 # def deconstruct: () -> Array[Node?]
967 alias deconstruct child_nodes
968
969 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, elements: Array[Prism::node], opening_loc: Location?, closing_loc: Location? }
970 def deconstruct_keys(keys)
971 { node_id: node_id, location: location, elements: elements, opening_loc: opening_loc, closing_loc: closing_loc }
972 end
973
974 # def contains_splat?: () -> bool
975 def contains_splat?
976 flags.anybits?(ArrayNodeFlags::CONTAINS_SPLAT)
977 end
978
979 # Represent the list of zero or more [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression) within the array.
980 attr_reader :elements
981
982 # Represents the optional source location for the opening token.
983 #
984 # [1,2,3] # "["
985 # %w[foo bar baz] # "%w["
986 # %I(apple orange banana) # "%I("
987 # foo = 1, 2, 3 # nil
988 def opening_loc
989 location = @opening_loc
990 case location
991 when nil
992 nil
993 when Location
994 location
995 else
996 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
997 end
998 end
999
1000 # Save the opening_loc location using the given saved source so that
1001 # it can be retrieved later.
1002 def save_opening_loc(repository)
1003 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
1004 end
1005
1006 # Represents the optional source location for the closing token.
1007 #
1008 # [1,2,3] # "]"
1009 # %w[foo bar baz] # "]"
1010 # %I(apple orange banana) # ")"
1011 # foo = 1, 2, 3 # nil
1012 def closing_loc
1013 location = @closing_loc
1014 case location
1015 when nil
1016 nil
1017 when Location
1018 location
1019 else
1020 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
1021 end
1022 end
1023
1024 # Save the closing_loc location using the given saved source so that
1025 # it can be retrieved later.
1026 def save_closing_loc(repository)
1027 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
1028 end
1029
1030 # def opening: () -> String?
1031 def opening
1032 opening_loc&.slice
1033 end
1034
1035 # def closing: () -> String?
1036 def closing
1037 closing_loc&.slice
1038 end
1039
1040 # def inspect -> String
1041 def inspect
1042 InspectVisitor.compose(self)
1043 end
1044
1045 # Return a symbol representation of this node type. See `Node#type`.
1046 def type
1047 :array_node
1048 end
1049
1050 # Return a symbol representation of this node type. See `Node::type`.
1051 def self.type
1052 :array_node
1053 end
1054
1055 # Implements case-equality for the node. This is effectively == but without
1056 # comparing the value of locations. Locations are checked only for presence.
1057 def ===(other)
1058 other.is_a?(ArrayNode) &&
1059 (flags === other.flags) &&
1060 (elements.length == other.elements.length) &&
1061 elements.zip(other.elements).all? { |left, right| left === right } &&
1062 (opening_loc.nil? == other.opening_loc.nil?) &&
1063 (closing_loc.nil? == other.closing_loc.nil?)
1064 end
1065 end
1066
1067 # Represents an array pattern in pattern matching.
1068 #
1069 # foo in 1, 2
1070 # ^^^^^^^^^^^
1071 #
1072 # foo in [1, 2]
1073 # ^^^^^^^^^^^^^
1074 #
1075 # foo in *bar
1076 # ^^^^^^^^^^^
1077 #
1078 # foo in Bar[]
1079 # ^^^^^^^^^^^^
1080 #
1081 # foo in Bar[1, 2, 3]
1082 # ^^^^^^^^^^^^^^^^^^^
1083 class ArrayPatternNode < Node
1084 # Initialize a new ArrayPatternNode node.
1085 def initialize(source, node_id, location, flags, constant, requireds, rest, posts, opening_loc, closing_loc)
1086 @source = source
1087 @node_id = node_id
1088 @location = location
1089 @flags = flags
1090 @constant = constant
1091 @requireds = requireds
1092 @rest = rest
1093 @posts = posts
1094 @opening_loc = opening_loc
1095 @closing_loc = closing_loc
1096 end
1097
1098 # def accept: (Visitor visitor) -> void
1099 def accept(visitor)
1100 visitor.visit_array_pattern_node(self)
1101 end
1102
1103 # def child_nodes: () -> Array[Node?]
1104 def child_nodes
1105 [constant, *requireds, rest, *posts]
1106 end
1107
1108 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
1109 def each_child_node
1110 return to_enum(:each_child_node) unless block_given?
1111
1112 yield constant if constant
1113 requireds.each { |node| yield node }
1114 yield rest if rest
1115 posts.each { |node| yield node }
1116 end
1117
1118 # def compact_child_nodes: () -> Array[Node]
1119 def compact_child_nodes
1120 compact = [] #: Array[Prism::node]
1121 compact << constant if constant
1122 compact.concat(requireds)
1123 compact << rest if rest
1124 compact.concat(posts)
1125 compact
1126 end
1127
1128 # def comment_targets: () -> Array[Node | Location]
1129 def comment_targets
1130 [*constant, *requireds, *rest, *posts, *opening_loc, *closing_loc] #: Array[Prism::node | Location]
1131 end
1132
1133 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?constant: ConstantPathNode | ConstantReadNode | nil, ?requireds: Array[Prism::node], ?rest: Prism::node?, ?posts: Array[Prism::node], ?opening_loc: Location?, ?closing_loc: Location?) -> ArrayPatternNode
1134 def copy(node_id: self.node_id, location: self.location, flags: self.flags, constant: self.constant, requireds: self.requireds, rest: self.rest, posts: self.posts, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
1135 ArrayPatternNode.new(source, node_id, location, flags, constant, requireds, rest, posts, opening_loc, closing_loc)
1136 end
1137
1138 # def deconstruct: () -> Array[Node?]
1139 alias deconstruct child_nodes
1140
1141 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, constant: ConstantPathNode | ConstantReadNode | nil, requireds: Array[Prism::node], rest: Prism::node?, posts: Array[Prism::node], opening_loc: Location?, closing_loc: Location? }
1142 def deconstruct_keys(keys)
1143 { node_id: node_id, location: location, constant: constant, requireds: requireds, rest: rest, posts: posts, opening_loc: opening_loc, closing_loc: closing_loc }
1144 end
1145
1146 # Represents the optional constant preceding the Array
1147 #
1148 # foo in Bar[]
1149 # ^^^
1150 #
1151 # foo in Bar[1, 2, 3]
1152 # ^^^
1153 #
1154 # foo in Bar::Baz[1, 2, 3]
1155 # ^^^^^^^^
1156 attr_reader :constant
1157
1158 # Represents the required elements of the array pattern.
1159 #
1160 # foo in [1, 2]
1161 # ^ ^
1162 attr_reader :requireds
1163
1164 # Represents the rest element of the array pattern.
1165 #
1166 # foo in *bar
1167 # ^^^^
1168 attr_reader :rest
1169
1170 # Represents the elements after the rest element of the array pattern.
1171 #
1172 # foo in *bar, baz
1173 # ^^^
1174 attr_reader :posts
1175
1176 # Represents the opening location of the array pattern.
1177 #
1178 # foo in [1, 2]
1179 # ^
1180 def opening_loc
1181 location = @opening_loc
1182 case location
1183 when nil
1184 nil
1185 when Location
1186 location
1187 else
1188 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
1189 end
1190 end
1191
1192 # Save the opening_loc location using the given saved source so that
1193 # it can be retrieved later.
1194 def save_opening_loc(repository)
1195 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
1196 end
1197
1198 # Represents the closing location of the array pattern.
1199 #
1200 # foo in [1, 2]
1201 # ^
1202 def closing_loc
1203 location = @closing_loc
1204 case location
1205 when nil
1206 nil
1207 when Location
1208 location
1209 else
1210 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
1211 end
1212 end
1213
1214 # Save the closing_loc location using the given saved source so that
1215 # it can be retrieved later.
1216 def save_closing_loc(repository)
1217 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
1218 end
1219
1220 # def opening: () -> String?
1221 def opening
1222 opening_loc&.slice
1223 end
1224
1225 # def closing: () -> String?
1226 def closing
1227 closing_loc&.slice
1228 end
1229
1230 # def inspect -> String
1231 def inspect
1232 InspectVisitor.compose(self)
1233 end
1234
1235 # Return a symbol representation of this node type. See `Node#type`.
1236 def type
1237 :array_pattern_node
1238 end
1239
1240 # Return a symbol representation of this node type. See `Node::type`.
1241 def self.type
1242 :array_pattern_node
1243 end
1244
1245 # Implements case-equality for the node. This is effectively == but without
1246 # comparing the value of locations. Locations are checked only for presence.
1247 def ===(other)
1248 other.is_a?(ArrayPatternNode) &&
1249 (constant === other.constant) &&
1250 (requireds.length == other.requireds.length) &&
1251 requireds.zip(other.requireds).all? { |left, right| left === right } &&
1252 (rest === other.rest) &&
1253 (posts.length == other.posts.length) &&
1254 posts.zip(other.posts).all? { |left, right| left === right } &&
1255 (opening_loc.nil? == other.opening_loc.nil?) &&
1256 (closing_loc.nil? == other.closing_loc.nil?)
1257 end
1258 end
1259
1260 # Represents a hash key/value pair.
1261 #
1262 # { a => b }
1263 # ^^^^^^
1264 class AssocNode < Node
1265 # Initialize a new AssocNode node.
1266 def initialize(source, node_id, location, flags, key, value, operator_loc)
1267 @source = source
1268 @node_id = node_id
1269 @location = location
1270 @flags = flags
1271 @key = key
1272 @value = value
1273 @operator_loc = operator_loc
1274 end
1275
1276 # def accept: (Visitor visitor) -> void
1277 def accept(visitor)
1278 visitor.visit_assoc_node(self)
1279 end
1280
1281 # def child_nodes: () -> Array[Node?]
1282 def child_nodes
1283 [key, value]
1284 end
1285
1286 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
1287 def each_child_node
1288 return to_enum(:each_child_node) unless block_given?
1289
1290 yield key
1291 yield value
1292 end
1293
1294 # def compact_child_nodes: () -> Array[Node]
1295 def compact_child_nodes
1296 [key, value]
1297 end
1298
1299 # def comment_targets: () -> Array[Node | Location]
1300 def comment_targets
1301 [key, value, *operator_loc] #: Array[Prism::node | Location]
1302 end
1303
1304 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?key: Prism::node, ?value: Prism::node, ?operator_loc: Location?) -> AssocNode
1305 def copy(node_id: self.node_id, location: self.location, flags: self.flags, key: self.key, value: self.value, operator_loc: self.operator_loc)
1306 AssocNode.new(source, node_id, location, flags, key, value, operator_loc)
1307 end
1308
1309 # def deconstruct: () -> Array[Node?]
1310 alias deconstruct child_nodes
1311
1312 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, key: Prism::node, value: Prism::node, operator_loc: Location? }
1313 def deconstruct_keys(keys)
1314 { node_id: node_id, location: location, key: key, value: value, operator_loc: operator_loc }
1315 end
1316
1317 # The key of the association. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1318 #
1319 # { a: b }
1320 # ^
1321 #
1322 # { foo => bar }
1323 # ^^^
1324 #
1325 # { def a; end => 1 }
1326 # ^^^^^^^^^^
1327 attr_reader :key
1328
1329 # The value of the association, if present. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1330 #
1331 # { foo => bar }
1332 # ^^^
1333 #
1334 # { x: 1 }
1335 # ^
1336 attr_reader :value
1337
1338 # The location of the `=>` operator, if present.
1339 #
1340 # { foo => bar }
1341 # ^^
1342 def operator_loc
1343 location = @operator_loc
1344 case location
1345 when nil
1346 nil
1347 when Location
1348 location
1349 else
1350 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
1351 end
1352 end
1353
1354 # Save the operator_loc location using the given saved source so that
1355 # it can be retrieved later.
1356 def save_operator_loc(repository)
1357 repository.enter(node_id, :operator_loc) unless @operator_loc.nil?
1358 end
1359
1360 # def operator: () -> String?
1361 def operator
1362 operator_loc&.slice
1363 end
1364
1365 # def inspect -> String
1366 def inspect
1367 InspectVisitor.compose(self)
1368 end
1369
1370 # Return a symbol representation of this node type. See `Node#type`.
1371 def type
1372 :assoc_node
1373 end
1374
1375 # Return a symbol representation of this node type. See `Node::type`.
1376 def self.type
1377 :assoc_node
1378 end
1379
1380 # Implements case-equality for the node. This is effectively == but without
1381 # comparing the value of locations. Locations are checked only for presence.
1382 def ===(other)
1383 other.is_a?(AssocNode) &&
1384 (key === other.key) &&
1385 (value === other.value) &&
1386 (operator_loc.nil? == other.operator_loc.nil?)
1387 end
1388 end
1389
1390 # Represents a splat in a hash literal.
1391 #
1392 # { **foo }
1393 # ^^^^^
1394 class AssocSplatNode < Node
1395 # Initialize a new AssocSplatNode node.
1396 def initialize(source, node_id, location, flags, value, operator_loc)
1397 @source = source
1398 @node_id = node_id
1399 @location = location
1400 @flags = flags
1401 @value = value
1402 @operator_loc = operator_loc
1403 end
1404
1405 # def accept: (Visitor visitor) -> void
1406 def accept(visitor)
1407 visitor.visit_assoc_splat_node(self)
1408 end
1409
1410 # def child_nodes: () -> Array[Node?]
1411 def child_nodes
1412 [value]
1413 end
1414
1415 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
1416 def each_child_node
1417 return to_enum(:each_child_node) unless block_given?
1418
1419 yield value if value
1420 end
1421
1422 # def compact_child_nodes: () -> Array[Node]
1423 def compact_child_nodes
1424 compact = [] #: Array[Prism::node]
1425 compact << value if value
1426 compact
1427 end
1428
1429 # def comment_targets: () -> Array[Node | Location]
1430 def comment_targets
1431 [*value, operator_loc] #: Array[Prism::node | Location]
1432 end
1433
1434 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node?, ?operator_loc: Location) -> AssocSplatNode
1435 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, operator_loc: self.operator_loc)
1436 AssocSplatNode.new(source, node_id, location, flags, value, operator_loc)
1437 end
1438
1439 # def deconstruct: () -> Array[Node?]
1440 alias deconstruct child_nodes
1441
1442 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, value: Prism::node?, operator_loc: Location }
1443 def deconstruct_keys(keys)
1444 { node_id: node_id, location: location, value: value, operator_loc: operator_loc }
1445 end
1446
1447 # The value to be splatted, if present. Will be missing when keyword rest argument forwarding is used.
1448 #
1449 # { **foo }
1450 # ^^^
1451 attr_reader :value
1452
1453 # The location of the `**` operator.
1454 #
1455 # { **x }
1456 # ^^
1457 def operator_loc
1458 location = @operator_loc
1459 return location if location.is_a?(Location)
1460 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
1461 end
1462
1463 # Save the operator_loc location using the given saved source so that
1464 # it can be retrieved later.
1465 def save_operator_loc(repository)
1466 repository.enter(node_id, :operator_loc)
1467 end
1468
1469 # def operator: () -> String
1470 def operator
1471 operator_loc.slice
1472 end
1473
1474 # def inspect -> String
1475 def inspect
1476 InspectVisitor.compose(self)
1477 end
1478
1479 # Return a symbol representation of this node type. See `Node#type`.
1480 def type
1481 :assoc_splat_node
1482 end
1483
1484 # Return a symbol representation of this node type. See `Node::type`.
1485 def self.type
1486 :assoc_splat_node
1487 end
1488
1489 # Implements case-equality for the node. This is effectively == but without
1490 # comparing the value of locations. Locations are checked only for presence.
1491 def ===(other)
1492 other.is_a?(AssocSplatNode) &&
1493 (value === other.value) &&
1494 (operator_loc.nil? == other.operator_loc.nil?)
1495 end
1496 end
1497
1498 # Represents reading a reference to a field in the previous match.
1499 #
1500 # $'
1501 # ^^
1502 class BackReferenceReadNode < Node
1503 # Initialize a new BackReferenceReadNode node.
1504 def initialize(source, node_id, location, flags, name)
1505 @source = source
1506 @node_id = node_id
1507 @location = location
1508 @flags = flags
1509 @name = name
1510 end
1511
1512 # def accept: (Visitor visitor) -> void
1513 def accept(visitor)
1514 visitor.visit_back_reference_read_node(self)
1515 end
1516
1517 # def child_nodes: () -> Array[Node?]
1518 def child_nodes
1519 []
1520 end
1521
1522 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
1523 def each_child_node
1524 return to_enum(:each_child_node) unless block_given?
1525
1526 end
1527
1528 # def compact_child_nodes: () -> Array[Node]
1529 def compact_child_nodes
1530 []
1531 end
1532
1533 # def comment_targets: () -> Array[Node | Location]
1534 def comment_targets
1535 [] #: Array[Prism::node | Location]
1536 end
1537
1538 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> BackReferenceReadNode
1539 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
1540 BackReferenceReadNode.new(source, node_id, location, flags, name)
1541 end
1542
1543 # def deconstruct: () -> Array[Node?]
1544 alias deconstruct child_nodes
1545
1546 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
1547 def deconstruct_keys(keys)
1548 { node_id: node_id, location: location, name: name }
1549 end
1550
1551 # The name of the back-reference variable, including the leading `$`.
1552 #
1553 # $& # name `:$&`
1554 #
1555 # $+ # name `:$+`
1556 attr_reader :name
1557
1558 # def inspect -> String
1559 def inspect
1560 InspectVisitor.compose(self)
1561 end
1562
1563 # Return a symbol representation of this node type. See `Node#type`.
1564 def type
1565 :back_reference_read_node
1566 end
1567
1568 # Return a symbol representation of this node type. See `Node::type`.
1569 def self.type
1570 :back_reference_read_node
1571 end
1572
1573 # Implements case-equality for the node. This is effectively == but without
1574 # comparing the value of locations. Locations are checked only for presence.
1575 def ===(other)
1576 other.is_a?(BackReferenceReadNode) &&
1577 (name === other.name)
1578 end
1579 end
1580
1581 # Represents a begin statement.
1582 #
1583 # begin
1584 # foo
1585 # end
1586 # ^^^^^
1587 class BeginNode < Node
1588 # Initialize a new BeginNode node.
1589 def initialize(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc)
1590 @source = source
1591 @node_id = node_id
1592 @location = location
1593 @flags = flags
1594 @begin_keyword_loc = begin_keyword_loc
1595 @statements = statements
1596 @rescue_clause = rescue_clause
1597 @else_clause = else_clause
1598 @ensure_clause = ensure_clause
1599 @end_keyword_loc = end_keyword_loc
1600 end
1601
1602 # def accept: (Visitor visitor) -> void
1603 def accept(visitor)
1604 visitor.visit_begin_node(self)
1605 end
1606
1607 # def child_nodes: () -> Array[Node?]
1608 def child_nodes
1609 [statements, rescue_clause, else_clause, ensure_clause]
1610 end
1611
1612 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
1613 def each_child_node
1614 return to_enum(:each_child_node) unless block_given?
1615
1616 yield statements if statements
1617 yield rescue_clause if rescue_clause
1618 yield else_clause if else_clause
1619 yield ensure_clause if ensure_clause
1620 end
1621
1622 # def compact_child_nodes: () -> Array[Node]
1623 def compact_child_nodes
1624 compact = [] #: Array[Prism::node]
1625 compact << statements if statements
1626 compact << rescue_clause if rescue_clause
1627 compact << else_clause if else_clause
1628 compact << ensure_clause if ensure_clause
1629 compact
1630 end
1631
1632 # def comment_targets: () -> Array[Node | Location]
1633 def comment_targets
1634 [*begin_keyword_loc, *statements, *rescue_clause, *else_clause, *ensure_clause, *end_keyword_loc] #: Array[Prism::node | Location]
1635 end
1636
1637 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?begin_keyword_loc: Location?, ?statements: StatementsNode?, ?rescue_clause: RescueNode?, ?else_clause: ElseNode?, ?ensure_clause: EnsureNode?, ?end_keyword_loc: Location?) -> BeginNode
1638 def copy(node_id: self.node_id, location: self.location, flags: self.flags, begin_keyword_loc: self.begin_keyword_loc, statements: self.statements, rescue_clause: self.rescue_clause, else_clause: self.else_clause, ensure_clause: self.ensure_clause, end_keyword_loc: self.end_keyword_loc)
1639 BeginNode.new(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc)
1640 end
1641
1642 # def deconstruct: () -> Array[Node?]
1643 alias deconstruct child_nodes
1644
1645 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, begin_keyword_loc: Location?, statements: StatementsNode?, rescue_clause: RescueNode?, else_clause: ElseNode?, ensure_clause: EnsureNode?, end_keyword_loc: Location? }
1646 def deconstruct_keys(keys)
1647 { node_id: node_id, location: location, begin_keyword_loc: begin_keyword_loc, statements: statements, rescue_clause: rescue_clause, else_clause: else_clause, ensure_clause: ensure_clause, end_keyword_loc: end_keyword_loc }
1648 end
1649
1650 # Represents the location of the `begin` keyword.
1651 #
1652 # begin x end
1653 # ^^^^^
1654 def begin_keyword_loc
1655 location = @begin_keyword_loc
1656 case location
1657 when nil
1658 nil
1659 when Location
1660 location
1661 else
1662 @begin_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
1663 end
1664 end
1665
1666 # Save the begin_keyword_loc location using the given saved source so that
1667 # it can be retrieved later.
1668 def save_begin_keyword_loc(repository)
1669 repository.enter(node_id, :begin_keyword_loc) unless @begin_keyword_loc.nil?
1670 end
1671
1672 # Represents the statements within the begin block.
1673 #
1674 # begin x end
1675 # ^
1676 attr_reader :statements
1677
1678 # Represents the rescue clause within the begin block.
1679 #
1680 # begin x; rescue y; end
1681 # ^^^^^^^^
1682 attr_reader :rescue_clause
1683
1684 # Represents the else clause within the begin block.
1685 #
1686 # begin x; rescue y; else z; end
1687 # ^^^^^^
1688 attr_reader :else_clause
1689
1690 # Represents the ensure clause within the begin block.
1691 #
1692 # begin x; ensure y; end
1693 # ^^^^^^^^
1694 attr_reader :ensure_clause
1695
1696 # Represents the location of the `end` keyword.
1697 #
1698 # begin x end
1699 # ^^^
1700 def end_keyword_loc
1701 location = @end_keyword_loc
1702 case location
1703 when nil
1704 nil
1705 when Location
1706 location
1707 else
1708 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
1709 end
1710 end
1711
1712 # Save the end_keyword_loc location using the given saved source so that
1713 # it can be retrieved later.
1714 def save_end_keyword_loc(repository)
1715 repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil?
1716 end
1717
1718 # def begin_keyword: () -> String?
1719 def begin_keyword
1720 begin_keyword_loc&.slice
1721 end
1722
1723 # def end_keyword: () -> String?
1724 def end_keyword
1725 end_keyword_loc&.slice
1726 end
1727
1728 # def inspect -> String
1729 def inspect
1730 InspectVisitor.compose(self)
1731 end
1732
1733 # Return a symbol representation of this node type. See `Node#type`.
1734 def type
1735 :begin_node
1736 end
1737
1738 # Return a symbol representation of this node type. See `Node::type`.
1739 def self.type
1740 :begin_node
1741 end
1742
1743 # Implements case-equality for the node. This is effectively == but without
1744 # comparing the value of locations. Locations are checked only for presence.
1745 def ===(other)
1746 other.is_a?(BeginNode) &&
1747 (begin_keyword_loc.nil? == other.begin_keyword_loc.nil?) &&
1748 (statements === other.statements) &&
1749 (rescue_clause === other.rescue_clause) &&
1750 (else_clause === other.else_clause) &&
1751 (ensure_clause === other.ensure_clause) &&
1752 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
1753 end
1754 end
1755
1756 # Represents a block argument using `&`.
1757 #
1758 # bar(&args)
1759 # ^^^^^^^^^^
1760 class BlockArgumentNode < Node
1761 # Initialize a new BlockArgumentNode node.
1762 def initialize(source, node_id, location, flags, expression, operator_loc)
1763 @source = source
1764 @node_id = node_id
1765 @location = location
1766 @flags = flags
1767 @expression = expression
1768 @operator_loc = operator_loc
1769 end
1770
1771 # def accept: (Visitor visitor) -> void
1772 def accept(visitor)
1773 visitor.visit_block_argument_node(self)
1774 end
1775
1776 # def child_nodes: () -> Array[Node?]
1777 def child_nodes
1778 [expression]
1779 end
1780
1781 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
1782 def each_child_node
1783 return to_enum(:each_child_node) unless block_given?
1784
1785 yield expression if expression
1786 end
1787
1788 # def compact_child_nodes: () -> Array[Node]
1789 def compact_child_nodes
1790 compact = [] #: Array[Prism::node]
1791 compact << expression if expression
1792 compact
1793 end
1794
1795 # def comment_targets: () -> Array[Node | Location]
1796 def comment_targets
1797 [*expression, operator_loc] #: Array[Prism::node | Location]
1798 end
1799
1800 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?expression: Prism::node?, ?operator_loc: Location) -> BlockArgumentNode
1801 def copy(node_id: self.node_id, location: self.location, flags: self.flags, expression: self.expression, operator_loc: self.operator_loc)
1802 BlockArgumentNode.new(source, node_id, location, flags, expression, operator_loc)
1803 end
1804
1805 # def deconstruct: () -> Array[Node?]
1806 alias deconstruct child_nodes
1807
1808 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, expression: Prism::node?, operator_loc: Location }
1809 def deconstruct_keys(keys)
1810 { node_id: node_id, location: location, expression: expression, operator_loc: operator_loc }
1811 end
1812
1813 # The expression that is being passed as a block argument. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1814 #
1815 # foo(&args)
1816 # ^^^^^
1817 attr_reader :expression
1818
1819 # Represents the location of the `&` operator.
1820 #
1821 # foo(&args)
1822 # ^
1823 def operator_loc
1824 location = @operator_loc
1825 return location if location.is_a?(Location)
1826 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
1827 end
1828
1829 # Save the operator_loc location using the given saved source so that
1830 # it can be retrieved later.
1831 def save_operator_loc(repository)
1832 repository.enter(node_id, :operator_loc)
1833 end
1834
1835 # def operator: () -> String
1836 def operator
1837 operator_loc.slice
1838 end
1839
1840 # def inspect -> String
1841 def inspect
1842 InspectVisitor.compose(self)
1843 end
1844
1845 # Return a symbol representation of this node type. See `Node#type`.
1846 def type
1847 :block_argument_node
1848 end
1849
1850 # Return a symbol representation of this node type. See `Node::type`.
1851 def self.type
1852 :block_argument_node
1853 end
1854
1855 # Implements case-equality for the node. This is effectively == but without
1856 # comparing the value of locations. Locations are checked only for presence.
1857 def ===(other)
1858 other.is_a?(BlockArgumentNode) &&
1859 (expression === other.expression) &&
1860 (operator_loc.nil? == other.operator_loc.nil?)
1861 end
1862 end
1863
1864 # Represents a block local variable.
1865 #
1866 # a { |; b| }
1867 # ^
1868 class BlockLocalVariableNode < Node
1869 # Initialize a new BlockLocalVariableNode node.
1870 def initialize(source, node_id, location, flags, name)
1871 @source = source
1872 @node_id = node_id
1873 @location = location
1874 @flags = flags
1875 @name = name
1876 end
1877
1878 # def accept: (Visitor visitor) -> void
1879 def accept(visitor)
1880 visitor.visit_block_local_variable_node(self)
1881 end
1882
1883 # def child_nodes: () -> Array[Node?]
1884 def child_nodes
1885 []
1886 end
1887
1888 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
1889 def each_child_node
1890 return to_enum(:each_child_node) unless block_given?
1891
1892 end
1893
1894 # def compact_child_nodes: () -> Array[Node]
1895 def compact_child_nodes
1896 []
1897 end
1898
1899 # def comment_targets: () -> Array[Node | Location]
1900 def comment_targets
1901 [] #: Array[Prism::node | Location]
1902 end
1903
1904 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> BlockLocalVariableNode
1905 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
1906 BlockLocalVariableNode.new(source, node_id, location, flags, name)
1907 end
1908
1909 # def deconstruct: () -> Array[Node?]
1910 alias deconstruct child_nodes
1911
1912 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
1913 def deconstruct_keys(keys)
1914 { node_id: node_id, location: location, name: name }
1915 end
1916
1917 # def repeated_parameter?: () -> bool
1918 def repeated_parameter?
1919 flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
1920 end
1921
1922 # The name of the block local variable.
1923 #
1924 # a { |; b| } # name `:b`
1925 # ^
1926 attr_reader :name
1927
1928 # def inspect -> String
1929 def inspect
1930 InspectVisitor.compose(self)
1931 end
1932
1933 # Return a symbol representation of this node type. See `Node#type`.
1934 def type
1935 :block_local_variable_node
1936 end
1937
1938 # Return a symbol representation of this node type. See `Node::type`.
1939 def self.type
1940 :block_local_variable_node
1941 end
1942
1943 # Implements case-equality for the node. This is effectively == but without
1944 # comparing the value of locations. Locations are checked only for presence.
1945 def ===(other)
1946 other.is_a?(BlockLocalVariableNode) &&
1947 (flags === other.flags) &&
1948 (name === other.name)
1949 end
1950 end
1951
1952 # Represents a block of ruby code.
1953 #
1954 # [1, 2, 3].each { |i| puts x }
1955 # ^^^^^^^^^^^^^^
1956 class BlockNode < Node
1957 # Initialize a new BlockNode node.
1958 def initialize(source, node_id, location, flags, locals, parameters, body, opening_loc, closing_loc)
1959 @source = source
1960 @node_id = node_id
1961 @location = location
1962 @flags = flags
1963 @locals = locals
1964 @parameters = parameters
1965 @body = body
1966 @opening_loc = opening_loc
1967 @closing_loc = closing_loc
1968 end
1969
1970 # def accept: (Visitor visitor) -> void
1971 def accept(visitor)
1972 visitor.visit_block_node(self)
1973 end
1974
1975 # def child_nodes: () -> Array[Node?]
1976 def child_nodes
1977 [parameters, body]
1978 end
1979
1980 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
1981 def each_child_node
1982 return to_enum(:each_child_node) unless block_given?
1983
1984 yield parameters if parameters
1985 yield body if body
1986 end
1987
1988 # def compact_child_nodes: () -> Array[Node]
1989 def compact_child_nodes
1990 compact = [] #: Array[Prism::node]
1991 compact << parameters if parameters
1992 compact << body if body
1993 compact
1994 end
1995
1996 # def comment_targets: () -> Array[Node | Location]
1997 def comment_targets
1998 [*parameters, *body, opening_loc, closing_loc] #: Array[Prism::node | Location]
1999 end
2000
2001 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array[Symbol], ?parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil, ?body: StatementsNode | BeginNode | nil, ?opening_loc: Location, ?closing_loc: Location) -> BlockNode
2002 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, parameters: self.parameters, body: self.body, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
2003 BlockNode.new(source, node_id, location, flags, locals, parameters, body, opening_loc, closing_loc)
2004 end
2005
2006 # def deconstruct: () -> Array[Node?]
2007 alias deconstruct child_nodes
2008
2009 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, locals: Array[Symbol], parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil, body: StatementsNode | BeginNode | nil, opening_loc: Location, closing_loc: Location }
2010 def deconstruct_keys(keys)
2011 { node_id: node_id, location: location, locals: locals, parameters: parameters, body: body, opening_loc: opening_loc, closing_loc: closing_loc }
2012 end
2013
2014 # The local variables declared in the block.
2015 #
2016 # [1, 2, 3].each { |i| puts x } # locals: [:i]
2017 # ^
2018 attr_reader :locals
2019
2020 # The parameters of the block.
2021 #
2022 # [1, 2, 3].each { |i| puts x }
2023 # ^^^
2024 # [1, 2, 3].each { puts _1 }
2025 # ^^^^^^^^^^^
2026 # [1, 2, 3].each { puts it }
2027 # ^^^^^^^^^^^
2028 attr_reader :parameters
2029
2030 # The body of the block.
2031 #
2032 # [1, 2, 3].each { |i| puts x }
2033 # ^^^^^^
2034 attr_reader :body
2035
2036 # Represents the location of the opening `{` or `do`.
2037 #
2038 # [1, 2, 3].each { |i| puts x }
2039 # ^
2040 def opening_loc
2041 location = @opening_loc
2042 return location if location.is_a?(Location)
2043 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2044 end
2045
2046 # Save the opening_loc location using the given saved source so that
2047 # it can be retrieved later.
2048 def save_opening_loc(repository)
2049 repository.enter(node_id, :opening_loc)
2050 end
2051
2052 # Represents the location of the closing `}` or `end`.
2053 #
2054 # [1, 2, 3].each { |i| puts x }
2055 # ^
2056 def closing_loc
2057 location = @closing_loc
2058 return location if location.is_a?(Location)
2059 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2060 end
2061
2062 # Save the closing_loc location using the given saved source so that
2063 # it can be retrieved later.
2064 def save_closing_loc(repository)
2065 repository.enter(node_id, :closing_loc)
2066 end
2067
2068 # def opening: () -> String
2069 def opening
2070 opening_loc.slice
2071 end
2072
2073 # def closing: () -> String
2074 def closing
2075 closing_loc.slice
2076 end
2077
2078 # def inspect -> String
2079 def inspect
2080 InspectVisitor.compose(self)
2081 end
2082
2083 # Return a symbol representation of this node type. See `Node#type`.
2084 def type
2085 :block_node
2086 end
2087
2088 # Return a symbol representation of this node type. See `Node::type`.
2089 def self.type
2090 :block_node
2091 end
2092
2093 # Implements case-equality for the node. This is effectively == but without
2094 # comparing the value of locations. Locations are checked only for presence.
2095 def ===(other)
2096 other.is_a?(BlockNode) &&
2097 (locals.length == other.locals.length) &&
2098 locals.zip(other.locals).all? { |left, right| left === right } &&
2099 (parameters === other.parameters) &&
2100 (body === other.body) &&
2101 (opening_loc.nil? == other.opening_loc.nil?) &&
2102 (closing_loc.nil? == other.closing_loc.nil?)
2103 end
2104 end
2105
2106 # Represents a block parameter of a method, block, or lambda definition.
2107 #
2108 # def a(&b)
2109 # ^^
2110 # end
2111 class BlockParameterNode < Node
2112 # Initialize a new BlockParameterNode node.
2113 def initialize(source, node_id, location, flags, name, name_loc, operator_loc)
2114 @source = source
2115 @node_id = node_id
2116 @location = location
2117 @flags = flags
2118 @name = name
2119 @name_loc = name_loc
2120 @operator_loc = operator_loc
2121 end
2122
2123 # def accept: (Visitor visitor) -> void
2124 def accept(visitor)
2125 visitor.visit_block_parameter_node(self)
2126 end
2127
2128 # def child_nodes: () -> Array[Node?]
2129 def child_nodes
2130 []
2131 end
2132
2133 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
2134 def each_child_node
2135 return to_enum(:each_child_node) unless block_given?
2136
2137 end
2138
2139 # def compact_child_nodes: () -> Array[Node]
2140 def compact_child_nodes
2141 []
2142 end
2143
2144 # def comment_targets: () -> Array[Node | Location]
2145 def comment_targets
2146 [*name_loc, operator_loc] #: Array[Prism::node | Location]
2147 end
2148
2149 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol?, ?name_loc: Location?, ?operator_loc: Location) -> BlockParameterNode
2150 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc)
2151 BlockParameterNode.new(source, node_id, location, flags, name, name_loc, operator_loc)
2152 end
2153
2154 # def deconstruct: () -> Array[Node?]
2155 alias deconstruct child_nodes
2156
2157 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol?, name_loc: Location?, operator_loc: Location }
2158 def deconstruct_keys(keys)
2159 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc }
2160 end
2161
2162 # def repeated_parameter?: () -> bool
2163 def repeated_parameter?
2164 flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
2165 end
2166
2167 # The name of the block parameter.
2168 #
2169 # def a(&b) # name `:b`
2170 # ^
2171 # end
2172 attr_reader :name
2173
2174 # Represents the location of the block parameter name.
2175 #
2176 # def a(&b)
2177 # ^
2178 def name_loc
2179 location = @name_loc
2180 case location
2181 when nil
2182 nil
2183 when Location
2184 location
2185 else
2186 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2187 end
2188 end
2189
2190 # Save the name_loc location using the given saved source so that
2191 # it can be retrieved later.
2192 def save_name_loc(repository)
2193 repository.enter(node_id, :name_loc) unless @name_loc.nil?
2194 end
2195
2196 # Represents the location of the `&` operator.
2197 #
2198 # def a(&b)
2199 # ^
2200 # end
2201 def operator_loc
2202 location = @operator_loc
2203 return location if location.is_a?(Location)
2204 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2205 end
2206
2207 # Save the operator_loc location using the given saved source so that
2208 # it can be retrieved later.
2209 def save_operator_loc(repository)
2210 repository.enter(node_id, :operator_loc)
2211 end
2212
2213 # def operator: () -> String
2214 def operator
2215 operator_loc.slice
2216 end
2217
2218 # def inspect -> String
2219 def inspect
2220 InspectVisitor.compose(self)
2221 end
2222
2223 # Return a symbol representation of this node type. See `Node#type`.
2224 def type
2225 :block_parameter_node
2226 end
2227
2228 # Return a symbol representation of this node type. See `Node::type`.
2229 def self.type
2230 :block_parameter_node
2231 end
2232
2233 # Implements case-equality for the node. This is effectively == but without
2234 # comparing the value of locations. Locations are checked only for presence.
2235 def ===(other)
2236 other.is_a?(BlockParameterNode) &&
2237 (flags === other.flags) &&
2238 (name === other.name) &&
2239 (name_loc.nil? == other.name_loc.nil?) &&
2240 (operator_loc.nil? == other.operator_loc.nil?)
2241 end
2242 end
2243
2244 # Represents a block's parameters declaration.
2245 #
2246 # -> (a, b = 1; local) { }
2247 # ^^^^^^^^^^^^^^^^^
2248 #
2249 # foo do |a, b = 1; local|
2250 # ^^^^^^^^^^^^^^^^^
2251 # end
2252 class BlockParametersNode < Node
2253 # Initialize a new BlockParametersNode node.
2254 def initialize(source, node_id, location, flags, parameters, locals, opening_loc, closing_loc)
2255 @source = source
2256 @node_id = node_id
2257 @location = location
2258 @flags = flags
2259 @parameters = parameters
2260 @locals = locals
2261 @opening_loc = opening_loc
2262 @closing_loc = closing_loc
2263 end
2264
2265 # def accept: (Visitor visitor) -> void
2266 def accept(visitor)
2267 visitor.visit_block_parameters_node(self)
2268 end
2269
2270 # def child_nodes: () -> Array[Node?]
2271 def child_nodes
2272 [parameters, *locals]
2273 end
2274
2275 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
2276 def each_child_node
2277 return to_enum(:each_child_node) unless block_given?
2278
2279 yield parameters if parameters
2280 locals.each { |node| yield node }
2281 end
2282
2283 # def compact_child_nodes: () -> Array[Node]
2284 def compact_child_nodes
2285 compact = [] #: Array[Prism::node]
2286 compact << parameters if parameters
2287 compact.concat(locals)
2288 compact
2289 end
2290
2291 # def comment_targets: () -> Array[Node | Location]
2292 def comment_targets
2293 [*parameters, *locals, *opening_loc, *closing_loc] #: Array[Prism::node | Location]
2294 end
2295
2296 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?parameters: ParametersNode?, ?locals: Array[BlockLocalVariableNode], ?opening_loc: Location?, ?closing_loc: Location?) -> BlockParametersNode
2297 def copy(node_id: self.node_id, location: self.location, flags: self.flags, parameters: self.parameters, locals: self.locals, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
2298 BlockParametersNode.new(source, node_id, location, flags, parameters, locals, opening_loc, closing_loc)
2299 end
2300
2301 # def deconstruct: () -> Array[Node?]
2302 alias deconstruct child_nodes
2303
2304 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, parameters: ParametersNode?, locals: Array[BlockLocalVariableNode], opening_loc: Location?, closing_loc: Location? }
2305 def deconstruct_keys(keys)
2306 { node_id: node_id, location: location, parameters: parameters, locals: locals, opening_loc: opening_loc, closing_loc: closing_loc }
2307 end
2308
2309 # Represents the parameters of the block.
2310 #
2311 # -> (a, b = 1; local) { }
2312 # ^^^^^^^^
2313 #
2314 # foo do |a, b = 1; local|
2315 # ^^^^^^^^
2316 # end
2317 attr_reader :parameters
2318
2319 # Represents the local variables of the block.
2320 #
2321 # -> (a, b = 1; local) { }
2322 # ^^^^^
2323 #
2324 # foo do |a, b = 1; local|
2325 # ^^^^^
2326 # end
2327 attr_reader :locals
2328
2329 # Represents the opening location of the block parameters.
2330 #
2331 # -> (a, b = 1; local) { }
2332 # ^
2333 #
2334 # foo do |a, b = 1; local|
2335 # ^
2336 # end
2337 def opening_loc
2338 location = @opening_loc
2339 case location
2340 when nil
2341 nil
2342 when Location
2343 location
2344 else
2345 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2346 end
2347 end
2348
2349 # Save the opening_loc location using the given saved source so that
2350 # it can be retrieved later.
2351 def save_opening_loc(repository)
2352 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
2353 end
2354
2355 # Represents the closing location of the block parameters.
2356 #
2357 # -> (a, b = 1; local) { }
2358 # ^
2359 #
2360 # foo do |a, b = 1; local|
2361 # ^
2362 # end
2363 def closing_loc
2364 location = @closing_loc
2365 case location
2366 when nil
2367 nil
2368 when Location
2369 location
2370 else
2371 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2372 end
2373 end
2374
2375 # Save the closing_loc location using the given saved source so that
2376 # it can be retrieved later.
2377 def save_closing_loc(repository)
2378 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
2379 end
2380
2381 # def opening: () -> String?
2382 def opening
2383 opening_loc&.slice
2384 end
2385
2386 # def closing: () -> String?
2387 def closing
2388 closing_loc&.slice
2389 end
2390
2391 # def inspect -> String
2392 def inspect
2393 InspectVisitor.compose(self)
2394 end
2395
2396 # Return a symbol representation of this node type. See `Node#type`.
2397 def type
2398 :block_parameters_node
2399 end
2400
2401 # Return a symbol representation of this node type. See `Node::type`.
2402 def self.type
2403 :block_parameters_node
2404 end
2405
2406 # Implements case-equality for the node. This is effectively == but without
2407 # comparing the value of locations. Locations are checked only for presence.
2408 def ===(other)
2409 other.is_a?(BlockParametersNode) &&
2410 (parameters === other.parameters) &&
2411 (locals.length == other.locals.length) &&
2412 locals.zip(other.locals).all? { |left, right| left === right } &&
2413 (opening_loc.nil? == other.opening_loc.nil?) &&
2414 (closing_loc.nil? == other.closing_loc.nil?)
2415 end
2416 end
2417
2418 # Represents the use of the `break` keyword.
2419 #
2420 # break foo
2421 # ^^^^^^^^^
2422 class BreakNode < Node
2423 # Initialize a new BreakNode node.
2424 def initialize(source, node_id, location, flags, arguments, keyword_loc)
2425 @source = source
2426 @node_id = node_id
2427 @location = location
2428 @flags = flags
2429 @arguments = arguments
2430 @keyword_loc = keyword_loc
2431 end
2432
2433 # def accept: (Visitor visitor) -> void
2434 def accept(visitor)
2435 visitor.visit_break_node(self)
2436 end
2437
2438 # def child_nodes: () -> Array[Node?]
2439 def child_nodes
2440 [arguments]
2441 end
2442
2443 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
2444 def each_child_node
2445 return to_enum(:each_child_node) unless block_given?
2446
2447 yield arguments if arguments
2448 end
2449
2450 # def compact_child_nodes: () -> Array[Node]
2451 def compact_child_nodes
2452 compact = [] #: Array[Prism::node]
2453 compact << arguments if arguments
2454 compact
2455 end
2456
2457 # def comment_targets: () -> Array[Node | Location]
2458 def comment_targets
2459 [*arguments, keyword_loc] #: Array[Prism::node | Location]
2460 end
2461
2462 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?arguments: ArgumentsNode?, ?keyword_loc: Location) -> BreakNode
2463 def copy(node_id: self.node_id, location: self.location, flags: self.flags, arguments: self.arguments, keyword_loc: self.keyword_loc)
2464 BreakNode.new(source, node_id, location, flags, arguments, keyword_loc)
2465 end
2466
2467 # def deconstruct: () -> Array[Node?]
2468 alias deconstruct child_nodes
2469
2470 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, arguments: ArgumentsNode?, keyword_loc: Location }
2471 def deconstruct_keys(keys)
2472 { node_id: node_id, location: location, arguments: arguments, keyword_loc: keyword_loc }
2473 end
2474
2475 # The arguments to the break statement, if present. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2476 #
2477 # break foo
2478 # ^^^
2479 attr_reader :arguments
2480
2481 # The location of the `break` keyword.
2482 #
2483 # break foo
2484 # ^^^^^
2485 def keyword_loc
2486 location = @keyword_loc
2487 return location if location.is_a?(Location)
2488 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2489 end
2490
2491 # Save the keyword_loc location using the given saved source so that
2492 # it can be retrieved later.
2493 def save_keyword_loc(repository)
2494 repository.enter(node_id, :keyword_loc)
2495 end
2496
2497 # def keyword: () -> String
2498 def keyword
2499 keyword_loc.slice
2500 end
2501
2502 # def inspect -> String
2503 def inspect
2504 InspectVisitor.compose(self)
2505 end
2506
2507 # Return a symbol representation of this node type. See `Node#type`.
2508 def type
2509 :break_node
2510 end
2511
2512 # Return a symbol representation of this node type. See `Node::type`.
2513 def self.type
2514 :break_node
2515 end
2516
2517 # Implements case-equality for the node. This is effectively == but without
2518 # comparing the value of locations. Locations are checked only for presence.
2519 def ===(other)
2520 other.is_a?(BreakNode) &&
2521 (arguments === other.arguments) &&
2522 (keyword_loc.nil? == other.keyword_loc.nil?)
2523 end
2524 end
2525
2526 # Represents the use of the `&&=` operator on a call.
2527 #
2528 # foo.bar &&= value
2529 # ^^^^^^^^^^^^^^^^^
2530 class CallAndWriteNode < Node
2531 # Initialize a new CallAndWriteNode node.
2532 def initialize(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, operator_loc, value)
2533 @source = source
2534 @node_id = node_id
2535 @location = location
2536 @flags = flags
2537 @receiver = receiver
2538 @call_operator_loc = call_operator_loc
2539 @message_loc = message_loc
2540 @read_name = read_name
2541 @write_name = write_name
2542 @operator_loc = operator_loc
2543 @value = value
2544 end
2545
2546 # def accept: (Visitor visitor) -> void
2547 def accept(visitor)
2548 visitor.visit_call_and_write_node(self)
2549 end
2550
2551 # def child_nodes: () -> Array[Node?]
2552 def child_nodes
2553 [receiver, value]
2554 end
2555
2556 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
2557 def each_child_node
2558 return to_enum(:each_child_node) unless block_given?
2559
2560 yield receiver if receiver
2561 yield value
2562 end
2563
2564 # def compact_child_nodes: () -> Array[Node]
2565 def compact_child_nodes
2566 compact = [] #: Array[Prism::node]
2567 compact << receiver if receiver
2568 compact << value
2569 compact
2570 end
2571
2572 # def comment_targets: () -> Array[Node | Location]
2573 def comment_targets
2574 [*receiver, *call_operator_loc, *message_loc, operator_loc, value] #: Array[Prism::node | Location]
2575 end
2576
2577 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?message_loc: Location?, ?read_name: Symbol, ?write_name: Symbol, ?operator_loc: Location, ?value: Prism::node) -> CallAndWriteNode
2578 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, message_loc: self.message_loc, read_name: self.read_name, write_name: self.write_name, operator_loc: self.operator_loc, value: self.value)
2579 CallAndWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, operator_loc, value)
2580 end
2581
2582 # def deconstruct: () -> Array[Node?]
2583 alias deconstruct child_nodes
2584
2585 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, message_loc: Location?, read_name: Symbol, write_name: Symbol, operator_loc: Location, value: Prism::node }
2586 def deconstruct_keys(keys)
2587 { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, read_name: read_name, write_name: write_name, operator_loc: operator_loc, value: value }
2588 end
2589
2590 # def safe_navigation?: () -> bool
2591 def safe_navigation?
2592 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
2593 end
2594
2595 # def variable_call?: () -> bool
2596 def variable_call?
2597 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
2598 end
2599
2600 # def attribute_write?: () -> bool
2601 def attribute_write?
2602 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
2603 end
2604
2605 # def ignore_visibility?: () -> bool
2606 def ignore_visibility?
2607 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
2608 end
2609
2610 # The object that the method is being called on. This can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2611 #
2612 # foo.bar &&= value
2613 # ^^^
2614 attr_reader :receiver
2615
2616 # Represents the location of the call operator.
2617 #
2618 # foo.bar &&= value
2619 # ^
2620 def call_operator_loc
2621 location = @call_operator_loc
2622 case location
2623 when nil
2624 nil
2625 when Location
2626 location
2627 else
2628 @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2629 end
2630 end
2631
2632 # Save the call_operator_loc location using the given saved source so that
2633 # it can be retrieved later.
2634 def save_call_operator_loc(repository)
2635 repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
2636 end
2637
2638 # Represents the location of the message.
2639 #
2640 # foo.bar &&= value
2641 # ^^^
2642 def message_loc
2643 location = @message_loc
2644 case location
2645 when nil
2646 nil
2647 when Location
2648 location
2649 else
2650 @message_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2651 end
2652 end
2653
2654 # Save the message_loc location using the given saved source so that
2655 # it can be retrieved later.
2656 def save_message_loc(repository)
2657 repository.enter(node_id, :message_loc) unless @message_loc.nil?
2658 end
2659
2660 # Represents the name of the method being called.
2661 #
2662 # foo.bar &&= value # read_name `:bar`
2663 # ^^^
2664 attr_reader :read_name
2665
2666 # Represents the name of the method being written to.
2667 #
2668 # foo.bar &&= value # write_name `:bar=`
2669 # ^^^
2670 attr_reader :write_name
2671
2672 # Represents the location of the operator.
2673 #
2674 # foo.bar &&= value
2675 # ^^^
2676 def operator_loc
2677 location = @operator_loc
2678 return location if location.is_a?(Location)
2679 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2680 end
2681
2682 # Save the operator_loc location using the given saved source so that
2683 # it can be retrieved later.
2684 def save_operator_loc(repository)
2685 repository.enter(node_id, :operator_loc)
2686 end
2687
2688 # Represents the value being assigned.
2689 #
2690 # foo.bar &&= value
2691 # ^^^^^
2692 attr_reader :value
2693
2694 # def call_operator: () -> String?
2695 def call_operator
2696 call_operator_loc&.slice
2697 end
2698
2699 # def message: () -> String?
2700 def message
2701 message_loc&.slice
2702 end
2703
2704 # def operator: () -> String
2705 def operator
2706 operator_loc.slice
2707 end
2708
2709 # def inspect -> String
2710 def inspect
2711 InspectVisitor.compose(self)
2712 end
2713
2714 # Return a symbol representation of this node type. See `Node#type`.
2715 def type
2716 :call_and_write_node
2717 end
2718
2719 # Return a symbol representation of this node type. See `Node::type`.
2720 def self.type
2721 :call_and_write_node
2722 end
2723
2724 # Implements case-equality for the node. This is effectively == but without
2725 # comparing the value of locations. Locations are checked only for presence.
2726 def ===(other)
2727 other.is_a?(CallAndWriteNode) &&
2728 (flags === other.flags) &&
2729 (receiver === other.receiver) &&
2730 (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
2731 (message_loc.nil? == other.message_loc.nil?) &&
2732 (read_name === other.read_name) &&
2733 (write_name === other.write_name) &&
2734 (operator_loc.nil? == other.operator_loc.nil?) &&
2735 (value === other.value)
2736 end
2737 end
2738
2739 # Represents a method call, in all of the various forms that can take.
2740 #
2741 # foo
2742 # ^^^
2743 #
2744 # foo()
2745 # ^^^^^
2746 #
2747 # +foo
2748 # ^^^^
2749 #
2750 # foo + bar
2751 # ^^^^^^^^^
2752 #
2753 # foo.bar
2754 # ^^^^^^^
2755 #
2756 # foo&.bar
2757 # ^^^^^^^^
2758 class CallNode < Node
2759 # Initialize a new CallNode node.
2760 def initialize(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc, opening_loc, arguments, closing_loc, equal_loc, block)
2761 @source = source
2762 @node_id = node_id
2763 @location = location
2764 @flags = flags
2765 @receiver = receiver
2766 @call_operator_loc = call_operator_loc
2767 @name = name
2768 @message_loc = message_loc
2769 @opening_loc = opening_loc
2770 @arguments = arguments
2771 @closing_loc = closing_loc
2772 @equal_loc = equal_loc
2773 @block = block
2774 end
2775
2776 # def accept: (Visitor visitor) -> void
2777 def accept(visitor)
2778 visitor.visit_call_node(self)
2779 end
2780
2781 # def child_nodes: () -> Array[Node?]
2782 def child_nodes
2783 [receiver, arguments, block]
2784 end
2785
2786 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
2787 def each_child_node
2788 return to_enum(:each_child_node) unless block_given?
2789
2790 yield receiver if receiver
2791 yield arguments if arguments
2792 yield block if block
2793 end
2794
2795 # def compact_child_nodes: () -> Array[Node]
2796 def compact_child_nodes
2797 compact = [] #: Array[Prism::node]
2798 compact << receiver if receiver
2799 compact << arguments if arguments
2800 compact << block if block
2801 compact
2802 end
2803
2804 # def comment_targets: () -> Array[Node | Location]
2805 def comment_targets
2806 [*receiver, *call_operator_loc, *message_loc, *opening_loc, *arguments, *closing_loc, *equal_loc, *block] #: Array[Prism::node | Location]
2807 end
2808
2809 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?name: Symbol, ?message_loc: Location?, ?opening_loc: Location?, ?arguments: ArgumentsNode?, ?closing_loc: Location?, ?equal_loc: Location?, ?block: BlockNode | BlockArgumentNode | nil) -> CallNode
2810 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, name: self.name, message_loc: self.message_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, equal_loc: self.equal_loc, block: self.block)
2811 CallNode.new(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc, opening_loc, arguments, closing_loc, equal_loc, block)
2812 end
2813
2814 # def deconstruct: () -> Array[Node?]
2815 alias deconstruct child_nodes
2816
2817 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, name: Symbol, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, equal_loc: Location?, block: BlockNode | BlockArgumentNode | nil }
2818 def deconstruct_keys(keys)
2819 { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, name: name, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, equal_loc: equal_loc, block: block }
2820 end
2821
2822 # def safe_navigation?: () -> bool
2823 def safe_navigation?
2824 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
2825 end
2826
2827 # def variable_call?: () -> bool
2828 def variable_call?
2829 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
2830 end
2831
2832 # def attribute_write?: () -> bool
2833 def attribute_write?
2834 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
2835 end
2836
2837 # def ignore_visibility?: () -> bool
2838 def ignore_visibility?
2839 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
2840 end
2841
2842 # The object that the method is being called on. This can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2843 #
2844 # foo.bar
2845 # ^^^
2846 #
2847 # +foo
2848 # ^^^
2849 #
2850 # foo + bar
2851 # ^^^
2852 attr_reader :receiver
2853
2854 # Represents the location of the call operator.
2855 #
2856 # foo.bar
2857 # ^
2858 #
2859 # foo&.bar
2860 # ^^
2861 def call_operator_loc
2862 location = @call_operator_loc
2863 case location
2864 when nil
2865 nil
2866 when Location
2867 location
2868 else
2869 @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2870 end
2871 end
2872
2873 # Save the call_operator_loc location using the given saved source so that
2874 # it can be retrieved later.
2875 def save_call_operator_loc(repository)
2876 repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
2877 end
2878
2879 # Represents the name of the method being called.
2880 #
2881 # foo.bar # name `:foo`
2882 # ^^^
2883 attr_reader :name
2884
2885 # Represents the location of the message.
2886 #
2887 # foo.bar
2888 # ^^^
2889 def message_loc
2890 location = @message_loc
2891 case location
2892 when nil
2893 nil
2894 when Location
2895 location
2896 else
2897 @message_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2898 end
2899 end
2900
2901 # Save the message_loc location using the given saved source so that
2902 # it can be retrieved later.
2903 def save_message_loc(repository)
2904 repository.enter(node_id, :message_loc) unless @message_loc.nil?
2905 end
2906
2907 # Represents the location of the left parenthesis.
2908 # foo(bar)
2909 # ^
2910 def opening_loc
2911 location = @opening_loc
2912 case location
2913 when nil
2914 nil
2915 when Location
2916 location
2917 else
2918 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2919 end
2920 end
2921
2922 # Save the opening_loc location using the given saved source so that
2923 # it can be retrieved later.
2924 def save_opening_loc(repository)
2925 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
2926 end
2927
2928 # Represents the arguments to the method call. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2929 #
2930 # foo(bar)
2931 # ^^^
2932 attr_reader :arguments
2933
2934 # Represents the location of the right parenthesis.
2935 #
2936 # foo(bar)
2937 # ^
2938 def closing_loc
2939 location = @closing_loc
2940 case location
2941 when nil
2942 nil
2943 when Location
2944 location
2945 else
2946 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2947 end
2948 end
2949
2950 # Save the closing_loc location using the given saved source so that
2951 # it can be retrieved later.
2952 def save_closing_loc(repository)
2953 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
2954 end
2955
2956 # Represents the location of the equal sign, in the case that this is an attribute write.
2957 #
2958 # foo.bar = value
2959 # ^
2960 #
2961 # foo[bar] = value
2962 # ^
2963 def equal_loc
2964 location = @equal_loc
2965 case location
2966 when nil
2967 nil
2968 when Location
2969 location
2970 else
2971 @equal_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
2972 end
2973 end
2974
2975 # Save the equal_loc location using the given saved source so that
2976 # it can be retrieved later.
2977 def save_equal_loc(repository)
2978 repository.enter(node_id, :equal_loc) unless @equal_loc.nil?
2979 end
2980
2981 # Represents the block that is being passed to the method.
2982 #
2983 # foo { |a| a }
2984 # ^^^^^^^^^
2985 attr_reader :block
2986
2987 # def call_operator: () -> String?
2988 def call_operator
2989 call_operator_loc&.slice
2990 end
2991
2992 # def message: () -> String?
2993 def message
2994 message_loc&.slice
2995 end
2996
2997 # def opening: () -> String?
2998 def opening
2999 opening_loc&.slice
3000 end
3001
3002 # def closing: () -> String?
3003 def closing
3004 closing_loc&.slice
3005 end
3006
3007 # def equal: () -> String?
3008 def equal
3009 equal_loc&.slice
3010 end
3011
3012 # def inspect -> String
3013 def inspect
3014 InspectVisitor.compose(self)
3015 end
3016
3017 # Return a symbol representation of this node type. See `Node#type`.
3018 def type
3019 :call_node
3020 end
3021
3022 # Return a symbol representation of this node type. See `Node::type`.
3023 def self.type
3024 :call_node
3025 end
3026
3027 # Implements case-equality for the node. This is effectively == but without
3028 # comparing the value of locations. Locations are checked only for presence.
3029 def ===(other)
3030 other.is_a?(CallNode) &&
3031 (flags === other.flags) &&
3032 (receiver === other.receiver) &&
3033 (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
3034 (name === other.name) &&
3035 (message_loc.nil? == other.message_loc.nil?) &&
3036 (opening_loc.nil? == other.opening_loc.nil?) &&
3037 (arguments === other.arguments) &&
3038 (closing_loc.nil? == other.closing_loc.nil?) &&
3039 (equal_loc.nil? == other.equal_loc.nil?) &&
3040 (block === other.block)
3041 end
3042 end
3043
3044 # Represents the use of an assignment operator on a call.
3045 #
3046 # foo.bar += baz
3047 # ^^^^^^^^^^^^^^
3048 class CallOperatorWriteNode < Node
3049 # Initialize a new CallOperatorWriteNode node.
3050 def initialize(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, binary_operator, binary_operator_loc, value)
3051 @source = source
3052 @node_id = node_id
3053 @location = location
3054 @flags = flags
3055 @receiver = receiver
3056 @call_operator_loc = call_operator_loc
3057 @message_loc = message_loc
3058 @read_name = read_name
3059 @write_name = write_name
3060 @binary_operator = binary_operator
3061 @binary_operator_loc = binary_operator_loc
3062 @value = value
3063 end
3064
3065 # def accept: (Visitor visitor) -> void
3066 def accept(visitor)
3067 visitor.visit_call_operator_write_node(self)
3068 end
3069
3070 # def child_nodes: () -> Array[Node?]
3071 def child_nodes
3072 [receiver, value]
3073 end
3074
3075 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
3076 def each_child_node
3077 return to_enum(:each_child_node) unless block_given?
3078
3079 yield receiver if receiver
3080 yield value
3081 end
3082
3083 # def compact_child_nodes: () -> Array[Node]
3084 def compact_child_nodes
3085 compact = [] #: Array[Prism::node]
3086 compact << receiver if receiver
3087 compact << value
3088 compact
3089 end
3090
3091 # def comment_targets: () -> Array[Node | Location]
3092 def comment_targets
3093 [*receiver, *call_operator_loc, *message_loc, binary_operator_loc, value] #: Array[Prism::node | Location]
3094 end
3095
3096 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?message_loc: Location?, ?read_name: Symbol, ?write_name: Symbol, ?binary_operator: Symbol, ?binary_operator_loc: Location, ?value: Prism::node) -> CallOperatorWriteNode
3097 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, message_loc: self.message_loc, read_name: self.read_name, write_name: self.write_name, binary_operator: self.binary_operator, binary_operator_loc: self.binary_operator_loc, value: self.value)
3098 CallOperatorWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, binary_operator, binary_operator_loc, value)
3099 end
3100
3101 # def deconstruct: () -> Array[Node?]
3102 alias deconstruct child_nodes
3103
3104 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, message_loc: Location?, read_name: Symbol, write_name: Symbol, binary_operator: Symbol, binary_operator_loc: Location, value: Prism::node }
3105 def deconstruct_keys(keys)
3106 { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, read_name: read_name, write_name: write_name, binary_operator: binary_operator, binary_operator_loc: binary_operator_loc, value: value }
3107 end
3108
3109 # def safe_navigation?: () -> bool
3110 def safe_navigation?
3111 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
3112 end
3113
3114 # def variable_call?: () -> bool
3115 def variable_call?
3116 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
3117 end
3118
3119 # def attribute_write?: () -> bool
3120 def attribute_write?
3121 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
3122 end
3123
3124 # def ignore_visibility?: () -> bool
3125 def ignore_visibility?
3126 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
3127 end
3128
3129 # The object that the method is being called on. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
3130 #
3131 # foo.bar += value
3132 # ^^^
3133 attr_reader :receiver
3134
3135 # Represents the location of the call operator.
3136 #
3137 # foo.bar += value
3138 # ^
3139 def call_operator_loc
3140 location = @call_operator_loc
3141 case location
3142 when nil
3143 nil
3144 when Location
3145 location
3146 else
3147 @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3148 end
3149 end
3150
3151 # Save the call_operator_loc location using the given saved source so that
3152 # it can be retrieved later.
3153 def save_call_operator_loc(repository)
3154 repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
3155 end
3156
3157 # Represents the location of the message.
3158 #
3159 # foo.bar += value
3160 # ^^^
3161 def message_loc
3162 location = @message_loc
3163 case location
3164 when nil
3165 nil
3166 when Location
3167 location
3168 else
3169 @message_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3170 end
3171 end
3172
3173 # Save the message_loc location using the given saved source so that
3174 # it can be retrieved later.
3175 def save_message_loc(repository)
3176 repository.enter(node_id, :message_loc) unless @message_loc.nil?
3177 end
3178
3179 # Represents the name of the method being called.
3180 #
3181 # foo.bar += value # read_name `:bar`
3182 # ^^^
3183 attr_reader :read_name
3184
3185 # Represents the name of the method being written to.
3186 #
3187 # foo.bar += value # write_name `:bar=`
3188 # ^^^
3189 attr_reader :write_name
3190
3191 # Represents the binary operator being used.
3192 #
3193 # foo.bar += value # binary_operator `:+`
3194 # ^
3195 attr_reader :binary_operator
3196
3197 # Represents the location of the binary operator.
3198 #
3199 # foo.bar += value
3200 # ^^
3201 def binary_operator_loc
3202 location = @binary_operator_loc
3203 return location if location.is_a?(Location)
3204 @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3205 end
3206
3207 # Save the binary_operator_loc location using the given saved source so that
3208 # it can be retrieved later.
3209 def save_binary_operator_loc(repository)
3210 repository.enter(node_id, :binary_operator_loc)
3211 end
3212
3213 # Represents the value being assigned.
3214 #
3215 # foo.bar += value
3216 # ^^^^^
3217 attr_reader :value
3218
3219 # def call_operator: () -> String?
3220 def call_operator
3221 call_operator_loc&.slice
3222 end
3223
3224 # def message: () -> String?
3225 def message
3226 message_loc&.slice
3227 end
3228
3229 # def inspect -> String
3230 def inspect
3231 InspectVisitor.compose(self)
3232 end
3233
3234 # Return a symbol representation of this node type. See `Node#type`.
3235 def type
3236 :call_operator_write_node
3237 end
3238
3239 # Return a symbol representation of this node type. See `Node::type`.
3240 def self.type
3241 :call_operator_write_node
3242 end
3243
3244 # Implements case-equality for the node. This is effectively == but without
3245 # comparing the value of locations. Locations are checked only for presence.
3246 def ===(other)
3247 other.is_a?(CallOperatorWriteNode) &&
3248 (flags === other.flags) &&
3249 (receiver === other.receiver) &&
3250 (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
3251 (message_loc.nil? == other.message_loc.nil?) &&
3252 (read_name === other.read_name) &&
3253 (write_name === other.write_name) &&
3254 (binary_operator === other.binary_operator) &&
3255 (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
3256 (value === other.value)
3257 end
3258 end
3259
3260 # Represents the use of the `||=` operator on a call.
3261 #
3262 # foo.bar ||= value
3263 # ^^^^^^^^^^^^^^^^^
3264 class CallOrWriteNode < Node
3265 # Initialize a new CallOrWriteNode node.
3266 def initialize(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, operator_loc, value)
3267 @source = source
3268 @node_id = node_id
3269 @location = location
3270 @flags = flags
3271 @receiver = receiver
3272 @call_operator_loc = call_operator_loc
3273 @message_loc = message_loc
3274 @read_name = read_name
3275 @write_name = write_name
3276 @operator_loc = operator_loc
3277 @value = value
3278 end
3279
3280 # def accept: (Visitor visitor) -> void
3281 def accept(visitor)
3282 visitor.visit_call_or_write_node(self)
3283 end
3284
3285 # def child_nodes: () -> Array[Node?]
3286 def child_nodes
3287 [receiver, value]
3288 end
3289
3290 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
3291 def each_child_node
3292 return to_enum(:each_child_node) unless block_given?
3293
3294 yield receiver if receiver
3295 yield value
3296 end
3297
3298 # def compact_child_nodes: () -> Array[Node]
3299 def compact_child_nodes
3300 compact = [] #: Array[Prism::node]
3301 compact << receiver if receiver
3302 compact << value
3303 compact
3304 end
3305
3306 # def comment_targets: () -> Array[Node | Location]
3307 def comment_targets
3308 [*receiver, *call_operator_loc, *message_loc, operator_loc, value] #: Array[Prism::node | Location]
3309 end
3310
3311 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?message_loc: Location?, ?read_name: Symbol, ?write_name: Symbol, ?operator_loc: Location, ?value: Prism::node) -> CallOrWriteNode
3312 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, message_loc: self.message_loc, read_name: self.read_name, write_name: self.write_name, operator_loc: self.operator_loc, value: self.value)
3313 CallOrWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, message_loc, read_name, write_name, operator_loc, value)
3314 end
3315
3316 # def deconstruct: () -> Array[Node?]
3317 alias deconstruct child_nodes
3318
3319 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, message_loc: Location?, read_name: Symbol, write_name: Symbol, operator_loc: Location, value: Prism::node }
3320 def deconstruct_keys(keys)
3321 { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, read_name: read_name, write_name: write_name, operator_loc: operator_loc, value: value }
3322 end
3323
3324 # def safe_navigation?: () -> bool
3325 def safe_navigation?
3326 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
3327 end
3328
3329 # def variable_call?: () -> bool
3330 def variable_call?
3331 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
3332 end
3333
3334 # def attribute_write?: () -> bool
3335 def attribute_write?
3336 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
3337 end
3338
3339 # def ignore_visibility?: () -> bool
3340 def ignore_visibility?
3341 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
3342 end
3343
3344 # The object that the method is being called on. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
3345 #
3346 # foo.bar ||= value
3347 # ^^^
3348 attr_reader :receiver
3349
3350 # Represents the location of the call operator.
3351 #
3352 # foo.bar ||= value
3353 # ^
3354 def call_operator_loc
3355 location = @call_operator_loc
3356 case location
3357 when nil
3358 nil
3359 when Location
3360 location
3361 else
3362 @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3363 end
3364 end
3365
3366 # Save the call_operator_loc location using the given saved source so that
3367 # it can be retrieved later.
3368 def save_call_operator_loc(repository)
3369 repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
3370 end
3371
3372 # Represents the location of the message.
3373 #
3374 # foo.bar ||= value
3375 # ^^^
3376 def message_loc
3377 location = @message_loc
3378 case location
3379 when nil
3380 nil
3381 when Location
3382 location
3383 else
3384 @message_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3385 end
3386 end
3387
3388 # Save the message_loc location using the given saved source so that
3389 # it can be retrieved later.
3390 def save_message_loc(repository)
3391 repository.enter(node_id, :message_loc) unless @message_loc.nil?
3392 end
3393
3394 # Represents the name of the method being called.
3395 #
3396 # foo.bar ||= value # read_name `:bar`
3397 # ^^^
3398 attr_reader :read_name
3399
3400 # Represents the name of the method being written to.
3401 #
3402 # foo.bar ||= value # write_name `:bar=`
3403 # ^^^
3404 attr_reader :write_name
3405
3406 # Represents the location of the operator.
3407 #
3408 # foo.bar ||= value
3409 # ^^^
3410 def operator_loc
3411 location = @operator_loc
3412 return location if location.is_a?(Location)
3413 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3414 end
3415
3416 # Save the operator_loc location using the given saved source so that
3417 # it can be retrieved later.
3418 def save_operator_loc(repository)
3419 repository.enter(node_id, :operator_loc)
3420 end
3421
3422 # Represents the value being assigned.
3423 #
3424 # foo.bar ||= value
3425 # ^^^^^
3426 attr_reader :value
3427
3428 # def call_operator: () -> String?
3429 def call_operator
3430 call_operator_loc&.slice
3431 end
3432
3433 # def message: () -> String?
3434 def message
3435 message_loc&.slice
3436 end
3437
3438 # def operator: () -> String
3439 def operator
3440 operator_loc.slice
3441 end
3442
3443 # def inspect -> String
3444 def inspect
3445 InspectVisitor.compose(self)
3446 end
3447
3448 # Return a symbol representation of this node type. See `Node#type`.
3449 def type
3450 :call_or_write_node
3451 end
3452
3453 # Return a symbol representation of this node type. See `Node::type`.
3454 def self.type
3455 :call_or_write_node
3456 end
3457
3458 # Implements case-equality for the node. This is effectively == but without
3459 # comparing the value of locations. Locations are checked only for presence.
3460 def ===(other)
3461 other.is_a?(CallOrWriteNode) &&
3462 (flags === other.flags) &&
3463 (receiver === other.receiver) &&
3464 (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
3465 (message_loc.nil? == other.message_loc.nil?) &&
3466 (read_name === other.read_name) &&
3467 (write_name === other.write_name) &&
3468 (operator_loc.nil? == other.operator_loc.nil?) &&
3469 (value === other.value)
3470 end
3471 end
3472
3473 # Represents assigning to a method call.
3474 #
3475 # foo.bar, = 1
3476 # ^^^^^^^
3477 #
3478 # begin
3479 # rescue => foo.bar
3480 # ^^^^^^^
3481 # end
3482 #
3483 # for foo.bar in baz do end
3484 # ^^^^^^^
3485 class CallTargetNode < Node
3486 # Initialize a new CallTargetNode node.
3487 def initialize(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc)
3488 @source = source
3489 @node_id = node_id
3490 @location = location
3491 @flags = flags
3492 @receiver = receiver
3493 @call_operator_loc = call_operator_loc
3494 @name = name
3495 @message_loc = message_loc
3496 end
3497
3498 # def accept: (Visitor visitor) -> void
3499 def accept(visitor)
3500 visitor.visit_call_target_node(self)
3501 end
3502
3503 # def child_nodes: () -> Array[Node?]
3504 def child_nodes
3505 [receiver]
3506 end
3507
3508 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
3509 def each_child_node
3510 return to_enum(:each_child_node) unless block_given?
3511
3512 yield receiver
3513 end
3514
3515 # def compact_child_nodes: () -> Array[Node]
3516 def compact_child_nodes
3517 [receiver]
3518 end
3519
3520 # def comment_targets: () -> Array[Node | Location]
3521 def comment_targets
3522 [receiver, call_operator_loc, message_loc] #: Array[Prism::node | Location]
3523 end
3524
3525 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node, ?call_operator_loc: Location, ?name: Symbol, ?message_loc: Location) -> CallTargetNode
3526 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, name: self.name, message_loc: self.message_loc)
3527 CallTargetNode.new(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc)
3528 end
3529
3530 # def deconstruct: () -> Array[Node?]
3531 alias deconstruct child_nodes
3532
3533 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node, call_operator_loc: Location, name: Symbol, message_loc: Location }
3534 def deconstruct_keys(keys)
3535 { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, name: name, message_loc: message_loc }
3536 end
3537
3538 # def safe_navigation?: () -> bool
3539 def safe_navigation?
3540 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
3541 end
3542
3543 # def variable_call?: () -> bool
3544 def variable_call?
3545 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
3546 end
3547
3548 # def attribute_write?: () -> bool
3549 def attribute_write?
3550 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
3551 end
3552
3553 # def ignore_visibility?: () -> bool
3554 def ignore_visibility?
3555 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
3556 end
3557
3558 # The object that the method is being called on. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
3559 #
3560 # foo.bar = 1
3561 # ^^^
3562 attr_reader :receiver
3563
3564 # Represents the location of the call operator.
3565 #
3566 # foo.bar = 1
3567 # ^
3568 def call_operator_loc
3569 location = @call_operator_loc
3570 return location if location.is_a?(Location)
3571 @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3572 end
3573
3574 # Save the call_operator_loc location using the given saved source so that
3575 # it can be retrieved later.
3576 def save_call_operator_loc(repository)
3577 repository.enter(node_id, :call_operator_loc)
3578 end
3579
3580 # Represents the name of the method being called.
3581 #
3582 # foo.bar = 1 # name `:foo`
3583 # ^^^
3584 attr_reader :name
3585
3586 # Represents the location of the message.
3587 #
3588 # foo.bar = 1
3589 # ^^^
3590 def message_loc
3591 location = @message_loc
3592 return location if location.is_a?(Location)
3593 @message_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3594 end
3595
3596 # Save the message_loc location using the given saved source so that
3597 # it can be retrieved later.
3598 def save_message_loc(repository)
3599 repository.enter(node_id, :message_loc)
3600 end
3601
3602 # def call_operator: () -> String
3603 def call_operator
3604 call_operator_loc.slice
3605 end
3606
3607 # def message: () -> String
3608 def message
3609 message_loc.slice
3610 end
3611
3612 # def inspect -> String
3613 def inspect
3614 InspectVisitor.compose(self)
3615 end
3616
3617 # Return a symbol representation of this node type. See `Node#type`.
3618 def type
3619 :call_target_node
3620 end
3621
3622 # Return a symbol representation of this node type. See `Node::type`.
3623 def self.type
3624 :call_target_node
3625 end
3626
3627 # Implements case-equality for the node. This is effectively == but without
3628 # comparing the value of locations. Locations are checked only for presence.
3629 def ===(other)
3630 other.is_a?(CallTargetNode) &&
3631 (flags === other.flags) &&
3632 (receiver === other.receiver) &&
3633 (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
3634 (name === other.name) &&
3635 (message_loc.nil? == other.message_loc.nil?)
3636 end
3637 end
3638
3639 # Represents assigning to a local variable in pattern matching.
3640 #
3641 # foo => [bar => baz]
3642 # ^^^^^^^^^^^^
3643 class CapturePatternNode < Node
3644 # Initialize a new CapturePatternNode node.
3645 def initialize(source, node_id, location, flags, value, target, operator_loc)
3646 @source = source
3647 @node_id = node_id
3648 @location = location
3649 @flags = flags
3650 @value = value
3651 @target = target
3652 @operator_loc = operator_loc
3653 end
3654
3655 # def accept: (Visitor visitor) -> void
3656 def accept(visitor)
3657 visitor.visit_capture_pattern_node(self)
3658 end
3659
3660 # def child_nodes: () -> Array[Node?]
3661 def child_nodes
3662 [value, target]
3663 end
3664
3665 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
3666 def each_child_node
3667 return to_enum(:each_child_node) unless block_given?
3668
3669 yield value
3670 yield target
3671 end
3672
3673 # def compact_child_nodes: () -> Array[Node]
3674 def compact_child_nodes
3675 [value, target]
3676 end
3677
3678 # def comment_targets: () -> Array[Node | Location]
3679 def comment_targets
3680 [value, target, operator_loc] #: Array[Prism::node | Location]
3681 end
3682
3683 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?target: LocalVariableTargetNode, ?operator_loc: Location) -> CapturePatternNode
3684 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, target: self.target, operator_loc: self.operator_loc)
3685 CapturePatternNode.new(source, node_id, location, flags, value, target, operator_loc)
3686 end
3687
3688 # def deconstruct: () -> Array[Node?]
3689 alias deconstruct child_nodes
3690
3691 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, value: Prism::node, target: LocalVariableTargetNode, operator_loc: Location }
3692 def deconstruct_keys(keys)
3693 { node_id: node_id, location: location, value: value, target: target, operator_loc: operator_loc }
3694 end
3695
3696 # Represents the value to capture.
3697 #
3698 # foo => bar
3699 # ^^^
3700 attr_reader :value
3701
3702 # Represents the target of the capture.
3703 #
3704 # foo => bar
3705 # ^^^
3706 attr_reader :target
3707
3708 # Represents the location of the `=>` operator.
3709 #
3710 # foo => bar
3711 # ^^
3712 def operator_loc
3713 location = @operator_loc
3714 return location if location.is_a?(Location)
3715 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3716 end
3717
3718 # Save the operator_loc location using the given saved source so that
3719 # it can be retrieved later.
3720 def save_operator_loc(repository)
3721 repository.enter(node_id, :operator_loc)
3722 end
3723
3724 # def operator: () -> String
3725 def operator
3726 operator_loc.slice
3727 end
3728
3729 # def inspect -> String
3730 def inspect
3731 InspectVisitor.compose(self)
3732 end
3733
3734 # Return a symbol representation of this node type. See `Node#type`.
3735 def type
3736 :capture_pattern_node
3737 end
3738
3739 # Return a symbol representation of this node type. See `Node::type`.
3740 def self.type
3741 :capture_pattern_node
3742 end
3743
3744 # Implements case-equality for the node. This is effectively == but without
3745 # comparing the value of locations. Locations are checked only for presence.
3746 def ===(other)
3747 other.is_a?(CapturePatternNode) &&
3748 (value === other.value) &&
3749 (target === other.target) &&
3750 (operator_loc.nil? == other.operator_loc.nil?)
3751 end
3752 end
3753
3754 # Represents the use of a case statement for pattern matching.
3755 #
3756 # case true
3757 # in false
3758 # end
3759 # ^^^^^^^^^
3760 class CaseMatchNode < Node
3761 # Initialize a new CaseMatchNode node.
3762 def initialize(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc)
3763 @source = source
3764 @node_id = node_id
3765 @location = location
3766 @flags = flags
3767 @predicate = predicate
3768 @conditions = conditions
3769 @else_clause = else_clause
3770 @case_keyword_loc = case_keyword_loc
3771 @end_keyword_loc = end_keyword_loc
3772 end
3773
3774 # def accept: (Visitor visitor) -> void
3775 def accept(visitor)
3776 visitor.visit_case_match_node(self)
3777 end
3778
3779 # def child_nodes: () -> Array[Node?]
3780 def child_nodes
3781 [predicate, *conditions, else_clause]
3782 end
3783
3784 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
3785 def each_child_node
3786 return to_enum(:each_child_node) unless block_given?
3787
3788 yield predicate if predicate
3789 conditions.each { |node| yield node }
3790 yield else_clause if else_clause
3791 end
3792
3793 # def compact_child_nodes: () -> Array[Node]
3794 def compact_child_nodes
3795 compact = [] #: Array[Prism::node]
3796 compact << predicate if predicate
3797 compact.concat(conditions)
3798 compact << else_clause if else_clause
3799 compact
3800 end
3801
3802 # def comment_targets: () -> Array[Node | Location]
3803 def comment_targets
3804 [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location]
3805 end
3806
3807 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?predicate: Prism::node?, ?conditions: Array[InNode], ?else_clause: ElseNode?, ?case_keyword_loc: Location, ?end_keyword_loc: Location) -> CaseMatchNode
3808 def copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, else_clause: self.else_clause, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc)
3809 CaseMatchNode.new(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc)
3810 end
3811
3812 # def deconstruct: () -> Array[Node?]
3813 alias deconstruct child_nodes
3814
3815 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, predicate: Prism::node?, conditions: Array[InNode], else_clause: ElseNode?, case_keyword_loc: Location, end_keyword_loc: Location }
3816 def deconstruct_keys(keys)
3817 { node_id: node_id, location: location, predicate: predicate, conditions: conditions, else_clause: else_clause, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc }
3818 end
3819
3820 # Represents the predicate of the case match. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
3821 #
3822 # case true; in false; end
3823 # ^^^^
3824 attr_reader :predicate
3825
3826 # Represents the conditions of the case match.
3827 #
3828 # case true; in false; end
3829 # ^^^^^^^^
3830 attr_reader :conditions
3831
3832 # Represents the else clause of the case match.
3833 #
3834 # case true; in false; else; end
3835 # ^^^^
3836 attr_reader :else_clause
3837
3838 # Represents the location of the `case` keyword.
3839 #
3840 # case true; in false; end
3841 # ^^^^
3842 def case_keyword_loc
3843 location = @case_keyword_loc
3844 return location if location.is_a?(Location)
3845 @case_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3846 end
3847
3848 # Save the case_keyword_loc location using the given saved source so that
3849 # it can be retrieved later.
3850 def save_case_keyword_loc(repository)
3851 repository.enter(node_id, :case_keyword_loc)
3852 end
3853
3854 # Represents the location of the `end` keyword.
3855 #
3856 # case true; in false; end
3857 # ^^^
3858 def end_keyword_loc
3859 location = @end_keyword_loc
3860 return location if location.is_a?(Location)
3861 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
3862 end
3863
3864 # Save the end_keyword_loc location using the given saved source so that
3865 # it can be retrieved later.
3866 def save_end_keyword_loc(repository)
3867 repository.enter(node_id, :end_keyword_loc)
3868 end
3869
3870 # def case_keyword: () -> String
3871 def case_keyword
3872 case_keyword_loc.slice
3873 end
3874
3875 # def end_keyword: () -> String
3876 def end_keyword
3877 end_keyword_loc.slice
3878 end
3879
3880 # def inspect -> String
3881 def inspect
3882 InspectVisitor.compose(self)
3883 end
3884
3885 # Return a symbol representation of this node type. See `Node#type`.
3886 def type
3887 :case_match_node
3888 end
3889
3890 # Return a symbol representation of this node type. See `Node::type`.
3891 def self.type
3892 :case_match_node
3893 end
3894
3895 # Implements case-equality for the node. This is effectively == but without
3896 # comparing the value of locations. Locations are checked only for presence.
3897 def ===(other)
3898 other.is_a?(CaseMatchNode) &&
3899 (predicate === other.predicate) &&
3900 (conditions.length == other.conditions.length) &&
3901 conditions.zip(other.conditions).all? { |left, right| left === right } &&
3902 (else_clause === other.else_clause) &&
3903 (case_keyword_loc.nil? == other.case_keyword_loc.nil?) &&
3904 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
3905 end
3906 end
3907
3908 # Represents the use of a case statement.
3909 #
3910 # case true
3911 # when false
3912 # end
3913 # ^^^^^^^^^^
3914 class CaseNode < Node
3915 # Initialize a new CaseNode node.
3916 def initialize(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc)
3917 @source = source
3918 @node_id = node_id
3919 @location = location
3920 @flags = flags
3921 @predicate = predicate
3922 @conditions = conditions
3923 @else_clause = else_clause
3924 @case_keyword_loc = case_keyword_loc
3925 @end_keyword_loc = end_keyword_loc
3926 end
3927
3928 # def accept: (Visitor visitor) -> void
3929 def accept(visitor)
3930 visitor.visit_case_node(self)
3931 end
3932
3933 # def child_nodes: () -> Array[Node?]
3934 def child_nodes
3935 [predicate, *conditions, else_clause]
3936 end
3937
3938 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
3939 def each_child_node
3940 return to_enum(:each_child_node) unless block_given?
3941
3942 yield predicate if predicate
3943 conditions.each { |node| yield node }
3944 yield else_clause if else_clause
3945 end
3946
3947 # def compact_child_nodes: () -> Array[Node]
3948 def compact_child_nodes
3949 compact = [] #: Array[Prism::node]
3950 compact << predicate if predicate
3951 compact.concat(conditions)
3952 compact << else_clause if else_clause
3953 compact
3954 end
3955
3956 # def comment_targets: () -> Array[Node | Location]
3957 def comment_targets
3958 [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location]
3959 end
3960
3961 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?predicate: Prism::node?, ?conditions: Array[WhenNode], ?else_clause: ElseNode?, ?case_keyword_loc: Location, ?end_keyword_loc: Location) -> CaseNode
3962 def copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, else_clause: self.else_clause, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc)
3963 CaseNode.new(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc)
3964 end
3965
3966 # def deconstruct: () -> Array[Node?]
3967 alias deconstruct child_nodes
3968
3969 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, predicate: Prism::node?, conditions: Array[WhenNode], else_clause: ElseNode?, case_keyword_loc: Location, end_keyword_loc: Location }
3970 def deconstruct_keys(keys)
3971 { node_id: node_id, location: location, predicate: predicate, conditions: conditions, else_clause: else_clause, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc }
3972 end
3973
3974 # Represents the predicate of the case statement. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
3975 #
3976 # case true; when false; end
3977 # ^^^^
3978 attr_reader :predicate
3979
3980 # Represents the conditions of the case statement.
3981 #
3982 # case true; when false; end
3983 # ^^^^^^^^^^
3984 attr_reader :conditions
3985
3986 # Represents the else clause of the case statement.
3987 #
3988 # case true; when false; else; end
3989 # ^^^^
3990 attr_reader :else_clause
3991
3992 # Represents the location of the `case` keyword.
3993 #
3994 # case true; when false; end
3995 # ^^^^
3996 def case_keyword_loc
3997 location = @case_keyword_loc
3998 return location if location.is_a?(Location)
3999 @case_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4000 end
4001
4002 # Save the case_keyword_loc location using the given saved source so that
4003 # it can be retrieved later.
4004 def save_case_keyword_loc(repository)
4005 repository.enter(node_id, :case_keyword_loc)
4006 end
4007
4008 # Represents the location of the `end` keyword.
4009 #
4010 # case true; when false; end
4011 # ^^^
4012 def end_keyword_loc
4013 location = @end_keyword_loc
4014 return location if location.is_a?(Location)
4015 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4016 end
4017
4018 # Save the end_keyword_loc location using the given saved source so that
4019 # it can be retrieved later.
4020 def save_end_keyword_loc(repository)
4021 repository.enter(node_id, :end_keyword_loc)
4022 end
4023
4024 # def case_keyword: () -> String
4025 def case_keyword
4026 case_keyword_loc.slice
4027 end
4028
4029 # def end_keyword: () -> String
4030 def end_keyword
4031 end_keyword_loc.slice
4032 end
4033
4034 # def inspect -> String
4035 def inspect
4036 InspectVisitor.compose(self)
4037 end
4038
4039 # Return a symbol representation of this node type. See `Node#type`.
4040 def type
4041 :case_node
4042 end
4043
4044 # Return a symbol representation of this node type. See `Node::type`.
4045 def self.type
4046 :case_node
4047 end
4048
4049 # Implements case-equality for the node. This is effectively == but without
4050 # comparing the value of locations. Locations are checked only for presence.
4051 def ===(other)
4052 other.is_a?(CaseNode) &&
4053 (predicate === other.predicate) &&
4054 (conditions.length == other.conditions.length) &&
4055 conditions.zip(other.conditions).all? { |left, right| left === right } &&
4056 (else_clause === other.else_clause) &&
4057 (case_keyword_loc.nil? == other.case_keyword_loc.nil?) &&
4058 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
4059 end
4060 end
4061
4062 # Represents a class declaration involving the `class` keyword.
4063 #
4064 # class Foo end
4065 # ^^^^^^^^^^^^^
4066 class ClassNode < Node
4067 # Initialize a new ClassNode node.
4068 def initialize(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name)
4069 @source = source
4070 @node_id = node_id
4071 @location = location
4072 @flags = flags
4073 @locals = locals
4074 @class_keyword_loc = class_keyword_loc
4075 @constant_path = constant_path
4076 @inheritance_operator_loc = inheritance_operator_loc
4077 @superclass = superclass
4078 @body = body
4079 @end_keyword_loc = end_keyword_loc
4080 @name = name
4081 end
4082
4083 # def accept: (Visitor visitor) -> void
4084 def accept(visitor)
4085 visitor.visit_class_node(self)
4086 end
4087
4088 # def child_nodes: () -> Array[Node?]
4089 def child_nodes
4090 [constant_path, superclass, body]
4091 end
4092
4093 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
4094 def each_child_node
4095 return to_enum(:each_child_node) unless block_given?
4096
4097 yield constant_path
4098 yield superclass if superclass
4099 yield body if body
4100 end
4101
4102 # def compact_child_nodes: () -> Array[Node]
4103 def compact_child_nodes
4104 compact = [] #: Array[Prism::node]
4105 compact << constant_path
4106 compact << superclass if superclass
4107 compact << body if body
4108 compact
4109 end
4110
4111 # def comment_targets: () -> Array[Node | Location]
4112 def comment_targets
4113 [class_keyword_loc, constant_path, *inheritance_operator_loc, *superclass, *body, end_keyword_loc] #: Array[Prism::node | Location]
4114 end
4115
4116 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array[Symbol], ?class_keyword_loc: Location, ?constant_path: ConstantReadNode | ConstantPathNode | CallNode, ?inheritance_operator_loc: Location?, ?superclass: Prism::node?, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ClassNode
4117 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, constant_path: self.constant_path, inheritance_operator_loc: self.inheritance_operator_loc, superclass: self.superclass, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name)
4118 ClassNode.new(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name)
4119 end
4120
4121 # def deconstruct: () -> Array[Node?]
4122 alias deconstruct child_nodes
4123
4124 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, locals: Array[Symbol], class_keyword_loc: Location, constant_path: ConstantReadNode | ConstantPathNode | CallNode, inheritance_operator_loc: Location?, superclass: Prism::node?, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location, name: Symbol }
4125 def deconstruct_keys(keys)
4126 { node_id: node_id, location: location, locals: locals, class_keyword_loc: class_keyword_loc, constant_path: constant_path, inheritance_operator_loc: inheritance_operator_loc, superclass: superclass, body: body, end_keyword_loc: end_keyword_loc, name: name }
4127 end
4128
4129 # attr_reader locals: Array[Symbol]
4130 attr_reader :locals
4131
4132 # Represents the location of the `class` keyword.
4133 #
4134 # class Foo end
4135 # ^^^^^
4136 def class_keyword_loc
4137 location = @class_keyword_loc
4138 return location if location.is_a?(Location)
4139 @class_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4140 end
4141
4142 # Save the class_keyword_loc location using the given saved source so that
4143 # it can be retrieved later.
4144 def save_class_keyword_loc(repository)
4145 repository.enter(node_id, :class_keyword_loc)
4146 end
4147
4148 # attr_reader constant_path: ConstantReadNode | ConstantPathNode | CallNode
4149 attr_reader :constant_path
4150
4151 # Represents the location of the `<` operator.
4152 #
4153 # class Foo < Bar
4154 # ^
4155 def inheritance_operator_loc
4156 location = @inheritance_operator_loc
4157 case location
4158 when nil
4159 nil
4160 when Location
4161 location
4162 else
4163 @inheritance_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4164 end
4165 end
4166
4167 # Save the inheritance_operator_loc location using the given saved source so that
4168 # it can be retrieved later.
4169 def save_inheritance_operator_loc(repository)
4170 repository.enter(node_id, :inheritance_operator_loc) unless @inheritance_operator_loc.nil?
4171 end
4172
4173 # Represents the superclass of the class.
4174 #
4175 # class Foo < Bar
4176 # ^^^
4177 attr_reader :superclass
4178
4179 # Represents the body of the class.
4180 #
4181 # class Foo
4182 # foo
4183 # ^^^
4184 attr_reader :body
4185
4186 # Represents the location of the `end` keyword.
4187 #
4188 # class Foo end
4189 # ^^^
4190 def end_keyword_loc
4191 location = @end_keyword_loc
4192 return location if location.is_a?(Location)
4193 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4194 end
4195
4196 # Save the end_keyword_loc location using the given saved source so that
4197 # it can be retrieved later.
4198 def save_end_keyword_loc(repository)
4199 repository.enter(node_id, :end_keyword_loc)
4200 end
4201
4202 # The name of the class.
4203 #
4204 # class Foo end # name `:Foo`
4205 attr_reader :name
4206
4207 # def class_keyword: () -> String
4208 def class_keyword
4209 class_keyword_loc.slice
4210 end
4211
4212 # def inheritance_operator: () -> String?
4213 def inheritance_operator
4214 inheritance_operator_loc&.slice
4215 end
4216
4217 # def end_keyword: () -> String
4218 def end_keyword
4219 end_keyword_loc.slice
4220 end
4221
4222 # def inspect -> String
4223 def inspect
4224 InspectVisitor.compose(self)
4225 end
4226
4227 # Return a symbol representation of this node type. See `Node#type`.
4228 def type
4229 :class_node
4230 end
4231
4232 # Return a symbol representation of this node type. See `Node::type`.
4233 def self.type
4234 :class_node
4235 end
4236
4237 # Implements case-equality for the node. This is effectively == but without
4238 # comparing the value of locations. Locations are checked only for presence.
4239 def ===(other)
4240 other.is_a?(ClassNode) &&
4241 (locals.length == other.locals.length) &&
4242 locals.zip(other.locals).all? { |left, right| left === right } &&
4243 (class_keyword_loc.nil? == other.class_keyword_loc.nil?) &&
4244 (constant_path === other.constant_path) &&
4245 (inheritance_operator_loc.nil? == other.inheritance_operator_loc.nil?) &&
4246 (superclass === other.superclass) &&
4247 (body === other.body) &&
4248 (end_keyword_loc.nil? == other.end_keyword_loc.nil?) &&
4249 (name === other.name)
4250 end
4251 end
4252
4253 # Represents the use of the `&&=` operator for assignment to a class variable.
4254 #
4255 # @@target &&= value
4256 # ^^^^^^^^^^^^^^^^^^
4257 class ClassVariableAndWriteNode < Node
4258 # Initialize a new ClassVariableAndWriteNode node.
4259 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
4260 @source = source
4261 @node_id = node_id
4262 @location = location
4263 @flags = flags
4264 @name = name
4265 @name_loc = name_loc
4266 @operator_loc = operator_loc
4267 @value = value
4268 end
4269
4270 # def accept: (Visitor visitor) -> void
4271 def accept(visitor)
4272 visitor.visit_class_variable_and_write_node(self)
4273 end
4274
4275 # def child_nodes: () -> Array[Node?]
4276 def child_nodes
4277 [value]
4278 end
4279
4280 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
4281 def each_child_node
4282 return to_enum(:each_child_node) unless block_given?
4283
4284 yield value
4285 end
4286
4287 # def compact_child_nodes: () -> Array[Node]
4288 def compact_child_nodes
4289 [value]
4290 end
4291
4292 # def comment_targets: () -> Array[Node | Location]
4293 def comment_targets
4294 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
4295 end
4296
4297 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ClassVariableAndWriteNode
4298 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
4299 ClassVariableAndWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
4300 end
4301
4302 # def deconstruct: () -> Array[Node?]
4303 alias deconstruct child_nodes
4304
4305 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
4306 def deconstruct_keys(keys)
4307 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
4308 end
4309
4310 # The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
4311 #
4312 # @@target &&= value # name `:@@target`
4313 # ^^^^^^^^
4314 attr_reader :name
4315
4316 # Represents the location of the variable name.
4317 #
4318 # @@target &&= value
4319 # ^^^^^^^^
4320 def name_loc
4321 location = @name_loc
4322 return location if location.is_a?(Location)
4323 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4324 end
4325
4326 # Save the name_loc location using the given saved source so that
4327 # it can be retrieved later.
4328 def save_name_loc(repository)
4329 repository.enter(node_id, :name_loc)
4330 end
4331
4332 # Represents the location of the `&&=` operator.
4333 #
4334 # @@target &&= value
4335 # ^^^
4336 def operator_loc
4337 location = @operator_loc
4338 return location if location.is_a?(Location)
4339 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4340 end
4341
4342 # Save the operator_loc location using the given saved source so that
4343 # it can be retrieved later.
4344 def save_operator_loc(repository)
4345 repository.enter(node_id, :operator_loc)
4346 end
4347
4348 # Represents the value being assigned. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
4349 #
4350 # @@target &&= value
4351 # ^^^^^
4352 attr_reader :value
4353
4354 # def operator: () -> String
4355 def operator
4356 operator_loc.slice
4357 end
4358
4359 # def inspect -> String
4360 def inspect
4361 InspectVisitor.compose(self)
4362 end
4363
4364 # Return a symbol representation of this node type. See `Node#type`.
4365 def type
4366 :class_variable_and_write_node
4367 end
4368
4369 # Return a symbol representation of this node type. See `Node::type`.
4370 def self.type
4371 :class_variable_and_write_node
4372 end
4373
4374 # Implements case-equality for the node. This is effectively == but without
4375 # comparing the value of locations. Locations are checked only for presence.
4376 def ===(other)
4377 other.is_a?(ClassVariableAndWriteNode) &&
4378 (name === other.name) &&
4379 (name_loc.nil? == other.name_loc.nil?) &&
4380 (operator_loc.nil? == other.operator_loc.nil?) &&
4381 (value === other.value)
4382 end
4383 end
4384
4385 # Represents assigning to a class variable using an operator that isn't `=`.
4386 #
4387 # @@target += value
4388 # ^^^^^^^^^^^^^^^^^
4389 class ClassVariableOperatorWriteNode < Node
4390 # Initialize a new ClassVariableOperatorWriteNode node.
4391 def initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
4392 @source = source
4393 @node_id = node_id
4394 @location = location
4395 @flags = flags
4396 @name = name
4397 @name_loc = name_loc
4398 @binary_operator_loc = binary_operator_loc
4399 @value = value
4400 @binary_operator = binary_operator
4401 end
4402
4403 # def accept: (Visitor visitor) -> void
4404 def accept(visitor)
4405 visitor.visit_class_variable_operator_write_node(self)
4406 end
4407
4408 # def child_nodes: () -> Array[Node?]
4409 def child_nodes
4410 [value]
4411 end
4412
4413 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
4414 def each_child_node
4415 return to_enum(:each_child_node) unless block_given?
4416
4417 yield value
4418 end
4419
4420 # def compact_child_nodes: () -> Array[Node]
4421 def compact_child_nodes
4422 [value]
4423 end
4424
4425 # def comment_targets: () -> Array[Node | Location]
4426 def comment_targets
4427 [name_loc, binary_operator_loc, value] #: Array[Prism::node | Location]
4428 end
4429
4430 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?binary_operator_loc: Location, ?value: Prism::node, ?binary_operator: Symbol) -> ClassVariableOperatorWriteNode
4431 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
4432 ClassVariableOperatorWriteNode.new(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
4433 end
4434
4435 # def deconstruct: () -> Array[Node?]
4436 alias deconstruct child_nodes
4437
4438 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Prism::node, binary_operator: Symbol }
4439 def deconstruct_keys(keys)
4440 { node_id: node_id, location: location, name: name, name_loc: name_loc, binary_operator_loc: binary_operator_loc, value: value, binary_operator: binary_operator }
4441 end
4442
4443 # attr_reader name: Symbol
4444 attr_reader :name
4445
4446 # attr_reader name_loc: Location
4447 def name_loc
4448 location = @name_loc
4449 return location if location.is_a?(Location)
4450 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4451 end
4452
4453 # Save the name_loc location using the given saved source so that
4454 # it can be retrieved later.
4455 def save_name_loc(repository)
4456 repository.enter(node_id, :name_loc)
4457 end
4458
4459 # attr_reader binary_operator_loc: Location
4460 def binary_operator_loc
4461 location = @binary_operator_loc
4462 return location if location.is_a?(Location)
4463 @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4464 end
4465
4466 # Save the binary_operator_loc location using the given saved source so that
4467 # it can be retrieved later.
4468 def save_binary_operator_loc(repository)
4469 repository.enter(node_id, :binary_operator_loc)
4470 end
4471
4472 # attr_reader value: Prism::node
4473 attr_reader :value
4474
4475 # attr_reader binary_operator: Symbol
4476 attr_reader :binary_operator
4477
4478 # def inspect -> String
4479 def inspect
4480 InspectVisitor.compose(self)
4481 end
4482
4483 # Return a symbol representation of this node type. See `Node#type`.
4484 def type
4485 :class_variable_operator_write_node
4486 end
4487
4488 # Return a symbol representation of this node type. See `Node::type`.
4489 def self.type
4490 :class_variable_operator_write_node
4491 end
4492
4493 # Implements case-equality for the node. This is effectively == but without
4494 # comparing the value of locations. Locations are checked only for presence.
4495 def ===(other)
4496 other.is_a?(ClassVariableOperatorWriteNode) &&
4497 (name === other.name) &&
4498 (name_loc.nil? == other.name_loc.nil?) &&
4499 (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
4500 (value === other.value) &&
4501 (binary_operator === other.binary_operator)
4502 end
4503 end
4504
4505 # Represents the use of the `||=` operator for assignment to a class variable.
4506 #
4507 # @@target ||= value
4508 # ^^^^^^^^^^^^^^^^^^
4509 class ClassVariableOrWriteNode < Node
4510 # Initialize a new ClassVariableOrWriteNode node.
4511 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
4512 @source = source
4513 @node_id = node_id
4514 @location = location
4515 @flags = flags
4516 @name = name
4517 @name_loc = name_loc
4518 @operator_loc = operator_loc
4519 @value = value
4520 end
4521
4522 # def accept: (Visitor visitor) -> void
4523 def accept(visitor)
4524 visitor.visit_class_variable_or_write_node(self)
4525 end
4526
4527 # def child_nodes: () -> Array[Node?]
4528 def child_nodes
4529 [value]
4530 end
4531
4532 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
4533 def each_child_node
4534 return to_enum(:each_child_node) unless block_given?
4535
4536 yield value
4537 end
4538
4539 # def compact_child_nodes: () -> Array[Node]
4540 def compact_child_nodes
4541 [value]
4542 end
4543
4544 # def comment_targets: () -> Array[Node | Location]
4545 def comment_targets
4546 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
4547 end
4548
4549 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ClassVariableOrWriteNode
4550 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
4551 ClassVariableOrWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
4552 end
4553
4554 # def deconstruct: () -> Array[Node?]
4555 alias deconstruct child_nodes
4556
4557 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
4558 def deconstruct_keys(keys)
4559 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
4560 end
4561
4562 # attr_reader name: Symbol
4563 attr_reader :name
4564
4565 # attr_reader name_loc: Location
4566 def name_loc
4567 location = @name_loc
4568 return location if location.is_a?(Location)
4569 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4570 end
4571
4572 # Save the name_loc location using the given saved source so that
4573 # it can be retrieved later.
4574 def save_name_loc(repository)
4575 repository.enter(node_id, :name_loc)
4576 end
4577
4578 # attr_reader operator_loc: Location
4579 def operator_loc
4580 location = @operator_loc
4581 return location if location.is_a?(Location)
4582 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4583 end
4584
4585 # Save the operator_loc location using the given saved source so that
4586 # it can be retrieved later.
4587 def save_operator_loc(repository)
4588 repository.enter(node_id, :operator_loc)
4589 end
4590
4591 # attr_reader value: Prism::node
4592 attr_reader :value
4593
4594 # def operator: () -> String
4595 def operator
4596 operator_loc.slice
4597 end
4598
4599 # def inspect -> String
4600 def inspect
4601 InspectVisitor.compose(self)
4602 end
4603
4604 # Return a symbol representation of this node type. See `Node#type`.
4605 def type
4606 :class_variable_or_write_node
4607 end
4608
4609 # Return a symbol representation of this node type. See `Node::type`.
4610 def self.type
4611 :class_variable_or_write_node
4612 end
4613
4614 # Implements case-equality for the node. This is effectively == but without
4615 # comparing the value of locations. Locations are checked only for presence.
4616 def ===(other)
4617 other.is_a?(ClassVariableOrWriteNode) &&
4618 (name === other.name) &&
4619 (name_loc.nil? == other.name_loc.nil?) &&
4620 (operator_loc.nil? == other.operator_loc.nil?) &&
4621 (value === other.value)
4622 end
4623 end
4624
4625 # Represents referencing a class variable.
4626 #
4627 # @@foo
4628 # ^^^^^
4629 class ClassVariableReadNode < Node
4630 # Initialize a new ClassVariableReadNode node.
4631 def initialize(source, node_id, location, flags, name)
4632 @source = source
4633 @node_id = node_id
4634 @location = location
4635 @flags = flags
4636 @name = name
4637 end
4638
4639 # def accept: (Visitor visitor) -> void
4640 def accept(visitor)
4641 visitor.visit_class_variable_read_node(self)
4642 end
4643
4644 # def child_nodes: () -> Array[Node?]
4645 def child_nodes
4646 []
4647 end
4648
4649 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
4650 def each_child_node
4651 return to_enum(:each_child_node) unless block_given?
4652
4653 end
4654
4655 # def compact_child_nodes: () -> Array[Node]
4656 def compact_child_nodes
4657 []
4658 end
4659
4660 # def comment_targets: () -> Array[Node | Location]
4661 def comment_targets
4662 [] #: Array[Prism::node | Location]
4663 end
4664
4665 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> ClassVariableReadNode
4666 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
4667 ClassVariableReadNode.new(source, node_id, location, flags, name)
4668 end
4669
4670 # def deconstruct: () -> Array[Node?]
4671 alias deconstruct child_nodes
4672
4673 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
4674 def deconstruct_keys(keys)
4675 { node_id: node_id, location: location, name: name }
4676 end
4677
4678 # The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
4679 #
4680 # @@abc # name `:@@abc`
4681 #
4682 # @@_test # name `:@@_test`
4683 attr_reader :name
4684
4685 # def inspect -> String
4686 def inspect
4687 InspectVisitor.compose(self)
4688 end
4689
4690 # Return a symbol representation of this node type. See `Node#type`.
4691 def type
4692 :class_variable_read_node
4693 end
4694
4695 # Return a symbol representation of this node type. See `Node::type`.
4696 def self.type
4697 :class_variable_read_node
4698 end
4699
4700 # Implements case-equality for the node. This is effectively == but without
4701 # comparing the value of locations. Locations are checked only for presence.
4702 def ===(other)
4703 other.is_a?(ClassVariableReadNode) &&
4704 (name === other.name)
4705 end
4706 end
4707
4708 # Represents writing to a class variable in a context that doesn't have an explicit value.
4709 #
4710 # @@foo, @@bar = baz
4711 # ^^^^^ ^^^^^
4712 class ClassVariableTargetNode < Node
4713 # Initialize a new ClassVariableTargetNode node.
4714 def initialize(source, node_id, location, flags, name)
4715 @source = source
4716 @node_id = node_id
4717 @location = location
4718 @flags = flags
4719 @name = name
4720 end
4721
4722 # def accept: (Visitor visitor) -> void
4723 def accept(visitor)
4724 visitor.visit_class_variable_target_node(self)
4725 end
4726
4727 # def child_nodes: () -> Array[Node?]
4728 def child_nodes
4729 []
4730 end
4731
4732 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
4733 def each_child_node
4734 return to_enum(:each_child_node) unless block_given?
4735
4736 end
4737
4738 # def compact_child_nodes: () -> Array[Node]
4739 def compact_child_nodes
4740 []
4741 end
4742
4743 # def comment_targets: () -> Array[Node | Location]
4744 def comment_targets
4745 [] #: Array[Prism::node | Location]
4746 end
4747
4748 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> ClassVariableTargetNode
4749 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
4750 ClassVariableTargetNode.new(source, node_id, location, flags, name)
4751 end
4752
4753 # def deconstruct: () -> Array[Node?]
4754 alias deconstruct child_nodes
4755
4756 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
4757 def deconstruct_keys(keys)
4758 { node_id: node_id, location: location, name: name }
4759 end
4760
4761 # attr_reader name: Symbol
4762 attr_reader :name
4763
4764 # def inspect -> String
4765 def inspect
4766 InspectVisitor.compose(self)
4767 end
4768
4769 # Return a symbol representation of this node type. See `Node#type`.
4770 def type
4771 :class_variable_target_node
4772 end
4773
4774 # Return a symbol representation of this node type. See `Node::type`.
4775 def self.type
4776 :class_variable_target_node
4777 end
4778
4779 # Implements case-equality for the node. This is effectively == but without
4780 # comparing the value of locations. Locations are checked only for presence.
4781 def ===(other)
4782 other.is_a?(ClassVariableTargetNode) &&
4783 (name === other.name)
4784 end
4785 end
4786
4787 # Represents writing to a class variable.
4788 #
4789 # @@foo = 1
4790 # ^^^^^^^^^
4791 class ClassVariableWriteNode < Node
4792 # Initialize a new ClassVariableWriteNode node.
4793 def initialize(source, node_id, location, flags, name, name_loc, value, operator_loc)
4794 @source = source
4795 @node_id = node_id
4796 @location = location
4797 @flags = flags
4798 @name = name
4799 @name_loc = name_loc
4800 @value = value
4801 @operator_loc = operator_loc
4802 end
4803
4804 # def accept: (Visitor visitor) -> void
4805 def accept(visitor)
4806 visitor.visit_class_variable_write_node(self)
4807 end
4808
4809 # def child_nodes: () -> Array[Node?]
4810 def child_nodes
4811 [value]
4812 end
4813
4814 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
4815 def each_child_node
4816 return to_enum(:each_child_node) unless block_given?
4817
4818 yield value
4819 end
4820
4821 # def compact_child_nodes: () -> Array[Node]
4822 def compact_child_nodes
4823 [value]
4824 end
4825
4826 # def comment_targets: () -> Array[Node | Location]
4827 def comment_targets
4828 [name_loc, value, operator_loc] #: Array[Prism::node | Location]
4829 end
4830
4831 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?value: Prism::node, ?operator_loc: Location) -> ClassVariableWriteNode
4832 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, value: self.value, operator_loc: self.operator_loc)
4833 ClassVariableWriteNode.new(source, node_id, location, flags, name, name_loc, value, operator_loc)
4834 end
4835
4836 # def deconstruct: () -> Array[Node?]
4837 alias deconstruct child_nodes
4838
4839 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, value: Prism::node, operator_loc: Location }
4840 def deconstruct_keys(keys)
4841 { node_id: node_id, location: location, name: name, name_loc: name_loc, value: value, operator_loc: operator_loc }
4842 end
4843
4844 # The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
4845 #
4846 # @@abc = 123 # name `@@abc`
4847 #
4848 # @@_test = :test # name `@@_test`
4849 attr_reader :name
4850
4851 # The location of the variable name.
4852 #
4853 # @@foo = :bar
4854 # ^^^^^
4855 def name_loc
4856 location = @name_loc
4857 return location if location.is_a?(Location)
4858 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4859 end
4860
4861 # Save the name_loc location using the given saved source so that
4862 # it can be retrieved later.
4863 def save_name_loc(repository)
4864 repository.enter(node_id, :name_loc)
4865 end
4866
4867 # The value to write to the class variable. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
4868 #
4869 # @@foo = :bar
4870 # ^^^^
4871 #
4872 # @@_xyz = 123
4873 # ^^^
4874 attr_reader :value
4875
4876 # The location of the `=` operator.
4877 #
4878 # @@foo = :bar
4879 # ^
4880 def operator_loc
4881 location = @operator_loc
4882 return location if location.is_a?(Location)
4883 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4884 end
4885
4886 # Save the operator_loc location using the given saved source so that
4887 # it can be retrieved later.
4888 def save_operator_loc(repository)
4889 repository.enter(node_id, :operator_loc)
4890 end
4891
4892 # def operator: () -> String
4893 def operator
4894 operator_loc.slice
4895 end
4896
4897 # def inspect -> String
4898 def inspect
4899 InspectVisitor.compose(self)
4900 end
4901
4902 # Return a symbol representation of this node type. See `Node#type`.
4903 def type
4904 :class_variable_write_node
4905 end
4906
4907 # Return a symbol representation of this node type. See `Node::type`.
4908 def self.type
4909 :class_variable_write_node
4910 end
4911
4912 # Implements case-equality for the node. This is effectively == but without
4913 # comparing the value of locations. Locations are checked only for presence.
4914 def ===(other)
4915 other.is_a?(ClassVariableWriteNode) &&
4916 (name === other.name) &&
4917 (name_loc.nil? == other.name_loc.nil?) &&
4918 (value === other.value) &&
4919 (operator_loc.nil? == other.operator_loc.nil?)
4920 end
4921 end
4922
4923 # Represents the use of the `&&=` operator for assignment to a constant.
4924 #
4925 # Target &&= value
4926 # ^^^^^^^^^^^^^^^^
4927 class ConstantAndWriteNode < Node
4928 # Initialize a new ConstantAndWriteNode node.
4929 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
4930 @source = source
4931 @node_id = node_id
4932 @location = location
4933 @flags = flags
4934 @name = name
4935 @name_loc = name_loc
4936 @operator_loc = operator_loc
4937 @value = value
4938 end
4939
4940 # def accept: (Visitor visitor) -> void
4941 def accept(visitor)
4942 visitor.visit_constant_and_write_node(self)
4943 end
4944
4945 # def child_nodes: () -> Array[Node?]
4946 def child_nodes
4947 [value]
4948 end
4949
4950 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
4951 def each_child_node
4952 return to_enum(:each_child_node) unless block_given?
4953
4954 yield value
4955 end
4956
4957 # def compact_child_nodes: () -> Array[Node]
4958 def compact_child_nodes
4959 [value]
4960 end
4961
4962 # def comment_targets: () -> Array[Node | Location]
4963 def comment_targets
4964 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
4965 end
4966
4967 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ConstantAndWriteNode
4968 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
4969 ConstantAndWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
4970 end
4971
4972 # def deconstruct: () -> Array[Node?]
4973 alias deconstruct child_nodes
4974
4975 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
4976 def deconstruct_keys(keys)
4977 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
4978 end
4979
4980 # attr_reader name: Symbol
4981 attr_reader :name
4982
4983 # attr_reader name_loc: Location
4984 def name_loc
4985 location = @name_loc
4986 return location if location.is_a?(Location)
4987 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
4988 end
4989
4990 # Save the name_loc location using the given saved source so that
4991 # it can be retrieved later.
4992 def save_name_loc(repository)
4993 repository.enter(node_id, :name_loc)
4994 end
4995
4996 # attr_reader operator_loc: Location
4997 def operator_loc
4998 location = @operator_loc
4999 return location if location.is_a?(Location)
5000 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5001 end
5002
5003 # Save the operator_loc location using the given saved source so that
5004 # it can be retrieved later.
5005 def save_operator_loc(repository)
5006 repository.enter(node_id, :operator_loc)
5007 end
5008
5009 # attr_reader value: Prism::node
5010 attr_reader :value
5011
5012 # def operator: () -> String
5013 def operator
5014 operator_loc.slice
5015 end
5016
5017 # def inspect -> String
5018 def inspect
5019 InspectVisitor.compose(self)
5020 end
5021
5022 # Return a symbol representation of this node type. See `Node#type`.
5023 def type
5024 :constant_and_write_node
5025 end
5026
5027 # Return a symbol representation of this node type. See `Node::type`.
5028 def self.type
5029 :constant_and_write_node
5030 end
5031
5032 # Implements case-equality for the node. This is effectively == but without
5033 # comparing the value of locations. Locations are checked only for presence.
5034 def ===(other)
5035 other.is_a?(ConstantAndWriteNode) &&
5036 (name === other.name) &&
5037 (name_loc.nil? == other.name_loc.nil?) &&
5038 (operator_loc.nil? == other.operator_loc.nil?) &&
5039 (value === other.value)
5040 end
5041 end
5042
5043 # Represents assigning to a constant using an operator that isn't `=`.
5044 #
5045 # Target += value
5046 # ^^^^^^^^^^^^^^^
5047 class ConstantOperatorWriteNode < Node
5048 # Initialize a new ConstantOperatorWriteNode node.
5049 def initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
5050 @source = source
5051 @node_id = node_id
5052 @location = location
5053 @flags = flags
5054 @name = name
5055 @name_loc = name_loc
5056 @binary_operator_loc = binary_operator_loc
5057 @value = value
5058 @binary_operator = binary_operator
5059 end
5060
5061 # def accept: (Visitor visitor) -> void
5062 def accept(visitor)
5063 visitor.visit_constant_operator_write_node(self)
5064 end
5065
5066 # def child_nodes: () -> Array[Node?]
5067 def child_nodes
5068 [value]
5069 end
5070
5071 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
5072 def each_child_node
5073 return to_enum(:each_child_node) unless block_given?
5074
5075 yield value
5076 end
5077
5078 # def compact_child_nodes: () -> Array[Node]
5079 def compact_child_nodes
5080 [value]
5081 end
5082
5083 # def comment_targets: () -> Array[Node | Location]
5084 def comment_targets
5085 [name_loc, binary_operator_loc, value] #: Array[Prism::node | Location]
5086 end
5087
5088 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?binary_operator_loc: Location, ?value: Prism::node, ?binary_operator: Symbol) -> ConstantOperatorWriteNode
5089 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
5090 ConstantOperatorWriteNode.new(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
5091 end
5092
5093 # def deconstruct: () -> Array[Node?]
5094 alias deconstruct child_nodes
5095
5096 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Prism::node, binary_operator: Symbol }
5097 def deconstruct_keys(keys)
5098 { node_id: node_id, location: location, name: name, name_loc: name_loc, binary_operator_loc: binary_operator_loc, value: value, binary_operator: binary_operator }
5099 end
5100
5101 # attr_reader name: Symbol
5102 attr_reader :name
5103
5104 # attr_reader name_loc: Location
5105 def name_loc
5106 location = @name_loc
5107 return location if location.is_a?(Location)
5108 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5109 end
5110
5111 # Save the name_loc location using the given saved source so that
5112 # it can be retrieved later.
5113 def save_name_loc(repository)
5114 repository.enter(node_id, :name_loc)
5115 end
5116
5117 # attr_reader binary_operator_loc: Location
5118 def binary_operator_loc
5119 location = @binary_operator_loc
5120 return location if location.is_a?(Location)
5121 @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5122 end
5123
5124 # Save the binary_operator_loc location using the given saved source so that
5125 # it can be retrieved later.
5126 def save_binary_operator_loc(repository)
5127 repository.enter(node_id, :binary_operator_loc)
5128 end
5129
5130 # attr_reader value: Prism::node
5131 attr_reader :value
5132
5133 # attr_reader binary_operator: Symbol
5134 attr_reader :binary_operator
5135
5136 # def inspect -> String
5137 def inspect
5138 InspectVisitor.compose(self)
5139 end
5140
5141 # Return a symbol representation of this node type. See `Node#type`.
5142 def type
5143 :constant_operator_write_node
5144 end
5145
5146 # Return a symbol representation of this node type. See `Node::type`.
5147 def self.type
5148 :constant_operator_write_node
5149 end
5150
5151 # Implements case-equality for the node. This is effectively == but without
5152 # comparing the value of locations. Locations are checked only for presence.
5153 def ===(other)
5154 other.is_a?(ConstantOperatorWriteNode) &&
5155 (name === other.name) &&
5156 (name_loc.nil? == other.name_loc.nil?) &&
5157 (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
5158 (value === other.value) &&
5159 (binary_operator === other.binary_operator)
5160 end
5161 end
5162
5163 # Represents the use of the `||=` operator for assignment to a constant.
5164 #
5165 # Target ||= value
5166 # ^^^^^^^^^^^^^^^^
5167 class ConstantOrWriteNode < Node
5168 # Initialize a new ConstantOrWriteNode node.
5169 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
5170 @source = source
5171 @node_id = node_id
5172 @location = location
5173 @flags = flags
5174 @name = name
5175 @name_loc = name_loc
5176 @operator_loc = operator_loc
5177 @value = value
5178 end
5179
5180 # def accept: (Visitor visitor) -> void
5181 def accept(visitor)
5182 visitor.visit_constant_or_write_node(self)
5183 end
5184
5185 # def child_nodes: () -> Array[Node?]
5186 def child_nodes
5187 [value]
5188 end
5189
5190 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
5191 def each_child_node
5192 return to_enum(:each_child_node) unless block_given?
5193
5194 yield value
5195 end
5196
5197 # def compact_child_nodes: () -> Array[Node]
5198 def compact_child_nodes
5199 [value]
5200 end
5201
5202 # def comment_targets: () -> Array[Node | Location]
5203 def comment_targets
5204 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
5205 end
5206
5207 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ConstantOrWriteNode
5208 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
5209 ConstantOrWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
5210 end
5211
5212 # def deconstruct: () -> Array[Node?]
5213 alias deconstruct child_nodes
5214
5215 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
5216 def deconstruct_keys(keys)
5217 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
5218 end
5219
5220 # attr_reader name: Symbol
5221 attr_reader :name
5222
5223 # attr_reader name_loc: Location
5224 def name_loc
5225 location = @name_loc
5226 return location if location.is_a?(Location)
5227 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5228 end
5229
5230 # Save the name_loc location using the given saved source so that
5231 # it can be retrieved later.
5232 def save_name_loc(repository)
5233 repository.enter(node_id, :name_loc)
5234 end
5235
5236 # attr_reader operator_loc: Location
5237 def operator_loc
5238 location = @operator_loc
5239 return location if location.is_a?(Location)
5240 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5241 end
5242
5243 # Save the operator_loc location using the given saved source so that
5244 # it can be retrieved later.
5245 def save_operator_loc(repository)
5246 repository.enter(node_id, :operator_loc)
5247 end
5248
5249 # attr_reader value: Prism::node
5250 attr_reader :value
5251
5252 # def operator: () -> String
5253 def operator
5254 operator_loc.slice
5255 end
5256
5257 # def inspect -> String
5258 def inspect
5259 InspectVisitor.compose(self)
5260 end
5261
5262 # Return a symbol representation of this node type. See `Node#type`.
5263 def type
5264 :constant_or_write_node
5265 end
5266
5267 # Return a symbol representation of this node type. See `Node::type`.
5268 def self.type
5269 :constant_or_write_node
5270 end
5271
5272 # Implements case-equality for the node. This is effectively == but without
5273 # comparing the value of locations. Locations are checked only for presence.
5274 def ===(other)
5275 other.is_a?(ConstantOrWriteNode) &&
5276 (name === other.name) &&
5277 (name_loc.nil? == other.name_loc.nil?) &&
5278 (operator_loc.nil? == other.operator_loc.nil?) &&
5279 (value === other.value)
5280 end
5281 end
5282
5283 # Represents the use of the `&&=` operator for assignment to a constant path.
5284 #
5285 # Parent::Child &&= value
5286 # ^^^^^^^^^^^^^^^^^^^^^^^
5287 class ConstantPathAndWriteNode < Node
5288 # Initialize a new ConstantPathAndWriteNode node.
5289 def initialize(source, node_id, location, flags, target, operator_loc, value)
5290 @source = source
5291 @node_id = node_id
5292 @location = location
5293 @flags = flags
5294 @target = target
5295 @operator_loc = operator_loc
5296 @value = value
5297 end
5298
5299 # def accept: (Visitor visitor) -> void
5300 def accept(visitor)
5301 visitor.visit_constant_path_and_write_node(self)
5302 end
5303
5304 # def child_nodes: () -> Array[Node?]
5305 def child_nodes
5306 [target, value]
5307 end
5308
5309 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
5310 def each_child_node
5311 return to_enum(:each_child_node) unless block_given?
5312
5313 yield target
5314 yield value
5315 end
5316
5317 # def compact_child_nodes: () -> Array[Node]
5318 def compact_child_nodes
5319 [target, value]
5320 end
5321
5322 # def comment_targets: () -> Array[Node | Location]
5323 def comment_targets
5324 [target, operator_loc, value] #: Array[Prism::node | Location]
5325 end
5326
5327 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathAndWriteNode
5328 def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value)
5329 ConstantPathAndWriteNode.new(source, node_id, location, flags, target, operator_loc, value)
5330 end
5331
5332 # def deconstruct: () -> Array[Node?]
5333 alias deconstruct child_nodes
5334
5335 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, target: ConstantPathNode, operator_loc: Location, value: Prism::node }
5336 def deconstruct_keys(keys)
5337 { node_id: node_id, location: location, target: target, operator_loc: operator_loc, value: value }
5338 end
5339
5340 # attr_reader target: ConstantPathNode
5341 attr_reader :target
5342
5343 # attr_reader operator_loc: Location
5344 def operator_loc
5345 location = @operator_loc
5346 return location if location.is_a?(Location)
5347 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5348 end
5349
5350 # Save the operator_loc location using the given saved source so that
5351 # it can be retrieved later.
5352 def save_operator_loc(repository)
5353 repository.enter(node_id, :operator_loc)
5354 end
5355
5356 # attr_reader value: Prism::node
5357 attr_reader :value
5358
5359 # def operator: () -> String
5360 def operator
5361 operator_loc.slice
5362 end
5363
5364 # def inspect -> String
5365 def inspect
5366 InspectVisitor.compose(self)
5367 end
5368
5369 # Return a symbol representation of this node type. See `Node#type`.
5370 def type
5371 :constant_path_and_write_node
5372 end
5373
5374 # Return a symbol representation of this node type. See `Node::type`.
5375 def self.type
5376 :constant_path_and_write_node
5377 end
5378
5379 # Implements case-equality for the node. This is effectively == but without
5380 # comparing the value of locations. Locations are checked only for presence.
5381 def ===(other)
5382 other.is_a?(ConstantPathAndWriteNode) &&
5383 (target === other.target) &&
5384 (operator_loc.nil? == other.operator_loc.nil?) &&
5385 (value === other.value)
5386 end
5387 end
5388
5389 # Represents accessing a constant through a path of `::` operators.
5390 #
5391 # Foo::Bar
5392 # ^^^^^^^^
5393 class ConstantPathNode < Node
5394 # Initialize a new ConstantPathNode node.
5395 def initialize(source, node_id, location, flags, parent, name, delimiter_loc, name_loc)
5396 @source = source
5397 @node_id = node_id
5398 @location = location
5399 @flags = flags
5400 @parent = parent
5401 @name = name
5402 @delimiter_loc = delimiter_loc
5403 @name_loc = name_loc
5404 end
5405
5406 # def accept: (Visitor visitor) -> void
5407 def accept(visitor)
5408 visitor.visit_constant_path_node(self)
5409 end
5410
5411 # def child_nodes: () -> Array[Node?]
5412 def child_nodes
5413 [parent]
5414 end
5415
5416 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
5417 def each_child_node
5418 return to_enum(:each_child_node) unless block_given?
5419
5420 yield parent if parent
5421 end
5422
5423 # def compact_child_nodes: () -> Array[Node]
5424 def compact_child_nodes
5425 compact = [] #: Array[Prism::node]
5426 compact << parent if parent
5427 compact
5428 end
5429
5430 # def comment_targets: () -> Array[Node | Location]
5431 def comment_targets
5432 [*parent, delimiter_loc, name_loc] #: Array[Prism::node | Location]
5433 end
5434
5435 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?parent: Prism::node?, ?name: Symbol?, ?delimiter_loc: Location, ?name_loc: Location) -> ConstantPathNode
5436 def copy(node_id: self.node_id, location: self.location, flags: self.flags, parent: self.parent, name: self.name, delimiter_loc: self.delimiter_loc, name_loc: self.name_loc)
5437 ConstantPathNode.new(source, node_id, location, flags, parent, name, delimiter_loc, name_loc)
5438 end
5439
5440 # def deconstruct: () -> Array[Node?]
5441 alias deconstruct child_nodes
5442
5443 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, parent: Prism::node?, name: Symbol?, delimiter_loc: Location, name_loc: Location }
5444 def deconstruct_keys(keys)
5445 { node_id: node_id, location: location, parent: parent, name: name, delimiter_loc: delimiter_loc, name_loc: name_loc }
5446 end
5447
5448 # The left-hand node of the path, if present. It can be `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression). It will be `nil` when the constant lookup is at the root of the module tree.
5449 #
5450 # Foo::Bar
5451 # ^^^
5452 #
5453 # self::Test
5454 # ^^^^
5455 #
5456 # a.b::C
5457 # ^^^
5458 attr_reader :parent
5459
5460 # The name of the constant being accessed. This could be `nil` in the event of a syntax error.
5461 attr_reader :name
5462
5463 # The location of the `::` delimiter.
5464 #
5465 # ::Foo
5466 # ^^
5467 #
5468 # One::Two
5469 # ^^
5470 def delimiter_loc
5471 location = @delimiter_loc
5472 return location if location.is_a?(Location)
5473 @delimiter_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5474 end
5475
5476 # Save the delimiter_loc location using the given saved source so that
5477 # it can be retrieved later.
5478 def save_delimiter_loc(repository)
5479 repository.enter(node_id, :delimiter_loc)
5480 end
5481
5482 # The location of the name of the constant.
5483 #
5484 # ::Foo
5485 # ^^^
5486 #
5487 # One::Two
5488 # ^^^
5489 def name_loc
5490 location = @name_loc
5491 return location if location.is_a?(Location)
5492 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5493 end
5494
5495 # Save the name_loc location using the given saved source so that
5496 # it can be retrieved later.
5497 def save_name_loc(repository)
5498 repository.enter(node_id, :name_loc)
5499 end
5500
5501 # def delimiter: () -> String
5502 def delimiter
5503 delimiter_loc.slice
5504 end
5505
5506 # def inspect -> String
5507 def inspect
5508 InspectVisitor.compose(self)
5509 end
5510
5511 # Return a symbol representation of this node type. See `Node#type`.
5512 def type
5513 :constant_path_node
5514 end
5515
5516 # Return a symbol representation of this node type. See `Node::type`.
5517 def self.type
5518 :constant_path_node
5519 end
5520
5521 # Implements case-equality for the node. This is effectively == but without
5522 # comparing the value of locations. Locations are checked only for presence.
5523 def ===(other)
5524 other.is_a?(ConstantPathNode) &&
5525 (parent === other.parent) &&
5526 (name === other.name) &&
5527 (delimiter_loc.nil? == other.delimiter_loc.nil?) &&
5528 (name_loc.nil? == other.name_loc.nil?)
5529 end
5530 end
5531
5532 # Represents assigning to a constant path using an operator that isn't `=`.
5533 #
5534 # Parent::Child += value
5535 # ^^^^^^^^^^^^^^^^^^^^^^
5536 class ConstantPathOperatorWriteNode < Node
5537 # Initialize a new ConstantPathOperatorWriteNode node.
5538 def initialize(source, node_id, location, flags, target, binary_operator_loc, value, binary_operator)
5539 @source = source
5540 @node_id = node_id
5541 @location = location
5542 @flags = flags
5543 @target = target
5544 @binary_operator_loc = binary_operator_loc
5545 @value = value
5546 @binary_operator = binary_operator
5547 end
5548
5549 # def accept: (Visitor visitor) -> void
5550 def accept(visitor)
5551 visitor.visit_constant_path_operator_write_node(self)
5552 end
5553
5554 # def child_nodes: () -> Array[Node?]
5555 def child_nodes
5556 [target, value]
5557 end
5558
5559 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
5560 def each_child_node
5561 return to_enum(:each_child_node) unless block_given?
5562
5563 yield target
5564 yield value
5565 end
5566
5567 # def compact_child_nodes: () -> Array[Node]
5568 def compact_child_nodes
5569 [target, value]
5570 end
5571
5572 # def comment_targets: () -> Array[Node | Location]
5573 def comment_targets
5574 [target, binary_operator_loc, value] #: Array[Prism::node | Location]
5575 end
5576
5577 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?binary_operator_loc: Location, ?value: Prism::node, ?binary_operator: Symbol) -> ConstantPathOperatorWriteNode
5578 def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
5579 ConstantPathOperatorWriteNode.new(source, node_id, location, flags, target, binary_operator_loc, value, binary_operator)
5580 end
5581
5582 # def deconstruct: () -> Array[Node?]
5583 alias deconstruct child_nodes
5584
5585 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, target: ConstantPathNode, binary_operator_loc: Location, value: Prism::node, binary_operator: Symbol }
5586 def deconstruct_keys(keys)
5587 { node_id: node_id, location: location, target: target, binary_operator_loc: binary_operator_loc, value: value, binary_operator: binary_operator }
5588 end
5589
5590 # attr_reader target: ConstantPathNode
5591 attr_reader :target
5592
5593 # attr_reader binary_operator_loc: Location
5594 def binary_operator_loc
5595 location = @binary_operator_loc
5596 return location if location.is_a?(Location)
5597 @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5598 end
5599
5600 # Save the binary_operator_loc location using the given saved source so that
5601 # it can be retrieved later.
5602 def save_binary_operator_loc(repository)
5603 repository.enter(node_id, :binary_operator_loc)
5604 end
5605
5606 # attr_reader value: Prism::node
5607 attr_reader :value
5608
5609 # attr_reader binary_operator: Symbol
5610 attr_reader :binary_operator
5611
5612 # def inspect -> String
5613 def inspect
5614 InspectVisitor.compose(self)
5615 end
5616
5617 # Return a symbol representation of this node type. See `Node#type`.
5618 def type
5619 :constant_path_operator_write_node
5620 end
5621
5622 # Return a symbol representation of this node type. See `Node::type`.
5623 def self.type
5624 :constant_path_operator_write_node
5625 end
5626
5627 # Implements case-equality for the node. This is effectively == but without
5628 # comparing the value of locations. Locations are checked only for presence.
5629 def ===(other)
5630 other.is_a?(ConstantPathOperatorWriteNode) &&
5631 (target === other.target) &&
5632 (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
5633 (value === other.value) &&
5634 (binary_operator === other.binary_operator)
5635 end
5636 end
5637
5638 # Represents the use of the `||=` operator for assignment to a constant path.
5639 #
5640 # Parent::Child ||= value
5641 # ^^^^^^^^^^^^^^^^^^^^^^^
5642 class ConstantPathOrWriteNode < Node
5643 # Initialize a new ConstantPathOrWriteNode node.
5644 def initialize(source, node_id, location, flags, target, operator_loc, value)
5645 @source = source
5646 @node_id = node_id
5647 @location = location
5648 @flags = flags
5649 @target = target
5650 @operator_loc = operator_loc
5651 @value = value
5652 end
5653
5654 # def accept: (Visitor visitor) -> void
5655 def accept(visitor)
5656 visitor.visit_constant_path_or_write_node(self)
5657 end
5658
5659 # def child_nodes: () -> Array[Node?]
5660 def child_nodes
5661 [target, value]
5662 end
5663
5664 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
5665 def each_child_node
5666 return to_enum(:each_child_node) unless block_given?
5667
5668 yield target
5669 yield value
5670 end
5671
5672 # def compact_child_nodes: () -> Array[Node]
5673 def compact_child_nodes
5674 [target, value]
5675 end
5676
5677 # def comment_targets: () -> Array[Node | Location]
5678 def comment_targets
5679 [target, operator_loc, value] #: Array[Prism::node | Location]
5680 end
5681
5682 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathOrWriteNode
5683 def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value)
5684 ConstantPathOrWriteNode.new(source, node_id, location, flags, target, operator_loc, value)
5685 end
5686
5687 # def deconstruct: () -> Array[Node?]
5688 alias deconstruct child_nodes
5689
5690 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, target: ConstantPathNode, operator_loc: Location, value: Prism::node }
5691 def deconstruct_keys(keys)
5692 { node_id: node_id, location: location, target: target, operator_loc: operator_loc, value: value }
5693 end
5694
5695 # attr_reader target: ConstantPathNode
5696 attr_reader :target
5697
5698 # attr_reader operator_loc: Location
5699 def operator_loc
5700 location = @operator_loc
5701 return location if location.is_a?(Location)
5702 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5703 end
5704
5705 # Save the operator_loc location using the given saved source so that
5706 # it can be retrieved later.
5707 def save_operator_loc(repository)
5708 repository.enter(node_id, :operator_loc)
5709 end
5710
5711 # attr_reader value: Prism::node
5712 attr_reader :value
5713
5714 # def operator: () -> String
5715 def operator
5716 operator_loc.slice
5717 end
5718
5719 # def inspect -> String
5720 def inspect
5721 InspectVisitor.compose(self)
5722 end
5723
5724 # Return a symbol representation of this node type. See `Node#type`.
5725 def type
5726 :constant_path_or_write_node
5727 end
5728
5729 # Return a symbol representation of this node type. See `Node::type`.
5730 def self.type
5731 :constant_path_or_write_node
5732 end
5733
5734 # Implements case-equality for the node. This is effectively == but without
5735 # comparing the value of locations. Locations are checked only for presence.
5736 def ===(other)
5737 other.is_a?(ConstantPathOrWriteNode) &&
5738 (target === other.target) &&
5739 (operator_loc.nil? == other.operator_loc.nil?) &&
5740 (value === other.value)
5741 end
5742 end
5743
5744 # Represents writing to a constant path in a context that doesn't have an explicit value.
5745 #
5746 # Foo::Foo, Bar::Bar = baz
5747 # ^^^^^^^^ ^^^^^^^^
5748 class ConstantPathTargetNode < Node
5749 # Initialize a new ConstantPathTargetNode node.
5750 def initialize(source, node_id, location, flags, parent, name, delimiter_loc, name_loc)
5751 @source = source
5752 @node_id = node_id
5753 @location = location
5754 @flags = flags
5755 @parent = parent
5756 @name = name
5757 @delimiter_loc = delimiter_loc
5758 @name_loc = name_loc
5759 end
5760
5761 # def accept: (Visitor visitor) -> void
5762 def accept(visitor)
5763 visitor.visit_constant_path_target_node(self)
5764 end
5765
5766 # def child_nodes: () -> Array[Node?]
5767 def child_nodes
5768 [parent]
5769 end
5770
5771 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
5772 def each_child_node
5773 return to_enum(:each_child_node) unless block_given?
5774
5775 yield parent if parent
5776 end
5777
5778 # def compact_child_nodes: () -> Array[Node]
5779 def compact_child_nodes
5780 compact = [] #: Array[Prism::node]
5781 compact << parent if parent
5782 compact
5783 end
5784
5785 # def comment_targets: () -> Array[Node | Location]
5786 def comment_targets
5787 [*parent, delimiter_loc, name_loc] #: Array[Prism::node | Location]
5788 end
5789
5790 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?parent: Prism::node?, ?name: Symbol?, ?delimiter_loc: Location, ?name_loc: Location) -> ConstantPathTargetNode
5791 def copy(node_id: self.node_id, location: self.location, flags: self.flags, parent: self.parent, name: self.name, delimiter_loc: self.delimiter_loc, name_loc: self.name_loc)
5792 ConstantPathTargetNode.new(source, node_id, location, flags, parent, name, delimiter_loc, name_loc)
5793 end
5794
5795 # def deconstruct: () -> Array[Node?]
5796 alias deconstruct child_nodes
5797
5798 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, parent: Prism::node?, name: Symbol?, delimiter_loc: Location, name_loc: Location }
5799 def deconstruct_keys(keys)
5800 { node_id: node_id, location: location, parent: parent, name: name, delimiter_loc: delimiter_loc, name_loc: name_loc }
5801 end
5802
5803 # attr_reader parent: Prism::node?
5804 attr_reader :parent
5805
5806 # attr_reader name: Symbol?
5807 attr_reader :name
5808
5809 # attr_reader delimiter_loc: Location
5810 def delimiter_loc
5811 location = @delimiter_loc
5812 return location if location.is_a?(Location)
5813 @delimiter_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5814 end
5815
5816 # Save the delimiter_loc location using the given saved source so that
5817 # it can be retrieved later.
5818 def save_delimiter_loc(repository)
5819 repository.enter(node_id, :delimiter_loc)
5820 end
5821
5822 # attr_reader name_loc: Location
5823 def name_loc
5824 location = @name_loc
5825 return location if location.is_a?(Location)
5826 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5827 end
5828
5829 # Save the name_loc location using the given saved source so that
5830 # it can be retrieved later.
5831 def save_name_loc(repository)
5832 repository.enter(node_id, :name_loc)
5833 end
5834
5835 # def delimiter: () -> String
5836 def delimiter
5837 delimiter_loc.slice
5838 end
5839
5840 # def inspect -> String
5841 def inspect
5842 InspectVisitor.compose(self)
5843 end
5844
5845 # Return a symbol representation of this node type. See `Node#type`.
5846 def type
5847 :constant_path_target_node
5848 end
5849
5850 # Return a symbol representation of this node type. See `Node::type`.
5851 def self.type
5852 :constant_path_target_node
5853 end
5854
5855 # Implements case-equality for the node. This is effectively == but without
5856 # comparing the value of locations. Locations are checked only for presence.
5857 def ===(other)
5858 other.is_a?(ConstantPathTargetNode) &&
5859 (parent === other.parent) &&
5860 (name === other.name) &&
5861 (delimiter_loc.nil? == other.delimiter_loc.nil?) &&
5862 (name_loc.nil? == other.name_loc.nil?)
5863 end
5864 end
5865
5866 # Represents writing to a constant path.
5867 #
5868 # ::Foo = 1
5869 # ^^^^^^^^^
5870 #
5871 # Foo::Bar = 1
5872 # ^^^^^^^^^^^^
5873 #
5874 # ::Foo::Bar = 1
5875 # ^^^^^^^^^^^^^^
5876 class ConstantPathWriteNode < Node
5877 # Initialize a new ConstantPathWriteNode node.
5878 def initialize(source, node_id, location, flags, target, operator_loc, value)
5879 @source = source
5880 @node_id = node_id
5881 @location = location
5882 @flags = flags
5883 @target = target
5884 @operator_loc = operator_loc
5885 @value = value
5886 end
5887
5888 # def accept: (Visitor visitor) -> void
5889 def accept(visitor)
5890 visitor.visit_constant_path_write_node(self)
5891 end
5892
5893 # def child_nodes: () -> Array[Node?]
5894 def child_nodes
5895 [target, value]
5896 end
5897
5898 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
5899 def each_child_node
5900 return to_enum(:each_child_node) unless block_given?
5901
5902 yield target
5903 yield value
5904 end
5905
5906 # def compact_child_nodes: () -> Array[Node]
5907 def compact_child_nodes
5908 [target, value]
5909 end
5910
5911 # def comment_targets: () -> Array[Node | Location]
5912 def comment_targets
5913 [target, operator_loc, value] #: Array[Prism::node | Location]
5914 end
5915
5916 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathWriteNode
5917 def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value)
5918 ConstantPathWriteNode.new(source, node_id, location, flags, target, operator_loc, value)
5919 end
5920
5921 # def deconstruct: () -> Array[Node?]
5922 alias deconstruct child_nodes
5923
5924 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, target: ConstantPathNode, operator_loc: Location, value: Prism::node }
5925 def deconstruct_keys(keys)
5926 { node_id: node_id, location: location, target: target, operator_loc: operator_loc, value: value }
5927 end
5928
5929 # A node representing the constant path being written to.
5930 #
5931 # Foo::Bar = 1
5932 # ^^^^^^^^
5933 #
5934 # ::Foo = :abc
5935 # ^^^^^
5936 attr_reader :target
5937
5938 # The location of the `=` operator.
5939 #
5940 # ::ABC = 123
5941 # ^
5942 def operator_loc
5943 location = @operator_loc
5944 return location if location.is_a?(Location)
5945 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
5946 end
5947
5948 # Save the operator_loc location using the given saved source so that
5949 # it can be retrieved later.
5950 def save_operator_loc(repository)
5951 repository.enter(node_id, :operator_loc)
5952 end
5953
5954 # The value to write to the constant path. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
5955 #
5956 # FOO::BAR = :abc
5957 # ^^^^
5958 attr_reader :value
5959
5960 # def operator: () -> String
5961 def operator
5962 operator_loc.slice
5963 end
5964
5965 # def inspect -> String
5966 def inspect
5967 InspectVisitor.compose(self)
5968 end
5969
5970 # Return a symbol representation of this node type. See `Node#type`.
5971 def type
5972 :constant_path_write_node
5973 end
5974
5975 # Return a symbol representation of this node type. See `Node::type`.
5976 def self.type
5977 :constant_path_write_node
5978 end
5979
5980 # Implements case-equality for the node. This is effectively == but without
5981 # comparing the value of locations. Locations are checked only for presence.
5982 def ===(other)
5983 other.is_a?(ConstantPathWriteNode) &&
5984 (target === other.target) &&
5985 (operator_loc.nil? == other.operator_loc.nil?) &&
5986 (value === other.value)
5987 end
5988 end
5989
5990 # Represents referencing a constant.
5991 #
5992 # Foo
5993 # ^^^
5994 class ConstantReadNode < Node
5995 # Initialize a new ConstantReadNode node.
5996 def initialize(source, node_id, location, flags, name)
5997 @source = source
5998 @node_id = node_id
5999 @location = location
6000 @flags = flags
6001 @name = name
6002 end
6003
6004 # def accept: (Visitor visitor) -> void
6005 def accept(visitor)
6006 visitor.visit_constant_read_node(self)
6007 end
6008
6009 # def child_nodes: () -> Array[Node?]
6010 def child_nodes
6011 []
6012 end
6013
6014 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
6015 def each_child_node
6016 return to_enum(:each_child_node) unless block_given?
6017
6018 end
6019
6020 # def compact_child_nodes: () -> Array[Node]
6021 def compact_child_nodes
6022 []
6023 end
6024
6025 # def comment_targets: () -> Array[Node | Location]
6026 def comment_targets
6027 [] #: Array[Prism::node | Location]
6028 end
6029
6030 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> ConstantReadNode
6031 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
6032 ConstantReadNode.new(source, node_id, location, flags, name)
6033 end
6034
6035 # def deconstruct: () -> Array[Node?]
6036 alias deconstruct child_nodes
6037
6038 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
6039 def deconstruct_keys(keys)
6040 { node_id: node_id, location: location, name: name }
6041 end
6042
6043 # The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
6044 #
6045 # X # name `:X`
6046 #
6047 # SOME_CONSTANT # name `:SOME_CONSTANT`
6048 attr_reader :name
6049
6050 # def inspect -> String
6051 def inspect
6052 InspectVisitor.compose(self)
6053 end
6054
6055 # Return a symbol representation of this node type. See `Node#type`.
6056 def type
6057 :constant_read_node
6058 end
6059
6060 # Return a symbol representation of this node type. See `Node::type`.
6061 def self.type
6062 :constant_read_node
6063 end
6064
6065 # Implements case-equality for the node. This is effectively == but without
6066 # comparing the value of locations. Locations are checked only for presence.
6067 def ===(other)
6068 other.is_a?(ConstantReadNode) &&
6069 (name === other.name)
6070 end
6071 end
6072
6073 # Represents writing to a constant in a context that doesn't have an explicit value.
6074 #
6075 # Foo, Bar = baz
6076 # ^^^ ^^^
6077 class ConstantTargetNode < Node
6078 # Initialize a new ConstantTargetNode node.
6079 def initialize(source, node_id, location, flags, name)
6080 @source = source
6081 @node_id = node_id
6082 @location = location
6083 @flags = flags
6084 @name = name
6085 end
6086
6087 # def accept: (Visitor visitor) -> void
6088 def accept(visitor)
6089 visitor.visit_constant_target_node(self)
6090 end
6091
6092 # def child_nodes: () -> Array[Node?]
6093 def child_nodes
6094 []
6095 end
6096
6097 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
6098 def each_child_node
6099 return to_enum(:each_child_node) unless block_given?
6100
6101 end
6102
6103 # def compact_child_nodes: () -> Array[Node]
6104 def compact_child_nodes
6105 []
6106 end
6107
6108 # def comment_targets: () -> Array[Node | Location]
6109 def comment_targets
6110 [] #: Array[Prism::node | Location]
6111 end
6112
6113 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> ConstantTargetNode
6114 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
6115 ConstantTargetNode.new(source, node_id, location, flags, name)
6116 end
6117
6118 # def deconstruct: () -> Array[Node?]
6119 alias deconstruct child_nodes
6120
6121 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
6122 def deconstruct_keys(keys)
6123 { node_id: node_id, location: location, name: name }
6124 end
6125
6126 # attr_reader name: Symbol
6127 attr_reader :name
6128
6129 # def inspect -> String
6130 def inspect
6131 InspectVisitor.compose(self)
6132 end
6133
6134 # Return a symbol representation of this node type. See `Node#type`.
6135 def type
6136 :constant_target_node
6137 end
6138
6139 # Return a symbol representation of this node type. See `Node::type`.
6140 def self.type
6141 :constant_target_node
6142 end
6143
6144 # Implements case-equality for the node. This is effectively == but without
6145 # comparing the value of locations. Locations are checked only for presence.
6146 def ===(other)
6147 other.is_a?(ConstantTargetNode) &&
6148 (name === other.name)
6149 end
6150 end
6151
6152 # Represents writing to a constant.
6153 #
6154 # Foo = 1
6155 # ^^^^^^^
6156 class ConstantWriteNode < Node
6157 # Initialize a new ConstantWriteNode node.
6158 def initialize(source, node_id, location, flags, name, name_loc, value, operator_loc)
6159 @source = source
6160 @node_id = node_id
6161 @location = location
6162 @flags = flags
6163 @name = name
6164 @name_loc = name_loc
6165 @value = value
6166 @operator_loc = operator_loc
6167 end
6168
6169 # def accept: (Visitor visitor) -> void
6170 def accept(visitor)
6171 visitor.visit_constant_write_node(self)
6172 end
6173
6174 # def child_nodes: () -> Array[Node?]
6175 def child_nodes
6176 [value]
6177 end
6178
6179 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
6180 def each_child_node
6181 return to_enum(:each_child_node) unless block_given?
6182
6183 yield value
6184 end
6185
6186 # def compact_child_nodes: () -> Array[Node]
6187 def compact_child_nodes
6188 [value]
6189 end
6190
6191 # def comment_targets: () -> Array[Node | Location]
6192 def comment_targets
6193 [name_loc, value, operator_loc] #: Array[Prism::node | Location]
6194 end
6195
6196 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?value: Prism::node, ?operator_loc: Location) -> ConstantWriteNode
6197 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, value: self.value, operator_loc: self.operator_loc)
6198 ConstantWriteNode.new(source, node_id, location, flags, name, name_loc, value, operator_loc)
6199 end
6200
6201 # def deconstruct: () -> Array[Node?]
6202 alias deconstruct child_nodes
6203
6204 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, value: Prism::node, operator_loc: Location }
6205 def deconstruct_keys(keys)
6206 { node_id: node_id, location: location, name: name, name_loc: name_loc, value: value, operator_loc: operator_loc }
6207 end
6208
6209 # The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
6210 #
6211 # Foo = :bar # name `:Foo`
6212 #
6213 # XYZ = 1 # name `:XYZ`
6214 attr_reader :name
6215
6216 # The location of the constant name.
6217 #
6218 # FOO = 1
6219 # ^^^
6220 def name_loc
6221 location = @name_loc
6222 return location if location.is_a?(Location)
6223 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6224 end
6225
6226 # Save the name_loc location using the given saved source so that
6227 # it can be retrieved later.
6228 def save_name_loc(repository)
6229 repository.enter(node_id, :name_loc)
6230 end
6231
6232 # The value to write to the constant. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
6233 #
6234 # FOO = :bar
6235 # ^^^^
6236 #
6237 # MyClass = Class.new
6238 # ^^^^^^^^^
6239 attr_reader :value
6240
6241 # The location of the `=` operator.
6242 #
6243 # FOO = :bar
6244 # ^
6245 def operator_loc
6246 location = @operator_loc
6247 return location if location.is_a?(Location)
6248 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6249 end
6250
6251 # Save the operator_loc location using the given saved source so that
6252 # it can be retrieved later.
6253 def save_operator_loc(repository)
6254 repository.enter(node_id, :operator_loc)
6255 end
6256
6257 # def operator: () -> String
6258 def operator
6259 operator_loc.slice
6260 end
6261
6262 # def inspect -> String
6263 def inspect
6264 InspectVisitor.compose(self)
6265 end
6266
6267 # Return a symbol representation of this node type. See `Node#type`.
6268 def type
6269 :constant_write_node
6270 end
6271
6272 # Return a symbol representation of this node type. See `Node::type`.
6273 def self.type
6274 :constant_write_node
6275 end
6276
6277 # Implements case-equality for the node. This is effectively == but without
6278 # comparing the value of locations. Locations are checked only for presence.
6279 def ===(other)
6280 other.is_a?(ConstantWriteNode) &&
6281 (name === other.name) &&
6282 (name_loc.nil? == other.name_loc.nil?) &&
6283 (value === other.value) &&
6284 (operator_loc.nil? == other.operator_loc.nil?)
6285 end
6286 end
6287
6288 # Represents a method definition.
6289 #
6290 # def method
6291 # end
6292 # ^^^^^^^^^^
6293 class DefNode < Node
6294 # Initialize a new DefNode node.
6295 def initialize(source, node_id, location, flags, name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc)
6296 @source = source
6297 @node_id = node_id
6298 @location = location
6299 @flags = flags
6300 @name = name
6301 @name_loc = name_loc
6302 @receiver = receiver
6303 @parameters = parameters
6304 @body = body
6305 @locals = locals
6306 @def_keyword_loc = def_keyword_loc
6307 @operator_loc = operator_loc
6308 @lparen_loc = lparen_loc
6309 @rparen_loc = rparen_loc
6310 @equal_loc = equal_loc
6311 @end_keyword_loc = end_keyword_loc
6312 end
6313
6314 # def accept: (Visitor visitor) -> void
6315 def accept(visitor)
6316 visitor.visit_def_node(self)
6317 end
6318
6319 # def child_nodes: () -> Array[Node?]
6320 def child_nodes
6321 [receiver, parameters, body]
6322 end
6323
6324 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
6325 def each_child_node
6326 return to_enum(:each_child_node) unless block_given?
6327
6328 yield receiver if receiver
6329 yield parameters if parameters
6330 yield body if body
6331 end
6332
6333 # def compact_child_nodes: () -> Array[Node]
6334 def compact_child_nodes
6335 compact = [] #: Array[Prism::node]
6336 compact << receiver if receiver
6337 compact << parameters if parameters
6338 compact << body if body
6339 compact
6340 end
6341
6342 # def comment_targets: () -> Array[Node | Location]
6343 def comment_targets
6344 [name_loc, *receiver, *parameters, *body, def_keyword_loc, *operator_loc, *lparen_loc, *rparen_loc, *equal_loc, *end_keyword_loc] #: Array[Prism::node | Location]
6345 end
6346
6347 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?receiver: Prism::node?, ?parameters: ParametersNode?, ?body: StatementsNode | BeginNode | nil, ?locals: Array[Symbol], ?def_keyword_loc: Location, ?operator_loc: Location?, ?lparen_loc: Location?, ?rparen_loc: Location?, ?equal_loc: Location?, ?end_keyword_loc: Location?) -> DefNode
6348 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, receiver: self.receiver, parameters: self.parameters, body: self.body, locals: self.locals, def_keyword_loc: self.def_keyword_loc, operator_loc: self.operator_loc, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, equal_loc: self.equal_loc, end_keyword_loc: self.end_keyword_loc)
6349 DefNode.new(source, node_id, location, flags, name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc)
6350 end
6351
6352 # def deconstruct: () -> Array[Node?]
6353 alias deconstruct child_nodes
6354
6355 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, receiver: Prism::node?, parameters: ParametersNode?, body: StatementsNode | BeginNode | nil, locals: Array[Symbol], def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location? }
6356 def deconstruct_keys(keys)
6357 { node_id: node_id, location: location, name: name, name_loc: name_loc, receiver: receiver, parameters: parameters, body: body, locals: locals, def_keyword_loc: def_keyword_loc, operator_loc: operator_loc, lparen_loc: lparen_loc, rparen_loc: rparen_loc, equal_loc: equal_loc, end_keyword_loc: end_keyword_loc }
6358 end
6359
6360 # attr_reader name: Symbol
6361 attr_reader :name
6362
6363 # attr_reader name_loc: Location
6364 def name_loc
6365 location = @name_loc
6366 return location if location.is_a?(Location)
6367 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6368 end
6369
6370 # Save the name_loc location using the given saved source so that
6371 # it can be retrieved later.
6372 def save_name_loc(repository)
6373 repository.enter(node_id, :name_loc)
6374 end
6375
6376 # attr_reader receiver: Prism::node?
6377 attr_reader :receiver
6378
6379 # attr_reader parameters: ParametersNode?
6380 attr_reader :parameters
6381
6382 # attr_reader body: StatementsNode | BeginNode | nil
6383 attr_reader :body
6384
6385 # attr_reader locals: Array[Symbol]
6386 attr_reader :locals
6387
6388 # attr_reader def_keyword_loc: Location
6389 def def_keyword_loc
6390 location = @def_keyword_loc
6391 return location if location.is_a?(Location)
6392 @def_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6393 end
6394
6395 # Save the def_keyword_loc location using the given saved source so that
6396 # it can be retrieved later.
6397 def save_def_keyword_loc(repository)
6398 repository.enter(node_id, :def_keyword_loc)
6399 end
6400
6401 # attr_reader operator_loc: Location?
6402 def operator_loc
6403 location = @operator_loc
6404 case location
6405 when nil
6406 nil
6407 when Location
6408 location
6409 else
6410 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6411 end
6412 end
6413
6414 # Save the operator_loc location using the given saved source so that
6415 # it can be retrieved later.
6416 def save_operator_loc(repository)
6417 repository.enter(node_id, :operator_loc) unless @operator_loc.nil?
6418 end
6419
6420 # attr_reader lparen_loc: Location?
6421 def lparen_loc
6422 location = @lparen_loc
6423 case location
6424 when nil
6425 nil
6426 when Location
6427 location
6428 else
6429 @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6430 end
6431 end
6432
6433 # Save the lparen_loc location using the given saved source so that
6434 # it can be retrieved later.
6435 def save_lparen_loc(repository)
6436 repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil?
6437 end
6438
6439 # attr_reader rparen_loc: Location?
6440 def rparen_loc
6441 location = @rparen_loc
6442 case location
6443 when nil
6444 nil
6445 when Location
6446 location
6447 else
6448 @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6449 end
6450 end
6451
6452 # Save the rparen_loc location using the given saved source so that
6453 # it can be retrieved later.
6454 def save_rparen_loc(repository)
6455 repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil?
6456 end
6457
6458 # attr_reader equal_loc: Location?
6459 def equal_loc
6460 location = @equal_loc
6461 case location
6462 when nil
6463 nil
6464 when Location
6465 location
6466 else
6467 @equal_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6468 end
6469 end
6470
6471 # Save the equal_loc location using the given saved source so that
6472 # it can be retrieved later.
6473 def save_equal_loc(repository)
6474 repository.enter(node_id, :equal_loc) unless @equal_loc.nil?
6475 end
6476
6477 # attr_reader end_keyword_loc: Location?
6478 def end_keyword_loc
6479 location = @end_keyword_loc
6480 case location
6481 when nil
6482 nil
6483 when Location
6484 location
6485 else
6486 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6487 end
6488 end
6489
6490 # Save the end_keyword_loc location using the given saved source so that
6491 # it can be retrieved later.
6492 def save_end_keyword_loc(repository)
6493 repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil?
6494 end
6495
6496 # def def_keyword: () -> String
6497 def def_keyword
6498 def_keyword_loc.slice
6499 end
6500
6501 # def operator: () -> String?
6502 def operator
6503 operator_loc&.slice
6504 end
6505
6506 # def lparen: () -> String?
6507 def lparen
6508 lparen_loc&.slice
6509 end
6510
6511 # def rparen: () -> String?
6512 def rparen
6513 rparen_loc&.slice
6514 end
6515
6516 # def equal: () -> String?
6517 def equal
6518 equal_loc&.slice
6519 end
6520
6521 # def end_keyword: () -> String?
6522 def end_keyword
6523 end_keyword_loc&.slice
6524 end
6525
6526 # def inspect -> String
6527 def inspect
6528 InspectVisitor.compose(self)
6529 end
6530
6531 # Return a symbol representation of this node type. See `Node#type`.
6532 def type
6533 :def_node
6534 end
6535
6536 # Return a symbol representation of this node type. See `Node::type`.
6537 def self.type
6538 :def_node
6539 end
6540
6541 # Implements case-equality for the node. This is effectively == but without
6542 # comparing the value of locations. Locations are checked only for presence.
6543 def ===(other)
6544 other.is_a?(DefNode) &&
6545 (name === other.name) &&
6546 (name_loc.nil? == other.name_loc.nil?) &&
6547 (receiver === other.receiver) &&
6548 (parameters === other.parameters) &&
6549 (body === other.body) &&
6550 (locals.length == other.locals.length) &&
6551 locals.zip(other.locals).all? { |left, right| left === right } &&
6552 (def_keyword_loc.nil? == other.def_keyword_loc.nil?) &&
6553 (operator_loc.nil? == other.operator_loc.nil?) &&
6554 (lparen_loc.nil? == other.lparen_loc.nil?) &&
6555 (rparen_loc.nil? == other.rparen_loc.nil?) &&
6556 (equal_loc.nil? == other.equal_loc.nil?) &&
6557 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
6558 end
6559 end
6560
6561 # Represents the use of the `defined?` keyword.
6562 #
6563 # defined?(a)
6564 # ^^^^^^^^^^^
6565 class DefinedNode < Node
6566 # Initialize a new DefinedNode node.
6567 def initialize(source, node_id, location, flags, lparen_loc, value, rparen_loc, keyword_loc)
6568 @source = source
6569 @node_id = node_id
6570 @location = location
6571 @flags = flags
6572 @lparen_loc = lparen_loc
6573 @value = value
6574 @rparen_loc = rparen_loc
6575 @keyword_loc = keyword_loc
6576 end
6577
6578 # def accept: (Visitor visitor) -> void
6579 def accept(visitor)
6580 visitor.visit_defined_node(self)
6581 end
6582
6583 # def child_nodes: () -> Array[Node?]
6584 def child_nodes
6585 [value]
6586 end
6587
6588 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
6589 def each_child_node
6590 return to_enum(:each_child_node) unless block_given?
6591
6592 yield value
6593 end
6594
6595 # def compact_child_nodes: () -> Array[Node]
6596 def compact_child_nodes
6597 [value]
6598 end
6599
6600 # def comment_targets: () -> Array[Node | Location]
6601 def comment_targets
6602 [*lparen_loc, value, *rparen_loc, keyword_loc] #: Array[Prism::node | Location]
6603 end
6604
6605 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?lparen_loc: Location?, ?value: Prism::node, ?rparen_loc: Location?, ?keyword_loc: Location) -> DefinedNode
6606 def copy(node_id: self.node_id, location: self.location, flags: self.flags, lparen_loc: self.lparen_loc, value: self.value, rparen_loc: self.rparen_loc, keyword_loc: self.keyword_loc)
6607 DefinedNode.new(source, node_id, location, flags, lparen_loc, value, rparen_loc, keyword_loc)
6608 end
6609
6610 # def deconstruct: () -> Array[Node?]
6611 alias deconstruct child_nodes
6612
6613 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, lparen_loc: Location?, value: Prism::node, rparen_loc: Location?, keyword_loc: Location }
6614 def deconstruct_keys(keys)
6615 { node_id: node_id, location: location, lparen_loc: lparen_loc, value: value, rparen_loc: rparen_loc, keyword_loc: keyword_loc }
6616 end
6617
6618 # attr_reader lparen_loc: Location?
6619 def lparen_loc
6620 location = @lparen_loc
6621 case location
6622 when nil
6623 nil
6624 when Location
6625 location
6626 else
6627 @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6628 end
6629 end
6630
6631 # Save the lparen_loc location using the given saved source so that
6632 # it can be retrieved later.
6633 def save_lparen_loc(repository)
6634 repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil?
6635 end
6636
6637 # attr_reader value: Prism::node
6638 attr_reader :value
6639
6640 # attr_reader rparen_loc: Location?
6641 def rparen_loc
6642 location = @rparen_loc
6643 case location
6644 when nil
6645 nil
6646 when Location
6647 location
6648 else
6649 @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6650 end
6651 end
6652
6653 # Save the rparen_loc location using the given saved source so that
6654 # it can be retrieved later.
6655 def save_rparen_loc(repository)
6656 repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil?
6657 end
6658
6659 # attr_reader keyword_loc: Location
6660 def keyword_loc
6661 location = @keyword_loc
6662 return location if location.is_a?(Location)
6663 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6664 end
6665
6666 # Save the keyword_loc location using the given saved source so that
6667 # it can be retrieved later.
6668 def save_keyword_loc(repository)
6669 repository.enter(node_id, :keyword_loc)
6670 end
6671
6672 # def lparen: () -> String?
6673 def lparen
6674 lparen_loc&.slice
6675 end
6676
6677 # def rparen: () -> String?
6678 def rparen
6679 rparen_loc&.slice
6680 end
6681
6682 # def keyword: () -> String
6683 def keyword
6684 keyword_loc.slice
6685 end
6686
6687 # def inspect -> String
6688 def inspect
6689 InspectVisitor.compose(self)
6690 end
6691
6692 # Return a symbol representation of this node type. See `Node#type`.
6693 def type
6694 :defined_node
6695 end
6696
6697 # Return a symbol representation of this node type. See `Node::type`.
6698 def self.type
6699 :defined_node
6700 end
6701
6702 # Implements case-equality for the node. This is effectively == but without
6703 # comparing the value of locations. Locations are checked only for presence.
6704 def ===(other)
6705 other.is_a?(DefinedNode) &&
6706 (lparen_loc.nil? == other.lparen_loc.nil?) &&
6707 (value === other.value) &&
6708 (rparen_loc.nil? == other.rparen_loc.nil?) &&
6709 (keyword_loc.nil? == other.keyword_loc.nil?)
6710 end
6711 end
6712
6713 # Represents an `else` clause in a `case`, `if`, or `unless` statement.
6714 #
6715 # if a then b else c end
6716 # ^^^^^^^^^^
6717 class ElseNode < Node
6718 # Initialize a new ElseNode node.
6719 def initialize(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc)
6720 @source = source
6721 @node_id = node_id
6722 @location = location
6723 @flags = flags
6724 @else_keyword_loc = else_keyword_loc
6725 @statements = statements
6726 @end_keyword_loc = end_keyword_loc
6727 end
6728
6729 # def accept: (Visitor visitor) -> void
6730 def accept(visitor)
6731 visitor.visit_else_node(self)
6732 end
6733
6734 # def child_nodes: () -> Array[Node?]
6735 def child_nodes
6736 [statements]
6737 end
6738
6739 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
6740 def each_child_node
6741 return to_enum(:each_child_node) unless block_given?
6742
6743 yield statements if statements
6744 end
6745
6746 # def compact_child_nodes: () -> Array[Node]
6747 def compact_child_nodes
6748 compact = [] #: Array[Prism::node]
6749 compact << statements if statements
6750 compact
6751 end
6752
6753 # def comment_targets: () -> Array[Node | Location]
6754 def comment_targets
6755 [else_keyword_loc, *statements, *end_keyword_loc] #: Array[Prism::node | Location]
6756 end
6757
6758 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?else_keyword_loc: Location, ?statements: StatementsNode?, ?end_keyword_loc: Location?) -> ElseNode
6759 def copy(node_id: self.node_id, location: self.location, flags: self.flags, else_keyword_loc: self.else_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc)
6760 ElseNode.new(source, node_id, location, flags, else_keyword_loc, statements, end_keyword_loc)
6761 end
6762
6763 # def deconstruct: () -> Array[Node?]
6764 alias deconstruct child_nodes
6765
6766 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, else_keyword_loc: Location, statements: StatementsNode?, end_keyword_loc: Location? }
6767 def deconstruct_keys(keys)
6768 { node_id: node_id, location: location, else_keyword_loc: else_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc }
6769 end
6770
6771 # attr_reader else_keyword_loc: Location
6772 def else_keyword_loc
6773 location = @else_keyword_loc
6774 return location if location.is_a?(Location)
6775 @else_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6776 end
6777
6778 # Save the else_keyword_loc location using the given saved source so that
6779 # it can be retrieved later.
6780 def save_else_keyword_loc(repository)
6781 repository.enter(node_id, :else_keyword_loc)
6782 end
6783
6784 # attr_reader statements: StatementsNode?
6785 attr_reader :statements
6786
6787 # attr_reader end_keyword_loc: Location?
6788 def end_keyword_loc
6789 location = @end_keyword_loc
6790 case location
6791 when nil
6792 nil
6793 when Location
6794 location
6795 else
6796 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6797 end
6798 end
6799
6800 # Save the end_keyword_loc location using the given saved source so that
6801 # it can be retrieved later.
6802 def save_end_keyword_loc(repository)
6803 repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil?
6804 end
6805
6806 # def else_keyword: () -> String
6807 def else_keyword
6808 else_keyword_loc.slice
6809 end
6810
6811 # def end_keyword: () -> String?
6812 def end_keyword
6813 end_keyword_loc&.slice
6814 end
6815
6816 # def inspect -> String
6817 def inspect
6818 InspectVisitor.compose(self)
6819 end
6820
6821 # Return a symbol representation of this node type. See `Node#type`.
6822 def type
6823 :else_node
6824 end
6825
6826 # Return a symbol representation of this node type. See `Node::type`.
6827 def self.type
6828 :else_node
6829 end
6830
6831 # Implements case-equality for the node. This is effectively == but without
6832 # comparing the value of locations. Locations are checked only for presence.
6833 def ===(other)
6834 other.is_a?(ElseNode) &&
6835 (else_keyword_loc.nil? == other.else_keyword_loc.nil?) &&
6836 (statements === other.statements) &&
6837 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
6838 end
6839 end
6840
6841 # Represents an interpolated set of statements.
6842 #
6843 # "foo #{bar}"
6844 # ^^^^^^
6845 class EmbeddedStatementsNode < Node
6846 # Initialize a new EmbeddedStatementsNode node.
6847 def initialize(source, node_id, location, flags, opening_loc, statements, closing_loc)
6848 @source = source
6849 @node_id = node_id
6850 @location = location
6851 @flags = flags
6852 @opening_loc = opening_loc
6853 @statements = statements
6854 @closing_loc = closing_loc
6855 end
6856
6857 # def accept: (Visitor visitor) -> void
6858 def accept(visitor)
6859 visitor.visit_embedded_statements_node(self)
6860 end
6861
6862 # def child_nodes: () -> Array[Node?]
6863 def child_nodes
6864 [statements]
6865 end
6866
6867 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
6868 def each_child_node
6869 return to_enum(:each_child_node) unless block_given?
6870
6871 yield statements if statements
6872 end
6873
6874 # def compact_child_nodes: () -> Array[Node]
6875 def compact_child_nodes
6876 compact = [] #: Array[Prism::node]
6877 compact << statements if statements
6878 compact
6879 end
6880
6881 # def comment_targets: () -> Array[Node | Location]
6882 def comment_targets
6883 [opening_loc, *statements, closing_loc] #: Array[Prism::node | Location]
6884 end
6885
6886 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?statements: StatementsNode?, ?closing_loc: Location) -> EmbeddedStatementsNode
6887 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, statements: self.statements, closing_loc: self.closing_loc)
6888 EmbeddedStatementsNode.new(source, node_id, location, flags, opening_loc, statements, closing_loc)
6889 end
6890
6891 # def deconstruct: () -> Array[Node?]
6892 alias deconstruct child_nodes
6893
6894 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location, statements: StatementsNode?, closing_loc: Location }
6895 def deconstruct_keys(keys)
6896 { node_id: node_id, location: location, opening_loc: opening_loc, statements: statements, closing_loc: closing_loc }
6897 end
6898
6899 # attr_reader opening_loc: Location
6900 def opening_loc
6901 location = @opening_loc
6902 return location if location.is_a?(Location)
6903 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6904 end
6905
6906 # Save the opening_loc location using the given saved source so that
6907 # it can be retrieved later.
6908 def save_opening_loc(repository)
6909 repository.enter(node_id, :opening_loc)
6910 end
6911
6912 # attr_reader statements: StatementsNode?
6913 attr_reader :statements
6914
6915 # attr_reader closing_loc: Location
6916 def closing_loc
6917 location = @closing_loc
6918 return location if location.is_a?(Location)
6919 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
6920 end
6921
6922 # Save the closing_loc location using the given saved source so that
6923 # it can be retrieved later.
6924 def save_closing_loc(repository)
6925 repository.enter(node_id, :closing_loc)
6926 end
6927
6928 # def opening: () -> String
6929 def opening
6930 opening_loc.slice
6931 end
6932
6933 # def closing: () -> String
6934 def closing
6935 closing_loc.slice
6936 end
6937
6938 # def inspect -> String
6939 def inspect
6940 InspectVisitor.compose(self)
6941 end
6942
6943 # Return a symbol representation of this node type. See `Node#type`.
6944 def type
6945 :embedded_statements_node
6946 end
6947
6948 # Return a symbol representation of this node type. See `Node::type`.
6949 def self.type
6950 :embedded_statements_node
6951 end
6952
6953 # Implements case-equality for the node. This is effectively == but without
6954 # comparing the value of locations. Locations are checked only for presence.
6955 def ===(other)
6956 other.is_a?(EmbeddedStatementsNode) &&
6957 (opening_loc.nil? == other.opening_loc.nil?) &&
6958 (statements === other.statements) &&
6959 (closing_loc.nil? == other.closing_loc.nil?)
6960 end
6961 end
6962
6963 # Represents an interpolated variable.
6964 #
6965 # "foo #@bar"
6966 # ^^^^^
6967 class EmbeddedVariableNode < Node
6968 # Initialize a new EmbeddedVariableNode node.
6969 def initialize(source, node_id, location, flags, operator_loc, variable)
6970 @source = source
6971 @node_id = node_id
6972 @location = location
6973 @flags = flags
6974 @operator_loc = operator_loc
6975 @variable = variable
6976 end
6977
6978 # def accept: (Visitor visitor) -> void
6979 def accept(visitor)
6980 visitor.visit_embedded_variable_node(self)
6981 end
6982
6983 # def child_nodes: () -> Array[Node?]
6984 def child_nodes
6985 [variable]
6986 end
6987
6988 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
6989 def each_child_node
6990 return to_enum(:each_child_node) unless block_given?
6991
6992 yield variable
6993 end
6994
6995 # def compact_child_nodes: () -> Array[Node]
6996 def compact_child_nodes
6997 [variable]
6998 end
6999
7000 # def comment_targets: () -> Array[Node | Location]
7001 def comment_targets
7002 [operator_loc, variable] #: Array[Prism::node | Location]
7003 end
7004
7005 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?operator_loc: Location, ?variable: InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode) -> EmbeddedVariableNode
7006 def copy(node_id: self.node_id, location: self.location, flags: self.flags, operator_loc: self.operator_loc, variable: self.variable)
7007 EmbeddedVariableNode.new(source, node_id, location, flags, operator_loc, variable)
7008 end
7009
7010 # def deconstruct: () -> Array[Node?]
7011 alias deconstruct child_nodes
7012
7013 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, operator_loc: Location, variable: InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode }
7014 def deconstruct_keys(keys)
7015 { node_id: node_id, location: location, operator_loc: operator_loc, variable: variable }
7016 end
7017
7018 # attr_reader operator_loc: Location
7019 def operator_loc
7020 location = @operator_loc
7021 return location if location.is_a?(Location)
7022 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7023 end
7024
7025 # Save the operator_loc location using the given saved source so that
7026 # it can be retrieved later.
7027 def save_operator_loc(repository)
7028 repository.enter(node_id, :operator_loc)
7029 end
7030
7031 # attr_reader variable: InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode
7032 attr_reader :variable
7033
7034 # def operator: () -> String
7035 def operator
7036 operator_loc.slice
7037 end
7038
7039 # def inspect -> String
7040 def inspect
7041 InspectVisitor.compose(self)
7042 end
7043
7044 # Return a symbol representation of this node type. See `Node#type`.
7045 def type
7046 :embedded_variable_node
7047 end
7048
7049 # Return a symbol representation of this node type. See `Node::type`.
7050 def self.type
7051 :embedded_variable_node
7052 end
7053
7054 # Implements case-equality for the node. This is effectively == but without
7055 # comparing the value of locations. Locations are checked only for presence.
7056 def ===(other)
7057 other.is_a?(EmbeddedVariableNode) &&
7058 (operator_loc.nil? == other.operator_loc.nil?) &&
7059 (variable === other.variable)
7060 end
7061 end
7062
7063 # Represents an `ensure` clause in a `begin` statement.
7064 #
7065 # begin
7066 # foo
7067 # ensure
7068 # ^^^^^^
7069 # bar
7070 # end
7071 class EnsureNode < Node
7072 # Initialize a new EnsureNode node.
7073 def initialize(source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc)
7074 @source = source
7075 @node_id = node_id
7076 @location = location
7077 @flags = flags
7078 @ensure_keyword_loc = ensure_keyword_loc
7079 @statements = statements
7080 @end_keyword_loc = end_keyword_loc
7081 end
7082
7083 # def accept: (Visitor visitor) -> void
7084 def accept(visitor)
7085 visitor.visit_ensure_node(self)
7086 end
7087
7088 # def child_nodes: () -> Array[Node?]
7089 def child_nodes
7090 [statements]
7091 end
7092
7093 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
7094 def each_child_node
7095 return to_enum(:each_child_node) unless block_given?
7096
7097 yield statements if statements
7098 end
7099
7100 # def compact_child_nodes: () -> Array[Node]
7101 def compact_child_nodes
7102 compact = [] #: Array[Prism::node]
7103 compact << statements if statements
7104 compact
7105 end
7106
7107 # def comment_targets: () -> Array[Node | Location]
7108 def comment_targets
7109 [ensure_keyword_loc, *statements, end_keyword_loc] #: Array[Prism::node | Location]
7110 end
7111
7112 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?ensure_keyword_loc: Location, ?statements: StatementsNode?, ?end_keyword_loc: Location) -> EnsureNode
7113 def copy(node_id: self.node_id, location: self.location, flags: self.flags, ensure_keyword_loc: self.ensure_keyword_loc, statements: self.statements, end_keyword_loc: self.end_keyword_loc)
7114 EnsureNode.new(source, node_id, location, flags, ensure_keyword_loc, statements, end_keyword_loc)
7115 end
7116
7117 # def deconstruct: () -> Array[Node?]
7118 alias deconstruct child_nodes
7119
7120 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, ensure_keyword_loc: Location, statements: StatementsNode?, end_keyword_loc: Location }
7121 def deconstruct_keys(keys)
7122 { node_id: node_id, location: location, ensure_keyword_loc: ensure_keyword_loc, statements: statements, end_keyword_loc: end_keyword_loc }
7123 end
7124
7125 # attr_reader ensure_keyword_loc: Location
7126 def ensure_keyword_loc
7127 location = @ensure_keyword_loc
7128 return location if location.is_a?(Location)
7129 @ensure_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7130 end
7131
7132 # Save the ensure_keyword_loc location using the given saved source so that
7133 # it can be retrieved later.
7134 def save_ensure_keyword_loc(repository)
7135 repository.enter(node_id, :ensure_keyword_loc)
7136 end
7137
7138 # attr_reader statements: StatementsNode?
7139 attr_reader :statements
7140
7141 # attr_reader end_keyword_loc: Location
7142 def end_keyword_loc
7143 location = @end_keyword_loc
7144 return location if location.is_a?(Location)
7145 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7146 end
7147
7148 # Save the end_keyword_loc location using the given saved source so that
7149 # it can be retrieved later.
7150 def save_end_keyword_loc(repository)
7151 repository.enter(node_id, :end_keyword_loc)
7152 end
7153
7154 # def ensure_keyword: () -> String
7155 def ensure_keyword
7156 ensure_keyword_loc.slice
7157 end
7158
7159 # def end_keyword: () -> String
7160 def end_keyword
7161 end_keyword_loc.slice
7162 end
7163
7164 # def inspect -> String
7165 def inspect
7166 InspectVisitor.compose(self)
7167 end
7168
7169 # Return a symbol representation of this node type. See `Node#type`.
7170 def type
7171 :ensure_node
7172 end
7173
7174 # Return a symbol representation of this node type. See `Node::type`.
7175 def self.type
7176 :ensure_node
7177 end
7178
7179 # Implements case-equality for the node. This is effectively == but without
7180 # comparing the value of locations. Locations are checked only for presence.
7181 def ===(other)
7182 other.is_a?(EnsureNode) &&
7183 (ensure_keyword_loc.nil? == other.ensure_keyword_loc.nil?) &&
7184 (statements === other.statements) &&
7185 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
7186 end
7187 end
7188
7189 # Represents the use of the literal `false` keyword.
7190 #
7191 # false
7192 # ^^^^^
7193 class FalseNode < Node
7194 # Initialize a new FalseNode node.
7195 def initialize(source, node_id, location, flags)
7196 @source = source
7197 @node_id = node_id
7198 @location = location
7199 @flags = flags
7200 end
7201
7202 # def accept: (Visitor visitor) -> void
7203 def accept(visitor)
7204 visitor.visit_false_node(self)
7205 end
7206
7207 # def child_nodes: () -> Array[Node?]
7208 def child_nodes
7209 []
7210 end
7211
7212 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
7213 def each_child_node
7214 return to_enum(:each_child_node) unless block_given?
7215
7216 end
7217
7218 # def compact_child_nodes: () -> Array[Node]
7219 def compact_child_nodes
7220 []
7221 end
7222
7223 # def comment_targets: () -> Array[Node | Location]
7224 def comment_targets
7225 [] #: Array[Prism::node | Location]
7226 end
7227
7228 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> FalseNode
7229 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
7230 FalseNode.new(source, node_id, location, flags)
7231 end
7232
7233 # def deconstruct: () -> Array[Node?]
7234 alias deconstruct child_nodes
7235
7236 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
7237 def deconstruct_keys(keys)
7238 { node_id: node_id, location: location }
7239 end
7240
7241 # def inspect -> String
7242 def inspect
7243 InspectVisitor.compose(self)
7244 end
7245
7246 # Return a symbol representation of this node type. See `Node#type`.
7247 def type
7248 :false_node
7249 end
7250
7251 # Return a symbol representation of this node type. See `Node::type`.
7252 def self.type
7253 :false_node
7254 end
7255
7256 # Implements case-equality for the node. This is effectively == but without
7257 # comparing the value of locations. Locations are checked only for presence.
7258 def ===(other)
7259 other.is_a?(FalseNode)
7260 end
7261 end
7262
7263 # Represents a find pattern in pattern matching.
7264 #
7265 # foo in *bar, baz, *qux
7266 # ^^^^^^^^^^^^^^^
7267 #
7268 # foo in [*bar, baz, *qux]
7269 # ^^^^^^^^^^^^^^^^^
7270 #
7271 # foo in Foo(*bar, baz, *qux)
7272 # ^^^^^^^^^^^^^^^^^^^^
7273 #
7274 # foo => *bar, baz, *qux
7275 # ^^^^^^^^^^^^^^^
7276 class FindPatternNode < Node
7277 # Initialize a new FindPatternNode node.
7278 def initialize(source, node_id, location, flags, constant, left, requireds, right, opening_loc, closing_loc)
7279 @source = source
7280 @node_id = node_id
7281 @location = location
7282 @flags = flags
7283 @constant = constant
7284 @left = left
7285 @requireds = requireds
7286 @right = right
7287 @opening_loc = opening_loc
7288 @closing_loc = closing_loc
7289 end
7290
7291 # def accept: (Visitor visitor) -> void
7292 def accept(visitor)
7293 visitor.visit_find_pattern_node(self)
7294 end
7295
7296 # def child_nodes: () -> Array[Node?]
7297 def child_nodes
7298 [constant, left, *requireds, right]
7299 end
7300
7301 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
7302 def each_child_node
7303 return to_enum(:each_child_node) unless block_given?
7304
7305 yield constant if constant
7306 yield left
7307 requireds.each { |node| yield node }
7308 yield right
7309 end
7310
7311 # def compact_child_nodes: () -> Array[Node]
7312 def compact_child_nodes
7313 compact = [] #: Array[Prism::node]
7314 compact << constant if constant
7315 compact << left
7316 compact.concat(requireds)
7317 compact << right
7318 compact
7319 end
7320
7321 # def comment_targets: () -> Array[Node | Location]
7322 def comment_targets
7323 [*constant, left, *requireds, right, *opening_loc, *closing_loc] #: Array[Prism::node | Location]
7324 end
7325
7326 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?constant: ConstantPathNode | ConstantReadNode | nil, ?left: SplatNode, ?requireds: Array[Prism::node], ?right: SplatNode | MissingNode, ?opening_loc: Location?, ?closing_loc: Location?) -> FindPatternNode
7327 def copy(node_id: self.node_id, location: self.location, flags: self.flags, constant: self.constant, left: self.left, requireds: self.requireds, right: self.right, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
7328 FindPatternNode.new(source, node_id, location, flags, constant, left, requireds, right, opening_loc, closing_loc)
7329 end
7330
7331 # def deconstruct: () -> Array[Node?]
7332 alias deconstruct child_nodes
7333
7334 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, constant: ConstantPathNode | ConstantReadNode | nil, left: SplatNode, requireds: Array[Prism::node], right: SplatNode | MissingNode, opening_loc: Location?, closing_loc: Location? }
7335 def deconstruct_keys(keys)
7336 { node_id: node_id, location: location, constant: constant, left: left, requireds: requireds, right: right, opening_loc: opening_loc, closing_loc: closing_loc }
7337 end
7338
7339 # Represents the optional constant preceding the pattern
7340 #
7341 # foo in Foo(*bar, baz, *qux)
7342 # ^^^
7343 attr_reader :constant
7344
7345 # Represents the first wildcard node in the pattern.
7346 #
7347 # foo in *bar, baz, *qux
7348 # ^^^^
7349 #
7350 # foo in Foo(*bar, baz, *qux)
7351 # ^^^^
7352 attr_reader :left
7353
7354 # Represents the nodes in between the wildcards.
7355 #
7356 # foo in *bar, baz, *qux
7357 # ^^^
7358 #
7359 # foo in Foo(*bar, baz, 1, *qux)
7360 # ^^^^^^
7361 attr_reader :requireds
7362
7363 # Represents the second wildcard node in the pattern.
7364 #
7365 # foo in *bar, baz, *qux
7366 # ^^^^
7367 #
7368 # foo in Foo(*bar, baz, *qux)
7369 # ^^^^
7370 attr_reader :right
7371
7372 # The location of the opening brace.
7373 #
7374 # foo in [*bar, baz, *qux]
7375 # ^
7376 #
7377 # foo in Foo(*bar, baz, *qux)
7378 # ^
7379 def opening_loc
7380 location = @opening_loc
7381 case location
7382 when nil
7383 nil
7384 when Location
7385 location
7386 else
7387 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7388 end
7389 end
7390
7391 # Save the opening_loc location using the given saved source so that
7392 # it can be retrieved later.
7393 def save_opening_loc(repository)
7394 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
7395 end
7396
7397 # The location of the closing brace.
7398 #
7399 # foo in [*bar, baz, *qux]
7400 # ^
7401 #
7402 # foo in Foo(*bar, baz, *qux)
7403 # ^
7404 def closing_loc
7405 location = @closing_loc
7406 case location
7407 when nil
7408 nil
7409 when Location
7410 location
7411 else
7412 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7413 end
7414 end
7415
7416 # Save the closing_loc location using the given saved source so that
7417 # it can be retrieved later.
7418 def save_closing_loc(repository)
7419 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
7420 end
7421
7422 # def opening: () -> String?
7423 def opening
7424 opening_loc&.slice
7425 end
7426
7427 # def closing: () -> String?
7428 def closing
7429 closing_loc&.slice
7430 end
7431
7432 # def inspect -> String
7433 def inspect
7434 InspectVisitor.compose(self)
7435 end
7436
7437 # Return a symbol representation of this node type. See `Node#type`.
7438 def type
7439 :find_pattern_node
7440 end
7441
7442 # Return a symbol representation of this node type. See `Node::type`.
7443 def self.type
7444 :find_pattern_node
7445 end
7446
7447 # Implements case-equality for the node. This is effectively == but without
7448 # comparing the value of locations. Locations are checked only for presence.
7449 def ===(other)
7450 other.is_a?(FindPatternNode) &&
7451 (constant === other.constant) &&
7452 (left === other.left) &&
7453 (requireds.length == other.requireds.length) &&
7454 requireds.zip(other.requireds).all? { |left, right| left === right } &&
7455 (right === other.right) &&
7456 (opening_loc.nil? == other.opening_loc.nil?) &&
7457 (closing_loc.nil? == other.closing_loc.nil?)
7458 end
7459 end
7460
7461 # Represents the use of the `..` or `...` operators to create flip flops.
7462 #
7463 # baz if foo .. bar
7464 # ^^^^^^^^^^
7465 class FlipFlopNode < Node
7466 # Initialize a new FlipFlopNode node.
7467 def initialize(source, node_id, location, flags, left, right, operator_loc)
7468 @source = source
7469 @node_id = node_id
7470 @location = location
7471 @flags = flags
7472 @left = left
7473 @right = right
7474 @operator_loc = operator_loc
7475 end
7476
7477 # def accept: (Visitor visitor) -> void
7478 def accept(visitor)
7479 visitor.visit_flip_flop_node(self)
7480 end
7481
7482 # def child_nodes: () -> Array[Node?]
7483 def child_nodes
7484 [left, right]
7485 end
7486
7487 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
7488 def each_child_node
7489 return to_enum(:each_child_node) unless block_given?
7490
7491 yield left if left
7492 yield right if right
7493 end
7494
7495 # def compact_child_nodes: () -> Array[Node]
7496 def compact_child_nodes
7497 compact = [] #: Array[Prism::node]
7498 compact << left if left
7499 compact << right if right
7500 compact
7501 end
7502
7503 # def comment_targets: () -> Array[Node | Location]
7504 def comment_targets
7505 [*left, *right, operator_loc] #: Array[Prism::node | Location]
7506 end
7507
7508 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node?, ?right: Prism::node?, ?operator_loc: Location) -> FlipFlopNode
7509 def copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc)
7510 FlipFlopNode.new(source, node_id, location, flags, left, right, operator_loc)
7511 end
7512
7513 # def deconstruct: () -> Array[Node?]
7514 alias deconstruct child_nodes
7515
7516 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, left: Prism::node?, right: Prism::node?, operator_loc: Location }
7517 def deconstruct_keys(keys)
7518 { node_id: node_id, location: location, left: left, right: right, operator_loc: operator_loc }
7519 end
7520
7521 # def exclude_end?: () -> bool
7522 def exclude_end?
7523 flags.anybits?(RangeFlags::EXCLUDE_END)
7524 end
7525
7526 # attr_reader left: Prism::node?
7527 attr_reader :left
7528
7529 # attr_reader right: Prism::node?
7530 attr_reader :right
7531
7532 # attr_reader operator_loc: Location
7533 def operator_loc
7534 location = @operator_loc
7535 return location if location.is_a?(Location)
7536 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7537 end
7538
7539 # Save the operator_loc location using the given saved source so that
7540 # it can be retrieved later.
7541 def save_operator_loc(repository)
7542 repository.enter(node_id, :operator_loc)
7543 end
7544
7545 # def operator: () -> String
7546 def operator
7547 operator_loc.slice
7548 end
7549
7550 # def inspect -> String
7551 def inspect
7552 InspectVisitor.compose(self)
7553 end
7554
7555 # Return a symbol representation of this node type. See `Node#type`.
7556 def type
7557 :flip_flop_node
7558 end
7559
7560 # Return a symbol representation of this node type. See `Node::type`.
7561 def self.type
7562 :flip_flop_node
7563 end
7564
7565 # Implements case-equality for the node. This is effectively == but without
7566 # comparing the value of locations. Locations are checked only for presence.
7567 def ===(other)
7568 other.is_a?(FlipFlopNode) &&
7569 (flags === other.flags) &&
7570 (left === other.left) &&
7571 (right === other.right) &&
7572 (operator_loc.nil? == other.operator_loc.nil?)
7573 end
7574 end
7575
7576 # Represents a floating point number literal.
7577 #
7578 # 1.0
7579 # ^^^
7580 class FloatNode < Node
7581 # Initialize a new FloatNode node.
7582 def initialize(source, node_id, location, flags, value)
7583 @source = source
7584 @node_id = node_id
7585 @location = location
7586 @flags = flags
7587 @value = value
7588 end
7589
7590 # def accept: (Visitor visitor) -> void
7591 def accept(visitor)
7592 visitor.visit_float_node(self)
7593 end
7594
7595 # def child_nodes: () -> Array[Node?]
7596 def child_nodes
7597 []
7598 end
7599
7600 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
7601 def each_child_node
7602 return to_enum(:each_child_node) unless block_given?
7603
7604 end
7605
7606 # def compact_child_nodes: () -> Array[Node]
7607 def compact_child_nodes
7608 []
7609 end
7610
7611 # def comment_targets: () -> Array[Node | Location]
7612 def comment_targets
7613 [] #: Array[Prism::node | Location]
7614 end
7615
7616 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Float) -> FloatNode
7617 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value)
7618 FloatNode.new(source, node_id, location, flags, value)
7619 end
7620
7621 # def deconstruct: () -> Array[Node?]
7622 alias deconstruct child_nodes
7623
7624 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, value: Float }
7625 def deconstruct_keys(keys)
7626 { node_id: node_id, location: location, value: value }
7627 end
7628
7629 # The value of the floating point number as a Float.
7630 attr_reader :value
7631
7632 # def inspect -> String
7633 def inspect
7634 InspectVisitor.compose(self)
7635 end
7636
7637 # Return a symbol representation of this node type. See `Node#type`.
7638 def type
7639 :float_node
7640 end
7641
7642 # Return a symbol representation of this node type. See `Node::type`.
7643 def self.type
7644 :float_node
7645 end
7646
7647 # Implements case-equality for the node. This is effectively == but without
7648 # comparing the value of locations. Locations are checked only for presence.
7649 def ===(other)
7650 other.is_a?(FloatNode) &&
7651 (value === other.value)
7652 end
7653 end
7654
7655 # Represents the use of the `for` keyword.
7656 #
7657 # for i in a end
7658 # ^^^^^^^^^^^^^^
7659 class ForNode < Node
7660 # Initialize a new ForNode node.
7661 def initialize(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc)
7662 @source = source
7663 @node_id = node_id
7664 @location = location
7665 @flags = flags
7666 @index = index
7667 @collection = collection
7668 @statements = statements
7669 @for_keyword_loc = for_keyword_loc
7670 @in_keyword_loc = in_keyword_loc
7671 @do_keyword_loc = do_keyword_loc
7672 @end_keyword_loc = end_keyword_loc
7673 end
7674
7675 # def accept: (Visitor visitor) -> void
7676 def accept(visitor)
7677 visitor.visit_for_node(self)
7678 end
7679
7680 # def child_nodes: () -> Array[Node?]
7681 def child_nodes
7682 [index, collection, statements]
7683 end
7684
7685 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
7686 def each_child_node
7687 return to_enum(:each_child_node) unless block_given?
7688
7689 yield index
7690 yield collection
7691 yield statements if statements
7692 end
7693
7694 # def compact_child_nodes: () -> Array[Node]
7695 def compact_child_nodes
7696 compact = [] #: Array[Prism::node]
7697 compact << index
7698 compact << collection
7699 compact << statements if statements
7700 compact
7701 end
7702
7703 # def comment_targets: () -> Array[Node | Location]
7704 def comment_targets
7705 [index, collection, *statements, for_keyword_loc, in_keyword_loc, *do_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location]
7706 end
7707
7708 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?index: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode, ?collection: Prism::node, ?statements: StatementsNode?, ?for_keyword_loc: Location, ?in_keyword_loc: Location, ?do_keyword_loc: Location?, ?end_keyword_loc: Location) -> ForNode
7709 def copy(node_id: self.node_id, location: self.location, flags: self.flags, index: self.index, collection: self.collection, statements: self.statements, for_keyword_loc: self.for_keyword_loc, in_keyword_loc: self.in_keyword_loc, do_keyword_loc: self.do_keyword_loc, end_keyword_loc: self.end_keyword_loc)
7710 ForNode.new(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc)
7711 end
7712
7713 # def deconstruct: () -> Array[Node?]
7714 alias deconstruct child_nodes
7715
7716 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, index: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode, collection: Prism::node, statements: StatementsNode?, for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: Location?, end_keyword_loc: Location }
7717 def deconstruct_keys(keys)
7718 { node_id: node_id, location: location, index: index, collection: collection, statements: statements, for_keyword_loc: for_keyword_loc, in_keyword_loc: in_keyword_loc, do_keyword_loc: do_keyword_loc, end_keyword_loc: end_keyword_loc }
7719 end
7720
7721 # The index expression for `for` loops.
7722 #
7723 # for i in a end
7724 # ^
7725 attr_reader :index
7726
7727 # The collection to iterate over.
7728 #
7729 # for i in a end
7730 # ^
7731 attr_reader :collection
7732
7733 # Represents the body of statements to execute for each iteration of the loop.
7734 #
7735 # for i in a
7736 # foo(i)
7737 # ^^^^^^
7738 # end
7739 attr_reader :statements
7740
7741 # The location of the `for` keyword.
7742 #
7743 # for i in a end
7744 # ^^^
7745 def for_keyword_loc
7746 location = @for_keyword_loc
7747 return location if location.is_a?(Location)
7748 @for_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7749 end
7750
7751 # Save the for_keyword_loc location using the given saved source so that
7752 # it can be retrieved later.
7753 def save_for_keyword_loc(repository)
7754 repository.enter(node_id, :for_keyword_loc)
7755 end
7756
7757 # The location of the `in` keyword.
7758 #
7759 # for i in a end
7760 # ^^
7761 def in_keyword_loc
7762 location = @in_keyword_loc
7763 return location if location.is_a?(Location)
7764 @in_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7765 end
7766
7767 # Save the in_keyword_loc location using the given saved source so that
7768 # it can be retrieved later.
7769 def save_in_keyword_loc(repository)
7770 repository.enter(node_id, :in_keyword_loc)
7771 end
7772
7773 # The location of the `do` keyword, if present.
7774 #
7775 # for i in a do end
7776 # ^^
7777 def do_keyword_loc
7778 location = @do_keyword_loc
7779 case location
7780 when nil
7781 nil
7782 when Location
7783 location
7784 else
7785 @do_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7786 end
7787 end
7788
7789 # Save the do_keyword_loc location using the given saved source so that
7790 # it can be retrieved later.
7791 def save_do_keyword_loc(repository)
7792 repository.enter(node_id, :do_keyword_loc) unless @do_keyword_loc.nil?
7793 end
7794
7795 # The location of the `end` keyword.
7796 #
7797 # for i in a end
7798 # ^^^
7799 def end_keyword_loc
7800 location = @end_keyword_loc
7801 return location if location.is_a?(Location)
7802 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
7803 end
7804
7805 # Save the end_keyword_loc location using the given saved source so that
7806 # it can be retrieved later.
7807 def save_end_keyword_loc(repository)
7808 repository.enter(node_id, :end_keyword_loc)
7809 end
7810
7811 # def for_keyword: () -> String
7812 def for_keyword
7813 for_keyword_loc.slice
7814 end
7815
7816 # def in_keyword: () -> String
7817 def in_keyword
7818 in_keyword_loc.slice
7819 end
7820
7821 # def do_keyword: () -> String?
7822 def do_keyword
7823 do_keyword_loc&.slice
7824 end
7825
7826 # def end_keyword: () -> String
7827 def end_keyword
7828 end_keyword_loc.slice
7829 end
7830
7831 # def inspect -> String
7832 def inspect
7833 InspectVisitor.compose(self)
7834 end
7835
7836 # Return a symbol representation of this node type. See `Node#type`.
7837 def type
7838 :for_node
7839 end
7840
7841 # Return a symbol representation of this node type. See `Node::type`.
7842 def self.type
7843 :for_node
7844 end
7845
7846 # Implements case-equality for the node. This is effectively == but without
7847 # comparing the value of locations. Locations are checked only for presence.
7848 def ===(other)
7849 other.is_a?(ForNode) &&
7850 (index === other.index) &&
7851 (collection === other.collection) &&
7852 (statements === other.statements) &&
7853 (for_keyword_loc.nil? == other.for_keyword_loc.nil?) &&
7854 (in_keyword_loc.nil? == other.in_keyword_loc.nil?) &&
7855 (do_keyword_loc.nil? == other.do_keyword_loc.nil?) &&
7856 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
7857 end
7858 end
7859
7860 # Represents forwarding all arguments to this method to another method.
7861 #
7862 # def foo(...)
7863 # bar(...)
7864 # ^^^
7865 # end
7866 class ForwardingArgumentsNode < Node
7867 # Initialize a new ForwardingArgumentsNode node.
7868 def initialize(source, node_id, location, flags)
7869 @source = source
7870 @node_id = node_id
7871 @location = location
7872 @flags = flags
7873 end
7874
7875 # def accept: (Visitor visitor) -> void
7876 def accept(visitor)
7877 visitor.visit_forwarding_arguments_node(self)
7878 end
7879
7880 # def child_nodes: () -> Array[Node?]
7881 def child_nodes
7882 []
7883 end
7884
7885 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
7886 def each_child_node
7887 return to_enum(:each_child_node) unless block_given?
7888
7889 end
7890
7891 # def compact_child_nodes: () -> Array[Node]
7892 def compact_child_nodes
7893 []
7894 end
7895
7896 # def comment_targets: () -> Array[Node | Location]
7897 def comment_targets
7898 [] #: Array[Prism::node | Location]
7899 end
7900
7901 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> ForwardingArgumentsNode
7902 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
7903 ForwardingArgumentsNode.new(source, node_id, location, flags)
7904 end
7905
7906 # def deconstruct: () -> Array[Node?]
7907 alias deconstruct child_nodes
7908
7909 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
7910 def deconstruct_keys(keys)
7911 { node_id: node_id, location: location }
7912 end
7913
7914 # def inspect -> String
7915 def inspect
7916 InspectVisitor.compose(self)
7917 end
7918
7919 # Return a symbol representation of this node type. See `Node#type`.
7920 def type
7921 :forwarding_arguments_node
7922 end
7923
7924 # Return a symbol representation of this node type. See `Node::type`.
7925 def self.type
7926 :forwarding_arguments_node
7927 end
7928
7929 # Implements case-equality for the node. This is effectively == but without
7930 # comparing the value of locations. Locations are checked only for presence.
7931 def ===(other)
7932 other.is_a?(ForwardingArgumentsNode)
7933 end
7934 end
7935
7936 # Represents the use of the forwarding parameter in a method, block, or lambda declaration.
7937 #
7938 # def foo(...)
7939 # ^^^
7940 # end
7941 class ForwardingParameterNode < Node
7942 # Initialize a new ForwardingParameterNode node.
7943 def initialize(source, node_id, location, flags)
7944 @source = source
7945 @node_id = node_id
7946 @location = location
7947 @flags = flags
7948 end
7949
7950 # def accept: (Visitor visitor) -> void
7951 def accept(visitor)
7952 visitor.visit_forwarding_parameter_node(self)
7953 end
7954
7955 # def child_nodes: () -> Array[Node?]
7956 def child_nodes
7957 []
7958 end
7959
7960 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
7961 def each_child_node
7962 return to_enum(:each_child_node) unless block_given?
7963
7964 end
7965
7966 # def compact_child_nodes: () -> Array[Node]
7967 def compact_child_nodes
7968 []
7969 end
7970
7971 # def comment_targets: () -> Array[Node | Location]
7972 def comment_targets
7973 [] #: Array[Prism::node | Location]
7974 end
7975
7976 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> ForwardingParameterNode
7977 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
7978 ForwardingParameterNode.new(source, node_id, location, flags)
7979 end
7980
7981 # def deconstruct: () -> Array[Node?]
7982 alias deconstruct child_nodes
7983
7984 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
7985 def deconstruct_keys(keys)
7986 { node_id: node_id, location: location }
7987 end
7988
7989 # def inspect -> String
7990 def inspect
7991 InspectVisitor.compose(self)
7992 end
7993
7994 # Return a symbol representation of this node type. See `Node#type`.
7995 def type
7996 :forwarding_parameter_node
7997 end
7998
7999 # Return a symbol representation of this node type. See `Node::type`.
8000 def self.type
8001 :forwarding_parameter_node
8002 end
8003
8004 # Implements case-equality for the node. This is effectively == but without
8005 # comparing the value of locations. Locations are checked only for presence.
8006 def ===(other)
8007 other.is_a?(ForwardingParameterNode)
8008 end
8009 end
8010
8011 # Represents the use of the `super` keyword without parentheses or arguments, but which might have a block.
8012 #
8013 # super
8014 # ^^^^^
8015 #
8016 # super { 123 }
8017 # ^^^^^^^^^^^^^
8018 #
8019 # If it has any other arguments, it would be a `SuperNode` instead.
8020 class ForwardingSuperNode < Node
8021 # Initialize a new ForwardingSuperNode node.
8022 def initialize(source, node_id, location, flags, block)
8023 @source = source
8024 @node_id = node_id
8025 @location = location
8026 @flags = flags
8027 @block = block
8028 end
8029
8030 # def accept: (Visitor visitor) -> void
8031 def accept(visitor)
8032 visitor.visit_forwarding_super_node(self)
8033 end
8034
8035 # def child_nodes: () -> Array[Node?]
8036 def child_nodes
8037 [block]
8038 end
8039
8040 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8041 def each_child_node
8042 return to_enum(:each_child_node) unless block_given?
8043
8044 yield block if block
8045 end
8046
8047 # def compact_child_nodes: () -> Array[Node]
8048 def compact_child_nodes
8049 compact = [] #: Array[Prism::node]
8050 compact << block if block
8051 compact
8052 end
8053
8054 # def comment_targets: () -> Array[Node | Location]
8055 def comment_targets
8056 [*block] #: Array[Prism::node | Location]
8057 end
8058
8059 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?block: BlockNode?) -> ForwardingSuperNode
8060 def copy(node_id: self.node_id, location: self.location, flags: self.flags, block: self.block)
8061 ForwardingSuperNode.new(source, node_id, location, flags, block)
8062 end
8063
8064 # def deconstruct: () -> Array[Node?]
8065 alias deconstruct child_nodes
8066
8067 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, block: BlockNode? }
8068 def deconstruct_keys(keys)
8069 { node_id: node_id, location: location, block: block }
8070 end
8071
8072 # All other arguments are forwarded as normal, except the original block is replaced with the new block.
8073 attr_reader :block
8074
8075 # def inspect -> String
8076 def inspect
8077 InspectVisitor.compose(self)
8078 end
8079
8080 # Return a symbol representation of this node type. See `Node#type`.
8081 def type
8082 :forwarding_super_node
8083 end
8084
8085 # Return a symbol representation of this node type. See `Node::type`.
8086 def self.type
8087 :forwarding_super_node
8088 end
8089
8090 # Implements case-equality for the node. This is effectively == but without
8091 # comparing the value of locations. Locations are checked only for presence.
8092 def ===(other)
8093 other.is_a?(ForwardingSuperNode) &&
8094 (block === other.block)
8095 end
8096 end
8097
8098 # Represents the use of the `&&=` operator for assignment to a global variable.
8099 #
8100 # $target &&= value
8101 # ^^^^^^^^^^^^^^^^^
8102 class GlobalVariableAndWriteNode < Node
8103 # Initialize a new GlobalVariableAndWriteNode node.
8104 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
8105 @source = source
8106 @node_id = node_id
8107 @location = location
8108 @flags = flags
8109 @name = name
8110 @name_loc = name_loc
8111 @operator_loc = operator_loc
8112 @value = value
8113 end
8114
8115 # def accept: (Visitor visitor) -> void
8116 def accept(visitor)
8117 visitor.visit_global_variable_and_write_node(self)
8118 end
8119
8120 # def child_nodes: () -> Array[Node?]
8121 def child_nodes
8122 [value]
8123 end
8124
8125 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8126 def each_child_node
8127 return to_enum(:each_child_node) unless block_given?
8128
8129 yield value
8130 end
8131
8132 # def compact_child_nodes: () -> Array[Node]
8133 def compact_child_nodes
8134 [value]
8135 end
8136
8137 # def comment_targets: () -> Array[Node | Location]
8138 def comment_targets
8139 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
8140 end
8141
8142 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> GlobalVariableAndWriteNode
8143 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
8144 GlobalVariableAndWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
8145 end
8146
8147 # def deconstruct: () -> Array[Node?]
8148 alias deconstruct child_nodes
8149
8150 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
8151 def deconstruct_keys(keys)
8152 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
8153 end
8154
8155 # attr_reader name: Symbol
8156 attr_reader :name
8157
8158 # attr_reader name_loc: Location
8159 def name_loc
8160 location = @name_loc
8161 return location if location.is_a?(Location)
8162 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8163 end
8164
8165 # Save the name_loc location using the given saved source so that
8166 # it can be retrieved later.
8167 def save_name_loc(repository)
8168 repository.enter(node_id, :name_loc)
8169 end
8170
8171 # attr_reader operator_loc: Location
8172 def operator_loc
8173 location = @operator_loc
8174 return location if location.is_a?(Location)
8175 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8176 end
8177
8178 # Save the operator_loc location using the given saved source so that
8179 # it can be retrieved later.
8180 def save_operator_loc(repository)
8181 repository.enter(node_id, :operator_loc)
8182 end
8183
8184 # attr_reader value: Prism::node
8185 attr_reader :value
8186
8187 # def operator: () -> String
8188 def operator
8189 operator_loc.slice
8190 end
8191
8192 # def inspect -> String
8193 def inspect
8194 InspectVisitor.compose(self)
8195 end
8196
8197 # Return a symbol representation of this node type. See `Node#type`.
8198 def type
8199 :global_variable_and_write_node
8200 end
8201
8202 # Return a symbol representation of this node type. See `Node::type`.
8203 def self.type
8204 :global_variable_and_write_node
8205 end
8206
8207 # Implements case-equality for the node. This is effectively == but without
8208 # comparing the value of locations. Locations are checked only for presence.
8209 def ===(other)
8210 other.is_a?(GlobalVariableAndWriteNode) &&
8211 (name === other.name) &&
8212 (name_loc.nil? == other.name_loc.nil?) &&
8213 (operator_loc.nil? == other.operator_loc.nil?) &&
8214 (value === other.value)
8215 end
8216 end
8217
8218 # Represents assigning to a global variable using an operator that isn't `=`.
8219 #
8220 # $target += value
8221 # ^^^^^^^^^^^^^^^^
8222 class GlobalVariableOperatorWriteNode < Node
8223 # Initialize a new GlobalVariableOperatorWriteNode node.
8224 def initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
8225 @source = source
8226 @node_id = node_id
8227 @location = location
8228 @flags = flags
8229 @name = name
8230 @name_loc = name_loc
8231 @binary_operator_loc = binary_operator_loc
8232 @value = value
8233 @binary_operator = binary_operator
8234 end
8235
8236 # def accept: (Visitor visitor) -> void
8237 def accept(visitor)
8238 visitor.visit_global_variable_operator_write_node(self)
8239 end
8240
8241 # def child_nodes: () -> Array[Node?]
8242 def child_nodes
8243 [value]
8244 end
8245
8246 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8247 def each_child_node
8248 return to_enum(:each_child_node) unless block_given?
8249
8250 yield value
8251 end
8252
8253 # def compact_child_nodes: () -> Array[Node]
8254 def compact_child_nodes
8255 [value]
8256 end
8257
8258 # def comment_targets: () -> Array[Node | Location]
8259 def comment_targets
8260 [name_loc, binary_operator_loc, value] #: Array[Prism::node | Location]
8261 end
8262
8263 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?binary_operator_loc: Location, ?value: Prism::node, ?binary_operator: Symbol) -> GlobalVariableOperatorWriteNode
8264 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
8265 GlobalVariableOperatorWriteNode.new(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
8266 end
8267
8268 # def deconstruct: () -> Array[Node?]
8269 alias deconstruct child_nodes
8270
8271 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Prism::node, binary_operator: Symbol }
8272 def deconstruct_keys(keys)
8273 { node_id: node_id, location: location, name: name, name_loc: name_loc, binary_operator_loc: binary_operator_loc, value: value, binary_operator: binary_operator }
8274 end
8275
8276 # attr_reader name: Symbol
8277 attr_reader :name
8278
8279 # attr_reader name_loc: Location
8280 def name_loc
8281 location = @name_loc
8282 return location if location.is_a?(Location)
8283 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8284 end
8285
8286 # Save the name_loc location using the given saved source so that
8287 # it can be retrieved later.
8288 def save_name_loc(repository)
8289 repository.enter(node_id, :name_loc)
8290 end
8291
8292 # attr_reader binary_operator_loc: Location
8293 def binary_operator_loc
8294 location = @binary_operator_loc
8295 return location if location.is_a?(Location)
8296 @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8297 end
8298
8299 # Save the binary_operator_loc location using the given saved source so that
8300 # it can be retrieved later.
8301 def save_binary_operator_loc(repository)
8302 repository.enter(node_id, :binary_operator_loc)
8303 end
8304
8305 # attr_reader value: Prism::node
8306 attr_reader :value
8307
8308 # attr_reader binary_operator: Symbol
8309 attr_reader :binary_operator
8310
8311 # def inspect -> String
8312 def inspect
8313 InspectVisitor.compose(self)
8314 end
8315
8316 # Return a symbol representation of this node type. See `Node#type`.
8317 def type
8318 :global_variable_operator_write_node
8319 end
8320
8321 # Return a symbol representation of this node type. See `Node::type`.
8322 def self.type
8323 :global_variable_operator_write_node
8324 end
8325
8326 # Implements case-equality for the node. This is effectively == but without
8327 # comparing the value of locations. Locations are checked only for presence.
8328 def ===(other)
8329 other.is_a?(GlobalVariableOperatorWriteNode) &&
8330 (name === other.name) &&
8331 (name_loc.nil? == other.name_loc.nil?) &&
8332 (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
8333 (value === other.value) &&
8334 (binary_operator === other.binary_operator)
8335 end
8336 end
8337
8338 # Represents the use of the `||=` operator for assignment to a global variable.
8339 #
8340 # $target ||= value
8341 # ^^^^^^^^^^^^^^^^^
8342 class GlobalVariableOrWriteNode < Node
8343 # Initialize a new GlobalVariableOrWriteNode node.
8344 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
8345 @source = source
8346 @node_id = node_id
8347 @location = location
8348 @flags = flags
8349 @name = name
8350 @name_loc = name_loc
8351 @operator_loc = operator_loc
8352 @value = value
8353 end
8354
8355 # def accept: (Visitor visitor) -> void
8356 def accept(visitor)
8357 visitor.visit_global_variable_or_write_node(self)
8358 end
8359
8360 # def child_nodes: () -> Array[Node?]
8361 def child_nodes
8362 [value]
8363 end
8364
8365 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8366 def each_child_node
8367 return to_enum(:each_child_node) unless block_given?
8368
8369 yield value
8370 end
8371
8372 # def compact_child_nodes: () -> Array[Node]
8373 def compact_child_nodes
8374 [value]
8375 end
8376
8377 # def comment_targets: () -> Array[Node | Location]
8378 def comment_targets
8379 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
8380 end
8381
8382 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> GlobalVariableOrWriteNode
8383 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
8384 GlobalVariableOrWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
8385 end
8386
8387 # def deconstruct: () -> Array[Node?]
8388 alias deconstruct child_nodes
8389
8390 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
8391 def deconstruct_keys(keys)
8392 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
8393 end
8394
8395 # attr_reader name: Symbol
8396 attr_reader :name
8397
8398 # attr_reader name_loc: Location
8399 def name_loc
8400 location = @name_loc
8401 return location if location.is_a?(Location)
8402 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8403 end
8404
8405 # Save the name_loc location using the given saved source so that
8406 # it can be retrieved later.
8407 def save_name_loc(repository)
8408 repository.enter(node_id, :name_loc)
8409 end
8410
8411 # attr_reader operator_loc: Location
8412 def operator_loc
8413 location = @operator_loc
8414 return location if location.is_a?(Location)
8415 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8416 end
8417
8418 # Save the operator_loc location using the given saved source so that
8419 # it can be retrieved later.
8420 def save_operator_loc(repository)
8421 repository.enter(node_id, :operator_loc)
8422 end
8423
8424 # attr_reader value: Prism::node
8425 attr_reader :value
8426
8427 # def operator: () -> String
8428 def operator
8429 operator_loc.slice
8430 end
8431
8432 # def inspect -> String
8433 def inspect
8434 InspectVisitor.compose(self)
8435 end
8436
8437 # Return a symbol representation of this node type. See `Node#type`.
8438 def type
8439 :global_variable_or_write_node
8440 end
8441
8442 # Return a symbol representation of this node type. See `Node::type`.
8443 def self.type
8444 :global_variable_or_write_node
8445 end
8446
8447 # Implements case-equality for the node. This is effectively == but without
8448 # comparing the value of locations. Locations are checked only for presence.
8449 def ===(other)
8450 other.is_a?(GlobalVariableOrWriteNode) &&
8451 (name === other.name) &&
8452 (name_loc.nil? == other.name_loc.nil?) &&
8453 (operator_loc.nil? == other.operator_loc.nil?) &&
8454 (value === other.value)
8455 end
8456 end
8457
8458 # Represents referencing a global variable.
8459 #
8460 # $foo
8461 # ^^^^
8462 class GlobalVariableReadNode < Node
8463 # Initialize a new GlobalVariableReadNode node.
8464 def initialize(source, node_id, location, flags, name)
8465 @source = source
8466 @node_id = node_id
8467 @location = location
8468 @flags = flags
8469 @name = name
8470 end
8471
8472 # def accept: (Visitor visitor) -> void
8473 def accept(visitor)
8474 visitor.visit_global_variable_read_node(self)
8475 end
8476
8477 # def child_nodes: () -> Array[Node?]
8478 def child_nodes
8479 []
8480 end
8481
8482 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8483 def each_child_node
8484 return to_enum(:each_child_node) unless block_given?
8485
8486 end
8487
8488 # def compact_child_nodes: () -> Array[Node]
8489 def compact_child_nodes
8490 []
8491 end
8492
8493 # def comment_targets: () -> Array[Node | Location]
8494 def comment_targets
8495 [] #: Array[Prism::node | Location]
8496 end
8497
8498 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> GlobalVariableReadNode
8499 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
8500 GlobalVariableReadNode.new(source, node_id, location, flags, name)
8501 end
8502
8503 # def deconstruct: () -> Array[Node?]
8504 alias deconstruct child_nodes
8505
8506 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
8507 def deconstruct_keys(keys)
8508 { node_id: node_id, location: location, name: name }
8509 end
8510
8511 # The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
8512 #
8513 # $foo # name `:$foo`
8514 #
8515 # $_Test # name `:$_Test`
8516 attr_reader :name
8517
8518 # def inspect -> String
8519 def inspect
8520 InspectVisitor.compose(self)
8521 end
8522
8523 # Return a symbol representation of this node type. See `Node#type`.
8524 def type
8525 :global_variable_read_node
8526 end
8527
8528 # Return a symbol representation of this node type. See `Node::type`.
8529 def self.type
8530 :global_variable_read_node
8531 end
8532
8533 # Implements case-equality for the node. This is effectively == but without
8534 # comparing the value of locations. Locations are checked only for presence.
8535 def ===(other)
8536 other.is_a?(GlobalVariableReadNode) &&
8537 (name === other.name)
8538 end
8539 end
8540
8541 # Represents writing to a global variable in a context that doesn't have an explicit value.
8542 #
8543 # $foo, $bar = baz
8544 # ^^^^ ^^^^
8545 class GlobalVariableTargetNode < Node
8546 # Initialize a new GlobalVariableTargetNode node.
8547 def initialize(source, node_id, location, flags, name)
8548 @source = source
8549 @node_id = node_id
8550 @location = location
8551 @flags = flags
8552 @name = name
8553 end
8554
8555 # def accept: (Visitor visitor) -> void
8556 def accept(visitor)
8557 visitor.visit_global_variable_target_node(self)
8558 end
8559
8560 # def child_nodes: () -> Array[Node?]
8561 def child_nodes
8562 []
8563 end
8564
8565 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8566 def each_child_node
8567 return to_enum(:each_child_node) unless block_given?
8568
8569 end
8570
8571 # def compact_child_nodes: () -> Array[Node]
8572 def compact_child_nodes
8573 []
8574 end
8575
8576 # def comment_targets: () -> Array[Node | Location]
8577 def comment_targets
8578 [] #: Array[Prism::node | Location]
8579 end
8580
8581 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> GlobalVariableTargetNode
8582 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
8583 GlobalVariableTargetNode.new(source, node_id, location, flags, name)
8584 end
8585
8586 # def deconstruct: () -> Array[Node?]
8587 alias deconstruct child_nodes
8588
8589 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
8590 def deconstruct_keys(keys)
8591 { node_id: node_id, location: location, name: name }
8592 end
8593
8594 # attr_reader name: Symbol
8595 attr_reader :name
8596
8597 # def inspect -> String
8598 def inspect
8599 InspectVisitor.compose(self)
8600 end
8601
8602 # Return a symbol representation of this node type. See `Node#type`.
8603 def type
8604 :global_variable_target_node
8605 end
8606
8607 # Return a symbol representation of this node type. See `Node::type`.
8608 def self.type
8609 :global_variable_target_node
8610 end
8611
8612 # Implements case-equality for the node. This is effectively == but without
8613 # comparing the value of locations. Locations are checked only for presence.
8614 def ===(other)
8615 other.is_a?(GlobalVariableTargetNode) &&
8616 (name === other.name)
8617 end
8618 end
8619
8620 # Represents writing to a global variable.
8621 #
8622 # $foo = 1
8623 # ^^^^^^^^
8624 class GlobalVariableWriteNode < Node
8625 # Initialize a new GlobalVariableWriteNode node.
8626 def initialize(source, node_id, location, flags, name, name_loc, value, operator_loc)
8627 @source = source
8628 @node_id = node_id
8629 @location = location
8630 @flags = flags
8631 @name = name
8632 @name_loc = name_loc
8633 @value = value
8634 @operator_loc = operator_loc
8635 end
8636
8637 # def accept: (Visitor visitor) -> void
8638 def accept(visitor)
8639 visitor.visit_global_variable_write_node(self)
8640 end
8641
8642 # def child_nodes: () -> Array[Node?]
8643 def child_nodes
8644 [value]
8645 end
8646
8647 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8648 def each_child_node
8649 return to_enum(:each_child_node) unless block_given?
8650
8651 yield value
8652 end
8653
8654 # def compact_child_nodes: () -> Array[Node]
8655 def compact_child_nodes
8656 [value]
8657 end
8658
8659 # def comment_targets: () -> Array[Node | Location]
8660 def comment_targets
8661 [name_loc, value, operator_loc] #: Array[Prism::node | Location]
8662 end
8663
8664 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?value: Prism::node, ?operator_loc: Location) -> GlobalVariableWriteNode
8665 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, value: self.value, operator_loc: self.operator_loc)
8666 GlobalVariableWriteNode.new(source, node_id, location, flags, name, name_loc, value, operator_loc)
8667 end
8668
8669 # def deconstruct: () -> Array[Node?]
8670 alias deconstruct child_nodes
8671
8672 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, value: Prism::node, operator_loc: Location }
8673 def deconstruct_keys(keys)
8674 { node_id: node_id, location: location, name: name, name_loc: name_loc, value: value, operator_loc: operator_loc }
8675 end
8676
8677 # The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
8678 #
8679 # $foo = :bar # name `:$foo`
8680 #
8681 # $_Test = 123 # name `:$_Test`
8682 attr_reader :name
8683
8684 # The location of the global variable's name.
8685 #
8686 # $foo = :bar
8687 # ^^^^
8688 def name_loc
8689 location = @name_loc
8690 return location if location.is_a?(Location)
8691 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8692 end
8693
8694 # Save the name_loc location using the given saved source so that
8695 # it can be retrieved later.
8696 def save_name_loc(repository)
8697 repository.enter(node_id, :name_loc)
8698 end
8699
8700 # The value to write to the global variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
8701 #
8702 # $foo = :bar
8703 # ^^^^
8704 #
8705 # $-xyz = 123
8706 # ^^^
8707 attr_reader :value
8708
8709 # The location of the `=` operator.
8710 #
8711 # $foo = :bar
8712 # ^
8713 def operator_loc
8714 location = @operator_loc
8715 return location if location.is_a?(Location)
8716 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8717 end
8718
8719 # Save the operator_loc location using the given saved source so that
8720 # it can be retrieved later.
8721 def save_operator_loc(repository)
8722 repository.enter(node_id, :operator_loc)
8723 end
8724
8725 # def operator: () -> String
8726 def operator
8727 operator_loc.slice
8728 end
8729
8730 # def inspect -> String
8731 def inspect
8732 InspectVisitor.compose(self)
8733 end
8734
8735 # Return a symbol representation of this node type. See `Node#type`.
8736 def type
8737 :global_variable_write_node
8738 end
8739
8740 # Return a symbol representation of this node type. See `Node::type`.
8741 def self.type
8742 :global_variable_write_node
8743 end
8744
8745 # Implements case-equality for the node. This is effectively == but without
8746 # comparing the value of locations. Locations are checked only for presence.
8747 def ===(other)
8748 other.is_a?(GlobalVariableWriteNode) &&
8749 (name === other.name) &&
8750 (name_loc.nil? == other.name_loc.nil?) &&
8751 (value === other.value) &&
8752 (operator_loc.nil? == other.operator_loc.nil?)
8753 end
8754 end
8755
8756 # Represents a hash literal.
8757 #
8758 # { a => b }
8759 # ^^^^^^^^^^
8760 class HashNode < Node
8761 # Initialize a new HashNode node.
8762 def initialize(source, node_id, location, flags, opening_loc, elements, closing_loc)
8763 @source = source
8764 @node_id = node_id
8765 @location = location
8766 @flags = flags
8767 @opening_loc = opening_loc
8768 @elements = elements
8769 @closing_loc = closing_loc
8770 end
8771
8772 # def accept: (Visitor visitor) -> void
8773 def accept(visitor)
8774 visitor.visit_hash_node(self)
8775 end
8776
8777 # def child_nodes: () -> Array[Node?]
8778 def child_nodes
8779 [*elements]
8780 end
8781
8782 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8783 def each_child_node
8784 return to_enum(:each_child_node) unless block_given?
8785
8786 elements.each { |node| yield node }
8787 end
8788
8789 # def compact_child_nodes: () -> Array[Node]
8790 def compact_child_nodes
8791 [*elements]
8792 end
8793
8794 # def comment_targets: () -> Array[Node | Location]
8795 def comment_targets
8796 [opening_loc, *elements, closing_loc] #: Array[Prism::node | Location]
8797 end
8798
8799 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?elements: Array[AssocNode | AssocSplatNode], ?closing_loc: Location) -> HashNode
8800 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, elements: self.elements, closing_loc: self.closing_loc)
8801 HashNode.new(source, node_id, location, flags, opening_loc, elements, closing_loc)
8802 end
8803
8804 # def deconstruct: () -> Array[Node?]
8805 alias deconstruct child_nodes
8806
8807 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location, elements: Array[AssocNode | AssocSplatNode], closing_loc: Location }
8808 def deconstruct_keys(keys)
8809 { node_id: node_id, location: location, opening_loc: opening_loc, elements: elements, closing_loc: closing_loc }
8810 end
8811
8812 # The location of the opening brace.
8813 #
8814 # { a => b }
8815 # ^
8816 def opening_loc
8817 location = @opening_loc
8818 return location if location.is_a?(Location)
8819 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8820 end
8821
8822 # Save the opening_loc location using the given saved source so that
8823 # it can be retrieved later.
8824 def save_opening_loc(repository)
8825 repository.enter(node_id, :opening_loc)
8826 end
8827
8828 # The elements of the hash. These can be either `AssocNode`s or `AssocSplatNode`s.
8829 #
8830 # { a: b }
8831 # ^^^^
8832 #
8833 # { **foo }
8834 # ^^^^^
8835 attr_reader :elements
8836
8837 # The location of the closing brace.
8838 #
8839 # { a => b }
8840 # ^
8841 def closing_loc
8842 location = @closing_loc
8843 return location if location.is_a?(Location)
8844 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
8845 end
8846
8847 # Save the closing_loc location using the given saved source so that
8848 # it can be retrieved later.
8849 def save_closing_loc(repository)
8850 repository.enter(node_id, :closing_loc)
8851 end
8852
8853 # def opening: () -> String
8854 def opening
8855 opening_loc.slice
8856 end
8857
8858 # def closing: () -> String
8859 def closing
8860 closing_loc.slice
8861 end
8862
8863 # def inspect -> String
8864 def inspect
8865 InspectVisitor.compose(self)
8866 end
8867
8868 # Return a symbol representation of this node type. See `Node#type`.
8869 def type
8870 :hash_node
8871 end
8872
8873 # Return a symbol representation of this node type. See `Node::type`.
8874 def self.type
8875 :hash_node
8876 end
8877
8878 # Implements case-equality for the node. This is effectively == but without
8879 # comparing the value of locations. Locations are checked only for presence.
8880 def ===(other)
8881 other.is_a?(HashNode) &&
8882 (opening_loc.nil? == other.opening_loc.nil?) &&
8883 (elements.length == other.elements.length) &&
8884 elements.zip(other.elements).all? { |left, right| left === right } &&
8885 (closing_loc.nil? == other.closing_loc.nil?)
8886 end
8887 end
8888
8889 # Represents a hash pattern in pattern matching.
8890 #
8891 # foo => { a: 1, b: 2 }
8892 # ^^^^^^^^^^^^^^
8893 #
8894 # foo => { a: 1, b: 2, **c }
8895 # ^^^^^^^^^^^^^^^^^^^
8896 #
8897 # foo => Bar[a: 1, b: 2]
8898 # ^^^^^^^^^^^^^^^
8899 #
8900 # foo in { a: 1, b: 2 }
8901 # ^^^^^^^^^^^^^^
8902 class HashPatternNode < Node
8903 # Initialize a new HashPatternNode node.
8904 def initialize(source, node_id, location, flags, constant, elements, rest, opening_loc, closing_loc)
8905 @source = source
8906 @node_id = node_id
8907 @location = location
8908 @flags = flags
8909 @constant = constant
8910 @elements = elements
8911 @rest = rest
8912 @opening_loc = opening_loc
8913 @closing_loc = closing_loc
8914 end
8915
8916 # def accept: (Visitor visitor) -> void
8917 def accept(visitor)
8918 visitor.visit_hash_pattern_node(self)
8919 end
8920
8921 # def child_nodes: () -> Array[Node?]
8922 def child_nodes
8923 [constant, *elements, rest]
8924 end
8925
8926 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
8927 def each_child_node
8928 return to_enum(:each_child_node) unless block_given?
8929
8930 yield constant if constant
8931 elements.each { |node| yield node }
8932 yield rest if rest
8933 end
8934
8935 # def compact_child_nodes: () -> Array[Node]
8936 def compact_child_nodes
8937 compact = [] #: Array[Prism::node]
8938 compact << constant if constant
8939 compact.concat(elements)
8940 compact << rest if rest
8941 compact
8942 end
8943
8944 # def comment_targets: () -> Array[Node | Location]
8945 def comment_targets
8946 [*constant, *elements, *rest, *opening_loc, *closing_loc] #: Array[Prism::node | Location]
8947 end
8948
8949 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?constant: ConstantPathNode | ConstantReadNode | nil, ?elements: Array[AssocNode], ?rest: AssocSplatNode | NoKeywordsParameterNode | nil, ?opening_loc: Location?, ?closing_loc: Location?) -> HashPatternNode
8950 def copy(node_id: self.node_id, location: self.location, flags: self.flags, constant: self.constant, elements: self.elements, rest: self.rest, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
8951 HashPatternNode.new(source, node_id, location, flags, constant, elements, rest, opening_loc, closing_loc)
8952 end
8953
8954 # def deconstruct: () -> Array[Node?]
8955 alias deconstruct child_nodes
8956
8957 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, constant: ConstantPathNode | ConstantReadNode | nil, elements: Array[AssocNode], rest: AssocSplatNode | NoKeywordsParameterNode | nil, opening_loc: Location?, closing_loc: Location? }
8958 def deconstruct_keys(keys)
8959 { node_id: node_id, location: location, constant: constant, elements: elements, rest: rest, opening_loc: opening_loc, closing_loc: closing_loc }
8960 end
8961
8962 # Represents the optional constant preceding the Hash.
8963 #
8964 # foo => Bar[a: 1, b: 2]
8965 # ^^^
8966 #
8967 # foo => Bar::Baz[a: 1, b: 2]
8968 # ^^^^^^^^
8969 attr_reader :constant
8970
8971 # Represents the explicit named hash keys and values.
8972 #
8973 # foo => { a: 1, b:, ** }
8974 # ^^^^^^^^
8975 attr_reader :elements
8976
8977 # Represents the rest of the Hash keys and values. This can be named, unnamed, or explicitly forbidden via `**nil`, this last one results in a `NoKeywordsParameterNode`.
8978 #
8979 # foo => { a: 1, b:, **c }
8980 # ^^^
8981 #
8982 # foo => { a: 1, b:, ** }
8983 # ^^
8984 #
8985 # foo => { a: 1, b:, **nil }
8986 # ^^^^^
8987 attr_reader :rest
8988
8989 # The location of the opening brace.
8990 #
8991 # foo => { a: 1 }
8992 # ^
8993 #
8994 # foo => Bar[a: 1]
8995 # ^
8996 def opening_loc
8997 location = @opening_loc
8998 case location
8999 when nil
9000 nil
9001 when Location
9002 location
9003 else
9004 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9005 end
9006 end
9007
9008 # Save the opening_loc location using the given saved source so that
9009 # it can be retrieved later.
9010 def save_opening_loc(repository)
9011 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
9012 end
9013
9014 # The location of the closing brace.
9015 #
9016 # foo => { a: 1 }
9017 # ^
9018 #
9019 # foo => Bar[a: 1]
9020 # ^
9021 def closing_loc
9022 location = @closing_loc
9023 case location
9024 when nil
9025 nil
9026 when Location
9027 location
9028 else
9029 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9030 end
9031 end
9032
9033 # Save the closing_loc location using the given saved source so that
9034 # it can be retrieved later.
9035 def save_closing_loc(repository)
9036 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
9037 end
9038
9039 # def opening: () -> String?
9040 def opening
9041 opening_loc&.slice
9042 end
9043
9044 # def closing: () -> String?
9045 def closing
9046 closing_loc&.slice
9047 end
9048
9049 # def inspect -> String
9050 def inspect
9051 InspectVisitor.compose(self)
9052 end
9053
9054 # Return a symbol representation of this node type. See `Node#type`.
9055 def type
9056 :hash_pattern_node
9057 end
9058
9059 # Return a symbol representation of this node type. See `Node::type`.
9060 def self.type
9061 :hash_pattern_node
9062 end
9063
9064 # Implements case-equality for the node. This is effectively == but without
9065 # comparing the value of locations. Locations are checked only for presence.
9066 def ===(other)
9067 other.is_a?(HashPatternNode) &&
9068 (constant === other.constant) &&
9069 (elements.length == other.elements.length) &&
9070 elements.zip(other.elements).all? { |left, right| left === right } &&
9071 (rest === other.rest) &&
9072 (opening_loc.nil? == other.opening_loc.nil?) &&
9073 (closing_loc.nil? == other.closing_loc.nil?)
9074 end
9075 end
9076
9077 # Represents the use of the `if` keyword, either in the block form or the modifier form, or a ternary expression.
9078 #
9079 # bar if foo
9080 # ^^^^^^^^^^
9081 #
9082 # if foo then bar end
9083 # ^^^^^^^^^^^^^^^^^^^
9084 #
9085 # foo ? bar : baz
9086 # ^^^^^^^^^^^^^^^
9087 class IfNode < Node
9088 # Initialize a new IfNode node.
9089 def initialize(source, node_id, location, flags, if_keyword_loc, predicate, then_keyword_loc, statements, subsequent, end_keyword_loc)
9090 @source = source
9091 @node_id = node_id
9092 @location = location
9093 @flags = flags
9094 @if_keyword_loc = if_keyword_loc
9095 @predicate = predicate
9096 @then_keyword_loc = then_keyword_loc
9097 @statements = statements
9098 @subsequent = subsequent
9099 @end_keyword_loc = end_keyword_loc
9100 end
9101
9102 # def accept: (Visitor visitor) -> void
9103 def accept(visitor)
9104 visitor.visit_if_node(self)
9105 end
9106
9107 # def child_nodes: () -> Array[Node?]
9108 def child_nodes
9109 [predicate, statements, subsequent]
9110 end
9111
9112 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
9113 def each_child_node
9114 return to_enum(:each_child_node) unless block_given?
9115
9116 yield predicate
9117 yield statements if statements
9118 yield subsequent if subsequent
9119 end
9120
9121 # def compact_child_nodes: () -> Array[Node]
9122 def compact_child_nodes
9123 compact = [] #: Array[Prism::node]
9124 compact << predicate
9125 compact << statements if statements
9126 compact << subsequent if subsequent
9127 compact
9128 end
9129
9130 # def comment_targets: () -> Array[Node | Location]
9131 def comment_targets
9132 [*if_keyword_loc, predicate, *then_keyword_loc, *statements, *subsequent, *end_keyword_loc] #: Array[Prism::node | Location]
9133 end
9134
9135 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?if_keyword_loc: Location?, ?predicate: Prism::node, ?then_keyword_loc: Location?, ?statements: StatementsNode?, ?subsequent: ElseNode | IfNode | nil, ?end_keyword_loc: Location?) -> IfNode
9136 def copy(node_id: self.node_id, location: self.location, flags: self.flags, if_keyword_loc: self.if_keyword_loc, predicate: self.predicate, then_keyword_loc: self.then_keyword_loc, statements: self.statements, subsequent: self.subsequent, end_keyword_loc: self.end_keyword_loc)
9137 IfNode.new(source, node_id, location, flags, if_keyword_loc, predicate, then_keyword_loc, statements, subsequent, end_keyword_loc)
9138 end
9139
9140 # def deconstruct: () -> Array[Node?]
9141 alias deconstruct child_nodes
9142
9143 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, if_keyword_loc: Location?, predicate: Prism::node, then_keyword_loc: Location?, statements: StatementsNode?, subsequent: ElseNode | IfNode | nil, end_keyword_loc: Location? }
9144 def deconstruct_keys(keys)
9145 { node_id: node_id, location: location, if_keyword_loc: if_keyword_loc, predicate: predicate, then_keyword_loc: then_keyword_loc, statements: statements, subsequent: subsequent, end_keyword_loc: end_keyword_loc }
9146 end
9147
9148 # The location of the `if` keyword if present.
9149 #
9150 # bar if foo
9151 # ^^
9152 #
9153 # The `if_keyword_loc` field will be `nil` when the `IfNode` represents a ternary expression.
9154 def if_keyword_loc
9155 location = @if_keyword_loc
9156 case location
9157 when nil
9158 nil
9159 when Location
9160 location
9161 else
9162 @if_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9163 end
9164 end
9165
9166 # Save the if_keyword_loc location using the given saved source so that
9167 # it can be retrieved later.
9168 def save_if_keyword_loc(repository)
9169 repository.enter(node_id, :if_keyword_loc) unless @if_keyword_loc.nil?
9170 end
9171
9172 # The node for the condition the `IfNode` is testing.
9173 #
9174 # if foo
9175 # ^^^
9176 # bar
9177 # end
9178 #
9179 # bar if foo
9180 # ^^^
9181 #
9182 # foo ? bar : baz
9183 # ^^^
9184 attr_reader :predicate
9185
9186 # The location of the `then` keyword (if present) or the `?` in a ternary expression, `nil` otherwise.
9187 #
9188 # if foo then bar end
9189 # ^^^^
9190 #
9191 # a ? b : c
9192 # ^
9193 def then_keyword_loc
9194 location = @then_keyword_loc
9195 case location
9196 when nil
9197 nil
9198 when Location
9199 location
9200 else
9201 @then_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9202 end
9203 end
9204
9205 # Save the then_keyword_loc location using the given saved source so that
9206 # it can be retrieved later.
9207 def save_then_keyword_loc(repository)
9208 repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil?
9209 end
9210
9211 # Represents the body of statements that will be executed when the predicate is evaluated as truthy. Will be `nil` when no body is provided.
9212 #
9213 # if foo
9214 # bar
9215 # ^^^
9216 # baz
9217 # ^^^
9218 # end
9219 attr_reader :statements
9220
9221 # Represents an `ElseNode` or an `IfNode` when there is an `else` or an `elsif` in the `if` statement.
9222 #
9223 # if foo
9224 # bar
9225 # elsif baz
9226 # ^^^^^^^^^
9227 # qux
9228 # ^^^
9229 # end
9230 # ^^^
9231 #
9232 # if foo then bar else baz end
9233 # ^^^^^^^^^^^^
9234 attr_reader :subsequent
9235
9236 # The location of the `end` keyword if present, `nil` otherwise.
9237 #
9238 # if foo
9239 # bar
9240 # end
9241 # ^^^
9242 def end_keyword_loc
9243 location = @end_keyword_loc
9244 case location
9245 when nil
9246 nil
9247 when Location
9248 location
9249 else
9250 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9251 end
9252 end
9253
9254 # Save the end_keyword_loc location using the given saved source so that
9255 # it can be retrieved later.
9256 def save_end_keyword_loc(repository)
9257 repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil?
9258 end
9259
9260 # def if_keyword: () -> String?
9261 def if_keyword
9262 if_keyword_loc&.slice
9263 end
9264
9265 # def then_keyword: () -> String?
9266 def then_keyword
9267 then_keyword_loc&.slice
9268 end
9269
9270 # def end_keyword: () -> String?
9271 def end_keyword
9272 end_keyword_loc&.slice
9273 end
9274
9275 # def inspect -> String
9276 def inspect
9277 InspectVisitor.compose(self)
9278 end
9279
9280 # Return a symbol representation of this node type. See `Node#type`.
9281 def type
9282 :if_node
9283 end
9284
9285 # Return a symbol representation of this node type. See `Node::type`.
9286 def self.type
9287 :if_node
9288 end
9289
9290 # Implements case-equality for the node. This is effectively == but without
9291 # comparing the value of locations. Locations are checked only for presence.
9292 def ===(other)
9293 other.is_a?(IfNode) &&
9294 (if_keyword_loc.nil? == other.if_keyword_loc.nil?) &&
9295 (predicate === other.predicate) &&
9296 (then_keyword_loc.nil? == other.then_keyword_loc.nil?) &&
9297 (statements === other.statements) &&
9298 (subsequent === other.subsequent) &&
9299 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
9300 end
9301 end
9302
9303 # Represents an imaginary number literal.
9304 #
9305 # 1.0i
9306 # ^^^^
9307 class ImaginaryNode < Node
9308 # Initialize a new ImaginaryNode node.
9309 def initialize(source, node_id, location, flags, numeric)
9310 @source = source
9311 @node_id = node_id
9312 @location = location
9313 @flags = flags
9314 @numeric = numeric
9315 end
9316
9317 # def accept: (Visitor visitor) -> void
9318 def accept(visitor)
9319 visitor.visit_imaginary_node(self)
9320 end
9321
9322 # def child_nodes: () -> Array[Node?]
9323 def child_nodes
9324 [numeric]
9325 end
9326
9327 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
9328 def each_child_node
9329 return to_enum(:each_child_node) unless block_given?
9330
9331 yield numeric
9332 end
9333
9334 # def compact_child_nodes: () -> Array[Node]
9335 def compact_child_nodes
9336 [numeric]
9337 end
9338
9339 # def comment_targets: () -> Array[Node | Location]
9340 def comment_targets
9341 [numeric] #: Array[Prism::node | Location]
9342 end
9343
9344 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?numeric: FloatNode | IntegerNode | RationalNode) -> ImaginaryNode
9345 def copy(node_id: self.node_id, location: self.location, flags: self.flags, numeric: self.numeric)
9346 ImaginaryNode.new(source, node_id, location, flags, numeric)
9347 end
9348
9349 # def deconstruct: () -> Array[Node?]
9350 alias deconstruct child_nodes
9351
9352 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, numeric: FloatNode | IntegerNode | RationalNode }
9353 def deconstruct_keys(keys)
9354 { node_id: node_id, location: location, numeric: numeric }
9355 end
9356
9357 # attr_reader numeric: FloatNode | IntegerNode | RationalNode
9358 attr_reader :numeric
9359
9360 # def inspect -> String
9361 def inspect
9362 InspectVisitor.compose(self)
9363 end
9364
9365 # Return a symbol representation of this node type. See `Node#type`.
9366 def type
9367 :imaginary_node
9368 end
9369
9370 # Return a symbol representation of this node type. See `Node::type`.
9371 def self.type
9372 :imaginary_node
9373 end
9374
9375 # Implements case-equality for the node. This is effectively == but without
9376 # comparing the value of locations. Locations are checked only for presence.
9377 def ===(other)
9378 other.is_a?(ImaginaryNode) &&
9379 (numeric === other.numeric)
9380 end
9381 end
9382
9383 # Represents a node that is implicitly being added to the tree but doesn't correspond directly to a node in the source.
9384 #
9385 # { foo: }
9386 # ^^^^
9387 #
9388 # { Foo: }
9389 # ^^^^
9390 #
9391 # foo in { bar: }
9392 # ^^^^
9393 class ImplicitNode < Node
9394 # Initialize a new ImplicitNode node.
9395 def initialize(source, node_id, location, flags, value)
9396 @source = source
9397 @node_id = node_id
9398 @location = location
9399 @flags = flags
9400 @value = value
9401 end
9402
9403 # def accept: (Visitor visitor) -> void
9404 def accept(visitor)
9405 visitor.visit_implicit_node(self)
9406 end
9407
9408 # def child_nodes: () -> Array[Node?]
9409 def child_nodes
9410 [value]
9411 end
9412
9413 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
9414 def each_child_node
9415 return to_enum(:each_child_node) unless block_given?
9416
9417 yield value
9418 end
9419
9420 # def compact_child_nodes: () -> Array[Node]
9421 def compact_child_nodes
9422 [value]
9423 end
9424
9425 # def comment_targets: () -> Array[Node | Location]
9426 def comment_targets
9427 [value] #: Array[Prism::node | Location]
9428 end
9429
9430 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: LocalVariableReadNode | CallNode | ConstantReadNode | LocalVariableTargetNode) -> ImplicitNode
9431 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value)
9432 ImplicitNode.new(source, node_id, location, flags, value)
9433 end
9434
9435 # def deconstruct: () -> Array[Node?]
9436 alias deconstruct child_nodes
9437
9438 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, value: LocalVariableReadNode | CallNode | ConstantReadNode | LocalVariableTargetNode }
9439 def deconstruct_keys(keys)
9440 { node_id: node_id, location: location, value: value }
9441 end
9442
9443 # attr_reader value: LocalVariableReadNode | CallNode | ConstantReadNode | LocalVariableTargetNode
9444 attr_reader :value
9445
9446 # def inspect -> String
9447 def inspect
9448 InspectVisitor.compose(self)
9449 end
9450
9451 # Return a symbol representation of this node type. See `Node#type`.
9452 def type
9453 :implicit_node
9454 end
9455
9456 # Return a symbol representation of this node type. See `Node::type`.
9457 def self.type
9458 :implicit_node
9459 end
9460
9461 # Implements case-equality for the node. This is effectively == but without
9462 # comparing the value of locations. Locations are checked only for presence.
9463 def ===(other)
9464 other.is_a?(ImplicitNode) &&
9465 (value === other.value)
9466 end
9467 end
9468
9469 # Represents using a trailing comma to indicate an implicit rest parameter.
9470 #
9471 # foo { |bar,| }
9472 # ^
9473 #
9474 # foo in [bar,]
9475 # ^
9476 #
9477 # for foo, in bar do end
9478 # ^
9479 #
9480 # foo, = bar
9481 # ^
9482 class ImplicitRestNode < Node
9483 # Initialize a new ImplicitRestNode node.
9484 def initialize(source, node_id, location, flags)
9485 @source = source
9486 @node_id = node_id
9487 @location = location
9488 @flags = flags
9489 end
9490
9491 # def accept: (Visitor visitor) -> void
9492 def accept(visitor)
9493 visitor.visit_implicit_rest_node(self)
9494 end
9495
9496 # def child_nodes: () -> Array[Node?]
9497 def child_nodes
9498 []
9499 end
9500
9501 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
9502 def each_child_node
9503 return to_enum(:each_child_node) unless block_given?
9504
9505 end
9506
9507 # def compact_child_nodes: () -> Array[Node]
9508 def compact_child_nodes
9509 []
9510 end
9511
9512 # def comment_targets: () -> Array[Node | Location]
9513 def comment_targets
9514 [] #: Array[Prism::node | Location]
9515 end
9516
9517 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> ImplicitRestNode
9518 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
9519 ImplicitRestNode.new(source, node_id, location, flags)
9520 end
9521
9522 # def deconstruct: () -> Array[Node?]
9523 alias deconstruct child_nodes
9524
9525 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
9526 def deconstruct_keys(keys)
9527 { node_id: node_id, location: location }
9528 end
9529
9530 # def inspect -> String
9531 def inspect
9532 InspectVisitor.compose(self)
9533 end
9534
9535 # Return a symbol representation of this node type. See `Node#type`.
9536 def type
9537 :implicit_rest_node
9538 end
9539
9540 # Return a symbol representation of this node type. See `Node::type`.
9541 def self.type
9542 :implicit_rest_node
9543 end
9544
9545 # Implements case-equality for the node. This is effectively == but without
9546 # comparing the value of locations. Locations are checked only for presence.
9547 def ===(other)
9548 other.is_a?(ImplicitRestNode)
9549 end
9550 end
9551
9552 # Represents the use of the `in` keyword in a case statement.
9553 #
9554 # case a; in b then c end
9555 # ^^^^^^^^^^^
9556 class InNode < Node
9557 # Initialize a new InNode node.
9558 def initialize(source, node_id, location, flags, pattern, statements, in_loc, then_loc)
9559 @source = source
9560 @node_id = node_id
9561 @location = location
9562 @flags = flags
9563 @pattern = pattern
9564 @statements = statements
9565 @in_loc = in_loc
9566 @then_loc = then_loc
9567 end
9568
9569 # def accept: (Visitor visitor) -> void
9570 def accept(visitor)
9571 visitor.visit_in_node(self)
9572 end
9573
9574 # def child_nodes: () -> Array[Node?]
9575 def child_nodes
9576 [pattern, statements]
9577 end
9578
9579 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
9580 def each_child_node
9581 return to_enum(:each_child_node) unless block_given?
9582
9583 yield pattern
9584 yield statements if statements
9585 end
9586
9587 # def compact_child_nodes: () -> Array[Node]
9588 def compact_child_nodes
9589 compact = [] #: Array[Prism::node]
9590 compact << pattern
9591 compact << statements if statements
9592 compact
9593 end
9594
9595 # def comment_targets: () -> Array[Node | Location]
9596 def comment_targets
9597 [pattern, *statements, in_loc, *then_loc] #: Array[Prism::node | Location]
9598 end
9599
9600 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?pattern: Prism::node, ?statements: StatementsNode?, ?in_loc: Location, ?then_loc: Location?) -> InNode
9601 def copy(node_id: self.node_id, location: self.location, flags: self.flags, pattern: self.pattern, statements: self.statements, in_loc: self.in_loc, then_loc: self.then_loc)
9602 InNode.new(source, node_id, location, flags, pattern, statements, in_loc, then_loc)
9603 end
9604
9605 # def deconstruct: () -> Array[Node?]
9606 alias deconstruct child_nodes
9607
9608 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, pattern: Prism::node, statements: StatementsNode?, in_loc: Location, then_loc: Location? }
9609 def deconstruct_keys(keys)
9610 { node_id: node_id, location: location, pattern: pattern, statements: statements, in_loc: in_loc, then_loc: then_loc }
9611 end
9612
9613 # attr_reader pattern: Prism::node
9614 attr_reader :pattern
9615
9616 # attr_reader statements: StatementsNode?
9617 attr_reader :statements
9618
9619 # attr_reader in_loc: Location
9620 def in_loc
9621 location = @in_loc
9622 return location if location.is_a?(Location)
9623 @in_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9624 end
9625
9626 # Save the in_loc location using the given saved source so that
9627 # it can be retrieved later.
9628 def save_in_loc(repository)
9629 repository.enter(node_id, :in_loc)
9630 end
9631
9632 # attr_reader then_loc: Location?
9633 def then_loc
9634 location = @then_loc
9635 case location
9636 when nil
9637 nil
9638 when Location
9639 location
9640 else
9641 @then_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9642 end
9643 end
9644
9645 # Save the then_loc location using the given saved source so that
9646 # it can be retrieved later.
9647 def save_then_loc(repository)
9648 repository.enter(node_id, :then_loc) unless @then_loc.nil?
9649 end
9650
9651 # def in: () -> String
9652 def in
9653 in_loc.slice
9654 end
9655
9656 # def then: () -> String?
9657 def then
9658 then_loc&.slice
9659 end
9660
9661 # def inspect -> String
9662 def inspect
9663 InspectVisitor.compose(self)
9664 end
9665
9666 # Return a symbol representation of this node type. See `Node#type`.
9667 def type
9668 :in_node
9669 end
9670
9671 # Return a symbol representation of this node type. See `Node::type`.
9672 def self.type
9673 :in_node
9674 end
9675
9676 # Implements case-equality for the node. This is effectively == but without
9677 # comparing the value of locations. Locations are checked only for presence.
9678 def ===(other)
9679 other.is_a?(InNode) &&
9680 (pattern === other.pattern) &&
9681 (statements === other.statements) &&
9682 (in_loc.nil? == other.in_loc.nil?) &&
9683 (then_loc.nil? == other.then_loc.nil?)
9684 end
9685 end
9686
9687 # Represents the use of the `&&=` operator on a call to the `[]` method.
9688 #
9689 # foo.bar[baz] &&= value
9690 # ^^^^^^^^^^^^^^^^^^^^^^
9691 class IndexAndWriteNode < Node
9692 # Initialize a new IndexAndWriteNode node.
9693 def initialize(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator_loc, value)
9694 @source = source
9695 @node_id = node_id
9696 @location = location
9697 @flags = flags
9698 @receiver = receiver
9699 @call_operator_loc = call_operator_loc
9700 @opening_loc = opening_loc
9701 @arguments = arguments
9702 @closing_loc = closing_loc
9703 @block = block
9704 @operator_loc = operator_loc
9705 @value = value
9706 end
9707
9708 # def accept: (Visitor visitor) -> void
9709 def accept(visitor)
9710 visitor.visit_index_and_write_node(self)
9711 end
9712
9713 # def child_nodes: () -> Array[Node?]
9714 def child_nodes
9715 [receiver, arguments, block, value]
9716 end
9717
9718 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
9719 def each_child_node
9720 return to_enum(:each_child_node) unless block_given?
9721
9722 yield receiver if receiver
9723 yield arguments if arguments
9724 yield block if block
9725 yield value
9726 end
9727
9728 # def compact_child_nodes: () -> Array[Node]
9729 def compact_child_nodes
9730 compact = [] #: Array[Prism::node]
9731 compact << receiver if receiver
9732 compact << arguments if arguments
9733 compact << block if block
9734 compact << value
9735 compact
9736 end
9737
9738 # def comment_targets: () -> Array[Node | Location]
9739 def comment_targets
9740 [*receiver, *call_operator_loc, opening_loc, *arguments, closing_loc, *block, operator_loc, value] #: Array[Prism::node | Location]
9741 end
9742
9743 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?, ?operator_loc: Location, ?value: Prism::node) -> IndexAndWriteNode
9744 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block, operator_loc: self.operator_loc, value: self.value)
9745 IndexAndWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator_loc, value)
9746 end
9747
9748 # def deconstruct: () -> Array[Node?]
9749 alias deconstruct child_nodes
9750
9751 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, opening_loc: Location, arguments: ArgumentsNode?, closing_loc: Location, block: BlockArgumentNode?, operator_loc: Location, value: Prism::node }
9752 def deconstruct_keys(keys)
9753 { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block, operator_loc: operator_loc, value: value }
9754 end
9755
9756 # def safe_navigation?: () -> bool
9757 def safe_navigation?
9758 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
9759 end
9760
9761 # def variable_call?: () -> bool
9762 def variable_call?
9763 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
9764 end
9765
9766 # def attribute_write?: () -> bool
9767 def attribute_write?
9768 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
9769 end
9770
9771 # def ignore_visibility?: () -> bool
9772 def ignore_visibility?
9773 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
9774 end
9775
9776 # attr_reader receiver: Prism::node?
9777 attr_reader :receiver
9778
9779 # attr_reader call_operator_loc: Location?
9780 def call_operator_loc
9781 location = @call_operator_loc
9782 case location
9783 when nil
9784 nil
9785 when Location
9786 location
9787 else
9788 @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9789 end
9790 end
9791
9792 # Save the call_operator_loc location using the given saved source so that
9793 # it can be retrieved later.
9794 def save_call_operator_loc(repository)
9795 repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
9796 end
9797
9798 # attr_reader opening_loc: Location
9799 def opening_loc
9800 location = @opening_loc
9801 return location if location.is_a?(Location)
9802 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9803 end
9804
9805 # Save the opening_loc location using the given saved source so that
9806 # it can be retrieved later.
9807 def save_opening_loc(repository)
9808 repository.enter(node_id, :opening_loc)
9809 end
9810
9811 # attr_reader arguments: ArgumentsNode?
9812 attr_reader :arguments
9813
9814 # attr_reader closing_loc: Location
9815 def closing_loc
9816 location = @closing_loc
9817 return location if location.is_a?(Location)
9818 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9819 end
9820
9821 # Save the closing_loc location using the given saved source so that
9822 # it can be retrieved later.
9823 def save_closing_loc(repository)
9824 repository.enter(node_id, :closing_loc)
9825 end
9826
9827 # attr_reader block: BlockArgumentNode?
9828 attr_reader :block
9829
9830 # attr_reader operator_loc: Location
9831 def operator_loc
9832 location = @operator_loc
9833 return location if location.is_a?(Location)
9834 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
9835 end
9836
9837 # Save the operator_loc location using the given saved source so that
9838 # it can be retrieved later.
9839 def save_operator_loc(repository)
9840 repository.enter(node_id, :operator_loc)
9841 end
9842
9843 # attr_reader value: Prism::node
9844 attr_reader :value
9845
9846 # def call_operator: () -> String?
9847 def call_operator
9848 call_operator_loc&.slice
9849 end
9850
9851 # def opening: () -> String
9852 def opening
9853 opening_loc.slice
9854 end
9855
9856 # def closing: () -> String
9857 def closing
9858 closing_loc.slice
9859 end
9860
9861 # def operator: () -> String
9862 def operator
9863 operator_loc.slice
9864 end
9865
9866 # def inspect -> String
9867 def inspect
9868 InspectVisitor.compose(self)
9869 end
9870
9871 # Return a symbol representation of this node type. See `Node#type`.
9872 def type
9873 :index_and_write_node
9874 end
9875
9876 # Return a symbol representation of this node type. See `Node::type`.
9877 def self.type
9878 :index_and_write_node
9879 end
9880
9881 # Implements case-equality for the node. This is effectively == but without
9882 # comparing the value of locations. Locations are checked only for presence.
9883 def ===(other)
9884 other.is_a?(IndexAndWriteNode) &&
9885 (flags === other.flags) &&
9886 (receiver === other.receiver) &&
9887 (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
9888 (opening_loc.nil? == other.opening_loc.nil?) &&
9889 (arguments === other.arguments) &&
9890 (closing_loc.nil? == other.closing_loc.nil?) &&
9891 (block === other.block) &&
9892 (operator_loc.nil? == other.operator_loc.nil?) &&
9893 (value === other.value)
9894 end
9895 end
9896
9897 # Represents the use of an assignment operator on a call to `[]`.
9898 #
9899 # foo.bar[baz] += value
9900 # ^^^^^^^^^^^^^^^^^^^^^
9901 class IndexOperatorWriteNode < Node
9902 # Initialize a new IndexOperatorWriteNode node.
9903 def initialize(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, binary_operator, binary_operator_loc, value)
9904 @source = source
9905 @node_id = node_id
9906 @location = location
9907 @flags = flags
9908 @receiver = receiver
9909 @call_operator_loc = call_operator_loc
9910 @opening_loc = opening_loc
9911 @arguments = arguments
9912 @closing_loc = closing_loc
9913 @block = block
9914 @binary_operator = binary_operator
9915 @binary_operator_loc = binary_operator_loc
9916 @value = value
9917 end
9918
9919 # def accept: (Visitor visitor) -> void
9920 def accept(visitor)
9921 visitor.visit_index_operator_write_node(self)
9922 end
9923
9924 # def child_nodes: () -> Array[Node?]
9925 def child_nodes
9926 [receiver, arguments, block, value]
9927 end
9928
9929 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
9930 def each_child_node
9931 return to_enum(:each_child_node) unless block_given?
9932
9933 yield receiver if receiver
9934 yield arguments if arguments
9935 yield block if block
9936 yield value
9937 end
9938
9939 # def compact_child_nodes: () -> Array[Node]
9940 def compact_child_nodes
9941 compact = [] #: Array[Prism::node]
9942 compact << receiver if receiver
9943 compact << arguments if arguments
9944 compact << block if block
9945 compact << value
9946 compact
9947 end
9948
9949 # def comment_targets: () -> Array[Node | Location]
9950 def comment_targets
9951 [*receiver, *call_operator_loc, opening_loc, *arguments, closing_loc, *block, binary_operator_loc, value] #: Array[Prism::node | Location]
9952 end
9953
9954 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?, ?binary_operator: Symbol, ?binary_operator_loc: Location, ?value: Prism::node) -> IndexOperatorWriteNode
9955 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block, binary_operator: self.binary_operator, binary_operator_loc: self.binary_operator_loc, value: self.value)
9956 IndexOperatorWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, binary_operator, binary_operator_loc, value)
9957 end
9958
9959 # def deconstruct: () -> Array[Node?]
9960 alias deconstruct child_nodes
9961
9962 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, opening_loc: Location, arguments: ArgumentsNode?, closing_loc: Location, block: BlockArgumentNode?, binary_operator: Symbol, binary_operator_loc: Location, value: Prism::node }
9963 def deconstruct_keys(keys)
9964 { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block, binary_operator: binary_operator, binary_operator_loc: binary_operator_loc, value: value }
9965 end
9966
9967 # def safe_navigation?: () -> bool
9968 def safe_navigation?
9969 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
9970 end
9971
9972 # def variable_call?: () -> bool
9973 def variable_call?
9974 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
9975 end
9976
9977 # def attribute_write?: () -> bool
9978 def attribute_write?
9979 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
9980 end
9981
9982 # def ignore_visibility?: () -> bool
9983 def ignore_visibility?
9984 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
9985 end
9986
9987 # attr_reader receiver: Prism::node?
9988 attr_reader :receiver
9989
9990 # attr_reader call_operator_loc: Location?
9991 def call_operator_loc
9992 location = @call_operator_loc
9993 case location
9994 when nil
9995 nil
9996 when Location
9997 location
9998 else
9999 @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10000 end
10001 end
10002
10003 # Save the call_operator_loc location using the given saved source so that
10004 # it can be retrieved later.
10005 def save_call_operator_loc(repository)
10006 repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
10007 end
10008
10009 # attr_reader opening_loc: Location
10010 def opening_loc
10011 location = @opening_loc
10012 return location if location.is_a?(Location)
10013 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10014 end
10015
10016 # Save the opening_loc location using the given saved source so that
10017 # it can be retrieved later.
10018 def save_opening_loc(repository)
10019 repository.enter(node_id, :opening_loc)
10020 end
10021
10022 # attr_reader arguments: ArgumentsNode?
10023 attr_reader :arguments
10024
10025 # attr_reader closing_loc: Location
10026 def closing_loc
10027 location = @closing_loc
10028 return location if location.is_a?(Location)
10029 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10030 end
10031
10032 # Save the closing_loc location using the given saved source so that
10033 # it can be retrieved later.
10034 def save_closing_loc(repository)
10035 repository.enter(node_id, :closing_loc)
10036 end
10037
10038 # attr_reader block: BlockArgumentNode?
10039 attr_reader :block
10040
10041 # attr_reader binary_operator: Symbol
10042 attr_reader :binary_operator
10043
10044 # attr_reader binary_operator_loc: Location
10045 def binary_operator_loc
10046 location = @binary_operator_loc
10047 return location if location.is_a?(Location)
10048 @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10049 end
10050
10051 # Save the binary_operator_loc location using the given saved source so that
10052 # it can be retrieved later.
10053 def save_binary_operator_loc(repository)
10054 repository.enter(node_id, :binary_operator_loc)
10055 end
10056
10057 # attr_reader value: Prism::node
10058 attr_reader :value
10059
10060 # def call_operator: () -> String?
10061 def call_operator
10062 call_operator_loc&.slice
10063 end
10064
10065 # def opening: () -> String
10066 def opening
10067 opening_loc.slice
10068 end
10069
10070 # def closing: () -> String
10071 def closing
10072 closing_loc.slice
10073 end
10074
10075 # def inspect -> String
10076 def inspect
10077 InspectVisitor.compose(self)
10078 end
10079
10080 # Return a symbol representation of this node type. See `Node#type`.
10081 def type
10082 :index_operator_write_node
10083 end
10084
10085 # Return a symbol representation of this node type. See `Node::type`.
10086 def self.type
10087 :index_operator_write_node
10088 end
10089
10090 # Implements case-equality for the node. This is effectively == but without
10091 # comparing the value of locations. Locations are checked only for presence.
10092 def ===(other)
10093 other.is_a?(IndexOperatorWriteNode) &&
10094 (flags === other.flags) &&
10095 (receiver === other.receiver) &&
10096 (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
10097 (opening_loc.nil? == other.opening_loc.nil?) &&
10098 (arguments === other.arguments) &&
10099 (closing_loc.nil? == other.closing_loc.nil?) &&
10100 (block === other.block) &&
10101 (binary_operator === other.binary_operator) &&
10102 (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
10103 (value === other.value)
10104 end
10105 end
10106
10107 # Represents the use of the `||=` operator on a call to `[]`.
10108 #
10109 # foo.bar[baz] ||= value
10110 # ^^^^^^^^^^^^^^^^^^^^^^
10111 class IndexOrWriteNode < Node
10112 # Initialize a new IndexOrWriteNode node.
10113 def initialize(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator_loc, value)
10114 @source = source
10115 @node_id = node_id
10116 @location = location
10117 @flags = flags
10118 @receiver = receiver
10119 @call_operator_loc = call_operator_loc
10120 @opening_loc = opening_loc
10121 @arguments = arguments
10122 @closing_loc = closing_loc
10123 @block = block
10124 @operator_loc = operator_loc
10125 @value = value
10126 end
10127
10128 # def accept: (Visitor visitor) -> void
10129 def accept(visitor)
10130 visitor.visit_index_or_write_node(self)
10131 end
10132
10133 # def child_nodes: () -> Array[Node?]
10134 def child_nodes
10135 [receiver, arguments, block, value]
10136 end
10137
10138 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
10139 def each_child_node
10140 return to_enum(:each_child_node) unless block_given?
10141
10142 yield receiver if receiver
10143 yield arguments if arguments
10144 yield block if block
10145 yield value
10146 end
10147
10148 # def compact_child_nodes: () -> Array[Node]
10149 def compact_child_nodes
10150 compact = [] #: Array[Prism::node]
10151 compact << receiver if receiver
10152 compact << arguments if arguments
10153 compact << block if block
10154 compact << value
10155 compact
10156 end
10157
10158 # def comment_targets: () -> Array[Node | Location]
10159 def comment_targets
10160 [*receiver, *call_operator_loc, opening_loc, *arguments, closing_loc, *block, operator_loc, value] #: Array[Prism::node | Location]
10161 end
10162
10163 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?, ?operator_loc: Location, ?value: Prism::node) -> IndexOrWriteNode
10164 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block, operator_loc: self.operator_loc, value: self.value)
10165 IndexOrWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator_loc, value)
10166 end
10167
10168 # def deconstruct: () -> Array[Node?]
10169 alias deconstruct child_nodes
10170
10171 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, opening_loc: Location, arguments: ArgumentsNode?, closing_loc: Location, block: BlockArgumentNode?, operator_loc: Location, value: Prism::node }
10172 def deconstruct_keys(keys)
10173 { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block, operator_loc: operator_loc, value: value }
10174 end
10175
10176 # def safe_navigation?: () -> bool
10177 def safe_navigation?
10178 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
10179 end
10180
10181 # def variable_call?: () -> bool
10182 def variable_call?
10183 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
10184 end
10185
10186 # def attribute_write?: () -> bool
10187 def attribute_write?
10188 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
10189 end
10190
10191 # def ignore_visibility?: () -> bool
10192 def ignore_visibility?
10193 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
10194 end
10195
10196 # attr_reader receiver: Prism::node?
10197 attr_reader :receiver
10198
10199 # attr_reader call_operator_loc: Location?
10200 def call_operator_loc
10201 location = @call_operator_loc
10202 case location
10203 when nil
10204 nil
10205 when Location
10206 location
10207 else
10208 @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10209 end
10210 end
10211
10212 # Save the call_operator_loc location using the given saved source so that
10213 # it can be retrieved later.
10214 def save_call_operator_loc(repository)
10215 repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
10216 end
10217
10218 # attr_reader opening_loc: Location
10219 def opening_loc
10220 location = @opening_loc
10221 return location if location.is_a?(Location)
10222 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10223 end
10224
10225 # Save the opening_loc location using the given saved source so that
10226 # it can be retrieved later.
10227 def save_opening_loc(repository)
10228 repository.enter(node_id, :opening_loc)
10229 end
10230
10231 # attr_reader arguments: ArgumentsNode?
10232 attr_reader :arguments
10233
10234 # attr_reader closing_loc: Location
10235 def closing_loc
10236 location = @closing_loc
10237 return location if location.is_a?(Location)
10238 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10239 end
10240
10241 # Save the closing_loc location using the given saved source so that
10242 # it can be retrieved later.
10243 def save_closing_loc(repository)
10244 repository.enter(node_id, :closing_loc)
10245 end
10246
10247 # attr_reader block: BlockArgumentNode?
10248 attr_reader :block
10249
10250 # attr_reader operator_loc: Location
10251 def operator_loc
10252 location = @operator_loc
10253 return location if location.is_a?(Location)
10254 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10255 end
10256
10257 # Save the operator_loc location using the given saved source so that
10258 # it can be retrieved later.
10259 def save_operator_loc(repository)
10260 repository.enter(node_id, :operator_loc)
10261 end
10262
10263 # attr_reader value: Prism::node
10264 attr_reader :value
10265
10266 # def call_operator: () -> String?
10267 def call_operator
10268 call_operator_loc&.slice
10269 end
10270
10271 # def opening: () -> String
10272 def opening
10273 opening_loc.slice
10274 end
10275
10276 # def closing: () -> String
10277 def closing
10278 closing_loc.slice
10279 end
10280
10281 # def operator: () -> String
10282 def operator
10283 operator_loc.slice
10284 end
10285
10286 # def inspect -> String
10287 def inspect
10288 InspectVisitor.compose(self)
10289 end
10290
10291 # Return a symbol representation of this node type. See `Node#type`.
10292 def type
10293 :index_or_write_node
10294 end
10295
10296 # Return a symbol representation of this node type. See `Node::type`.
10297 def self.type
10298 :index_or_write_node
10299 end
10300
10301 # Implements case-equality for the node. This is effectively == but without
10302 # comparing the value of locations. Locations are checked only for presence.
10303 def ===(other)
10304 other.is_a?(IndexOrWriteNode) &&
10305 (flags === other.flags) &&
10306 (receiver === other.receiver) &&
10307 (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
10308 (opening_loc.nil? == other.opening_loc.nil?) &&
10309 (arguments === other.arguments) &&
10310 (closing_loc.nil? == other.closing_loc.nil?) &&
10311 (block === other.block) &&
10312 (operator_loc.nil? == other.operator_loc.nil?) &&
10313 (value === other.value)
10314 end
10315 end
10316
10317 # Represents assigning to an index.
10318 #
10319 # foo[bar], = 1
10320 # ^^^^^^^^
10321 #
10322 # begin
10323 # rescue => foo[bar]
10324 # ^^^^^^^^
10325 # end
10326 #
10327 # for foo[bar] in baz do end
10328 # ^^^^^^^^
10329 class IndexTargetNode < Node
10330 # Initialize a new IndexTargetNode node.
10331 def initialize(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block)
10332 @source = source
10333 @node_id = node_id
10334 @location = location
10335 @flags = flags
10336 @receiver = receiver
10337 @opening_loc = opening_loc
10338 @arguments = arguments
10339 @closing_loc = closing_loc
10340 @block = block
10341 end
10342
10343 # def accept: (Visitor visitor) -> void
10344 def accept(visitor)
10345 visitor.visit_index_target_node(self)
10346 end
10347
10348 # def child_nodes: () -> Array[Node?]
10349 def child_nodes
10350 [receiver, arguments, block]
10351 end
10352
10353 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
10354 def each_child_node
10355 return to_enum(:each_child_node) unless block_given?
10356
10357 yield receiver
10358 yield arguments if arguments
10359 yield block if block
10360 end
10361
10362 # def compact_child_nodes: () -> Array[Node]
10363 def compact_child_nodes
10364 compact = [] #: Array[Prism::node]
10365 compact << receiver
10366 compact << arguments if arguments
10367 compact << block if block
10368 compact
10369 end
10370
10371 # def comment_targets: () -> Array[Node | Location]
10372 def comment_targets
10373 [receiver, opening_loc, *arguments, closing_loc, *block] #: Array[Prism::node | Location]
10374 end
10375
10376 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?) -> IndexTargetNode
10377 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block)
10378 IndexTargetNode.new(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block)
10379 end
10380
10381 # def deconstruct: () -> Array[Node?]
10382 alias deconstruct child_nodes
10383
10384 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, receiver: Prism::node, opening_loc: Location, arguments: ArgumentsNode?, closing_loc: Location, block: BlockArgumentNode? }
10385 def deconstruct_keys(keys)
10386 { node_id: node_id, location: location, receiver: receiver, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block }
10387 end
10388
10389 # def safe_navigation?: () -> bool
10390 def safe_navigation?
10391 flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
10392 end
10393
10394 # def variable_call?: () -> bool
10395 def variable_call?
10396 flags.anybits?(CallNodeFlags::VARIABLE_CALL)
10397 end
10398
10399 # def attribute_write?: () -> bool
10400 def attribute_write?
10401 flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
10402 end
10403
10404 # def ignore_visibility?: () -> bool
10405 def ignore_visibility?
10406 flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
10407 end
10408
10409 # attr_reader receiver: Prism::node
10410 attr_reader :receiver
10411
10412 # attr_reader opening_loc: Location
10413 def opening_loc
10414 location = @opening_loc
10415 return location if location.is_a?(Location)
10416 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10417 end
10418
10419 # Save the opening_loc location using the given saved source so that
10420 # it can be retrieved later.
10421 def save_opening_loc(repository)
10422 repository.enter(node_id, :opening_loc)
10423 end
10424
10425 # attr_reader arguments: ArgumentsNode?
10426 attr_reader :arguments
10427
10428 # attr_reader closing_loc: Location
10429 def closing_loc
10430 location = @closing_loc
10431 return location if location.is_a?(Location)
10432 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10433 end
10434
10435 # Save the closing_loc location using the given saved source so that
10436 # it can be retrieved later.
10437 def save_closing_loc(repository)
10438 repository.enter(node_id, :closing_loc)
10439 end
10440
10441 # attr_reader block: BlockArgumentNode?
10442 attr_reader :block
10443
10444 # def opening: () -> String
10445 def opening
10446 opening_loc.slice
10447 end
10448
10449 # def closing: () -> String
10450 def closing
10451 closing_loc.slice
10452 end
10453
10454 # def inspect -> String
10455 def inspect
10456 InspectVisitor.compose(self)
10457 end
10458
10459 # Return a symbol representation of this node type. See `Node#type`.
10460 def type
10461 :index_target_node
10462 end
10463
10464 # Return a symbol representation of this node type. See `Node::type`.
10465 def self.type
10466 :index_target_node
10467 end
10468
10469 # Implements case-equality for the node. This is effectively == but without
10470 # comparing the value of locations. Locations are checked only for presence.
10471 def ===(other)
10472 other.is_a?(IndexTargetNode) &&
10473 (flags === other.flags) &&
10474 (receiver === other.receiver) &&
10475 (opening_loc.nil? == other.opening_loc.nil?) &&
10476 (arguments === other.arguments) &&
10477 (closing_loc.nil? == other.closing_loc.nil?) &&
10478 (block === other.block)
10479 end
10480 end
10481
10482 # Represents the use of the `&&=` operator for assignment to an instance variable.
10483 #
10484 # @target &&= value
10485 # ^^^^^^^^^^^^^^^^^
10486 class InstanceVariableAndWriteNode < Node
10487 # Initialize a new InstanceVariableAndWriteNode node.
10488 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
10489 @source = source
10490 @node_id = node_id
10491 @location = location
10492 @flags = flags
10493 @name = name
10494 @name_loc = name_loc
10495 @operator_loc = operator_loc
10496 @value = value
10497 end
10498
10499 # def accept: (Visitor visitor) -> void
10500 def accept(visitor)
10501 visitor.visit_instance_variable_and_write_node(self)
10502 end
10503
10504 # def child_nodes: () -> Array[Node?]
10505 def child_nodes
10506 [value]
10507 end
10508
10509 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
10510 def each_child_node
10511 return to_enum(:each_child_node) unless block_given?
10512
10513 yield value
10514 end
10515
10516 # def compact_child_nodes: () -> Array[Node]
10517 def compact_child_nodes
10518 [value]
10519 end
10520
10521 # def comment_targets: () -> Array[Node | Location]
10522 def comment_targets
10523 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
10524 end
10525
10526 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> InstanceVariableAndWriteNode
10527 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
10528 InstanceVariableAndWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
10529 end
10530
10531 # def deconstruct: () -> Array[Node?]
10532 alias deconstruct child_nodes
10533
10534 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
10535 def deconstruct_keys(keys)
10536 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
10537 end
10538
10539 # attr_reader name: Symbol
10540 attr_reader :name
10541
10542 # attr_reader name_loc: Location
10543 def name_loc
10544 location = @name_loc
10545 return location if location.is_a?(Location)
10546 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10547 end
10548
10549 # Save the name_loc location using the given saved source so that
10550 # it can be retrieved later.
10551 def save_name_loc(repository)
10552 repository.enter(node_id, :name_loc)
10553 end
10554
10555 # attr_reader operator_loc: Location
10556 def operator_loc
10557 location = @operator_loc
10558 return location if location.is_a?(Location)
10559 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10560 end
10561
10562 # Save the operator_loc location using the given saved source so that
10563 # it can be retrieved later.
10564 def save_operator_loc(repository)
10565 repository.enter(node_id, :operator_loc)
10566 end
10567
10568 # attr_reader value: Prism::node
10569 attr_reader :value
10570
10571 # def operator: () -> String
10572 def operator
10573 operator_loc.slice
10574 end
10575
10576 # def inspect -> String
10577 def inspect
10578 InspectVisitor.compose(self)
10579 end
10580
10581 # Return a symbol representation of this node type. See `Node#type`.
10582 def type
10583 :instance_variable_and_write_node
10584 end
10585
10586 # Return a symbol representation of this node type. See `Node::type`.
10587 def self.type
10588 :instance_variable_and_write_node
10589 end
10590
10591 # Implements case-equality for the node. This is effectively == but without
10592 # comparing the value of locations. Locations are checked only for presence.
10593 def ===(other)
10594 other.is_a?(InstanceVariableAndWriteNode) &&
10595 (name === other.name) &&
10596 (name_loc.nil? == other.name_loc.nil?) &&
10597 (operator_loc.nil? == other.operator_loc.nil?) &&
10598 (value === other.value)
10599 end
10600 end
10601
10602 # Represents assigning to an instance variable using an operator that isn't `=`.
10603 #
10604 # @target += value
10605 # ^^^^^^^^^^^^^^^^
10606 class InstanceVariableOperatorWriteNode < Node
10607 # Initialize a new InstanceVariableOperatorWriteNode node.
10608 def initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
10609 @source = source
10610 @node_id = node_id
10611 @location = location
10612 @flags = flags
10613 @name = name
10614 @name_loc = name_loc
10615 @binary_operator_loc = binary_operator_loc
10616 @value = value
10617 @binary_operator = binary_operator
10618 end
10619
10620 # def accept: (Visitor visitor) -> void
10621 def accept(visitor)
10622 visitor.visit_instance_variable_operator_write_node(self)
10623 end
10624
10625 # def child_nodes: () -> Array[Node?]
10626 def child_nodes
10627 [value]
10628 end
10629
10630 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
10631 def each_child_node
10632 return to_enum(:each_child_node) unless block_given?
10633
10634 yield value
10635 end
10636
10637 # def compact_child_nodes: () -> Array[Node]
10638 def compact_child_nodes
10639 [value]
10640 end
10641
10642 # def comment_targets: () -> Array[Node | Location]
10643 def comment_targets
10644 [name_loc, binary_operator_loc, value] #: Array[Prism::node | Location]
10645 end
10646
10647 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?binary_operator_loc: Location, ?value: Prism::node, ?binary_operator: Symbol) -> InstanceVariableOperatorWriteNode
10648 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
10649 InstanceVariableOperatorWriteNode.new(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
10650 end
10651
10652 # def deconstruct: () -> Array[Node?]
10653 alias deconstruct child_nodes
10654
10655 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Prism::node, binary_operator: Symbol }
10656 def deconstruct_keys(keys)
10657 { node_id: node_id, location: location, name: name, name_loc: name_loc, binary_operator_loc: binary_operator_loc, value: value, binary_operator: binary_operator }
10658 end
10659
10660 # attr_reader name: Symbol
10661 attr_reader :name
10662
10663 # attr_reader name_loc: Location
10664 def name_loc
10665 location = @name_loc
10666 return location if location.is_a?(Location)
10667 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10668 end
10669
10670 # Save the name_loc location using the given saved source so that
10671 # it can be retrieved later.
10672 def save_name_loc(repository)
10673 repository.enter(node_id, :name_loc)
10674 end
10675
10676 # attr_reader binary_operator_loc: Location
10677 def binary_operator_loc
10678 location = @binary_operator_loc
10679 return location if location.is_a?(Location)
10680 @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10681 end
10682
10683 # Save the binary_operator_loc location using the given saved source so that
10684 # it can be retrieved later.
10685 def save_binary_operator_loc(repository)
10686 repository.enter(node_id, :binary_operator_loc)
10687 end
10688
10689 # attr_reader value: Prism::node
10690 attr_reader :value
10691
10692 # attr_reader binary_operator: Symbol
10693 attr_reader :binary_operator
10694
10695 # def inspect -> String
10696 def inspect
10697 InspectVisitor.compose(self)
10698 end
10699
10700 # Return a symbol representation of this node type. See `Node#type`.
10701 def type
10702 :instance_variable_operator_write_node
10703 end
10704
10705 # Return a symbol representation of this node type. See `Node::type`.
10706 def self.type
10707 :instance_variable_operator_write_node
10708 end
10709
10710 # Implements case-equality for the node. This is effectively == but without
10711 # comparing the value of locations. Locations are checked only for presence.
10712 def ===(other)
10713 other.is_a?(InstanceVariableOperatorWriteNode) &&
10714 (name === other.name) &&
10715 (name_loc.nil? == other.name_loc.nil?) &&
10716 (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
10717 (value === other.value) &&
10718 (binary_operator === other.binary_operator)
10719 end
10720 end
10721
10722 # Represents the use of the `||=` operator for assignment to an instance variable.
10723 #
10724 # @target ||= value
10725 # ^^^^^^^^^^^^^^^^^
10726 class InstanceVariableOrWriteNode < Node
10727 # Initialize a new InstanceVariableOrWriteNode node.
10728 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
10729 @source = source
10730 @node_id = node_id
10731 @location = location
10732 @flags = flags
10733 @name = name
10734 @name_loc = name_loc
10735 @operator_loc = operator_loc
10736 @value = value
10737 end
10738
10739 # def accept: (Visitor visitor) -> void
10740 def accept(visitor)
10741 visitor.visit_instance_variable_or_write_node(self)
10742 end
10743
10744 # def child_nodes: () -> Array[Node?]
10745 def child_nodes
10746 [value]
10747 end
10748
10749 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
10750 def each_child_node
10751 return to_enum(:each_child_node) unless block_given?
10752
10753 yield value
10754 end
10755
10756 # def compact_child_nodes: () -> Array[Node]
10757 def compact_child_nodes
10758 [value]
10759 end
10760
10761 # def comment_targets: () -> Array[Node | Location]
10762 def comment_targets
10763 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
10764 end
10765
10766 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> InstanceVariableOrWriteNode
10767 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
10768 InstanceVariableOrWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
10769 end
10770
10771 # def deconstruct: () -> Array[Node?]
10772 alias deconstruct child_nodes
10773
10774 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
10775 def deconstruct_keys(keys)
10776 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
10777 end
10778
10779 # attr_reader name: Symbol
10780 attr_reader :name
10781
10782 # attr_reader name_loc: Location
10783 def name_loc
10784 location = @name_loc
10785 return location if location.is_a?(Location)
10786 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10787 end
10788
10789 # Save the name_loc location using the given saved source so that
10790 # it can be retrieved later.
10791 def save_name_loc(repository)
10792 repository.enter(node_id, :name_loc)
10793 end
10794
10795 # attr_reader operator_loc: Location
10796 def operator_loc
10797 location = @operator_loc
10798 return location if location.is_a?(Location)
10799 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
10800 end
10801
10802 # Save the operator_loc location using the given saved source so that
10803 # it can be retrieved later.
10804 def save_operator_loc(repository)
10805 repository.enter(node_id, :operator_loc)
10806 end
10807
10808 # attr_reader value: Prism::node
10809 attr_reader :value
10810
10811 # def operator: () -> String
10812 def operator
10813 operator_loc.slice
10814 end
10815
10816 # def inspect -> String
10817 def inspect
10818 InspectVisitor.compose(self)
10819 end
10820
10821 # Return a symbol representation of this node type. See `Node#type`.
10822 def type
10823 :instance_variable_or_write_node
10824 end
10825
10826 # Return a symbol representation of this node type. See `Node::type`.
10827 def self.type
10828 :instance_variable_or_write_node
10829 end
10830
10831 # Implements case-equality for the node. This is effectively == but without
10832 # comparing the value of locations. Locations are checked only for presence.
10833 def ===(other)
10834 other.is_a?(InstanceVariableOrWriteNode) &&
10835 (name === other.name) &&
10836 (name_loc.nil? == other.name_loc.nil?) &&
10837 (operator_loc.nil? == other.operator_loc.nil?) &&
10838 (value === other.value)
10839 end
10840 end
10841
10842 # Represents referencing an instance variable.
10843 #
10844 # @foo
10845 # ^^^^
10846 class InstanceVariableReadNode < Node
10847 # Initialize a new InstanceVariableReadNode node.
10848 def initialize(source, node_id, location, flags, name)
10849 @source = source
10850 @node_id = node_id
10851 @location = location
10852 @flags = flags
10853 @name = name
10854 end
10855
10856 # def accept: (Visitor visitor) -> void
10857 def accept(visitor)
10858 visitor.visit_instance_variable_read_node(self)
10859 end
10860
10861 # def child_nodes: () -> Array[Node?]
10862 def child_nodes
10863 []
10864 end
10865
10866 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
10867 def each_child_node
10868 return to_enum(:each_child_node) unless block_given?
10869
10870 end
10871
10872 # def compact_child_nodes: () -> Array[Node]
10873 def compact_child_nodes
10874 []
10875 end
10876
10877 # def comment_targets: () -> Array[Node | Location]
10878 def comment_targets
10879 [] #: Array[Prism::node | Location]
10880 end
10881
10882 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> InstanceVariableReadNode
10883 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
10884 InstanceVariableReadNode.new(source, node_id, location, flags, name)
10885 end
10886
10887 # def deconstruct: () -> Array[Node?]
10888 alias deconstruct child_nodes
10889
10890 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
10891 def deconstruct_keys(keys)
10892 { node_id: node_id, location: location, name: name }
10893 end
10894
10895 # The name of the instance variable, which is a `@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
10896 #
10897 # @x # name `:@x`
10898 #
10899 # @_test # name `:@_test`
10900 attr_reader :name
10901
10902 # def inspect -> String
10903 def inspect
10904 InspectVisitor.compose(self)
10905 end
10906
10907 # Return a symbol representation of this node type. See `Node#type`.
10908 def type
10909 :instance_variable_read_node
10910 end
10911
10912 # Return a symbol representation of this node type. See `Node::type`.
10913 def self.type
10914 :instance_variable_read_node
10915 end
10916
10917 # Implements case-equality for the node. This is effectively == but without
10918 # comparing the value of locations. Locations are checked only for presence.
10919 def ===(other)
10920 other.is_a?(InstanceVariableReadNode) &&
10921 (name === other.name)
10922 end
10923 end
10924
10925 # Represents writing to an instance variable in a context that doesn't have an explicit value.
10926 #
10927 # @foo, @bar = baz
10928 # ^^^^ ^^^^
10929 class InstanceVariableTargetNode < Node
10930 # Initialize a new InstanceVariableTargetNode node.
10931 def initialize(source, node_id, location, flags, name)
10932 @source = source
10933 @node_id = node_id
10934 @location = location
10935 @flags = flags
10936 @name = name
10937 end
10938
10939 # def accept: (Visitor visitor) -> void
10940 def accept(visitor)
10941 visitor.visit_instance_variable_target_node(self)
10942 end
10943
10944 # def child_nodes: () -> Array[Node?]
10945 def child_nodes
10946 []
10947 end
10948
10949 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
10950 def each_child_node
10951 return to_enum(:each_child_node) unless block_given?
10952
10953 end
10954
10955 # def compact_child_nodes: () -> Array[Node]
10956 def compact_child_nodes
10957 []
10958 end
10959
10960 # def comment_targets: () -> Array[Node | Location]
10961 def comment_targets
10962 [] #: Array[Prism::node | Location]
10963 end
10964
10965 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> InstanceVariableTargetNode
10966 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
10967 InstanceVariableTargetNode.new(source, node_id, location, flags, name)
10968 end
10969
10970 # def deconstruct: () -> Array[Node?]
10971 alias deconstruct child_nodes
10972
10973 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
10974 def deconstruct_keys(keys)
10975 { node_id: node_id, location: location, name: name }
10976 end
10977
10978 # attr_reader name: Symbol
10979 attr_reader :name
10980
10981 # def inspect -> String
10982 def inspect
10983 InspectVisitor.compose(self)
10984 end
10985
10986 # Return a symbol representation of this node type. See `Node#type`.
10987 def type
10988 :instance_variable_target_node
10989 end
10990
10991 # Return a symbol representation of this node type. See `Node::type`.
10992 def self.type
10993 :instance_variable_target_node
10994 end
10995
10996 # Implements case-equality for the node. This is effectively == but without
10997 # comparing the value of locations. Locations are checked only for presence.
10998 def ===(other)
10999 other.is_a?(InstanceVariableTargetNode) &&
11000 (name === other.name)
11001 end
11002 end
11003
11004 # Represents writing to an instance variable.
11005 #
11006 # @foo = 1
11007 # ^^^^^^^^
11008 class InstanceVariableWriteNode < Node
11009 # Initialize a new InstanceVariableWriteNode node.
11010 def initialize(source, node_id, location, flags, name, name_loc, value, operator_loc)
11011 @source = source
11012 @node_id = node_id
11013 @location = location
11014 @flags = flags
11015 @name = name
11016 @name_loc = name_loc
11017 @value = value
11018 @operator_loc = operator_loc
11019 end
11020
11021 # def accept: (Visitor visitor) -> void
11022 def accept(visitor)
11023 visitor.visit_instance_variable_write_node(self)
11024 end
11025
11026 # def child_nodes: () -> Array[Node?]
11027 def child_nodes
11028 [value]
11029 end
11030
11031 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
11032 def each_child_node
11033 return to_enum(:each_child_node) unless block_given?
11034
11035 yield value
11036 end
11037
11038 # def compact_child_nodes: () -> Array[Node]
11039 def compact_child_nodes
11040 [value]
11041 end
11042
11043 # def comment_targets: () -> Array[Node | Location]
11044 def comment_targets
11045 [name_loc, value, operator_loc] #: Array[Prism::node | Location]
11046 end
11047
11048 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?value: Prism::node, ?operator_loc: Location) -> InstanceVariableWriteNode
11049 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, value: self.value, operator_loc: self.operator_loc)
11050 InstanceVariableWriteNode.new(source, node_id, location, flags, name, name_loc, value, operator_loc)
11051 end
11052
11053 # def deconstruct: () -> Array[Node?]
11054 alias deconstruct child_nodes
11055
11056 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, value: Prism::node, operator_loc: Location }
11057 def deconstruct_keys(keys)
11058 { node_id: node_id, location: location, name: name, name_loc: name_loc, value: value, operator_loc: operator_loc }
11059 end
11060
11061 # The name of the instance variable, which is a `@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
11062 #
11063 # @x = :y # name `:@x`
11064 #
11065 # @_foo = "bar" # name `@_foo`
11066 attr_reader :name
11067
11068 # The location of the variable name.
11069 #
11070 # @_x = 1
11071 # ^^^
11072 def name_loc
11073 location = @name_loc
11074 return location if location.is_a?(Location)
11075 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11076 end
11077
11078 # Save the name_loc location using the given saved source so that
11079 # it can be retrieved later.
11080 def save_name_loc(repository)
11081 repository.enter(node_id, :name_loc)
11082 end
11083
11084 # The value to write to the instance variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
11085 #
11086 # @foo = :bar
11087 # ^^^^
11088 #
11089 # @_x = 1234
11090 # ^^^^
11091 attr_reader :value
11092
11093 # The location of the `=` operator.
11094 #
11095 # @x = y
11096 # ^
11097 def operator_loc
11098 location = @operator_loc
11099 return location if location.is_a?(Location)
11100 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11101 end
11102
11103 # Save the operator_loc location using the given saved source so that
11104 # it can be retrieved later.
11105 def save_operator_loc(repository)
11106 repository.enter(node_id, :operator_loc)
11107 end
11108
11109 # def operator: () -> String
11110 def operator
11111 operator_loc.slice
11112 end
11113
11114 # def inspect -> String
11115 def inspect
11116 InspectVisitor.compose(self)
11117 end
11118
11119 # Return a symbol representation of this node type. See `Node#type`.
11120 def type
11121 :instance_variable_write_node
11122 end
11123
11124 # Return a symbol representation of this node type. See `Node::type`.
11125 def self.type
11126 :instance_variable_write_node
11127 end
11128
11129 # Implements case-equality for the node. This is effectively == but without
11130 # comparing the value of locations. Locations are checked only for presence.
11131 def ===(other)
11132 other.is_a?(InstanceVariableWriteNode) &&
11133 (name === other.name) &&
11134 (name_loc.nil? == other.name_loc.nil?) &&
11135 (value === other.value) &&
11136 (operator_loc.nil? == other.operator_loc.nil?)
11137 end
11138 end
11139
11140 # Represents an integer number literal.
11141 #
11142 # 1
11143 # ^
11144 class IntegerNode < Node
11145 # Initialize a new IntegerNode node.
11146 def initialize(source, node_id, location, flags, value)
11147 @source = source
11148 @node_id = node_id
11149 @location = location
11150 @flags = flags
11151 @value = value
11152 end
11153
11154 # def accept: (Visitor visitor) -> void
11155 def accept(visitor)
11156 visitor.visit_integer_node(self)
11157 end
11158
11159 # def child_nodes: () -> Array[Node?]
11160 def child_nodes
11161 []
11162 end
11163
11164 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
11165 def each_child_node
11166 return to_enum(:each_child_node) unless block_given?
11167
11168 end
11169
11170 # def compact_child_nodes: () -> Array[Node]
11171 def compact_child_nodes
11172 []
11173 end
11174
11175 # def comment_targets: () -> Array[Node | Location]
11176 def comment_targets
11177 [] #: Array[Prism::node | Location]
11178 end
11179
11180 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Integer) -> IntegerNode
11181 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value)
11182 IntegerNode.new(source, node_id, location, flags, value)
11183 end
11184
11185 # def deconstruct: () -> Array[Node?]
11186 alias deconstruct child_nodes
11187
11188 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, value: Integer }
11189 def deconstruct_keys(keys)
11190 { node_id: node_id, location: location, value: value }
11191 end
11192
11193 # def binary?: () -> bool
11194 def binary?
11195 flags.anybits?(IntegerBaseFlags::BINARY)
11196 end
11197
11198 # def decimal?: () -> bool
11199 def decimal?
11200 flags.anybits?(IntegerBaseFlags::DECIMAL)
11201 end
11202
11203 # def octal?: () -> bool
11204 def octal?
11205 flags.anybits?(IntegerBaseFlags::OCTAL)
11206 end
11207
11208 # def hexadecimal?: () -> bool
11209 def hexadecimal?
11210 flags.anybits?(IntegerBaseFlags::HEXADECIMAL)
11211 end
11212
11213 # The value of the integer literal as a number.
11214 attr_reader :value
11215
11216 # def inspect -> String
11217 def inspect
11218 InspectVisitor.compose(self)
11219 end
11220
11221 # Return a symbol representation of this node type. See `Node#type`.
11222 def type
11223 :integer_node
11224 end
11225
11226 # Return a symbol representation of this node type. See `Node::type`.
11227 def self.type
11228 :integer_node
11229 end
11230
11231 # Implements case-equality for the node. This is effectively == but without
11232 # comparing the value of locations. Locations are checked only for presence.
11233 def ===(other)
11234 other.is_a?(IntegerNode) &&
11235 (flags === other.flags) &&
11236 (value === other.value)
11237 end
11238 end
11239
11240 # Represents a regular expression literal that contains interpolation that is being used in the predicate of a conditional to implicitly match against the last line read by an IO object.
11241 #
11242 # if /foo #{bar} baz/ then end
11243 # ^^^^^^^^^^^^^^^^
11244 class InterpolatedMatchLastLineNode < Node
11245 # Initialize a new InterpolatedMatchLastLineNode node.
11246 def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc)
11247 @source = source
11248 @node_id = node_id
11249 @location = location
11250 @flags = flags
11251 @opening_loc = opening_loc
11252 @parts = parts
11253 @closing_loc = closing_loc
11254 end
11255
11256 # def accept: (Visitor visitor) -> void
11257 def accept(visitor)
11258 visitor.visit_interpolated_match_last_line_node(self)
11259 end
11260
11261 # def child_nodes: () -> Array[Node?]
11262 def child_nodes
11263 [*parts]
11264 end
11265
11266 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
11267 def each_child_node
11268 return to_enum(:each_child_node) unless block_given?
11269
11270 parts.each { |node| yield node }
11271 end
11272
11273 # def compact_child_nodes: () -> Array[Node]
11274 def compact_child_nodes
11275 [*parts]
11276 end
11277
11278 # def comment_targets: () -> Array[Node | Location]
11279 def comment_targets
11280 [opening_loc, *parts, closing_loc] #: Array[Prism::node | Location]
11281 end
11282
11283 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location) -> InterpolatedMatchLastLineNode
11284 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc)
11285 InterpolatedMatchLastLineNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc)
11286 end
11287
11288 # def deconstruct: () -> Array[Node?]
11289 alias deconstruct child_nodes
11290
11291 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], closing_loc: Location }
11292 def deconstruct_keys(keys)
11293 { node_id: node_id, location: location, opening_loc: opening_loc, parts: parts, closing_loc: closing_loc }
11294 end
11295
11296 # def ignore_case?: () -> bool
11297 def ignore_case?
11298 flags.anybits?(RegularExpressionFlags::IGNORE_CASE)
11299 end
11300
11301 # def extended?: () -> bool
11302 def extended?
11303 flags.anybits?(RegularExpressionFlags::EXTENDED)
11304 end
11305
11306 # def multi_line?: () -> bool
11307 def multi_line?
11308 flags.anybits?(RegularExpressionFlags::MULTI_LINE)
11309 end
11310
11311 # def once?: () -> bool
11312 def once?
11313 flags.anybits?(RegularExpressionFlags::ONCE)
11314 end
11315
11316 # def euc_jp?: () -> bool
11317 def euc_jp?
11318 flags.anybits?(RegularExpressionFlags::EUC_JP)
11319 end
11320
11321 # def ascii_8bit?: () -> bool
11322 def ascii_8bit?
11323 flags.anybits?(RegularExpressionFlags::ASCII_8BIT)
11324 end
11325
11326 # def windows_31j?: () -> bool
11327 def windows_31j?
11328 flags.anybits?(RegularExpressionFlags::WINDOWS_31J)
11329 end
11330
11331 # def utf_8?: () -> bool
11332 def utf_8?
11333 flags.anybits?(RegularExpressionFlags::UTF_8)
11334 end
11335
11336 # def forced_utf8_encoding?: () -> bool
11337 def forced_utf8_encoding?
11338 flags.anybits?(RegularExpressionFlags::FORCED_UTF8_ENCODING)
11339 end
11340
11341 # def forced_binary_encoding?: () -> bool
11342 def forced_binary_encoding?
11343 flags.anybits?(RegularExpressionFlags::FORCED_BINARY_ENCODING)
11344 end
11345
11346 # def forced_us_ascii_encoding?: () -> bool
11347 def forced_us_ascii_encoding?
11348 flags.anybits?(RegularExpressionFlags::FORCED_US_ASCII_ENCODING)
11349 end
11350
11351 # attr_reader opening_loc: Location
11352 def opening_loc
11353 location = @opening_loc
11354 return location if location.is_a?(Location)
11355 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11356 end
11357
11358 # Save the opening_loc location using the given saved source so that
11359 # it can be retrieved later.
11360 def save_opening_loc(repository)
11361 repository.enter(node_id, :opening_loc)
11362 end
11363
11364 # attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
11365 attr_reader :parts
11366
11367 # attr_reader closing_loc: Location
11368 def closing_loc
11369 location = @closing_loc
11370 return location if location.is_a?(Location)
11371 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11372 end
11373
11374 # Save the closing_loc location using the given saved source so that
11375 # it can be retrieved later.
11376 def save_closing_loc(repository)
11377 repository.enter(node_id, :closing_loc)
11378 end
11379
11380 # def opening: () -> String
11381 def opening
11382 opening_loc.slice
11383 end
11384
11385 # def closing: () -> String
11386 def closing
11387 closing_loc.slice
11388 end
11389
11390 # def inspect -> String
11391 def inspect
11392 InspectVisitor.compose(self)
11393 end
11394
11395 # Return a symbol representation of this node type. See `Node#type`.
11396 def type
11397 :interpolated_match_last_line_node
11398 end
11399
11400 # Return a symbol representation of this node type. See `Node::type`.
11401 def self.type
11402 :interpolated_match_last_line_node
11403 end
11404
11405 # Implements case-equality for the node. This is effectively == but without
11406 # comparing the value of locations. Locations are checked only for presence.
11407 def ===(other)
11408 other.is_a?(InterpolatedMatchLastLineNode) &&
11409 (flags === other.flags) &&
11410 (opening_loc.nil? == other.opening_loc.nil?) &&
11411 (parts.length == other.parts.length) &&
11412 parts.zip(other.parts).all? { |left, right| left === right } &&
11413 (closing_loc.nil? == other.closing_loc.nil?)
11414 end
11415 end
11416
11417 # Represents a regular expression literal that contains interpolation.
11418 #
11419 # /foo #{bar} baz/
11420 # ^^^^^^^^^^^^^^^^
11421 class InterpolatedRegularExpressionNode < Node
11422 # Initialize a new InterpolatedRegularExpressionNode node.
11423 def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc)
11424 @source = source
11425 @node_id = node_id
11426 @location = location
11427 @flags = flags
11428 @opening_loc = opening_loc
11429 @parts = parts
11430 @closing_loc = closing_loc
11431 end
11432
11433 # def accept: (Visitor visitor) -> void
11434 def accept(visitor)
11435 visitor.visit_interpolated_regular_expression_node(self)
11436 end
11437
11438 # def child_nodes: () -> Array[Node?]
11439 def child_nodes
11440 [*parts]
11441 end
11442
11443 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
11444 def each_child_node
11445 return to_enum(:each_child_node) unless block_given?
11446
11447 parts.each { |node| yield node }
11448 end
11449
11450 # def compact_child_nodes: () -> Array[Node]
11451 def compact_child_nodes
11452 [*parts]
11453 end
11454
11455 # def comment_targets: () -> Array[Node | Location]
11456 def comment_targets
11457 [opening_loc, *parts, closing_loc] #: Array[Prism::node | Location]
11458 end
11459
11460 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location) -> InterpolatedRegularExpressionNode
11461 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc)
11462 InterpolatedRegularExpressionNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc)
11463 end
11464
11465 # def deconstruct: () -> Array[Node?]
11466 alias deconstruct child_nodes
11467
11468 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], closing_loc: Location }
11469 def deconstruct_keys(keys)
11470 { node_id: node_id, location: location, opening_loc: opening_loc, parts: parts, closing_loc: closing_loc }
11471 end
11472
11473 # def ignore_case?: () -> bool
11474 def ignore_case?
11475 flags.anybits?(RegularExpressionFlags::IGNORE_CASE)
11476 end
11477
11478 # def extended?: () -> bool
11479 def extended?
11480 flags.anybits?(RegularExpressionFlags::EXTENDED)
11481 end
11482
11483 # def multi_line?: () -> bool
11484 def multi_line?
11485 flags.anybits?(RegularExpressionFlags::MULTI_LINE)
11486 end
11487
11488 # def once?: () -> bool
11489 def once?
11490 flags.anybits?(RegularExpressionFlags::ONCE)
11491 end
11492
11493 # def euc_jp?: () -> bool
11494 def euc_jp?
11495 flags.anybits?(RegularExpressionFlags::EUC_JP)
11496 end
11497
11498 # def ascii_8bit?: () -> bool
11499 def ascii_8bit?
11500 flags.anybits?(RegularExpressionFlags::ASCII_8BIT)
11501 end
11502
11503 # def windows_31j?: () -> bool
11504 def windows_31j?
11505 flags.anybits?(RegularExpressionFlags::WINDOWS_31J)
11506 end
11507
11508 # def utf_8?: () -> bool
11509 def utf_8?
11510 flags.anybits?(RegularExpressionFlags::UTF_8)
11511 end
11512
11513 # def forced_utf8_encoding?: () -> bool
11514 def forced_utf8_encoding?
11515 flags.anybits?(RegularExpressionFlags::FORCED_UTF8_ENCODING)
11516 end
11517
11518 # def forced_binary_encoding?: () -> bool
11519 def forced_binary_encoding?
11520 flags.anybits?(RegularExpressionFlags::FORCED_BINARY_ENCODING)
11521 end
11522
11523 # def forced_us_ascii_encoding?: () -> bool
11524 def forced_us_ascii_encoding?
11525 flags.anybits?(RegularExpressionFlags::FORCED_US_ASCII_ENCODING)
11526 end
11527
11528 # attr_reader opening_loc: Location
11529 def opening_loc
11530 location = @opening_loc
11531 return location if location.is_a?(Location)
11532 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11533 end
11534
11535 # Save the opening_loc location using the given saved source so that
11536 # it can be retrieved later.
11537 def save_opening_loc(repository)
11538 repository.enter(node_id, :opening_loc)
11539 end
11540
11541 # attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
11542 attr_reader :parts
11543
11544 # attr_reader closing_loc: Location
11545 def closing_loc
11546 location = @closing_loc
11547 return location if location.is_a?(Location)
11548 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11549 end
11550
11551 # Save the closing_loc location using the given saved source so that
11552 # it can be retrieved later.
11553 def save_closing_loc(repository)
11554 repository.enter(node_id, :closing_loc)
11555 end
11556
11557 # def opening: () -> String
11558 def opening
11559 opening_loc.slice
11560 end
11561
11562 # def closing: () -> String
11563 def closing
11564 closing_loc.slice
11565 end
11566
11567 # def inspect -> String
11568 def inspect
11569 InspectVisitor.compose(self)
11570 end
11571
11572 # Return a symbol representation of this node type. See `Node#type`.
11573 def type
11574 :interpolated_regular_expression_node
11575 end
11576
11577 # Return a symbol representation of this node type. See `Node::type`.
11578 def self.type
11579 :interpolated_regular_expression_node
11580 end
11581
11582 # Implements case-equality for the node. This is effectively == but without
11583 # comparing the value of locations. Locations are checked only for presence.
11584 def ===(other)
11585 other.is_a?(InterpolatedRegularExpressionNode) &&
11586 (flags === other.flags) &&
11587 (opening_loc.nil? == other.opening_loc.nil?) &&
11588 (parts.length == other.parts.length) &&
11589 parts.zip(other.parts).all? { |left, right| left === right } &&
11590 (closing_loc.nil? == other.closing_loc.nil?)
11591 end
11592 end
11593
11594 # Represents a string literal that contains interpolation.
11595 #
11596 # "foo #{bar} baz"
11597 # ^^^^^^^^^^^^^^^^
11598 class InterpolatedStringNode < Node
11599 # Initialize a new InterpolatedStringNode node.
11600 def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc)
11601 @source = source
11602 @node_id = node_id
11603 @location = location
11604 @flags = flags
11605 @opening_loc = opening_loc
11606 @parts = parts
11607 @closing_loc = closing_loc
11608 end
11609
11610 # def accept: (Visitor visitor) -> void
11611 def accept(visitor)
11612 visitor.visit_interpolated_string_node(self)
11613 end
11614
11615 # def child_nodes: () -> Array[Node?]
11616 def child_nodes
11617 [*parts]
11618 end
11619
11620 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
11621 def each_child_node
11622 return to_enum(:each_child_node) unless block_given?
11623
11624 parts.each { |node| yield node }
11625 end
11626
11627 # def compact_child_nodes: () -> Array[Node]
11628 def compact_child_nodes
11629 [*parts]
11630 end
11631
11632 # def comment_targets: () -> Array[Node | Location]
11633 def comment_targets
11634 [*opening_loc, *parts, *closing_loc] #: Array[Prism::node | Location]
11635 end
11636
11637 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location?, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode | InterpolatedStringNode | XStringNode | InterpolatedXStringNode | SymbolNode | InterpolatedSymbolNode], ?closing_loc: Location?) -> InterpolatedStringNode
11638 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc)
11639 InterpolatedStringNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc)
11640 end
11641
11642 # def deconstruct: () -> Array[Node?]
11643 alias deconstruct child_nodes
11644
11645 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location?, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode | InterpolatedStringNode | XStringNode | InterpolatedXStringNode | SymbolNode | InterpolatedSymbolNode], closing_loc: Location? }
11646 def deconstruct_keys(keys)
11647 { node_id: node_id, location: location, opening_loc: opening_loc, parts: parts, closing_loc: closing_loc }
11648 end
11649
11650 # def frozen?: () -> bool
11651 def frozen?
11652 flags.anybits?(InterpolatedStringNodeFlags::FROZEN)
11653 end
11654
11655 # def mutable?: () -> bool
11656 def mutable?
11657 flags.anybits?(InterpolatedStringNodeFlags::MUTABLE)
11658 end
11659
11660 # attr_reader opening_loc: Location?
11661 def opening_loc
11662 location = @opening_loc
11663 case location
11664 when nil
11665 nil
11666 when Location
11667 location
11668 else
11669 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11670 end
11671 end
11672
11673 # Save the opening_loc location using the given saved source so that
11674 # it can be retrieved later.
11675 def save_opening_loc(repository)
11676 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
11677 end
11678
11679 # attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode | InterpolatedStringNode | XStringNode | InterpolatedXStringNode | SymbolNode | InterpolatedSymbolNode]
11680 attr_reader :parts
11681
11682 # attr_reader closing_loc: Location?
11683 def closing_loc
11684 location = @closing_loc
11685 case location
11686 when nil
11687 nil
11688 when Location
11689 location
11690 else
11691 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11692 end
11693 end
11694
11695 # Save the closing_loc location using the given saved source so that
11696 # it can be retrieved later.
11697 def save_closing_loc(repository)
11698 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
11699 end
11700
11701 # def opening: () -> String?
11702 def opening
11703 opening_loc&.slice
11704 end
11705
11706 # def closing: () -> String?
11707 def closing
11708 closing_loc&.slice
11709 end
11710
11711 # def inspect -> String
11712 def inspect
11713 InspectVisitor.compose(self)
11714 end
11715
11716 # Return a symbol representation of this node type. See `Node#type`.
11717 def type
11718 :interpolated_string_node
11719 end
11720
11721 # Return a symbol representation of this node type. See `Node::type`.
11722 def self.type
11723 :interpolated_string_node
11724 end
11725
11726 # Implements case-equality for the node. This is effectively == but without
11727 # comparing the value of locations. Locations are checked only for presence.
11728 def ===(other)
11729 other.is_a?(InterpolatedStringNode) &&
11730 (flags === other.flags) &&
11731 (opening_loc.nil? == other.opening_loc.nil?) &&
11732 (parts.length == other.parts.length) &&
11733 parts.zip(other.parts).all? { |left, right| left === right } &&
11734 (closing_loc.nil? == other.closing_loc.nil?)
11735 end
11736 end
11737
11738 # Represents a symbol literal that contains interpolation.
11739 #
11740 # :"foo #{bar} baz"
11741 # ^^^^^^^^^^^^^^^^^
11742 class InterpolatedSymbolNode < Node
11743 # Initialize a new InterpolatedSymbolNode node.
11744 def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc)
11745 @source = source
11746 @node_id = node_id
11747 @location = location
11748 @flags = flags
11749 @opening_loc = opening_loc
11750 @parts = parts
11751 @closing_loc = closing_loc
11752 end
11753
11754 # def accept: (Visitor visitor) -> void
11755 def accept(visitor)
11756 visitor.visit_interpolated_symbol_node(self)
11757 end
11758
11759 # def child_nodes: () -> Array[Node?]
11760 def child_nodes
11761 [*parts]
11762 end
11763
11764 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
11765 def each_child_node
11766 return to_enum(:each_child_node) unless block_given?
11767
11768 parts.each { |node| yield node }
11769 end
11770
11771 # def compact_child_nodes: () -> Array[Node]
11772 def compact_child_nodes
11773 [*parts]
11774 end
11775
11776 # def comment_targets: () -> Array[Node | Location]
11777 def comment_targets
11778 [*opening_loc, *parts, *closing_loc] #: Array[Prism::node | Location]
11779 end
11780
11781 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location?, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location?) -> InterpolatedSymbolNode
11782 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc)
11783 InterpolatedSymbolNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc)
11784 end
11785
11786 # def deconstruct: () -> Array[Node?]
11787 alias deconstruct child_nodes
11788
11789 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location?, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], closing_loc: Location? }
11790 def deconstruct_keys(keys)
11791 { node_id: node_id, location: location, opening_loc: opening_loc, parts: parts, closing_loc: closing_loc }
11792 end
11793
11794 # attr_reader opening_loc: Location?
11795 def opening_loc
11796 location = @opening_loc
11797 case location
11798 when nil
11799 nil
11800 when Location
11801 location
11802 else
11803 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11804 end
11805 end
11806
11807 # Save the opening_loc location using the given saved source so that
11808 # it can be retrieved later.
11809 def save_opening_loc(repository)
11810 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
11811 end
11812
11813 # attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
11814 attr_reader :parts
11815
11816 # attr_reader closing_loc: Location?
11817 def closing_loc
11818 location = @closing_loc
11819 case location
11820 when nil
11821 nil
11822 when Location
11823 location
11824 else
11825 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11826 end
11827 end
11828
11829 # Save the closing_loc location using the given saved source so that
11830 # it can be retrieved later.
11831 def save_closing_loc(repository)
11832 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
11833 end
11834
11835 # def opening: () -> String?
11836 def opening
11837 opening_loc&.slice
11838 end
11839
11840 # def closing: () -> String?
11841 def closing
11842 closing_loc&.slice
11843 end
11844
11845 # def inspect -> String
11846 def inspect
11847 InspectVisitor.compose(self)
11848 end
11849
11850 # Return a symbol representation of this node type. See `Node#type`.
11851 def type
11852 :interpolated_symbol_node
11853 end
11854
11855 # Return a symbol representation of this node type. See `Node::type`.
11856 def self.type
11857 :interpolated_symbol_node
11858 end
11859
11860 # Implements case-equality for the node. This is effectively == but without
11861 # comparing the value of locations. Locations are checked only for presence.
11862 def ===(other)
11863 other.is_a?(InterpolatedSymbolNode) &&
11864 (opening_loc.nil? == other.opening_loc.nil?) &&
11865 (parts.length == other.parts.length) &&
11866 parts.zip(other.parts).all? { |left, right| left === right } &&
11867 (closing_loc.nil? == other.closing_loc.nil?)
11868 end
11869 end
11870
11871 # Represents an xstring literal that contains interpolation.
11872 #
11873 # `foo #{bar} baz`
11874 # ^^^^^^^^^^^^^^^^
11875 class InterpolatedXStringNode < Node
11876 # Initialize a new InterpolatedXStringNode node.
11877 def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc)
11878 @source = source
11879 @node_id = node_id
11880 @location = location
11881 @flags = flags
11882 @opening_loc = opening_loc
11883 @parts = parts
11884 @closing_loc = closing_loc
11885 end
11886
11887 # def accept: (Visitor visitor) -> void
11888 def accept(visitor)
11889 visitor.visit_interpolated_x_string_node(self)
11890 end
11891
11892 # def child_nodes: () -> Array[Node?]
11893 def child_nodes
11894 [*parts]
11895 end
11896
11897 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
11898 def each_child_node
11899 return to_enum(:each_child_node) unless block_given?
11900
11901 parts.each { |node| yield node }
11902 end
11903
11904 # def compact_child_nodes: () -> Array[Node]
11905 def compact_child_nodes
11906 [*parts]
11907 end
11908
11909 # def comment_targets: () -> Array[Node | Location]
11910 def comment_targets
11911 [opening_loc, *parts, closing_loc] #: Array[Prism::node | Location]
11912 end
11913
11914 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location) -> InterpolatedXStringNode
11915 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc)
11916 InterpolatedXStringNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc)
11917 end
11918
11919 # def deconstruct: () -> Array[Node?]
11920 alias deconstruct child_nodes
11921
11922 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], closing_loc: Location }
11923 def deconstruct_keys(keys)
11924 { node_id: node_id, location: location, opening_loc: opening_loc, parts: parts, closing_loc: closing_loc }
11925 end
11926
11927 # attr_reader opening_loc: Location
11928 def opening_loc
11929 location = @opening_loc
11930 return location if location.is_a?(Location)
11931 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11932 end
11933
11934 # Save the opening_loc location using the given saved source so that
11935 # it can be retrieved later.
11936 def save_opening_loc(repository)
11937 repository.enter(node_id, :opening_loc)
11938 end
11939
11940 # attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
11941 attr_reader :parts
11942
11943 # attr_reader closing_loc: Location
11944 def closing_loc
11945 location = @closing_loc
11946 return location if location.is_a?(Location)
11947 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
11948 end
11949
11950 # Save the closing_loc location using the given saved source so that
11951 # it can be retrieved later.
11952 def save_closing_loc(repository)
11953 repository.enter(node_id, :closing_loc)
11954 end
11955
11956 # def opening: () -> String
11957 def opening
11958 opening_loc.slice
11959 end
11960
11961 # def closing: () -> String
11962 def closing
11963 closing_loc.slice
11964 end
11965
11966 # def inspect -> String
11967 def inspect
11968 InspectVisitor.compose(self)
11969 end
11970
11971 # Return a symbol representation of this node type. See `Node#type`.
11972 def type
11973 :interpolated_x_string_node
11974 end
11975
11976 # Return a symbol representation of this node type. See `Node::type`.
11977 def self.type
11978 :interpolated_x_string_node
11979 end
11980
11981 # Implements case-equality for the node. This is effectively == but without
11982 # comparing the value of locations. Locations are checked only for presence.
11983 def ===(other)
11984 other.is_a?(InterpolatedXStringNode) &&
11985 (opening_loc.nil? == other.opening_loc.nil?) &&
11986 (parts.length == other.parts.length) &&
11987 parts.zip(other.parts).all? { |left, right| left === right } &&
11988 (closing_loc.nil? == other.closing_loc.nil?)
11989 end
11990 end
11991
11992 # Represents reading from the implicit `it` local variable.
11993 #
11994 # -> { it }
11995 # ^^
11996 class ItLocalVariableReadNode < Node
11997 # Initialize a new ItLocalVariableReadNode node.
11998 def initialize(source, node_id, location, flags)
11999 @source = source
12000 @node_id = node_id
12001 @location = location
12002 @flags = flags
12003 end
12004
12005 # def accept: (Visitor visitor) -> void
12006 def accept(visitor)
12007 visitor.visit_it_local_variable_read_node(self)
12008 end
12009
12010 # def child_nodes: () -> Array[Node?]
12011 def child_nodes
12012 []
12013 end
12014
12015 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12016 def each_child_node
12017 return to_enum(:each_child_node) unless block_given?
12018
12019 end
12020
12021 # def compact_child_nodes: () -> Array[Node]
12022 def compact_child_nodes
12023 []
12024 end
12025
12026 # def comment_targets: () -> Array[Node | Location]
12027 def comment_targets
12028 [] #: Array[Prism::node | Location]
12029 end
12030
12031 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> ItLocalVariableReadNode
12032 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
12033 ItLocalVariableReadNode.new(source, node_id, location, flags)
12034 end
12035
12036 # def deconstruct: () -> Array[Node?]
12037 alias deconstruct child_nodes
12038
12039 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
12040 def deconstruct_keys(keys)
12041 { node_id: node_id, location: location }
12042 end
12043
12044 # def inspect -> String
12045 def inspect
12046 InspectVisitor.compose(self)
12047 end
12048
12049 # Return a symbol representation of this node type. See `Node#type`.
12050 def type
12051 :it_local_variable_read_node
12052 end
12053
12054 # Return a symbol representation of this node type. See `Node::type`.
12055 def self.type
12056 :it_local_variable_read_node
12057 end
12058
12059 # Implements case-equality for the node. This is effectively == but without
12060 # comparing the value of locations. Locations are checked only for presence.
12061 def ===(other)
12062 other.is_a?(ItLocalVariableReadNode)
12063 end
12064 end
12065
12066 # Represents an implicit set of parameters through the use of the `it` keyword within a block or lambda.
12067 #
12068 # -> { it + it }
12069 # ^^^^^^^^^^^^^^
12070 class ItParametersNode < Node
12071 # Initialize a new ItParametersNode node.
12072 def initialize(source, node_id, location, flags)
12073 @source = source
12074 @node_id = node_id
12075 @location = location
12076 @flags = flags
12077 end
12078
12079 # def accept: (Visitor visitor) -> void
12080 def accept(visitor)
12081 visitor.visit_it_parameters_node(self)
12082 end
12083
12084 # def child_nodes: () -> Array[Node?]
12085 def child_nodes
12086 []
12087 end
12088
12089 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12090 def each_child_node
12091 return to_enum(:each_child_node) unless block_given?
12092
12093 end
12094
12095 # def compact_child_nodes: () -> Array[Node]
12096 def compact_child_nodes
12097 []
12098 end
12099
12100 # def comment_targets: () -> Array[Node | Location]
12101 def comment_targets
12102 [] #: Array[Prism::node | Location]
12103 end
12104
12105 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> ItParametersNode
12106 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
12107 ItParametersNode.new(source, node_id, location, flags)
12108 end
12109
12110 # def deconstruct: () -> Array[Node?]
12111 alias deconstruct child_nodes
12112
12113 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
12114 def deconstruct_keys(keys)
12115 { node_id: node_id, location: location }
12116 end
12117
12118 # def inspect -> String
12119 def inspect
12120 InspectVisitor.compose(self)
12121 end
12122
12123 # Return a symbol representation of this node type. See `Node#type`.
12124 def type
12125 :it_parameters_node
12126 end
12127
12128 # Return a symbol representation of this node type. See `Node::type`.
12129 def self.type
12130 :it_parameters_node
12131 end
12132
12133 # Implements case-equality for the node. This is effectively == but without
12134 # comparing the value of locations. Locations are checked only for presence.
12135 def ===(other)
12136 other.is_a?(ItParametersNode)
12137 end
12138 end
12139
12140 # Represents a hash literal without opening and closing braces.
12141 #
12142 # foo(a: b)
12143 # ^^^^
12144 class KeywordHashNode < Node
12145 # Initialize a new KeywordHashNode node.
12146 def initialize(source, node_id, location, flags, elements)
12147 @source = source
12148 @node_id = node_id
12149 @location = location
12150 @flags = flags
12151 @elements = elements
12152 end
12153
12154 # def accept: (Visitor visitor) -> void
12155 def accept(visitor)
12156 visitor.visit_keyword_hash_node(self)
12157 end
12158
12159 # def child_nodes: () -> Array[Node?]
12160 def child_nodes
12161 [*elements]
12162 end
12163
12164 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12165 def each_child_node
12166 return to_enum(:each_child_node) unless block_given?
12167
12168 elements.each { |node| yield node }
12169 end
12170
12171 # def compact_child_nodes: () -> Array[Node]
12172 def compact_child_nodes
12173 [*elements]
12174 end
12175
12176 # def comment_targets: () -> Array[Node | Location]
12177 def comment_targets
12178 [*elements] #: Array[Prism::node | Location]
12179 end
12180
12181 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?elements: Array[AssocNode | AssocSplatNode]) -> KeywordHashNode
12182 def copy(node_id: self.node_id, location: self.location, flags: self.flags, elements: self.elements)
12183 KeywordHashNode.new(source, node_id, location, flags, elements)
12184 end
12185
12186 # def deconstruct: () -> Array[Node?]
12187 alias deconstruct child_nodes
12188
12189 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, elements: Array[AssocNode | AssocSplatNode] }
12190 def deconstruct_keys(keys)
12191 { node_id: node_id, location: location, elements: elements }
12192 end
12193
12194 # def symbol_keys?: () -> bool
12195 def symbol_keys?
12196 flags.anybits?(KeywordHashNodeFlags::SYMBOL_KEYS)
12197 end
12198
12199 # attr_reader elements: Array[AssocNode | AssocSplatNode]
12200 attr_reader :elements
12201
12202 # def inspect -> String
12203 def inspect
12204 InspectVisitor.compose(self)
12205 end
12206
12207 # Return a symbol representation of this node type. See `Node#type`.
12208 def type
12209 :keyword_hash_node
12210 end
12211
12212 # Return a symbol representation of this node type. See `Node::type`.
12213 def self.type
12214 :keyword_hash_node
12215 end
12216
12217 # Implements case-equality for the node. This is effectively == but without
12218 # comparing the value of locations. Locations are checked only for presence.
12219 def ===(other)
12220 other.is_a?(KeywordHashNode) &&
12221 (flags === other.flags) &&
12222 (elements.length == other.elements.length) &&
12223 elements.zip(other.elements).all? { |left, right| left === right }
12224 end
12225 end
12226
12227 # Represents a keyword rest parameter to a method, block, or lambda definition.
12228 #
12229 # def a(**b)
12230 # ^^^
12231 # end
12232 class KeywordRestParameterNode < Node
12233 # Initialize a new KeywordRestParameterNode node.
12234 def initialize(source, node_id, location, flags, name, name_loc, operator_loc)
12235 @source = source
12236 @node_id = node_id
12237 @location = location
12238 @flags = flags
12239 @name = name
12240 @name_loc = name_loc
12241 @operator_loc = operator_loc
12242 end
12243
12244 # def accept: (Visitor visitor) -> void
12245 def accept(visitor)
12246 visitor.visit_keyword_rest_parameter_node(self)
12247 end
12248
12249 # def child_nodes: () -> Array[Node?]
12250 def child_nodes
12251 []
12252 end
12253
12254 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12255 def each_child_node
12256 return to_enum(:each_child_node) unless block_given?
12257
12258 end
12259
12260 # def compact_child_nodes: () -> Array[Node]
12261 def compact_child_nodes
12262 []
12263 end
12264
12265 # def comment_targets: () -> Array[Node | Location]
12266 def comment_targets
12267 [*name_loc, operator_loc] #: Array[Prism::node | Location]
12268 end
12269
12270 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol?, ?name_loc: Location?, ?operator_loc: Location) -> KeywordRestParameterNode
12271 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc)
12272 KeywordRestParameterNode.new(source, node_id, location, flags, name, name_loc, operator_loc)
12273 end
12274
12275 # def deconstruct: () -> Array[Node?]
12276 alias deconstruct child_nodes
12277
12278 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol?, name_loc: Location?, operator_loc: Location }
12279 def deconstruct_keys(keys)
12280 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc }
12281 end
12282
12283 # def repeated_parameter?: () -> bool
12284 def repeated_parameter?
12285 flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
12286 end
12287
12288 # attr_reader name: Symbol?
12289 attr_reader :name
12290
12291 # attr_reader name_loc: Location?
12292 def name_loc
12293 location = @name_loc
12294 case location
12295 when nil
12296 nil
12297 when Location
12298 location
12299 else
12300 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12301 end
12302 end
12303
12304 # Save the name_loc location using the given saved source so that
12305 # it can be retrieved later.
12306 def save_name_loc(repository)
12307 repository.enter(node_id, :name_loc) unless @name_loc.nil?
12308 end
12309
12310 # attr_reader operator_loc: Location
12311 def operator_loc
12312 location = @operator_loc
12313 return location if location.is_a?(Location)
12314 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12315 end
12316
12317 # Save the operator_loc location using the given saved source so that
12318 # it can be retrieved later.
12319 def save_operator_loc(repository)
12320 repository.enter(node_id, :operator_loc)
12321 end
12322
12323 # def operator: () -> String
12324 def operator
12325 operator_loc.slice
12326 end
12327
12328 # def inspect -> String
12329 def inspect
12330 InspectVisitor.compose(self)
12331 end
12332
12333 # Return a symbol representation of this node type. See `Node#type`.
12334 def type
12335 :keyword_rest_parameter_node
12336 end
12337
12338 # Return a symbol representation of this node type. See `Node::type`.
12339 def self.type
12340 :keyword_rest_parameter_node
12341 end
12342
12343 # Implements case-equality for the node. This is effectively == but without
12344 # comparing the value of locations. Locations are checked only for presence.
12345 def ===(other)
12346 other.is_a?(KeywordRestParameterNode) &&
12347 (flags === other.flags) &&
12348 (name === other.name) &&
12349 (name_loc.nil? == other.name_loc.nil?) &&
12350 (operator_loc.nil? == other.operator_loc.nil?)
12351 end
12352 end
12353
12354 # Represents using a lambda literal (not the lambda method call).
12355 #
12356 # ->(value) { value * 2 }
12357 # ^^^^^^^^^^^^^^^^^^^^^^^
12358 class LambdaNode < Node
12359 # Initialize a new LambdaNode node.
12360 def initialize(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body)
12361 @source = source
12362 @node_id = node_id
12363 @location = location
12364 @flags = flags
12365 @locals = locals
12366 @operator_loc = operator_loc
12367 @opening_loc = opening_loc
12368 @closing_loc = closing_loc
12369 @parameters = parameters
12370 @body = body
12371 end
12372
12373 # def accept: (Visitor visitor) -> void
12374 def accept(visitor)
12375 visitor.visit_lambda_node(self)
12376 end
12377
12378 # def child_nodes: () -> Array[Node?]
12379 def child_nodes
12380 [parameters, body]
12381 end
12382
12383 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12384 def each_child_node
12385 return to_enum(:each_child_node) unless block_given?
12386
12387 yield parameters if parameters
12388 yield body if body
12389 end
12390
12391 # def compact_child_nodes: () -> Array[Node]
12392 def compact_child_nodes
12393 compact = [] #: Array[Prism::node]
12394 compact << parameters if parameters
12395 compact << body if body
12396 compact
12397 end
12398
12399 # def comment_targets: () -> Array[Node | Location]
12400 def comment_targets
12401 [operator_loc, opening_loc, closing_loc, *parameters, *body] #: Array[Prism::node | Location]
12402 end
12403
12404 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array[Symbol], ?operator_loc: Location, ?opening_loc: Location, ?closing_loc: Location, ?parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil, ?body: StatementsNode | BeginNode | nil) -> LambdaNode
12405 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, operator_loc: self.operator_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc, parameters: self.parameters, body: self.body)
12406 LambdaNode.new(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body)
12407 end
12408
12409 # def deconstruct: () -> Array[Node?]
12410 alias deconstruct child_nodes
12411
12412 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, locals: Array[Symbol], operator_loc: Location, opening_loc: Location, closing_loc: Location, parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil, body: StatementsNode | BeginNode | nil }
12413 def deconstruct_keys(keys)
12414 { node_id: node_id, location: location, locals: locals, operator_loc: operator_loc, opening_loc: opening_loc, closing_loc: closing_loc, parameters: parameters, body: body }
12415 end
12416
12417 # attr_reader locals: Array[Symbol]
12418 attr_reader :locals
12419
12420 # attr_reader operator_loc: Location
12421 def operator_loc
12422 location = @operator_loc
12423 return location if location.is_a?(Location)
12424 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12425 end
12426
12427 # Save the operator_loc location using the given saved source so that
12428 # it can be retrieved later.
12429 def save_operator_loc(repository)
12430 repository.enter(node_id, :operator_loc)
12431 end
12432
12433 # attr_reader opening_loc: Location
12434 def opening_loc
12435 location = @opening_loc
12436 return location if location.is_a?(Location)
12437 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12438 end
12439
12440 # Save the opening_loc location using the given saved source so that
12441 # it can be retrieved later.
12442 def save_opening_loc(repository)
12443 repository.enter(node_id, :opening_loc)
12444 end
12445
12446 # attr_reader closing_loc: Location
12447 def closing_loc
12448 location = @closing_loc
12449 return location if location.is_a?(Location)
12450 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12451 end
12452
12453 # Save the closing_loc location using the given saved source so that
12454 # it can be retrieved later.
12455 def save_closing_loc(repository)
12456 repository.enter(node_id, :closing_loc)
12457 end
12458
12459 # attr_reader parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil
12460 attr_reader :parameters
12461
12462 # attr_reader body: StatementsNode | BeginNode | nil
12463 attr_reader :body
12464
12465 # def operator: () -> String
12466 def operator
12467 operator_loc.slice
12468 end
12469
12470 # def opening: () -> String
12471 def opening
12472 opening_loc.slice
12473 end
12474
12475 # def closing: () -> String
12476 def closing
12477 closing_loc.slice
12478 end
12479
12480 # def inspect -> String
12481 def inspect
12482 InspectVisitor.compose(self)
12483 end
12484
12485 # Return a symbol representation of this node type. See `Node#type`.
12486 def type
12487 :lambda_node
12488 end
12489
12490 # Return a symbol representation of this node type. See `Node::type`.
12491 def self.type
12492 :lambda_node
12493 end
12494
12495 # Implements case-equality for the node. This is effectively == but without
12496 # comparing the value of locations. Locations are checked only for presence.
12497 def ===(other)
12498 other.is_a?(LambdaNode) &&
12499 (locals.length == other.locals.length) &&
12500 locals.zip(other.locals).all? { |left, right| left === right } &&
12501 (operator_loc.nil? == other.operator_loc.nil?) &&
12502 (opening_loc.nil? == other.opening_loc.nil?) &&
12503 (closing_loc.nil? == other.closing_loc.nil?) &&
12504 (parameters === other.parameters) &&
12505 (body === other.body)
12506 end
12507 end
12508
12509 # Represents the use of the `&&=` operator for assignment to a local variable.
12510 #
12511 # target &&= value
12512 # ^^^^^^^^^^^^^^^^
12513 class LocalVariableAndWriteNode < Node
12514 # Initialize a new LocalVariableAndWriteNode node.
12515 def initialize(source, node_id, location, flags, name_loc, operator_loc, value, name, depth)
12516 @source = source
12517 @node_id = node_id
12518 @location = location
12519 @flags = flags
12520 @name_loc = name_loc
12521 @operator_loc = operator_loc
12522 @value = value
12523 @name = name
12524 @depth = depth
12525 end
12526
12527 # def accept: (Visitor visitor) -> void
12528 def accept(visitor)
12529 visitor.visit_local_variable_and_write_node(self)
12530 end
12531
12532 # def child_nodes: () -> Array[Node?]
12533 def child_nodes
12534 [value]
12535 end
12536
12537 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12538 def each_child_node
12539 return to_enum(:each_child_node) unless block_given?
12540
12541 yield value
12542 end
12543
12544 # def compact_child_nodes: () -> Array[Node]
12545 def compact_child_nodes
12546 [value]
12547 end
12548
12549 # def comment_targets: () -> Array[Node | Location]
12550 def comment_targets
12551 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
12552 end
12553
12554 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node, ?name: Symbol, ?depth: Integer) -> LocalVariableAndWriteNode
12555 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value, name: self.name, depth: self.depth)
12556 LocalVariableAndWriteNode.new(source, node_id, location, flags, name_loc, operator_loc, value, name, depth)
12557 end
12558
12559 # def deconstruct: () -> Array[Node?]
12560 alias deconstruct child_nodes
12561
12562 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name_loc: Location, operator_loc: Location, value: Prism::node, name: Symbol, depth: Integer }
12563 def deconstruct_keys(keys)
12564 { node_id: node_id, location: location, name_loc: name_loc, operator_loc: operator_loc, value: value, name: name, depth: depth }
12565 end
12566
12567 # attr_reader name_loc: Location
12568 def name_loc
12569 location = @name_loc
12570 return location if location.is_a?(Location)
12571 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12572 end
12573
12574 # Save the name_loc location using the given saved source so that
12575 # it can be retrieved later.
12576 def save_name_loc(repository)
12577 repository.enter(node_id, :name_loc)
12578 end
12579
12580 # attr_reader operator_loc: Location
12581 def operator_loc
12582 location = @operator_loc
12583 return location if location.is_a?(Location)
12584 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12585 end
12586
12587 # Save the operator_loc location using the given saved source so that
12588 # it can be retrieved later.
12589 def save_operator_loc(repository)
12590 repository.enter(node_id, :operator_loc)
12591 end
12592
12593 # attr_reader value: Prism::node
12594 attr_reader :value
12595
12596 # attr_reader name: Symbol
12597 attr_reader :name
12598
12599 # attr_reader depth: Integer
12600 attr_reader :depth
12601
12602 # def operator: () -> String
12603 def operator
12604 operator_loc.slice
12605 end
12606
12607 # def inspect -> String
12608 def inspect
12609 InspectVisitor.compose(self)
12610 end
12611
12612 # Return a symbol representation of this node type. See `Node#type`.
12613 def type
12614 :local_variable_and_write_node
12615 end
12616
12617 # Return a symbol representation of this node type. See `Node::type`.
12618 def self.type
12619 :local_variable_and_write_node
12620 end
12621
12622 # Implements case-equality for the node. This is effectively == but without
12623 # comparing the value of locations. Locations are checked only for presence.
12624 def ===(other)
12625 other.is_a?(LocalVariableAndWriteNode) &&
12626 (name_loc.nil? == other.name_loc.nil?) &&
12627 (operator_loc.nil? == other.operator_loc.nil?) &&
12628 (value === other.value) &&
12629 (name === other.name) &&
12630 (depth === other.depth)
12631 end
12632 end
12633
12634 # Represents assigning to a local variable using an operator that isn't `=`.
12635 #
12636 # target += value
12637 # ^^^^^^^^^^^^^^^
12638 class LocalVariableOperatorWriteNode < Node
12639 # Initialize a new LocalVariableOperatorWriteNode node.
12640 def initialize(source, node_id, location, flags, name_loc, binary_operator_loc, value, name, binary_operator, depth)
12641 @source = source
12642 @node_id = node_id
12643 @location = location
12644 @flags = flags
12645 @name_loc = name_loc
12646 @binary_operator_loc = binary_operator_loc
12647 @value = value
12648 @name = name
12649 @binary_operator = binary_operator
12650 @depth = depth
12651 end
12652
12653 # def accept: (Visitor visitor) -> void
12654 def accept(visitor)
12655 visitor.visit_local_variable_operator_write_node(self)
12656 end
12657
12658 # def child_nodes: () -> Array[Node?]
12659 def child_nodes
12660 [value]
12661 end
12662
12663 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12664 def each_child_node
12665 return to_enum(:each_child_node) unless block_given?
12666
12667 yield value
12668 end
12669
12670 # def compact_child_nodes: () -> Array[Node]
12671 def compact_child_nodes
12672 [value]
12673 end
12674
12675 # def comment_targets: () -> Array[Node | Location]
12676 def comment_targets
12677 [name_loc, binary_operator_loc, value] #: Array[Prism::node | Location]
12678 end
12679
12680 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name_loc: Location, ?binary_operator_loc: Location, ?value: Prism::node, ?name: Symbol, ?binary_operator: Symbol, ?depth: Integer) -> LocalVariableOperatorWriteNode
12681 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, name: self.name, binary_operator: self.binary_operator, depth: self.depth)
12682 LocalVariableOperatorWriteNode.new(source, node_id, location, flags, name_loc, binary_operator_loc, value, name, binary_operator, depth)
12683 end
12684
12685 # def deconstruct: () -> Array[Node?]
12686 alias deconstruct child_nodes
12687
12688 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name_loc: Location, binary_operator_loc: Location, value: Prism::node, name: Symbol, binary_operator: Symbol, depth: Integer }
12689 def deconstruct_keys(keys)
12690 { node_id: node_id, location: location, name_loc: name_loc, binary_operator_loc: binary_operator_loc, value: value, name: name, binary_operator: binary_operator, depth: depth }
12691 end
12692
12693 # attr_reader name_loc: Location
12694 def name_loc
12695 location = @name_loc
12696 return location if location.is_a?(Location)
12697 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12698 end
12699
12700 # Save the name_loc location using the given saved source so that
12701 # it can be retrieved later.
12702 def save_name_loc(repository)
12703 repository.enter(node_id, :name_loc)
12704 end
12705
12706 # attr_reader binary_operator_loc: Location
12707 def binary_operator_loc
12708 location = @binary_operator_loc
12709 return location if location.is_a?(Location)
12710 @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12711 end
12712
12713 # Save the binary_operator_loc location using the given saved source so that
12714 # it can be retrieved later.
12715 def save_binary_operator_loc(repository)
12716 repository.enter(node_id, :binary_operator_loc)
12717 end
12718
12719 # attr_reader value: Prism::node
12720 attr_reader :value
12721
12722 # attr_reader name: Symbol
12723 attr_reader :name
12724
12725 # attr_reader binary_operator: Symbol
12726 attr_reader :binary_operator
12727
12728 # attr_reader depth: Integer
12729 attr_reader :depth
12730
12731 # def inspect -> String
12732 def inspect
12733 InspectVisitor.compose(self)
12734 end
12735
12736 # Return a symbol representation of this node type. See `Node#type`.
12737 def type
12738 :local_variable_operator_write_node
12739 end
12740
12741 # Return a symbol representation of this node type. See `Node::type`.
12742 def self.type
12743 :local_variable_operator_write_node
12744 end
12745
12746 # Implements case-equality for the node. This is effectively == but without
12747 # comparing the value of locations. Locations are checked only for presence.
12748 def ===(other)
12749 other.is_a?(LocalVariableOperatorWriteNode) &&
12750 (name_loc.nil? == other.name_loc.nil?) &&
12751 (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
12752 (value === other.value) &&
12753 (name === other.name) &&
12754 (binary_operator === other.binary_operator) &&
12755 (depth === other.depth)
12756 end
12757 end
12758
12759 # Represents the use of the `||=` operator for assignment to a local variable.
12760 #
12761 # target ||= value
12762 # ^^^^^^^^^^^^^^^^
12763 class LocalVariableOrWriteNode < Node
12764 # Initialize a new LocalVariableOrWriteNode node.
12765 def initialize(source, node_id, location, flags, name_loc, operator_loc, value, name, depth)
12766 @source = source
12767 @node_id = node_id
12768 @location = location
12769 @flags = flags
12770 @name_loc = name_loc
12771 @operator_loc = operator_loc
12772 @value = value
12773 @name = name
12774 @depth = depth
12775 end
12776
12777 # def accept: (Visitor visitor) -> void
12778 def accept(visitor)
12779 visitor.visit_local_variable_or_write_node(self)
12780 end
12781
12782 # def child_nodes: () -> Array[Node?]
12783 def child_nodes
12784 [value]
12785 end
12786
12787 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12788 def each_child_node
12789 return to_enum(:each_child_node) unless block_given?
12790
12791 yield value
12792 end
12793
12794 # def compact_child_nodes: () -> Array[Node]
12795 def compact_child_nodes
12796 [value]
12797 end
12798
12799 # def comment_targets: () -> Array[Node | Location]
12800 def comment_targets
12801 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
12802 end
12803
12804 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node, ?name: Symbol, ?depth: Integer) -> LocalVariableOrWriteNode
12805 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value, name: self.name, depth: self.depth)
12806 LocalVariableOrWriteNode.new(source, node_id, location, flags, name_loc, operator_loc, value, name, depth)
12807 end
12808
12809 # def deconstruct: () -> Array[Node?]
12810 alias deconstruct child_nodes
12811
12812 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name_loc: Location, operator_loc: Location, value: Prism::node, name: Symbol, depth: Integer }
12813 def deconstruct_keys(keys)
12814 { node_id: node_id, location: location, name_loc: name_loc, operator_loc: operator_loc, value: value, name: name, depth: depth }
12815 end
12816
12817 # attr_reader name_loc: Location
12818 def name_loc
12819 location = @name_loc
12820 return location if location.is_a?(Location)
12821 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12822 end
12823
12824 # Save the name_loc location using the given saved source so that
12825 # it can be retrieved later.
12826 def save_name_loc(repository)
12827 repository.enter(node_id, :name_loc)
12828 end
12829
12830 # attr_reader operator_loc: Location
12831 def operator_loc
12832 location = @operator_loc
12833 return location if location.is_a?(Location)
12834 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
12835 end
12836
12837 # Save the operator_loc location using the given saved source so that
12838 # it can be retrieved later.
12839 def save_operator_loc(repository)
12840 repository.enter(node_id, :operator_loc)
12841 end
12842
12843 # attr_reader value: Prism::node
12844 attr_reader :value
12845
12846 # attr_reader name: Symbol
12847 attr_reader :name
12848
12849 # attr_reader depth: Integer
12850 attr_reader :depth
12851
12852 # def operator: () -> String
12853 def operator
12854 operator_loc.slice
12855 end
12856
12857 # def inspect -> String
12858 def inspect
12859 InspectVisitor.compose(self)
12860 end
12861
12862 # Return a symbol representation of this node type. See `Node#type`.
12863 def type
12864 :local_variable_or_write_node
12865 end
12866
12867 # Return a symbol representation of this node type. See `Node::type`.
12868 def self.type
12869 :local_variable_or_write_node
12870 end
12871
12872 # Implements case-equality for the node. This is effectively == but without
12873 # comparing the value of locations. Locations are checked only for presence.
12874 def ===(other)
12875 other.is_a?(LocalVariableOrWriteNode) &&
12876 (name_loc.nil? == other.name_loc.nil?) &&
12877 (operator_loc.nil? == other.operator_loc.nil?) &&
12878 (value === other.value) &&
12879 (name === other.name) &&
12880 (depth === other.depth)
12881 end
12882 end
12883
12884 # Represents reading a local variable. Note that this requires that a local variable of the same name has already been written to in the same scope, otherwise it is parsed as a method call.
12885 #
12886 # foo
12887 # ^^^
12888 class LocalVariableReadNode < Node
12889 # Initialize a new LocalVariableReadNode node.
12890 def initialize(source, node_id, location, flags, name, depth)
12891 @source = source
12892 @node_id = node_id
12893 @location = location
12894 @flags = flags
12895 @name = name
12896 @depth = depth
12897 end
12898
12899 # def accept: (Visitor visitor) -> void
12900 def accept(visitor)
12901 visitor.visit_local_variable_read_node(self)
12902 end
12903
12904 # def child_nodes: () -> Array[Node?]
12905 def child_nodes
12906 []
12907 end
12908
12909 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
12910 def each_child_node
12911 return to_enum(:each_child_node) unless block_given?
12912
12913 end
12914
12915 # def compact_child_nodes: () -> Array[Node]
12916 def compact_child_nodes
12917 []
12918 end
12919
12920 # def comment_targets: () -> Array[Node | Location]
12921 def comment_targets
12922 [] #: Array[Prism::node | Location]
12923 end
12924
12925 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?depth: Integer) -> LocalVariableReadNode
12926 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, depth: self.depth)
12927 LocalVariableReadNode.new(source, node_id, location, flags, name, depth)
12928 end
12929
12930 # def deconstruct: () -> Array[Node?]
12931 alias deconstruct child_nodes
12932
12933 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, depth: Integer }
12934 def deconstruct_keys(keys)
12935 { node_id: node_id, location: location, name: name, depth: depth }
12936 end
12937
12938 # The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
12939 #
12940 # x # name `:x`
12941 #
12942 # _Test # name `:_Test`
12943 #
12944 # Note that this can also be an underscore followed by a number for the default block parameters.
12945 #
12946 # _1 # name `:_1`
12947 attr_reader :name
12948
12949 # The number of visible scopes that should be searched to find the origin of this local variable.
12950 #
12951 # foo = 1; foo # depth 0
12952 #
12953 # bar = 2; tap { bar } # depth 1
12954 #
12955 # The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
12956 attr_reader :depth
12957
12958 # def inspect -> String
12959 def inspect
12960 InspectVisitor.compose(self)
12961 end
12962
12963 # Return a symbol representation of this node type. See `Node#type`.
12964 def type
12965 :local_variable_read_node
12966 end
12967
12968 # Return a symbol representation of this node type. See `Node::type`.
12969 def self.type
12970 :local_variable_read_node
12971 end
12972
12973 # Implements case-equality for the node. This is effectively == but without
12974 # comparing the value of locations. Locations are checked only for presence.
12975 def ===(other)
12976 other.is_a?(LocalVariableReadNode) &&
12977 (name === other.name) &&
12978 (depth === other.depth)
12979 end
12980 end
12981
12982 # Represents writing to a local variable in a context that doesn't have an explicit value.
12983 #
12984 # foo, bar = baz
12985 # ^^^ ^^^
12986 #
12987 # foo => baz
12988 # ^^^
12989 class LocalVariableTargetNode < Node
12990 # Initialize a new LocalVariableTargetNode node.
12991 def initialize(source, node_id, location, flags, name, depth)
12992 @source = source
12993 @node_id = node_id
12994 @location = location
12995 @flags = flags
12996 @name = name
12997 @depth = depth
12998 end
12999
13000 # def accept: (Visitor visitor) -> void
13001 def accept(visitor)
13002 visitor.visit_local_variable_target_node(self)
13003 end
13004
13005 # def child_nodes: () -> Array[Node?]
13006 def child_nodes
13007 []
13008 end
13009
13010 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
13011 def each_child_node
13012 return to_enum(:each_child_node) unless block_given?
13013
13014 end
13015
13016 # def compact_child_nodes: () -> Array[Node]
13017 def compact_child_nodes
13018 []
13019 end
13020
13021 # def comment_targets: () -> Array[Node | Location]
13022 def comment_targets
13023 [] #: Array[Prism::node | Location]
13024 end
13025
13026 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?depth: Integer) -> LocalVariableTargetNode
13027 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, depth: self.depth)
13028 LocalVariableTargetNode.new(source, node_id, location, flags, name, depth)
13029 end
13030
13031 # def deconstruct: () -> Array[Node?]
13032 alias deconstruct child_nodes
13033
13034 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, depth: Integer }
13035 def deconstruct_keys(keys)
13036 { node_id: node_id, location: location, name: name, depth: depth }
13037 end
13038
13039 # attr_reader name: Symbol
13040 attr_reader :name
13041
13042 # attr_reader depth: Integer
13043 attr_reader :depth
13044
13045 # def inspect -> String
13046 def inspect
13047 InspectVisitor.compose(self)
13048 end
13049
13050 # Return a symbol representation of this node type. See `Node#type`.
13051 def type
13052 :local_variable_target_node
13053 end
13054
13055 # Return a symbol representation of this node type. See `Node::type`.
13056 def self.type
13057 :local_variable_target_node
13058 end
13059
13060 # Implements case-equality for the node. This is effectively == but without
13061 # comparing the value of locations. Locations are checked only for presence.
13062 def ===(other)
13063 other.is_a?(LocalVariableTargetNode) &&
13064 (name === other.name) &&
13065 (depth === other.depth)
13066 end
13067 end
13068
13069 # Represents writing to a local variable.
13070 #
13071 # foo = 1
13072 # ^^^^^^^
13073 class LocalVariableWriteNode < Node
13074 # Initialize a new LocalVariableWriteNode node.
13075 def initialize(source, node_id, location, flags, name, depth, name_loc, value, operator_loc)
13076 @source = source
13077 @node_id = node_id
13078 @location = location
13079 @flags = flags
13080 @name = name
13081 @depth = depth
13082 @name_loc = name_loc
13083 @value = value
13084 @operator_loc = operator_loc
13085 end
13086
13087 # def accept: (Visitor visitor) -> void
13088 def accept(visitor)
13089 visitor.visit_local_variable_write_node(self)
13090 end
13091
13092 # def child_nodes: () -> Array[Node?]
13093 def child_nodes
13094 [value]
13095 end
13096
13097 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
13098 def each_child_node
13099 return to_enum(:each_child_node) unless block_given?
13100
13101 yield value
13102 end
13103
13104 # def compact_child_nodes: () -> Array[Node]
13105 def compact_child_nodes
13106 [value]
13107 end
13108
13109 # def comment_targets: () -> Array[Node | Location]
13110 def comment_targets
13111 [name_loc, value, operator_loc] #: Array[Prism::node | Location]
13112 end
13113
13114 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?depth: Integer, ?name_loc: Location, ?value: Prism::node, ?operator_loc: Location) -> LocalVariableWriteNode
13115 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, depth: self.depth, name_loc: self.name_loc, value: self.value, operator_loc: self.operator_loc)
13116 LocalVariableWriteNode.new(source, node_id, location, flags, name, depth, name_loc, value, operator_loc)
13117 end
13118
13119 # def deconstruct: () -> Array[Node?]
13120 alias deconstruct child_nodes
13121
13122 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, depth: Integer, name_loc: Location, value: Prism::node, operator_loc: Location }
13123 def deconstruct_keys(keys)
13124 { node_id: node_id, location: location, name: name, depth: depth, name_loc: name_loc, value: value, operator_loc: operator_loc }
13125 end
13126
13127 # The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
13128 #
13129 # foo = :bar # name `:foo`
13130 #
13131 # abc = 123 # name `:abc`
13132 attr_reader :name
13133
13134 # The number of semantic scopes we have to traverse to find the declaration of this variable.
13135 #
13136 # foo = 1 # depth 0
13137 #
13138 # tap { foo = 1 } # depth 1
13139 #
13140 # The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
13141 attr_reader :depth
13142
13143 # The location of the variable name.
13144 #
13145 # foo = :bar
13146 # ^^^
13147 def name_loc
13148 location = @name_loc
13149 return location if location.is_a?(Location)
13150 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13151 end
13152
13153 # Save the name_loc location using the given saved source so that
13154 # it can be retrieved later.
13155 def save_name_loc(repository)
13156 repository.enter(node_id, :name_loc)
13157 end
13158
13159 # The value to write to the local variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
13160 #
13161 # foo = :bar
13162 # ^^^^
13163 #
13164 # abc = 1234
13165 # ^^^^
13166 #
13167 # Note that since the name of a local variable is known before the value is parsed, it is valid for a local variable to appear within the value of its own write.
13168 #
13169 # foo = foo
13170 attr_reader :value
13171
13172 # The location of the `=` operator.
13173 #
13174 # x = :y
13175 # ^
13176 def operator_loc
13177 location = @operator_loc
13178 return location if location.is_a?(Location)
13179 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13180 end
13181
13182 # Save the operator_loc location using the given saved source so that
13183 # it can be retrieved later.
13184 def save_operator_loc(repository)
13185 repository.enter(node_id, :operator_loc)
13186 end
13187
13188 # def operator: () -> String
13189 def operator
13190 operator_loc.slice
13191 end
13192
13193 # def inspect -> String
13194 def inspect
13195 InspectVisitor.compose(self)
13196 end
13197
13198 # Return a symbol representation of this node type. See `Node#type`.
13199 def type
13200 :local_variable_write_node
13201 end
13202
13203 # Return a symbol representation of this node type. See `Node::type`.
13204 def self.type
13205 :local_variable_write_node
13206 end
13207
13208 # Implements case-equality for the node. This is effectively == but without
13209 # comparing the value of locations. Locations are checked only for presence.
13210 def ===(other)
13211 other.is_a?(LocalVariableWriteNode) &&
13212 (name === other.name) &&
13213 (depth === other.depth) &&
13214 (name_loc.nil? == other.name_loc.nil?) &&
13215 (value === other.value) &&
13216 (operator_loc.nil? == other.operator_loc.nil?)
13217 end
13218 end
13219
13220 # Represents a regular expression literal used in the predicate of a conditional to implicitly match against the last line read by an IO object.
13221 #
13222 # if /foo/i then end
13223 # ^^^^^^
13224 class MatchLastLineNode < Node
13225 # Initialize a new MatchLastLineNode node.
13226 def initialize(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped)
13227 @source = source
13228 @node_id = node_id
13229 @location = location
13230 @flags = flags
13231 @opening_loc = opening_loc
13232 @content_loc = content_loc
13233 @closing_loc = closing_loc
13234 @unescaped = unescaped
13235 end
13236
13237 # def accept: (Visitor visitor) -> void
13238 def accept(visitor)
13239 visitor.visit_match_last_line_node(self)
13240 end
13241
13242 # def child_nodes: () -> Array[Node?]
13243 def child_nodes
13244 []
13245 end
13246
13247 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
13248 def each_child_node
13249 return to_enum(:each_child_node) unless block_given?
13250
13251 end
13252
13253 # def compact_child_nodes: () -> Array[Node]
13254 def compact_child_nodes
13255 []
13256 end
13257
13258 # def comment_targets: () -> Array[Node | Location]
13259 def comment_targets
13260 [opening_loc, content_loc, closing_loc] #: Array[Prism::node | Location]
13261 end
13262
13263 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?content_loc: Location, ?closing_loc: Location, ?unescaped: String) -> MatchLastLineNode
13264 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, content_loc: self.content_loc, closing_loc: self.closing_loc, unescaped: self.unescaped)
13265 MatchLastLineNode.new(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped)
13266 end
13267
13268 # def deconstruct: () -> Array[Node?]
13269 alias deconstruct child_nodes
13270
13271 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String }
13272 def deconstruct_keys(keys)
13273 { node_id: node_id, location: location, opening_loc: opening_loc, content_loc: content_loc, closing_loc: closing_loc, unescaped: unescaped }
13274 end
13275
13276 # def ignore_case?: () -> bool
13277 def ignore_case?
13278 flags.anybits?(RegularExpressionFlags::IGNORE_CASE)
13279 end
13280
13281 # def extended?: () -> bool
13282 def extended?
13283 flags.anybits?(RegularExpressionFlags::EXTENDED)
13284 end
13285
13286 # def multi_line?: () -> bool
13287 def multi_line?
13288 flags.anybits?(RegularExpressionFlags::MULTI_LINE)
13289 end
13290
13291 # def once?: () -> bool
13292 def once?
13293 flags.anybits?(RegularExpressionFlags::ONCE)
13294 end
13295
13296 # def euc_jp?: () -> bool
13297 def euc_jp?
13298 flags.anybits?(RegularExpressionFlags::EUC_JP)
13299 end
13300
13301 # def ascii_8bit?: () -> bool
13302 def ascii_8bit?
13303 flags.anybits?(RegularExpressionFlags::ASCII_8BIT)
13304 end
13305
13306 # def windows_31j?: () -> bool
13307 def windows_31j?
13308 flags.anybits?(RegularExpressionFlags::WINDOWS_31J)
13309 end
13310
13311 # def utf_8?: () -> bool
13312 def utf_8?
13313 flags.anybits?(RegularExpressionFlags::UTF_8)
13314 end
13315
13316 # def forced_utf8_encoding?: () -> bool
13317 def forced_utf8_encoding?
13318 flags.anybits?(RegularExpressionFlags::FORCED_UTF8_ENCODING)
13319 end
13320
13321 # def forced_binary_encoding?: () -> bool
13322 def forced_binary_encoding?
13323 flags.anybits?(RegularExpressionFlags::FORCED_BINARY_ENCODING)
13324 end
13325
13326 # def forced_us_ascii_encoding?: () -> bool
13327 def forced_us_ascii_encoding?
13328 flags.anybits?(RegularExpressionFlags::FORCED_US_ASCII_ENCODING)
13329 end
13330
13331 # attr_reader opening_loc: Location
13332 def opening_loc
13333 location = @opening_loc
13334 return location if location.is_a?(Location)
13335 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13336 end
13337
13338 # Save the opening_loc location using the given saved source so that
13339 # it can be retrieved later.
13340 def save_opening_loc(repository)
13341 repository.enter(node_id, :opening_loc)
13342 end
13343
13344 # attr_reader content_loc: Location
13345 def content_loc
13346 location = @content_loc
13347 return location if location.is_a?(Location)
13348 @content_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13349 end
13350
13351 # Save the content_loc location using the given saved source so that
13352 # it can be retrieved later.
13353 def save_content_loc(repository)
13354 repository.enter(node_id, :content_loc)
13355 end
13356
13357 # attr_reader closing_loc: Location
13358 def closing_loc
13359 location = @closing_loc
13360 return location if location.is_a?(Location)
13361 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13362 end
13363
13364 # Save the closing_loc location using the given saved source so that
13365 # it can be retrieved later.
13366 def save_closing_loc(repository)
13367 repository.enter(node_id, :closing_loc)
13368 end
13369
13370 # attr_reader unescaped: String
13371 attr_reader :unescaped
13372
13373 # def opening: () -> String
13374 def opening
13375 opening_loc.slice
13376 end
13377
13378 # def content: () -> String
13379 def content
13380 content_loc.slice
13381 end
13382
13383 # def closing: () -> String
13384 def closing
13385 closing_loc.slice
13386 end
13387
13388 # def inspect -> String
13389 def inspect
13390 InspectVisitor.compose(self)
13391 end
13392
13393 # Return a symbol representation of this node type. See `Node#type`.
13394 def type
13395 :match_last_line_node
13396 end
13397
13398 # Return a symbol representation of this node type. See `Node::type`.
13399 def self.type
13400 :match_last_line_node
13401 end
13402
13403 # Implements case-equality for the node. This is effectively == but without
13404 # comparing the value of locations. Locations are checked only for presence.
13405 def ===(other)
13406 other.is_a?(MatchLastLineNode) &&
13407 (flags === other.flags) &&
13408 (opening_loc.nil? == other.opening_loc.nil?) &&
13409 (content_loc.nil? == other.content_loc.nil?) &&
13410 (closing_loc.nil? == other.closing_loc.nil?) &&
13411 (unescaped === other.unescaped)
13412 end
13413 end
13414
13415 # Represents the use of the modifier `in` operator.
13416 #
13417 # foo in bar
13418 # ^^^^^^^^^^
13419 class MatchPredicateNode < Node
13420 # Initialize a new MatchPredicateNode node.
13421 def initialize(source, node_id, location, flags, value, pattern, operator_loc)
13422 @source = source
13423 @node_id = node_id
13424 @location = location
13425 @flags = flags
13426 @value = value
13427 @pattern = pattern
13428 @operator_loc = operator_loc
13429 end
13430
13431 # def accept: (Visitor visitor) -> void
13432 def accept(visitor)
13433 visitor.visit_match_predicate_node(self)
13434 end
13435
13436 # def child_nodes: () -> Array[Node?]
13437 def child_nodes
13438 [value, pattern]
13439 end
13440
13441 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
13442 def each_child_node
13443 return to_enum(:each_child_node) unless block_given?
13444
13445 yield value
13446 yield pattern
13447 end
13448
13449 # def compact_child_nodes: () -> Array[Node]
13450 def compact_child_nodes
13451 [value, pattern]
13452 end
13453
13454 # def comment_targets: () -> Array[Node | Location]
13455 def comment_targets
13456 [value, pattern, operator_loc] #: Array[Prism::node | Location]
13457 end
13458
13459 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?pattern: Prism::node, ?operator_loc: Location) -> MatchPredicateNode
13460 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, pattern: self.pattern, operator_loc: self.operator_loc)
13461 MatchPredicateNode.new(source, node_id, location, flags, value, pattern, operator_loc)
13462 end
13463
13464 # def deconstruct: () -> Array[Node?]
13465 alias deconstruct child_nodes
13466
13467 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, value: Prism::node, pattern: Prism::node, operator_loc: Location }
13468 def deconstruct_keys(keys)
13469 { node_id: node_id, location: location, value: value, pattern: pattern, operator_loc: operator_loc }
13470 end
13471
13472 # attr_reader value: Prism::node
13473 attr_reader :value
13474
13475 # attr_reader pattern: Prism::node
13476 attr_reader :pattern
13477
13478 # attr_reader operator_loc: Location
13479 def operator_loc
13480 location = @operator_loc
13481 return location if location.is_a?(Location)
13482 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13483 end
13484
13485 # Save the operator_loc location using the given saved source so that
13486 # it can be retrieved later.
13487 def save_operator_loc(repository)
13488 repository.enter(node_id, :operator_loc)
13489 end
13490
13491 # def operator: () -> String
13492 def operator
13493 operator_loc.slice
13494 end
13495
13496 # def inspect -> String
13497 def inspect
13498 InspectVisitor.compose(self)
13499 end
13500
13501 # Return a symbol representation of this node type. See `Node#type`.
13502 def type
13503 :match_predicate_node
13504 end
13505
13506 # Return a symbol representation of this node type. See `Node::type`.
13507 def self.type
13508 :match_predicate_node
13509 end
13510
13511 # Implements case-equality for the node. This is effectively == but without
13512 # comparing the value of locations. Locations are checked only for presence.
13513 def ===(other)
13514 other.is_a?(MatchPredicateNode) &&
13515 (value === other.value) &&
13516 (pattern === other.pattern) &&
13517 (operator_loc.nil? == other.operator_loc.nil?)
13518 end
13519 end
13520
13521 # Represents the use of the `=>` operator.
13522 #
13523 # foo => bar
13524 # ^^^^^^^^^^
13525 class MatchRequiredNode < Node
13526 # Initialize a new MatchRequiredNode node.
13527 def initialize(source, node_id, location, flags, value, pattern, operator_loc)
13528 @source = source
13529 @node_id = node_id
13530 @location = location
13531 @flags = flags
13532 @value = value
13533 @pattern = pattern
13534 @operator_loc = operator_loc
13535 end
13536
13537 # def accept: (Visitor visitor) -> void
13538 def accept(visitor)
13539 visitor.visit_match_required_node(self)
13540 end
13541
13542 # def child_nodes: () -> Array[Node?]
13543 def child_nodes
13544 [value, pattern]
13545 end
13546
13547 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
13548 def each_child_node
13549 return to_enum(:each_child_node) unless block_given?
13550
13551 yield value
13552 yield pattern
13553 end
13554
13555 # def compact_child_nodes: () -> Array[Node]
13556 def compact_child_nodes
13557 [value, pattern]
13558 end
13559
13560 # def comment_targets: () -> Array[Node | Location]
13561 def comment_targets
13562 [value, pattern, operator_loc] #: Array[Prism::node | Location]
13563 end
13564
13565 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?pattern: Prism::node, ?operator_loc: Location) -> MatchRequiredNode
13566 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, pattern: self.pattern, operator_loc: self.operator_loc)
13567 MatchRequiredNode.new(source, node_id, location, flags, value, pattern, operator_loc)
13568 end
13569
13570 # def deconstruct: () -> Array[Node?]
13571 alias deconstruct child_nodes
13572
13573 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, value: Prism::node, pattern: Prism::node, operator_loc: Location }
13574 def deconstruct_keys(keys)
13575 { node_id: node_id, location: location, value: value, pattern: pattern, operator_loc: operator_loc }
13576 end
13577
13578 # Represents the left-hand side of the operator.
13579 #
13580 # foo => bar
13581 # ^^^
13582 attr_reader :value
13583
13584 # Represents the right-hand side of the operator. The type of the node depends on the expression.
13585 #
13586 # Anything that looks like a local variable name (including `_`) will result in a `LocalVariableTargetNode`.
13587 #
13588 # foo => a # This is equivalent to writing `a = foo`
13589 # ^
13590 #
13591 # Using an explicit `Array` or combining expressions with `,` will result in a `ArrayPatternNode`. This can be preceded by a constant.
13592 #
13593 # foo => [a]
13594 # ^^^
13595 #
13596 # foo => a, b
13597 # ^^^^
13598 #
13599 # foo => Bar[a, b]
13600 # ^^^^^^^^^
13601 #
13602 # If the array pattern contains at least two wildcard matches, a `FindPatternNode` is created instead.
13603 #
13604 # foo => *, 1, *a
13605 # ^^^^^
13606 #
13607 # Using an explicit `Hash` or a constant with square brackets and hash keys in the square brackets will result in a `HashPatternNode`.
13608 #
13609 # foo => { a: 1, b: }
13610 #
13611 # foo => Bar[a: 1, b:]
13612 #
13613 # foo => Bar[**]
13614 #
13615 # To use any variable that needs run time evaluation, pinning is required. This results in a `PinnedVariableNode`
13616 #
13617 # foo => ^a
13618 # ^^
13619 #
13620 # Similar, any expression can be used with pinning. This results in a `PinnedExpressionNode`.
13621 #
13622 # foo => ^(a + 1)
13623 #
13624 # Anything else will result in the regular node for that expression, for example a `ConstantReadNode`.
13625 #
13626 # foo => CONST
13627 attr_reader :pattern
13628
13629 # The location of the operator.
13630 #
13631 # foo => bar
13632 # ^^
13633 def operator_loc
13634 location = @operator_loc
13635 return location if location.is_a?(Location)
13636 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13637 end
13638
13639 # Save the operator_loc location using the given saved source so that
13640 # it can be retrieved later.
13641 def save_operator_loc(repository)
13642 repository.enter(node_id, :operator_loc)
13643 end
13644
13645 # def operator: () -> String
13646 def operator
13647 operator_loc.slice
13648 end
13649
13650 # def inspect -> String
13651 def inspect
13652 InspectVisitor.compose(self)
13653 end
13654
13655 # Return a symbol representation of this node type. See `Node#type`.
13656 def type
13657 :match_required_node
13658 end
13659
13660 # Return a symbol representation of this node type. See `Node::type`.
13661 def self.type
13662 :match_required_node
13663 end
13664
13665 # Implements case-equality for the node. This is effectively == but without
13666 # comparing the value of locations. Locations are checked only for presence.
13667 def ===(other)
13668 other.is_a?(MatchRequiredNode) &&
13669 (value === other.value) &&
13670 (pattern === other.pattern) &&
13671 (operator_loc.nil? == other.operator_loc.nil?)
13672 end
13673 end
13674
13675 # Represents writing local variables using a regular expression match with named capture groups.
13676 #
13677 # /(?<foo>bar)/ =~ baz
13678 # ^^^^^^^^^^^^^^^^^^^^
13679 class MatchWriteNode < Node
13680 # Initialize a new MatchWriteNode node.
13681 def initialize(source, node_id, location, flags, call, targets)
13682 @source = source
13683 @node_id = node_id
13684 @location = location
13685 @flags = flags
13686 @call = call
13687 @targets = targets
13688 end
13689
13690 # def accept: (Visitor visitor) -> void
13691 def accept(visitor)
13692 visitor.visit_match_write_node(self)
13693 end
13694
13695 # def child_nodes: () -> Array[Node?]
13696 def child_nodes
13697 [call, *targets]
13698 end
13699
13700 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
13701 def each_child_node
13702 return to_enum(:each_child_node) unless block_given?
13703
13704 yield call
13705 targets.each { |node| yield node }
13706 end
13707
13708 # def compact_child_nodes: () -> Array[Node]
13709 def compact_child_nodes
13710 [call, *targets]
13711 end
13712
13713 # def comment_targets: () -> Array[Node | Location]
13714 def comment_targets
13715 [call, *targets] #: Array[Prism::node | Location]
13716 end
13717
13718 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?call: CallNode, ?targets: Array[LocalVariableTargetNode]) -> MatchWriteNode
13719 def copy(node_id: self.node_id, location: self.location, flags: self.flags, call: self.call, targets: self.targets)
13720 MatchWriteNode.new(source, node_id, location, flags, call, targets)
13721 end
13722
13723 # def deconstruct: () -> Array[Node?]
13724 alias deconstruct child_nodes
13725
13726 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, call: CallNode, targets: Array[LocalVariableTargetNode] }
13727 def deconstruct_keys(keys)
13728 { node_id: node_id, location: location, call: call, targets: targets }
13729 end
13730
13731 # attr_reader call: CallNode
13732 attr_reader :call
13733
13734 # attr_reader targets: Array[LocalVariableTargetNode]
13735 attr_reader :targets
13736
13737 # def inspect -> String
13738 def inspect
13739 InspectVisitor.compose(self)
13740 end
13741
13742 # Return a symbol representation of this node type. See `Node#type`.
13743 def type
13744 :match_write_node
13745 end
13746
13747 # Return a symbol representation of this node type. See `Node::type`.
13748 def self.type
13749 :match_write_node
13750 end
13751
13752 # Implements case-equality for the node. This is effectively == but without
13753 # comparing the value of locations. Locations are checked only for presence.
13754 def ===(other)
13755 other.is_a?(MatchWriteNode) &&
13756 (call === other.call) &&
13757 (targets.length == other.targets.length) &&
13758 targets.zip(other.targets).all? { |left, right| left === right }
13759 end
13760 end
13761
13762 # Represents a node that is missing from the source and results in a syntax error.
13763 class MissingNode < Node
13764 # Initialize a new MissingNode node.
13765 def initialize(source, node_id, location, flags)
13766 @source = source
13767 @node_id = node_id
13768 @location = location
13769 @flags = flags
13770 end
13771
13772 # def accept: (Visitor visitor) -> void
13773 def accept(visitor)
13774 visitor.visit_missing_node(self)
13775 end
13776
13777 # def child_nodes: () -> Array[Node?]
13778 def child_nodes
13779 []
13780 end
13781
13782 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
13783 def each_child_node
13784 return to_enum(:each_child_node) unless block_given?
13785
13786 end
13787
13788 # def compact_child_nodes: () -> Array[Node]
13789 def compact_child_nodes
13790 []
13791 end
13792
13793 # def comment_targets: () -> Array[Node | Location]
13794 def comment_targets
13795 [] #: Array[Prism::node | Location]
13796 end
13797
13798 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> MissingNode
13799 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
13800 MissingNode.new(source, node_id, location, flags)
13801 end
13802
13803 # def deconstruct: () -> Array[Node?]
13804 alias deconstruct child_nodes
13805
13806 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
13807 def deconstruct_keys(keys)
13808 { node_id: node_id, location: location }
13809 end
13810
13811 # def inspect -> String
13812 def inspect
13813 InspectVisitor.compose(self)
13814 end
13815
13816 # Return a symbol representation of this node type. See `Node#type`.
13817 def type
13818 :missing_node
13819 end
13820
13821 # Return a symbol representation of this node type. See `Node::type`.
13822 def self.type
13823 :missing_node
13824 end
13825
13826 # Implements case-equality for the node. This is effectively == but without
13827 # comparing the value of locations. Locations are checked only for presence.
13828 def ===(other)
13829 other.is_a?(MissingNode)
13830 end
13831 end
13832
13833 # Represents a module declaration involving the `module` keyword.
13834 #
13835 # module Foo end
13836 # ^^^^^^^^^^^^^^
13837 class ModuleNode < Node
13838 # Initialize a new ModuleNode node.
13839 def initialize(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name)
13840 @source = source
13841 @node_id = node_id
13842 @location = location
13843 @flags = flags
13844 @locals = locals
13845 @module_keyword_loc = module_keyword_loc
13846 @constant_path = constant_path
13847 @body = body
13848 @end_keyword_loc = end_keyword_loc
13849 @name = name
13850 end
13851
13852 # def accept: (Visitor visitor) -> void
13853 def accept(visitor)
13854 visitor.visit_module_node(self)
13855 end
13856
13857 # def child_nodes: () -> Array[Node?]
13858 def child_nodes
13859 [constant_path, body]
13860 end
13861
13862 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
13863 def each_child_node
13864 return to_enum(:each_child_node) unless block_given?
13865
13866 yield constant_path
13867 yield body if body
13868 end
13869
13870 # def compact_child_nodes: () -> Array[Node]
13871 def compact_child_nodes
13872 compact = [] #: Array[Prism::node]
13873 compact << constant_path
13874 compact << body if body
13875 compact
13876 end
13877
13878 # def comment_targets: () -> Array[Node | Location]
13879 def comment_targets
13880 [module_keyword_loc, constant_path, *body, end_keyword_loc] #: Array[Prism::node | Location]
13881 end
13882
13883 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array[Symbol], ?module_keyword_loc: Location, ?constant_path: ConstantReadNode | ConstantPathNode | MissingNode, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ModuleNode
13884 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, module_keyword_loc: self.module_keyword_loc, constant_path: self.constant_path, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name)
13885 ModuleNode.new(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name)
13886 end
13887
13888 # def deconstruct: () -> Array[Node?]
13889 alias deconstruct child_nodes
13890
13891 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, locals: Array[Symbol], module_keyword_loc: Location, constant_path: ConstantReadNode | ConstantPathNode | MissingNode, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location, name: Symbol }
13892 def deconstruct_keys(keys)
13893 { node_id: node_id, location: location, locals: locals, module_keyword_loc: module_keyword_loc, constant_path: constant_path, body: body, end_keyword_loc: end_keyword_loc, name: name }
13894 end
13895
13896 # attr_reader locals: Array[Symbol]
13897 attr_reader :locals
13898
13899 # attr_reader module_keyword_loc: Location
13900 def module_keyword_loc
13901 location = @module_keyword_loc
13902 return location if location.is_a?(Location)
13903 @module_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13904 end
13905
13906 # Save the module_keyword_loc location using the given saved source so that
13907 # it can be retrieved later.
13908 def save_module_keyword_loc(repository)
13909 repository.enter(node_id, :module_keyword_loc)
13910 end
13911
13912 # attr_reader constant_path: ConstantReadNode | ConstantPathNode | MissingNode
13913 attr_reader :constant_path
13914
13915 # attr_reader body: StatementsNode | BeginNode | nil
13916 attr_reader :body
13917
13918 # attr_reader end_keyword_loc: Location
13919 def end_keyword_loc
13920 location = @end_keyword_loc
13921 return location if location.is_a?(Location)
13922 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
13923 end
13924
13925 # Save the end_keyword_loc location using the given saved source so that
13926 # it can be retrieved later.
13927 def save_end_keyword_loc(repository)
13928 repository.enter(node_id, :end_keyword_loc)
13929 end
13930
13931 # attr_reader name: Symbol
13932 attr_reader :name
13933
13934 # def module_keyword: () -> String
13935 def module_keyword
13936 module_keyword_loc.slice
13937 end
13938
13939 # def end_keyword: () -> String
13940 def end_keyword
13941 end_keyword_loc.slice
13942 end
13943
13944 # def inspect -> String
13945 def inspect
13946 InspectVisitor.compose(self)
13947 end
13948
13949 # Return a symbol representation of this node type. See `Node#type`.
13950 def type
13951 :module_node
13952 end
13953
13954 # Return a symbol representation of this node type. See `Node::type`.
13955 def self.type
13956 :module_node
13957 end
13958
13959 # Implements case-equality for the node. This is effectively == but without
13960 # comparing the value of locations. Locations are checked only for presence.
13961 def ===(other)
13962 other.is_a?(ModuleNode) &&
13963 (locals.length == other.locals.length) &&
13964 locals.zip(other.locals).all? { |left, right| left === right } &&
13965 (module_keyword_loc.nil? == other.module_keyword_loc.nil?) &&
13966 (constant_path === other.constant_path) &&
13967 (body === other.body) &&
13968 (end_keyword_loc.nil? == other.end_keyword_loc.nil?) &&
13969 (name === other.name)
13970 end
13971 end
13972
13973 # Represents a multi-target expression.
13974 #
13975 # a, (b, c) = 1, 2, 3
13976 # ^^^^^^
13977 #
13978 # This can be a part of `MultiWriteNode` as above, or the target of a `for` loop
13979 #
13980 # for a, b in [[1, 2], [3, 4]]
13981 # ^^^^
13982 class MultiTargetNode < Node
13983 # Initialize a new MultiTargetNode node.
13984 def initialize(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc)
13985 @source = source
13986 @node_id = node_id
13987 @location = location
13988 @flags = flags
13989 @lefts = lefts
13990 @rest = rest
13991 @rights = rights
13992 @lparen_loc = lparen_loc
13993 @rparen_loc = rparen_loc
13994 end
13995
13996 # def accept: (Visitor visitor) -> void
13997 def accept(visitor)
13998 visitor.visit_multi_target_node(self)
13999 end
14000
14001 # def child_nodes: () -> Array[Node?]
14002 def child_nodes
14003 [*lefts, rest, *rights]
14004 end
14005
14006 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14007 def each_child_node
14008 return to_enum(:each_child_node) unless block_given?
14009
14010 lefts.each { |node| yield node }
14011 yield rest if rest
14012 rights.each { |node| yield node }
14013 end
14014
14015 # def compact_child_nodes: () -> Array[Node]
14016 def compact_child_nodes
14017 compact = [] #: Array[Prism::node]
14018 compact.concat(lefts)
14019 compact << rest if rest
14020 compact.concat(rights)
14021 compact
14022 end
14023
14024 # def comment_targets: () -> Array[Node | Location]
14025 def comment_targets
14026 [*lefts, *rest, *rights, *lparen_loc, *rparen_loc] #: Array[Prism::node | Location]
14027 end
14028
14029 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], ?rest: ImplicitRestNode | SplatNode | nil, ?rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], ?lparen_loc: Location?, ?rparen_loc: Location?) -> MultiTargetNode
14030 def copy(node_id: self.node_id, location: self.location, flags: self.flags, lefts: self.lefts, rest: self.rest, rights: self.rights, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc)
14031 MultiTargetNode.new(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc)
14032 end
14033
14034 # def deconstruct: () -> Array[Node?]
14035 alias deconstruct child_nodes
14036
14037 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], rest: ImplicitRestNode | SplatNode | nil, rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], lparen_loc: Location?, rparen_loc: Location? }
14038 def deconstruct_keys(keys)
14039 { node_id: node_id, location: location, lefts: lefts, rest: rest, rights: rights, lparen_loc: lparen_loc, rparen_loc: rparen_loc }
14040 end
14041
14042 # Represents the targets expressions before a splat node.
14043 #
14044 # a, (b, c, *) = 1, 2, 3, 4, 5
14045 # ^^^^
14046 #
14047 # The splat node can be absent, in that case all target expressions are in the left field.
14048 #
14049 # a, (b, c) = 1, 2, 3, 4, 5
14050 # ^^^^
14051 attr_reader :lefts
14052
14053 # Represents a splat node in the target expression.
14054 #
14055 # a, (b, *c) = 1, 2, 3, 4
14056 # ^^
14057 #
14058 # The variable can be empty, this results in a `SplatNode` with a `nil` expression field.
14059 #
14060 # a, (b, *) = 1, 2, 3, 4
14061 # ^
14062 #
14063 # If the `*` is omitted, this field will contain an `ImplicitRestNode`
14064 #
14065 # a, (b,) = 1, 2, 3, 4
14066 # ^
14067 attr_reader :rest
14068
14069 # Represents the targets expressions after a splat node.
14070 #
14071 # a, (*, b, c) = 1, 2, 3, 4, 5
14072 # ^^^^
14073 attr_reader :rights
14074
14075 # The location of the opening parenthesis.
14076 #
14077 # a, (b, c) = 1, 2, 3
14078 # ^
14079 def lparen_loc
14080 location = @lparen_loc
14081 case location
14082 when nil
14083 nil
14084 when Location
14085 location
14086 else
14087 @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14088 end
14089 end
14090
14091 # Save the lparen_loc location using the given saved source so that
14092 # it can be retrieved later.
14093 def save_lparen_loc(repository)
14094 repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil?
14095 end
14096
14097 # The location of the closing parenthesis.
14098 #
14099 # a, (b, c) = 1, 2, 3
14100 # ^
14101 def rparen_loc
14102 location = @rparen_loc
14103 case location
14104 when nil
14105 nil
14106 when Location
14107 location
14108 else
14109 @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14110 end
14111 end
14112
14113 # Save the rparen_loc location using the given saved source so that
14114 # it can be retrieved later.
14115 def save_rparen_loc(repository)
14116 repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil?
14117 end
14118
14119 # def lparen: () -> String?
14120 def lparen
14121 lparen_loc&.slice
14122 end
14123
14124 # def rparen: () -> String?
14125 def rparen
14126 rparen_loc&.slice
14127 end
14128
14129 # def inspect -> String
14130 def inspect
14131 InspectVisitor.compose(self)
14132 end
14133
14134 # Return a symbol representation of this node type. See `Node#type`.
14135 def type
14136 :multi_target_node
14137 end
14138
14139 # Return a symbol representation of this node type. See `Node::type`.
14140 def self.type
14141 :multi_target_node
14142 end
14143
14144 # Implements case-equality for the node. This is effectively == but without
14145 # comparing the value of locations. Locations are checked only for presence.
14146 def ===(other)
14147 other.is_a?(MultiTargetNode) &&
14148 (lefts.length == other.lefts.length) &&
14149 lefts.zip(other.lefts).all? { |left, right| left === right } &&
14150 (rest === other.rest) &&
14151 (rights.length == other.rights.length) &&
14152 rights.zip(other.rights).all? { |left, right| left === right } &&
14153 (lparen_loc.nil? == other.lparen_loc.nil?) &&
14154 (rparen_loc.nil? == other.rparen_loc.nil?)
14155 end
14156 end
14157
14158 # Represents a write to a multi-target expression.
14159 #
14160 # a, b, c = 1, 2, 3
14161 # ^^^^^^^^^^^^^^^^^
14162 class MultiWriteNode < Node
14163 # Initialize a new MultiWriteNode node.
14164 def initialize(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc, operator_loc, value)
14165 @source = source
14166 @node_id = node_id
14167 @location = location
14168 @flags = flags
14169 @lefts = lefts
14170 @rest = rest
14171 @rights = rights
14172 @lparen_loc = lparen_loc
14173 @rparen_loc = rparen_loc
14174 @operator_loc = operator_loc
14175 @value = value
14176 end
14177
14178 # def accept: (Visitor visitor) -> void
14179 def accept(visitor)
14180 visitor.visit_multi_write_node(self)
14181 end
14182
14183 # def child_nodes: () -> Array[Node?]
14184 def child_nodes
14185 [*lefts, rest, *rights, value]
14186 end
14187
14188 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14189 def each_child_node
14190 return to_enum(:each_child_node) unless block_given?
14191
14192 lefts.each { |node| yield node }
14193 yield rest if rest
14194 rights.each { |node| yield node }
14195 yield value
14196 end
14197
14198 # def compact_child_nodes: () -> Array[Node]
14199 def compact_child_nodes
14200 compact = [] #: Array[Prism::node]
14201 compact.concat(lefts)
14202 compact << rest if rest
14203 compact.concat(rights)
14204 compact << value
14205 compact
14206 end
14207
14208 # def comment_targets: () -> Array[Node | Location]
14209 def comment_targets
14210 [*lefts, *rest, *rights, *lparen_loc, *rparen_loc, operator_loc, value] #: Array[Prism::node | Location]
14211 end
14212
14213 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode], ?rest: ImplicitRestNode | SplatNode | nil, ?rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode], ?lparen_loc: Location?, ?rparen_loc: Location?, ?operator_loc: Location, ?value: Prism::node) -> MultiWriteNode
14214 def copy(node_id: self.node_id, location: self.location, flags: self.flags, lefts: self.lefts, rest: self.rest, rights: self.rights, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, operator_loc: self.operator_loc, value: self.value)
14215 MultiWriteNode.new(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc, operator_loc, value)
14216 end
14217
14218 # def deconstruct: () -> Array[Node?]
14219 alias deconstruct child_nodes
14220
14221 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode], rest: ImplicitRestNode | SplatNode | nil, rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode], lparen_loc: Location?, rparen_loc: Location?, operator_loc: Location, value: Prism::node }
14222 def deconstruct_keys(keys)
14223 { node_id: node_id, location: location, lefts: lefts, rest: rest, rights: rights, lparen_loc: lparen_loc, rparen_loc: rparen_loc, operator_loc: operator_loc, value: value }
14224 end
14225
14226 # Represents the targets expressions before a splat node.
14227 #
14228 # a, b, * = 1, 2, 3, 4, 5
14229 # ^^^^
14230 #
14231 # The splat node can be absent, in that case all target expressions are in the left field.
14232 #
14233 # a, b, c = 1, 2, 3, 4, 5
14234 # ^^^^^^^
14235 attr_reader :lefts
14236
14237 # Represents a splat node in the target expression.
14238 #
14239 # a, b, *c = 1, 2, 3, 4
14240 # ^^
14241 #
14242 # The variable can be empty, this results in a `SplatNode` with a `nil` expression field.
14243 #
14244 # a, b, * = 1, 2, 3, 4
14245 # ^
14246 #
14247 # If the `*` is omitted, this field will contain an `ImplicitRestNode`
14248 #
14249 # a, b, = 1, 2, 3, 4
14250 # ^
14251 attr_reader :rest
14252
14253 # Represents the targets expressions after a splat node.
14254 #
14255 # a, *, b, c = 1, 2, 3, 4, 5
14256 # ^^^^
14257 attr_reader :rights
14258
14259 # The location of the opening parenthesis.
14260 #
14261 # (a, b, c) = 1, 2, 3
14262 # ^
14263 def lparen_loc
14264 location = @lparen_loc
14265 case location
14266 when nil
14267 nil
14268 when Location
14269 location
14270 else
14271 @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14272 end
14273 end
14274
14275 # Save the lparen_loc location using the given saved source so that
14276 # it can be retrieved later.
14277 def save_lparen_loc(repository)
14278 repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil?
14279 end
14280
14281 # The location of the closing parenthesis.
14282 #
14283 # (a, b, c) = 1, 2, 3
14284 # ^
14285 def rparen_loc
14286 location = @rparen_loc
14287 case location
14288 when nil
14289 nil
14290 when Location
14291 location
14292 else
14293 @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14294 end
14295 end
14296
14297 # Save the rparen_loc location using the given saved source so that
14298 # it can be retrieved later.
14299 def save_rparen_loc(repository)
14300 repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil?
14301 end
14302
14303 # The location of the operator.
14304 #
14305 # a, b, c = 1, 2, 3
14306 # ^
14307 def operator_loc
14308 location = @operator_loc
14309 return location if location.is_a?(Location)
14310 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14311 end
14312
14313 # Save the operator_loc location using the given saved source so that
14314 # it can be retrieved later.
14315 def save_operator_loc(repository)
14316 repository.enter(node_id, :operator_loc)
14317 end
14318
14319 # The value to write to the targets. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
14320 #
14321 # a, b, c = 1, 2, 3
14322 # ^^^^^^^
14323 attr_reader :value
14324
14325 # def lparen: () -> String?
14326 def lparen
14327 lparen_loc&.slice
14328 end
14329
14330 # def rparen: () -> String?
14331 def rparen
14332 rparen_loc&.slice
14333 end
14334
14335 # def operator: () -> String
14336 def operator
14337 operator_loc.slice
14338 end
14339
14340 # def inspect -> String
14341 def inspect
14342 InspectVisitor.compose(self)
14343 end
14344
14345 # Return a symbol representation of this node type. See `Node#type`.
14346 def type
14347 :multi_write_node
14348 end
14349
14350 # Return a symbol representation of this node type. See `Node::type`.
14351 def self.type
14352 :multi_write_node
14353 end
14354
14355 # Implements case-equality for the node. This is effectively == but without
14356 # comparing the value of locations. Locations are checked only for presence.
14357 def ===(other)
14358 other.is_a?(MultiWriteNode) &&
14359 (lefts.length == other.lefts.length) &&
14360 lefts.zip(other.lefts).all? { |left, right| left === right } &&
14361 (rest === other.rest) &&
14362 (rights.length == other.rights.length) &&
14363 rights.zip(other.rights).all? { |left, right| left === right } &&
14364 (lparen_loc.nil? == other.lparen_loc.nil?) &&
14365 (rparen_loc.nil? == other.rparen_loc.nil?) &&
14366 (operator_loc.nil? == other.operator_loc.nil?) &&
14367 (value === other.value)
14368 end
14369 end
14370
14371 # Represents the use of the `next` keyword.
14372 #
14373 # next 1
14374 # ^^^^^^
14375 class NextNode < Node
14376 # Initialize a new NextNode node.
14377 def initialize(source, node_id, location, flags, arguments, keyword_loc)
14378 @source = source
14379 @node_id = node_id
14380 @location = location
14381 @flags = flags
14382 @arguments = arguments
14383 @keyword_loc = keyword_loc
14384 end
14385
14386 # def accept: (Visitor visitor) -> void
14387 def accept(visitor)
14388 visitor.visit_next_node(self)
14389 end
14390
14391 # def child_nodes: () -> Array[Node?]
14392 def child_nodes
14393 [arguments]
14394 end
14395
14396 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14397 def each_child_node
14398 return to_enum(:each_child_node) unless block_given?
14399
14400 yield arguments if arguments
14401 end
14402
14403 # def compact_child_nodes: () -> Array[Node]
14404 def compact_child_nodes
14405 compact = [] #: Array[Prism::node]
14406 compact << arguments if arguments
14407 compact
14408 end
14409
14410 # def comment_targets: () -> Array[Node | Location]
14411 def comment_targets
14412 [*arguments, keyword_loc] #: Array[Prism::node | Location]
14413 end
14414
14415 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?arguments: ArgumentsNode?, ?keyword_loc: Location) -> NextNode
14416 def copy(node_id: self.node_id, location: self.location, flags: self.flags, arguments: self.arguments, keyword_loc: self.keyword_loc)
14417 NextNode.new(source, node_id, location, flags, arguments, keyword_loc)
14418 end
14419
14420 # def deconstruct: () -> Array[Node?]
14421 alias deconstruct child_nodes
14422
14423 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, arguments: ArgumentsNode?, keyword_loc: Location }
14424 def deconstruct_keys(keys)
14425 { node_id: node_id, location: location, arguments: arguments, keyword_loc: keyword_loc }
14426 end
14427
14428 # attr_reader arguments: ArgumentsNode?
14429 attr_reader :arguments
14430
14431 # attr_reader keyword_loc: Location
14432 def keyword_loc
14433 location = @keyword_loc
14434 return location if location.is_a?(Location)
14435 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14436 end
14437
14438 # Save the keyword_loc location using the given saved source so that
14439 # it can be retrieved later.
14440 def save_keyword_loc(repository)
14441 repository.enter(node_id, :keyword_loc)
14442 end
14443
14444 # def keyword: () -> String
14445 def keyword
14446 keyword_loc.slice
14447 end
14448
14449 # def inspect -> String
14450 def inspect
14451 InspectVisitor.compose(self)
14452 end
14453
14454 # Return a symbol representation of this node type. See `Node#type`.
14455 def type
14456 :next_node
14457 end
14458
14459 # Return a symbol representation of this node type. See `Node::type`.
14460 def self.type
14461 :next_node
14462 end
14463
14464 # Implements case-equality for the node. This is effectively == but without
14465 # comparing the value of locations. Locations are checked only for presence.
14466 def ===(other)
14467 other.is_a?(NextNode) &&
14468 (arguments === other.arguments) &&
14469 (keyword_loc.nil? == other.keyword_loc.nil?)
14470 end
14471 end
14472
14473 # Represents the use of the `nil` keyword.
14474 #
14475 # nil
14476 # ^^^
14477 class NilNode < Node
14478 # Initialize a new NilNode node.
14479 def initialize(source, node_id, location, flags)
14480 @source = source
14481 @node_id = node_id
14482 @location = location
14483 @flags = flags
14484 end
14485
14486 # def accept: (Visitor visitor) -> void
14487 def accept(visitor)
14488 visitor.visit_nil_node(self)
14489 end
14490
14491 # def child_nodes: () -> Array[Node?]
14492 def child_nodes
14493 []
14494 end
14495
14496 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14497 def each_child_node
14498 return to_enum(:each_child_node) unless block_given?
14499
14500 end
14501
14502 # def compact_child_nodes: () -> Array[Node]
14503 def compact_child_nodes
14504 []
14505 end
14506
14507 # def comment_targets: () -> Array[Node | Location]
14508 def comment_targets
14509 [] #: Array[Prism::node | Location]
14510 end
14511
14512 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> NilNode
14513 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
14514 NilNode.new(source, node_id, location, flags)
14515 end
14516
14517 # def deconstruct: () -> Array[Node?]
14518 alias deconstruct child_nodes
14519
14520 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
14521 def deconstruct_keys(keys)
14522 { node_id: node_id, location: location }
14523 end
14524
14525 # def inspect -> String
14526 def inspect
14527 InspectVisitor.compose(self)
14528 end
14529
14530 # Return a symbol representation of this node type. See `Node#type`.
14531 def type
14532 :nil_node
14533 end
14534
14535 # Return a symbol representation of this node type. See `Node::type`.
14536 def self.type
14537 :nil_node
14538 end
14539
14540 # Implements case-equality for the node. This is effectively == but without
14541 # comparing the value of locations. Locations are checked only for presence.
14542 def ===(other)
14543 other.is_a?(NilNode)
14544 end
14545 end
14546
14547 # Represents the use of `**nil` inside method arguments.
14548 #
14549 # def a(**nil)
14550 # ^^^^^
14551 # end
14552 class NoKeywordsParameterNode < Node
14553 # Initialize a new NoKeywordsParameterNode node.
14554 def initialize(source, node_id, location, flags, operator_loc, keyword_loc)
14555 @source = source
14556 @node_id = node_id
14557 @location = location
14558 @flags = flags
14559 @operator_loc = operator_loc
14560 @keyword_loc = keyword_loc
14561 end
14562
14563 # def accept: (Visitor visitor) -> void
14564 def accept(visitor)
14565 visitor.visit_no_keywords_parameter_node(self)
14566 end
14567
14568 # def child_nodes: () -> Array[Node?]
14569 def child_nodes
14570 []
14571 end
14572
14573 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14574 def each_child_node
14575 return to_enum(:each_child_node) unless block_given?
14576
14577 end
14578
14579 # def compact_child_nodes: () -> Array[Node]
14580 def compact_child_nodes
14581 []
14582 end
14583
14584 # def comment_targets: () -> Array[Node | Location]
14585 def comment_targets
14586 [operator_loc, keyword_loc] #: Array[Prism::node | Location]
14587 end
14588
14589 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?operator_loc: Location, ?keyword_loc: Location) -> NoKeywordsParameterNode
14590 def copy(node_id: self.node_id, location: self.location, flags: self.flags, operator_loc: self.operator_loc, keyword_loc: self.keyword_loc)
14591 NoKeywordsParameterNode.new(source, node_id, location, flags, operator_loc, keyword_loc)
14592 end
14593
14594 # def deconstruct: () -> Array[Node?]
14595 alias deconstruct child_nodes
14596
14597 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, operator_loc: Location, keyword_loc: Location }
14598 def deconstruct_keys(keys)
14599 { node_id: node_id, location: location, operator_loc: operator_loc, keyword_loc: keyword_loc }
14600 end
14601
14602 # attr_reader operator_loc: Location
14603 def operator_loc
14604 location = @operator_loc
14605 return location if location.is_a?(Location)
14606 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14607 end
14608
14609 # Save the operator_loc location using the given saved source so that
14610 # it can be retrieved later.
14611 def save_operator_loc(repository)
14612 repository.enter(node_id, :operator_loc)
14613 end
14614
14615 # attr_reader keyword_loc: Location
14616 def keyword_loc
14617 location = @keyword_loc
14618 return location if location.is_a?(Location)
14619 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14620 end
14621
14622 # Save the keyword_loc location using the given saved source so that
14623 # it can be retrieved later.
14624 def save_keyword_loc(repository)
14625 repository.enter(node_id, :keyword_loc)
14626 end
14627
14628 # def operator: () -> String
14629 def operator
14630 operator_loc.slice
14631 end
14632
14633 # def keyword: () -> String
14634 def keyword
14635 keyword_loc.slice
14636 end
14637
14638 # def inspect -> String
14639 def inspect
14640 InspectVisitor.compose(self)
14641 end
14642
14643 # Return a symbol representation of this node type. See `Node#type`.
14644 def type
14645 :no_keywords_parameter_node
14646 end
14647
14648 # Return a symbol representation of this node type. See `Node::type`.
14649 def self.type
14650 :no_keywords_parameter_node
14651 end
14652
14653 # Implements case-equality for the node. This is effectively == but without
14654 # comparing the value of locations. Locations are checked only for presence.
14655 def ===(other)
14656 other.is_a?(NoKeywordsParameterNode) &&
14657 (operator_loc.nil? == other.operator_loc.nil?) &&
14658 (keyword_loc.nil? == other.keyword_loc.nil?)
14659 end
14660 end
14661
14662 # Represents an implicit set of parameters through the use of numbered parameters within a block or lambda.
14663 #
14664 # -> { _1 + _2 }
14665 # ^^^^^^^^^^^^^^
14666 class NumberedParametersNode < Node
14667 # Initialize a new NumberedParametersNode node.
14668 def initialize(source, node_id, location, flags, maximum)
14669 @source = source
14670 @node_id = node_id
14671 @location = location
14672 @flags = flags
14673 @maximum = maximum
14674 end
14675
14676 # def accept: (Visitor visitor) -> void
14677 def accept(visitor)
14678 visitor.visit_numbered_parameters_node(self)
14679 end
14680
14681 # def child_nodes: () -> Array[Node?]
14682 def child_nodes
14683 []
14684 end
14685
14686 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14687 def each_child_node
14688 return to_enum(:each_child_node) unless block_given?
14689
14690 end
14691
14692 # def compact_child_nodes: () -> Array[Node]
14693 def compact_child_nodes
14694 []
14695 end
14696
14697 # def comment_targets: () -> Array[Node | Location]
14698 def comment_targets
14699 [] #: Array[Prism::node | Location]
14700 end
14701
14702 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?maximum: Integer) -> NumberedParametersNode
14703 def copy(node_id: self.node_id, location: self.location, flags: self.flags, maximum: self.maximum)
14704 NumberedParametersNode.new(source, node_id, location, flags, maximum)
14705 end
14706
14707 # def deconstruct: () -> Array[Node?]
14708 alias deconstruct child_nodes
14709
14710 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, maximum: Integer }
14711 def deconstruct_keys(keys)
14712 { node_id: node_id, location: location, maximum: maximum }
14713 end
14714
14715 # attr_reader maximum: Integer
14716 attr_reader :maximum
14717
14718 # def inspect -> String
14719 def inspect
14720 InspectVisitor.compose(self)
14721 end
14722
14723 # Return a symbol representation of this node type. See `Node#type`.
14724 def type
14725 :numbered_parameters_node
14726 end
14727
14728 # Return a symbol representation of this node type. See `Node::type`.
14729 def self.type
14730 :numbered_parameters_node
14731 end
14732
14733 # Implements case-equality for the node. This is effectively == but without
14734 # comparing the value of locations. Locations are checked only for presence.
14735 def ===(other)
14736 other.is_a?(NumberedParametersNode) &&
14737 (maximum === other.maximum)
14738 end
14739 end
14740
14741 # Represents reading a numbered reference to a capture in the previous match.
14742 #
14743 # $1
14744 # ^^
14745 class NumberedReferenceReadNode < Node
14746 # Initialize a new NumberedReferenceReadNode node.
14747 def initialize(source, node_id, location, flags, number)
14748 @source = source
14749 @node_id = node_id
14750 @location = location
14751 @flags = flags
14752 @number = number
14753 end
14754
14755 # def accept: (Visitor visitor) -> void
14756 def accept(visitor)
14757 visitor.visit_numbered_reference_read_node(self)
14758 end
14759
14760 # def child_nodes: () -> Array[Node?]
14761 def child_nodes
14762 []
14763 end
14764
14765 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14766 def each_child_node
14767 return to_enum(:each_child_node) unless block_given?
14768
14769 end
14770
14771 # def compact_child_nodes: () -> Array[Node]
14772 def compact_child_nodes
14773 []
14774 end
14775
14776 # def comment_targets: () -> Array[Node | Location]
14777 def comment_targets
14778 [] #: Array[Prism::node | Location]
14779 end
14780
14781 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?number: Integer) -> NumberedReferenceReadNode
14782 def copy(node_id: self.node_id, location: self.location, flags: self.flags, number: self.number)
14783 NumberedReferenceReadNode.new(source, node_id, location, flags, number)
14784 end
14785
14786 # def deconstruct: () -> Array[Node?]
14787 alias deconstruct child_nodes
14788
14789 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, number: Integer }
14790 def deconstruct_keys(keys)
14791 { node_id: node_id, location: location, number: number }
14792 end
14793
14794 # The (1-indexed, from the left) number of the capture group. Numbered references that are too large result in this value being `0`.
14795 #
14796 # $1 # number `1`
14797 #
14798 # $5432 # number `5432`
14799 #
14800 # $4294967296 # number `0`
14801 attr_reader :number
14802
14803 # def inspect -> String
14804 def inspect
14805 InspectVisitor.compose(self)
14806 end
14807
14808 # Return a symbol representation of this node type. See `Node#type`.
14809 def type
14810 :numbered_reference_read_node
14811 end
14812
14813 # Return a symbol representation of this node type. See `Node::type`.
14814 def self.type
14815 :numbered_reference_read_node
14816 end
14817
14818 # Implements case-equality for the node. This is effectively == but without
14819 # comparing the value of locations. Locations are checked only for presence.
14820 def ===(other)
14821 other.is_a?(NumberedReferenceReadNode) &&
14822 (number === other.number)
14823 end
14824 end
14825
14826 # Represents an optional keyword parameter to a method, block, or lambda definition.
14827 #
14828 # def a(b: 1)
14829 # ^^^^
14830 # end
14831 class OptionalKeywordParameterNode < Node
14832 # Initialize a new OptionalKeywordParameterNode node.
14833 def initialize(source, node_id, location, flags, name, name_loc, value)
14834 @source = source
14835 @node_id = node_id
14836 @location = location
14837 @flags = flags
14838 @name = name
14839 @name_loc = name_loc
14840 @value = value
14841 end
14842
14843 # def accept: (Visitor visitor) -> void
14844 def accept(visitor)
14845 visitor.visit_optional_keyword_parameter_node(self)
14846 end
14847
14848 # def child_nodes: () -> Array[Node?]
14849 def child_nodes
14850 [value]
14851 end
14852
14853 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14854 def each_child_node
14855 return to_enum(:each_child_node) unless block_given?
14856
14857 yield value
14858 end
14859
14860 # def compact_child_nodes: () -> Array[Node]
14861 def compact_child_nodes
14862 [value]
14863 end
14864
14865 # def comment_targets: () -> Array[Node | Location]
14866 def comment_targets
14867 [name_loc, value] #: Array[Prism::node | Location]
14868 end
14869
14870 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?value: Prism::node) -> OptionalKeywordParameterNode
14871 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, value: self.value)
14872 OptionalKeywordParameterNode.new(source, node_id, location, flags, name, name_loc, value)
14873 end
14874
14875 # def deconstruct: () -> Array[Node?]
14876 alias deconstruct child_nodes
14877
14878 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, value: Prism::node }
14879 def deconstruct_keys(keys)
14880 { node_id: node_id, location: location, name: name, name_loc: name_loc, value: value }
14881 end
14882
14883 # def repeated_parameter?: () -> bool
14884 def repeated_parameter?
14885 flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
14886 end
14887
14888 # attr_reader name: Symbol
14889 attr_reader :name
14890
14891 # attr_reader name_loc: Location
14892 def name_loc
14893 location = @name_loc
14894 return location if location.is_a?(Location)
14895 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
14896 end
14897
14898 # Save the name_loc location using the given saved source so that
14899 # it can be retrieved later.
14900 def save_name_loc(repository)
14901 repository.enter(node_id, :name_loc)
14902 end
14903
14904 # attr_reader value: Prism::node
14905 attr_reader :value
14906
14907 # def inspect -> String
14908 def inspect
14909 InspectVisitor.compose(self)
14910 end
14911
14912 # Return a symbol representation of this node type. See `Node#type`.
14913 def type
14914 :optional_keyword_parameter_node
14915 end
14916
14917 # Return a symbol representation of this node type. See `Node::type`.
14918 def self.type
14919 :optional_keyword_parameter_node
14920 end
14921
14922 # Implements case-equality for the node. This is effectively == but without
14923 # comparing the value of locations. Locations are checked only for presence.
14924 def ===(other)
14925 other.is_a?(OptionalKeywordParameterNode) &&
14926 (flags === other.flags) &&
14927 (name === other.name) &&
14928 (name_loc.nil? == other.name_loc.nil?) &&
14929 (value === other.value)
14930 end
14931 end
14932
14933 # Represents an optional parameter to a method, block, or lambda definition.
14934 #
14935 # def a(b = 1)
14936 # ^^^^^
14937 # end
14938 class OptionalParameterNode < Node
14939 # Initialize a new OptionalParameterNode node.
14940 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value)
14941 @source = source
14942 @node_id = node_id
14943 @location = location
14944 @flags = flags
14945 @name = name
14946 @name_loc = name_loc
14947 @operator_loc = operator_loc
14948 @value = value
14949 end
14950
14951 # def accept: (Visitor visitor) -> void
14952 def accept(visitor)
14953 visitor.visit_optional_parameter_node(self)
14954 end
14955
14956 # def child_nodes: () -> Array[Node?]
14957 def child_nodes
14958 [value]
14959 end
14960
14961 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
14962 def each_child_node
14963 return to_enum(:each_child_node) unless block_given?
14964
14965 yield value
14966 end
14967
14968 # def compact_child_nodes: () -> Array[Node]
14969 def compact_child_nodes
14970 [value]
14971 end
14972
14973 # def comment_targets: () -> Array[Node | Location]
14974 def comment_targets
14975 [name_loc, operator_loc, value] #: Array[Prism::node | Location]
14976 end
14977
14978 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> OptionalParameterNode
14979 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
14980 OptionalParameterNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
14981 end
14982
14983 # def deconstruct: () -> Array[Node?]
14984 alias deconstruct child_nodes
14985
14986 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
14987 def deconstruct_keys(keys)
14988 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value }
14989 end
14990
14991 # def repeated_parameter?: () -> bool
14992 def repeated_parameter?
14993 flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
14994 end
14995
14996 # attr_reader name: Symbol
14997 attr_reader :name
14998
14999 # attr_reader name_loc: Location
15000 def name_loc
15001 location = @name_loc
15002 return location if location.is_a?(Location)
15003 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15004 end
15005
15006 # Save the name_loc location using the given saved source so that
15007 # it can be retrieved later.
15008 def save_name_loc(repository)
15009 repository.enter(node_id, :name_loc)
15010 end
15011
15012 # attr_reader operator_loc: Location
15013 def operator_loc
15014 location = @operator_loc
15015 return location if location.is_a?(Location)
15016 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15017 end
15018
15019 # Save the operator_loc location using the given saved source so that
15020 # it can be retrieved later.
15021 def save_operator_loc(repository)
15022 repository.enter(node_id, :operator_loc)
15023 end
15024
15025 # attr_reader value: Prism::node
15026 attr_reader :value
15027
15028 # def operator: () -> String
15029 def operator
15030 operator_loc.slice
15031 end
15032
15033 # def inspect -> String
15034 def inspect
15035 InspectVisitor.compose(self)
15036 end
15037
15038 # Return a symbol representation of this node type. See `Node#type`.
15039 def type
15040 :optional_parameter_node
15041 end
15042
15043 # Return a symbol representation of this node type. See `Node::type`.
15044 def self.type
15045 :optional_parameter_node
15046 end
15047
15048 # Implements case-equality for the node. This is effectively == but without
15049 # comparing the value of locations. Locations are checked only for presence.
15050 def ===(other)
15051 other.is_a?(OptionalParameterNode) &&
15052 (flags === other.flags) &&
15053 (name === other.name) &&
15054 (name_loc.nil? == other.name_loc.nil?) &&
15055 (operator_loc.nil? == other.operator_loc.nil?) &&
15056 (value === other.value)
15057 end
15058 end
15059
15060 # Represents the use of the `||` operator or the `or` keyword.
15061 #
15062 # left or right
15063 # ^^^^^^^^^^^^^
15064 class OrNode < Node
15065 # Initialize a new OrNode node.
15066 def initialize(source, node_id, location, flags, left, right, operator_loc)
15067 @source = source
15068 @node_id = node_id
15069 @location = location
15070 @flags = flags
15071 @left = left
15072 @right = right
15073 @operator_loc = operator_loc
15074 end
15075
15076 # def accept: (Visitor visitor) -> void
15077 def accept(visitor)
15078 visitor.visit_or_node(self)
15079 end
15080
15081 # def child_nodes: () -> Array[Node?]
15082 def child_nodes
15083 [left, right]
15084 end
15085
15086 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
15087 def each_child_node
15088 return to_enum(:each_child_node) unless block_given?
15089
15090 yield left
15091 yield right
15092 end
15093
15094 # def compact_child_nodes: () -> Array[Node]
15095 def compact_child_nodes
15096 [left, right]
15097 end
15098
15099 # def comment_targets: () -> Array[Node | Location]
15100 def comment_targets
15101 [left, right, operator_loc] #: Array[Prism::node | Location]
15102 end
15103
15104 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node, ?right: Prism::node, ?operator_loc: Location) -> OrNode
15105 def copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc)
15106 OrNode.new(source, node_id, location, flags, left, right, operator_loc)
15107 end
15108
15109 # def deconstruct: () -> Array[Node?]
15110 alias deconstruct child_nodes
15111
15112 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, left: Prism::node, right: Prism::node, operator_loc: Location }
15113 def deconstruct_keys(keys)
15114 { node_id: node_id, location: location, left: left, right: right, operator_loc: operator_loc }
15115 end
15116
15117 # Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
15118 #
15119 # left or right
15120 # ^^^^
15121 #
15122 # 1 || 2
15123 # ^
15124 attr_reader :left
15125
15126 # Represents the right side of the expression.
15127 #
15128 # left || right
15129 # ^^^^^
15130 #
15131 # 1 or 2
15132 # ^
15133 attr_reader :right
15134
15135 # The location of the `or` keyword or the `||` operator.
15136 #
15137 # left or right
15138 # ^^
15139 def operator_loc
15140 location = @operator_loc
15141 return location if location.is_a?(Location)
15142 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15143 end
15144
15145 # Save the operator_loc location using the given saved source so that
15146 # it can be retrieved later.
15147 def save_operator_loc(repository)
15148 repository.enter(node_id, :operator_loc)
15149 end
15150
15151 # def operator: () -> String
15152 def operator
15153 operator_loc.slice
15154 end
15155
15156 # def inspect -> String
15157 def inspect
15158 InspectVisitor.compose(self)
15159 end
15160
15161 # Return a symbol representation of this node type. See `Node#type`.
15162 def type
15163 :or_node
15164 end
15165
15166 # Return a symbol representation of this node type. See `Node::type`.
15167 def self.type
15168 :or_node
15169 end
15170
15171 # Implements case-equality for the node. This is effectively == but without
15172 # comparing the value of locations. Locations are checked only for presence.
15173 def ===(other)
15174 other.is_a?(OrNode) &&
15175 (left === other.left) &&
15176 (right === other.right) &&
15177 (operator_loc.nil? == other.operator_loc.nil?)
15178 end
15179 end
15180
15181 # Represents the list of parameters on a method, block, or lambda definition.
15182 #
15183 # def a(b, c, d)
15184 # ^^^^^^^
15185 # end
15186 class ParametersNode < Node
15187 # Initialize a new ParametersNode node.
15188 def initialize(source, node_id, location, flags, requireds, optionals, rest, posts, keywords, keyword_rest, block)
15189 @source = source
15190 @node_id = node_id
15191 @location = location
15192 @flags = flags
15193 @requireds = requireds
15194 @optionals = optionals
15195 @rest = rest
15196 @posts = posts
15197 @keywords = keywords
15198 @keyword_rest = keyword_rest
15199 @block = block
15200 end
15201
15202 # def accept: (Visitor visitor) -> void
15203 def accept(visitor)
15204 visitor.visit_parameters_node(self)
15205 end
15206
15207 # def child_nodes: () -> Array[Node?]
15208 def child_nodes
15209 [*requireds, *optionals, rest, *posts, *keywords, keyword_rest, block]
15210 end
15211
15212 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
15213 def each_child_node
15214 return to_enum(:each_child_node) unless block_given?
15215
15216 requireds.each { |node| yield node }
15217 optionals.each { |node| yield node }
15218 yield rest if rest
15219 posts.each { |node| yield node }
15220 keywords.each { |node| yield node }
15221 yield keyword_rest if keyword_rest
15222 yield block if block
15223 end
15224
15225 # def compact_child_nodes: () -> Array[Node]
15226 def compact_child_nodes
15227 compact = [] #: Array[Prism::node]
15228 compact.concat(requireds)
15229 compact.concat(optionals)
15230 compact << rest if rest
15231 compact.concat(posts)
15232 compact.concat(keywords)
15233 compact << keyword_rest if keyword_rest
15234 compact << block if block
15235 compact
15236 end
15237
15238 # def comment_targets: () -> Array[Node | Location]
15239 def comment_targets
15240 [*requireds, *optionals, *rest, *posts, *keywords, *keyword_rest, *block] #: Array[Prism::node | Location]
15241 end
15242
15243 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?requireds: Array[RequiredParameterNode | MultiTargetNode], ?optionals: Array[OptionalParameterNode], ?rest: RestParameterNode | ImplicitRestNode | nil, ?posts: Array[RequiredParameterNode | MultiTargetNode | KeywordRestParameterNode | NoKeywordsParameterNode | ForwardingParameterNode], ?keywords: Array[RequiredKeywordParameterNode | OptionalKeywordParameterNode], ?keyword_rest: KeywordRestParameterNode | ForwardingParameterNode | NoKeywordsParameterNode | nil, ?block: BlockParameterNode?) -> ParametersNode
15244 def copy(node_id: self.node_id, location: self.location, flags: self.flags, requireds: self.requireds, optionals: self.optionals, rest: self.rest, posts: self.posts, keywords: self.keywords, keyword_rest: self.keyword_rest, block: self.block)
15245 ParametersNode.new(source, node_id, location, flags, requireds, optionals, rest, posts, keywords, keyword_rest, block)
15246 end
15247
15248 # def deconstruct: () -> Array[Node?]
15249 alias deconstruct child_nodes
15250
15251 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, requireds: Array[RequiredParameterNode | MultiTargetNode], optionals: Array[OptionalParameterNode], rest: RestParameterNode | ImplicitRestNode | nil, posts: Array[RequiredParameterNode | MultiTargetNode | KeywordRestParameterNode | NoKeywordsParameterNode | ForwardingParameterNode], keywords: Array[RequiredKeywordParameterNode | OptionalKeywordParameterNode], keyword_rest: KeywordRestParameterNode | ForwardingParameterNode | NoKeywordsParameterNode | nil, block: BlockParameterNode? }
15252 def deconstruct_keys(keys)
15253 { node_id: node_id, location: location, requireds: requireds, optionals: optionals, rest: rest, posts: posts, keywords: keywords, keyword_rest: keyword_rest, block: block }
15254 end
15255
15256 # attr_reader requireds: Array[RequiredParameterNode | MultiTargetNode]
15257 attr_reader :requireds
15258
15259 # attr_reader optionals: Array[OptionalParameterNode]
15260 attr_reader :optionals
15261
15262 # attr_reader rest: RestParameterNode | ImplicitRestNode | nil
15263 attr_reader :rest
15264
15265 # attr_reader posts: Array[RequiredParameterNode | MultiTargetNode | KeywordRestParameterNode | NoKeywordsParameterNode | ForwardingParameterNode]
15266 attr_reader :posts
15267
15268 # attr_reader keywords: Array[RequiredKeywordParameterNode | OptionalKeywordParameterNode]
15269 attr_reader :keywords
15270
15271 # attr_reader keyword_rest: KeywordRestParameterNode | ForwardingParameterNode | NoKeywordsParameterNode | nil
15272 attr_reader :keyword_rest
15273
15274 # attr_reader block: BlockParameterNode?
15275 attr_reader :block
15276
15277 # def inspect -> String
15278 def inspect
15279 InspectVisitor.compose(self)
15280 end
15281
15282 # Return a symbol representation of this node type. See `Node#type`.
15283 def type
15284 :parameters_node
15285 end
15286
15287 # Return a symbol representation of this node type. See `Node::type`.
15288 def self.type
15289 :parameters_node
15290 end
15291
15292 # Implements case-equality for the node. This is effectively == but without
15293 # comparing the value of locations. Locations are checked only for presence.
15294 def ===(other)
15295 other.is_a?(ParametersNode) &&
15296 (requireds.length == other.requireds.length) &&
15297 requireds.zip(other.requireds).all? { |left, right| left === right } &&
15298 (optionals.length == other.optionals.length) &&
15299 optionals.zip(other.optionals).all? { |left, right| left === right } &&
15300 (rest === other.rest) &&
15301 (posts.length == other.posts.length) &&
15302 posts.zip(other.posts).all? { |left, right| left === right } &&
15303 (keywords.length == other.keywords.length) &&
15304 keywords.zip(other.keywords).all? { |left, right| left === right } &&
15305 (keyword_rest === other.keyword_rest) &&
15306 (block === other.block)
15307 end
15308 end
15309
15310 # Represents a parenthesized expression
15311 #
15312 # (10 + 34)
15313 # ^^^^^^^^^
15314 class ParenthesesNode < Node
15315 # Initialize a new ParenthesesNode node.
15316 def initialize(source, node_id, location, flags, body, opening_loc, closing_loc)
15317 @source = source
15318 @node_id = node_id
15319 @location = location
15320 @flags = flags
15321 @body = body
15322 @opening_loc = opening_loc
15323 @closing_loc = closing_loc
15324 end
15325
15326 # def accept: (Visitor visitor) -> void
15327 def accept(visitor)
15328 visitor.visit_parentheses_node(self)
15329 end
15330
15331 # def child_nodes: () -> Array[Node?]
15332 def child_nodes
15333 [body]
15334 end
15335
15336 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
15337 def each_child_node
15338 return to_enum(:each_child_node) unless block_given?
15339
15340 yield body if body
15341 end
15342
15343 # def compact_child_nodes: () -> Array[Node]
15344 def compact_child_nodes
15345 compact = [] #: Array[Prism::node]
15346 compact << body if body
15347 compact
15348 end
15349
15350 # def comment_targets: () -> Array[Node | Location]
15351 def comment_targets
15352 [*body, opening_loc, closing_loc] #: Array[Prism::node | Location]
15353 end
15354
15355 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?body: Prism::node?, ?opening_loc: Location, ?closing_loc: Location) -> ParenthesesNode
15356 def copy(node_id: self.node_id, location: self.location, flags: self.flags, body: self.body, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
15357 ParenthesesNode.new(source, node_id, location, flags, body, opening_loc, closing_loc)
15358 end
15359
15360 # def deconstruct: () -> Array[Node?]
15361 alias deconstruct child_nodes
15362
15363 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, body: Prism::node?, opening_loc: Location, closing_loc: Location }
15364 def deconstruct_keys(keys)
15365 { node_id: node_id, location: location, body: body, opening_loc: opening_loc, closing_loc: closing_loc }
15366 end
15367
15368 # def multiple_statements?: () -> bool
15369 def multiple_statements?
15370 flags.anybits?(ParenthesesNodeFlags::MULTIPLE_STATEMENTS)
15371 end
15372
15373 # attr_reader body: Prism::node?
15374 attr_reader :body
15375
15376 # attr_reader opening_loc: Location
15377 def opening_loc
15378 location = @opening_loc
15379 return location if location.is_a?(Location)
15380 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15381 end
15382
15383 # Save the opening_loc location using the given saved source so that
15384 # it can be retrieved later.
15385 def save_opening_loc(repository)
15386 repository.enter(node_id, :opening_loc)
15387 end
15388
15389 # attr_reader closing_loc: Location
15390 def closing_loc
15391 location = @closing_loc
15392 return location if location.is_a?(Location)
15393 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15394 end
15395
15396 # Save the closing_loc location using the given saved source so that
15397 # it can be retrieved later.
15398 def save_closing_loc(repository)
15399 repository.enter(node_id, :closing_loc)
15400 end
15401
15402 # def opening: () -> String
15403 def opening
15404 opening_loc.slice
15405 end
15406
15407 # def closing: () -> String
15408 def closing
15409 closing_loc.slice
15410 end
15411
15412 # def inspect -> String
15413 def inspect
15414 InspectVisitor.compose(self)
15415 end
15416
15417 # Return a symbol representation of this node type. See `Node#type`.
15418 def type
15419 :parentheses_node
15420 end
15421
15422 # Return a symbol representation of this node type. See `Node::type`.
15423 def self.type
15424 :parentheses_node
15425 end
15426
15427 # Implements case-equality for the node. This is effectively == but without
15428 # comparing the value of locations. Locations are checked only for presence.
15429 def ===(other)
15430 other.is_a?(ParenthesesNode) &&
15431 (flags === other.flags) &&
15432 (body === other.body) &&
15433 (opening_loc.nil? == other.opening_loc.nil?) &&
15434 (closing_loc.nil? == other.closing_loc.nil?)
15435 end
15436 end
15437
15438 # Represents the use of the `^` operator for pinning an expression in a pattern matching expression.
15439 #
15440 # foo in ^(bar)
15441 # ^^^^^^
15442 class PinnedExpressionNode < Node
15443 # Initialize a new PinnedExpressionNode node.
15444 def initialize(source, node_id, location, flags, expression, operator_loc, lparen_loc, rparen_loc)
15445 @source = source
15446 @node_id = node_id
15447 @location = location
15448 @flags = flags
15449 @expression = expression
15450 @operator_loc = operator_loc
15451 @lparen_loc = lparen_loc
15452 @rparen_loc = rparen_loc
15453 end
15454
15455 # def accept: (Visitor visitor) -> void
15456 def accept(visitor)
15457 visitor.visit_pinned_expression_node(self)
15458 end
15459
15460 # def child_nodes: () -> Array[Node?]
15461 def child_nodes
15462 [expression]
15463 end
15464
15465 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
15466 def each_child_node
15467 return to_enum(:each_child_node) unless block_given?
15468
15469 yield expression
15470 end
15471
15472 # def compact_child_nodes: () -> Array[Node]
15473 def compact_child_nodes
15474 [expression]
15475 end
15476
15477 # def comment_targets: () -> Array[Node | Location]
15478 def comment_targets
15479 [expression, operator_loc, lparen_loc, rparen_loc] #: Array[Prism::node | Location]
15480 end
15481
15482 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?expression: Prism::node, ?operator_loc: Location, ?lparen_loc: Location, ?rparen_loc: Location) -> PinnedExpressionNode
15483 def copy(node_id: self.node_id, location: self.location, flags: self.flags, expression: self.expression, operator_loc: self.operator_loc, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc)
15484 PinnedExpressionNode.new(source, node_id, location, flags, expression, operator_loc, lparen_loc, rparen_loc)
15485 end
15486
15487 # def deconstruct: () -> Array[Node?]
15488 alias deconstruct child_nodes
15489
15490 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, expression: Prism::node, operator_loc: Location, lparen_loc: Location, rparen_loc: Location }
15491 def deconstruct_keys(keys)
15492 { node_id: node_id, location: location, expression: expression, operator_loc: operator_loc, lparen_loc: lparen_loc, rparen_loc: rparen_loc }
15493 end
15494
15495 # The expression used in the pinned expression
15496 #
15497 # foo in ^(bar)
15498 # ^^^
15499 attr_reader :expression
15500
15501 # The location of the `^` operator
15502 #
15503 # foo in ^(bar)
15504 # ^
15505 def operator_loc
15506 location = @operator_loc
15507 return location if location.is_a?(Location)
15508 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15509 end
15510
15511 # Save the operator_loc location using the given saved source so that
15512 # it can be retrieved later.
15513 def save_operator_loc(repository)
15514 repository.enter(node_id, :operator_loc)
15515 end
15516
15517 # The location of the opening parenthesis.
15518 #
15519 # foo in ^(bar)
15520 # ^
15521 def lparen_loc
15522 location = @lparen_loc
15523 return location if location.is_a?(Location)
15524 @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15525 end
15526
15527 # Save the lparen_loc location using the given saved source so that
15528 # it can be retrieved later.
15529 def save_lparen_loc(repository)
15530 repository.enter(node_id, :lparen_loc)
15531 end
15532
15533 # The location of the closing parenthesis.
15534 #
15535 # foo in ^(bar)
15536 # ^
15537 def rparen_loc
15538 location = @rparen_loc
15539 return location if location.is_a?(Location)
15540 @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15541 end
15542
15543 # Save the rparen_loc location using the given saved source so that
15544 # it can be retrieved later.
15545 def save_rparen_loc(repository)
15546 repository.enter(node_id, :rparen_loc)
15547 end
15548
15549 # def operator: () -> String
15550 def operator
15551 operator_loc.slice
15552 end
15553
15554 # def lparen: () -> String
15555 def lparen
15556 lparen_loc.slice
15557 end
15558
15559 # def rparen: () -> String
15560 def rparen
15561 rparen_loc.slice
15562 end
15563
15564 # def inspect -> String
15565 def inspect
15566 InspectVisitor.compose(self)
15567 end
15568
15569 # Return a symbol representation of this node type. See `Node#type`.
15570 def type
15571 :pinned_expression_node
15572 end
15573
15574 # Return a symbol representation of this node type. See `Node::type`.
15575 def self.type
15576 :pinned_expression_node
15577 end
15578
15579 # Implements case-equality for the node. This is effectively == but without
15580 # comparing the value of locations. Locations are checked only for presence.
15581 def ===(other)
15582 other.is_a?(PinnedExpressionNode) &&
15583 (expression === other.expression) &&
15584 (operator_loc.nil? == other.operator_loc.nil?) &&
15585 (lparen_loc.nil? == other.lparen_loc.nil?) &&
15586 (rparen_loc.nil? == other.rparen_loc.nil?)
15587 end
15588 end
15589
15590 # Represents the use of the `^` operator for pinning a variable in a pattern matching expression.
15591 #
15592 # foo in ^bar
15593 # ^^^^
15594 class PinnedVariableNode < Node
15595 # Initialize a new PinnedVariableNode node.
15596 def initialize(source, node_id, location, flags, variable, operator_loc)
15597 @source = source
15598 @node_id = node_id
15599 @location = location
15600 @flags = flags
15601 @variable = variable
15602 @operator_loc = operator_loc
15603 end
15604
15605 # def accept: (Visitor visitor) -> void
15606 def accept(visitor)
15607 visitor.visit_pinned_variable_node(self)
15608 end
15609
15610 # def child_nodes: () -> Array[Node?]
15611 def child_nodes
15612 [variable]
15613 end
15614
15615 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
15616 def each_child_node
15617 return to_enum(:each_child_node) unless block_given?
15618
15619 yield variable
15620 end
15621
15622 # def compact_child_nodes: () -> Array[Node]
15623 def compact_child_nodes
15624 [variable]
15625 end
15626
15627 # def comment_targets: () -> Array[Node | Location]
15628 def comment_targets
15629 [variable, operator_loc] #: Array[Prism::node | Location]
15630 end
15631
15632 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?variable: LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode | MissingNode, ?operator_loc: Location) -> PinnedVariableNode
15633 def copy(node_id: self.node_id, location: self.location, flags: self.flags, variable: self.variable, operator_loc: self.operator_loc)
15634 PinnedVariableNode.new(source, node_id, location, flags, variable, operator_loc)
15635 end
15636
15637 # def deconstruct: () -> Array[Node?]
15638 alias deconstruct child_nodes
15639
15640 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, variable: LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode | MissingNode, operator_loc: Location }
15641 def deconstruct_keys(keys)
15642 { node_id: node_id, location: location, variable: variable, operator_loc: operator_loc }
15643 end
15644
15645 # The variable used in the pinned expression
15646 #
15647 # foo in ^bar
15648 # ^^^
15649 attr_reader :variable
15650
15651 # The location of the `^` operator
15652 #
15653 # foo in ^bar
15654 # ^
15655 def operator_loc
15656 location = @operator_loc
15657 return location if location.is_a?(Location)
15658 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15659 end
15660
15661 # Save the operator_loc location using the given saved source so that
15662 # it can be retrieved later.
15663 def save_operator_loc(repository)
15664 repository.enter(node_id, :operator_loc)
15665 end
15666
15667 # def operator: () -> String
15668 def operator
15669 operator_loc.slice
15670 end
15671
15672 # def inspect -> String
15673 def inspect
15674 InspectVisitor.compose(self)
15675 end
15676
15677 # Return a symbol representation of this node type. See `Node#type`.
15678 def type
15679 :pinned_variable_node
15680 end
15681
15682 # Return a symbol representation of this node type. See `Node::type`.
15683 def self.type
15684 :pinned_variable_node
15685 end
15686
15687 # Implements case-equality for the node. This is effectively == but without
15688 # comparing the value of locations. Locations are checked only for presence.
15689 def ===(other)
15690 other.is_a?(PinnedVariableNode) &&
15691 (variable === other.variable) &&
15692 (operator_loc.nil? == other.operator_loc.nil?)
15693 end
15694 end
15695
15696 # Represents the use of the `END` keyword.
15697 #
15698 # END { foo }
15699 # ^^^^^^^^^^^
15700 class PostExecutionNode < Node
15701 # Initialize a new PostExecutionNode node.
15702 def initialize(source, node_id, location, flags, statements, keyword_loc, opening_loc, closing_loc)
15703 @source = source
15704 @node_id = node_id
15705 @location = location
15706 @flags = flags
15707 @statements = statements
15708 @keyword_loc = keyword_loc
15709 @opening_loc = opening_loc
15710 @closing_loc = closing_loc
15711 end
15712
15713 # def accept: (Visitor visitor) -> void
15714 def accept(visitor)
15715 visitor.visit_post_execution_node(self)
15716 end
15717
15718 # def child_nodes: () -> Array[Node?]
15719 def child_nodes
15720 [statements]
15721 end
15722
15723 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
15724 def each_child_node
15725 return to_enum(:each_child_node) unless block_given?
15726
15727 yield statements if statements
15728 end
15729
15730 # def compact_child_nodes: () -> Array[Node]
15731 def compact_child_nodes
15732 compact = [] #: Array[Prism::node]
15733 compact << statements if statements
15734 compact
15735 end
15736
15737 # def comment_targets: () -> Array[Node | Location]
15738 def comment_targets
15739 [*statements, keyword_loc, opening_loc, closing_loc] #: Array[Prism::node | Location]
15740 end
15741
15742 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?statements: StatementsNode?, ?keyword_loc: Location, ?opening_loc: Location, ?closing_loc: Location) -> PostExecutionNode
15743 def copy(node_id: self.node_id, location: self.location, flags: self.flags, statements: self.statements, keyword_loc: self.keyword_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
15744 PostExecutionNode.new(source, node_id, location, flags, statements, keyword_loc, opening_loc, closing_loc)
15745 end
15746
15747 # def deconstruct: () -> Array[Node?]
15748 alias deconstruct child_nodes
15749
15750 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, statements: StatementsNode?, keyword_loc: Location, opening_loc: Location, closing_loc: Location }
15751 def deconstruct_keys(keys)
15752 { node_id: node_id, location: location, statements: statements, keyword_loc: keyword_loc, opening_loc: opening_loc, closing_loc: closing_loc }
15753 end
15754
15755 # attr_reader statements: StatementsNode?
15756 attr_reader :statements
15757
15758 # attr_reader keyword_loc: Location
15759 def keyword_loc
15760 location = @keyword_loc
15761 return location if location.is_a?(Location)
15762 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15763 end
15764
15765 # Save the keyword_loc location using the given saved source so that
15766 # it can be retrieved later.
15767 def save_keyword_loc(repository)
15768 repository.enter(node_id, :keyword_loc)
15769 end
15770
15771 # attr_reader opening_loc: Location
15772 def opening_loc
15773 location = @opening_loc
15774 return location if location.is_a?(Location)
15775 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15776 end
15777
15778 # Save the opening_loc location using the given saved source so that
15779 # it can be retrieved later.
15780 def save_opening_loc(repository)
15781 repository.enter(node_id, :opening_loc)
15782 end
15783
15784 # attr_reader closing_loc: Location
15785 def closing_loc
15786 location = @closing_loc
15787 return location if location.is_a?(Location)
15788 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15789 end
15790
15791 # Save the closing_loc location using the given saved source so that
15792 # it can be retrieved later.
15793 def save_closing_loc(repository)
15794 repository.enter(node_id, :closing_loc)
15795 end
15796
15797 # def keyword: () -> String
15798 def keyword
15799 keyword_loc.slice
15800 end
15801
15802 # def opening: () -> String
15803 def opening
15804 opening_loc.slice
15805 end
15806
15807 # def closing: () -> String
15808 def closing
15809 closing_loc.slice
15810 end
15811
15812 # def inspect -> String
15813 def inspect
15814 InspectVisitor.compose(self)
15815 end
15816
15817 # Return a symbol representation of this node type. See `Node#type`.
15818 def type
15819 :post_execution_node
15820 end
15821
15822 # Return a symbol representation of this node type. See `Node::type`.
15823 def self.type
15824 :post_execution_node
15825 end
15826
15827 # Implements case-equality for the node. This is effectively == but without
15828 # comparing the value of locations. Locations are checked only for presence.
15829 def ===(other)
15830 other.is_a?(PostExecutionNode) &&
15831 (statements === other.statements) &&
15832 (keyword_loc.nil? == other.keyword_loc.nil?) &&
15833 (opening_loc.nil? == other.opening_loc.nil?) &&
15834 (closing_loc.nil? == other.closing_loc.nil?)
15835 end
15836 end
15837
15838 # Represents the use of the `BEGIN` keyword.
15839 #
15840 # BEGIN { foo }
15841 # ^^^^^^^^^^^^^
15842 class PreExecutionNode < Node
15843 # Initialize a new PreExecutionNode node.
15844 def initialize(source, node_id, location, flags, statements, keyword_loc, opening_loc, closing_loc)
15845 @source = source
15846 @node_id = node_id
15847 @location = location
15848 @flags = flags
15849 @statements = statements
15850 @keyword_loc = keyword_loc
15851 @opening_loc = opening_loc
15852 @closing_loc = closing_loc
15853 end
15854
15855 # def accept: (Visitor visitor) -> void
15856 def accept(visitor)
15857 visitor.visit_pre_execution_node(self)
15858 end
15859
15860 # def child_nodes: () -> Array[Node?]
15861 def child_nodes
15862 [statements]
15863 end
15864
15865 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
15866 def each_child_node
15867 return to_enum(:each_child_node) unless block_given?
15868
15869 yield statements if statements
15870 end
15871
15872 # def compact_child_nodes: () -> Array[Node]
15873 def compact_child_nodes
15874 compact = [] #: Array[Prism::node]
15875 compact << statements if statements
15876 compact
15877 end
15878
15879 # def comment_targets: () -> Array[Node | Location]
15880 def comment_targets
15881 [*statements, keyword_loc, opening_loc, closing_loc] #: Array[Prism::node | Location]
15882 end
15883
15884 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?statements: StatementsNode?, ?keyword_loc: Location, ?opening_loc: Location, ?closing_loc: Location) -> PreExecutionNode
15885 def copy(node_id: self.node_id, location: self.location, flags: self.flags, statements: self.statements, keyword_loc: self.keyword_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc)
15886 PreExecutionNode.new(source, node_id, location, flags, statements, keyword_loc, opening_loc, closing_loc)
15887 end
15888
15889 # def deconstruct: () -> Array[Node?]
15890 alias deconstruct child_nodes
15891
15892 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, statements: StatementsNode?, keyword_loc: Location, opening_loc: Location, closing_loc: Location }
15893 def deconstruct_keys(keys)
15894 { node_id: node_id, location: location, statements: statements, keyword_loc: keyword_loc, opening_loc: opening_loc, closing_loc: closing_loc }
15895 end
15896
15897 # attr_reader statements: StatementsNode?
15898 attr_reader :statements
15899
15900 # attr_reader keyword_loc: Location
15901 def keyword_loc
15902 location = @keyword_loc
15903 return location if location.is_a?(Location)
15904 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15905 end
15906
15907 # Save the keyword_loc location using the given saved source so that
15908 # it can be retrieved later.
15909 def save_keyword_loc(repository)
15910 repository.enter(node_id, :keyword_loc)
15911 end
15912
15913 # attr_reader opening_loc: Location
15914 def opening_loc
15915 location = @opening_loc
15916 return location if location.is_a?(Location)
15917 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15918 end
15919
15920 # Save the opening_loc location using the given saved source so that
15921 # it can be retrieved later.
15922 def save_opening_loc(repository)
15923 repository.enter(node_id, :opening_loc)
15924 end
15925
15926 # attr_reader closing_loc: Location
15927 def closing_loc
15928 location = @closing_loc
15929 return location if location.is_a?(Location)
15930 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
15931 end
15932
15933 # Save the closing_loc location using the given saved source so that
15934 # it can be retrieved later.
15935 def save_closing_loc(repository)
15936 repository.enter(node_id, :closing_loc)
15937 end
15938
15939 # def keyword: () -> String
15940 def keyword
15941 keyword_loc.slice
15942 end
15943
15944 # def opening: () -> String
15945 def opening
15946 opening_loc.slice
15947 end
15948
15949 # def closing: () -> String
15950 def closing
15951 closing_loc.slice
15952 end
15953
15954 # def inspect -> String
15955 def inspect
15956 InspectVisitor.compose(self)
15957 end
15958
15959 # Return a symbol representation of this node type. See `Node#type`.
15960 def type
15961 :pre_execution_node
15962 end
15963
15964 # Return a symbol representation of this node type. See `Node::type`.
15965 def self.type
15966 :pre_execution_node
15967 end
15968
15969 # Implements case-equality for the node. This is effectively == but without
15970 # comparing the value of locations. Locations are checked only for presence.
15971 def ===(other)
15972 other.is_a?(PreExecutionNode) &&
15973 (statements === other.statements) &&
15974 (keyword_loc.nil? == other.keyword_loc.nil?) &&
15975 (opening_loc.nil? == other.opening_loc.nil?) &&
15976 (closing_loc.nil? == other.closing_loc.nil?)
15977 end
15978 end
15979
15980 # The top level node of any parse tree.
15981 class ProgramNode < Node
15982 # Initialize a new ProgramNode node.
15983 def initialize(source, node_id, location, flags, locals, statements)
15984 @source = source
15985 @node_id = node_id
15986 @location = location
15987 @flags = flags
15988 @locals = locals
15989 @statements = statements
15990 end
15991
15992 # def accept: (Visitor visitor) -> void
15993 def accept(visitor)
15994 visitor.visit_program_node(self)
15995 end
15996
15997 # def child_nodes: () -> Array[Node?]
15998 def child_nodes
15999 [statements]
16000 end
16001
16002 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16003 def each_child_node
16004 return to_enum(:each_child_node) unless block_given?
16005
16006 yield statements
16007 end
16008
16009 # def compact_child_nodes: () -> Array[Node]
16010 def compact_child_nodes
16011 [statements]
16012 end
16013
16014 # def comment_targets: () -> Array[Node | Location]
16015 def comment_targets
16016 [statements] #: Array[Prism::node | Location]
16017 end
16018
16019 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array[Symbol], ?statements: StatementsNode) -> ProgramNode
16020 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, statements: self.statements)
16021 ProgramNode.new(source, node_id, location, flags, locals, statements)
16022 end
16023
16024 # def deconstruct: () -> Array[Node?]
16025 alias deconstruct child_nodes
16026
16027 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, locals: Array[Symbol], statements: StatementsNode }
16028 def deconstruct_keys(keys)
16029 { node_id: node_id, location: location, locals: locals, statements: statements }
16030 end
16031
16032 # attr_reader locals: Array[Symbol]
16033 attr_reader :locals
16034
16035 # attr_reader statements: StatementsNode
16036 attr_reader :statements
16037
16038 # def inspect -> String
16039 def inspect
16040 InspectVisitor.compose(self)
16041 end
16042
16043 # Return a symbol representation of this node type. See `Node#type`.
16044 def type
16045 :program_node
16046 end
16047
16048 # Return a symbol representation of this node type. See `Node::type`.
16049 def self.type
16050 :program_node
16051 end
16052
16053 # Implements case-equality for the node. This is effectively == but without
16054 # comparing the value of locations. Locations are checked only for presence.
16055 def ===(other)
16056 other.is_a?(ProgramNode) &&
16057 (locals.length == other.locals.length) &&
16058 locals.zip(other.locals).all? { |left, right| left === right } &&
16059 (statements === other.statements)
16060 end
16061 end
16062
16063 # Represents the use of the `..` or `...` operators.
16064 #
16065 # 1..2
16066 # ^^^^
16067 #
16068 # c if a =~ /left/ ... b =~ /right/
16069 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16070 class RangeNode < Node
16071 # Initialize a new RangeNode node.
16072 def initialize(source, node_id, location, flags, left, right, operator_loc)
16073 @source = source
16074 @node_id = node_id
16075 @location = location
16076 @flags = flags
16077 @left = left
16078 @right = right
16079 @operator_loc = operator_loc
16080 end
16081
16082 # def accept: (Visitor visitor) -> void
16083 def accept(visitor)
16084 visitor.visit_range_node(self)
16085 end
16086
16087 # def child_nodes: () -> Array[Node?]
16088 def child_nodes
16089 [left, right]
16090 end
16091
16092 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16093 def each_child_node
16094 return to_enum(:each_child_node) unless block_given?
16095
16096 yield left if left
16097 yield right if right
16098 end
16099
16100 # def compact_child_nodes: () -> Array[Node]
16101 def compact_child_nodes
16102 compact = [] #: Array[Prism::node]
16103 compact << left if left
16104 compact << right if right
16105 compact
16106 end
16107
16108 # def comment_targets: () -> Array[Node | Location]
16109 def comment_targets
16110 [*left, *right, operator_loc] #: Array[Prism::node | Location]
16111 end
16112
16113 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node?, ?right: Prism::node?, ?operator_loc: Location) -> RangeNode
16114 def copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc)
16115 RangeNode.new(source, node_id, location, flags, left, right, operator_loc)
16116 end
16117
16118 # def deconstruct: () -> Array[Node?]
16119 alias deconstruct child_nodes
16120
16121 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, left: Prism::node?, right: Prism::node?, operator_loc: Location }
16122 def deconstruct_keys(keys)
16123 { node_id: node_id, location: location, left: left, right: right, operator_loc: operator_loc }
16124 end
16125
16126 # def exclude_end?: () -> bool
16127 def exclude_end?
16128 flags.anybits?(RangeFlags::EXCLUDE_END)
16129 end
16130
16131 # The left-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
16132 #
16133 # 1...
16134 # ^
16135 #
16136 # hello...goodbye
16137 # ^^^^^
16138 attr_reader :left
16139
16140 # The right-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
16141 #
16142 # ..5
16143 # ^
16144 #
16145 # 1...foo
16146 # ^^^
16147 # If neither right-hand or left-hand side was included, this will be a MissingNode.
16148 attr_reader :right
16149
16150 # The location of the `..` or `...` operator.
16151 def operator_loc
16152 location = @operator_loc
16153 return location if location.is_a?(Location)
16154 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16155 end
16156
16157 # Save the operator_loc location using the given saved source so that
16158 # it can be retrieved later.
16159 def save_operator_loc(repository)
16160 repository.enter(node_id, :operator_loc)
16161 end
16162
16163 # def operator: () -> String
16164 def operator
16165 operator_loc.slice
16166 end
16167
16168 # def inspect -> String
16169 def inspect
16170 InspectVisitor.compose(self)
16171 end
16172
16173 # Return a symbol representation of this node type. See `Node#type`.
16174 def type
16175 :range_node
16176 end
16177
16178 # Return a symbol representation of this node type. See `Node::type`.
16179 def self.type
16180 :range_node
16181 end
16182
16183 # Implements case-equality for the node. This is effectively == but without
16184 # comparing the value of locations. Locations are checked only for presence.
16185 def ===(other)
16186 other.is_a?(RangeNode) &&
16187 (flags === other.flags) &&
16188 (left === other.left) &&
16189 (right === other.right) &&
16190 (operator_loc.nil? == other.operator_loc.nil?)
16191 end
16192 end
16193
16194 # Represents a rational number literal.
16195 #
16196 # 1.0r
16197 # ^^^^
16198 class RationalNode < Node
16199 # Initialize a new RationalNode node.
16200 def initialize(source, node_id, location, flags, numerator, denominator)
16201 @source = source
16202 @node_id = node_id
16203 @location = location
16204 @flags = flags
16205 @numerator = numerator
16206 @denominator = denominator
16207 end
16208
16209 # def accept: (Visitor visitor) -> void
16210 def accept(visitor)
16211 visitor.visit_rational_node(self)
16212 end
16213
16214 # def child_nodes: () -> Array[Node?]
16215 def child_nodes
16216 []
16217 end
16218
16219 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16220 def each_child_node
16221 return to_enum(:each_child_node) unless block_given?
16222
16223 end
16224
16225 # def compact_child_nodes: () -> Array[Node]
16226 def compact_child_nodes
16227 []
16228 end
16229
16230 # def comment_targets: () -> Array[Node | Location]
16231 def comment_targets
16232 [] #: Array[Prism::node | Location]
16233 end
16234
16235 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?numerator: Integer, ?denominator: Integer) -> RationalNode
16236 def copy(node_id: self.node_id, location: self.location, flags: self.flags, numerator: self.numerator, denominator: self.denominator)
16237 RationalNode.new(source, node_id, location, flags, numerator, denominator)
16238 end
16239
16240 # def deconstruct: () -> Array[Node?]
16241 alias deconstruct child_nodes
16242
16243 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, numerator: Integer, denominator: Integer }
16244 def deconstruct_keys(keys)
16245 { node_id: node_id, location: location, numerator: numerator, denominator: denominator }
16246 end
16247
16248 # def binary?: () -> bool
16249 def binary?
16250 flags.anybits?(IntegerBaseFlags::BINARY)
16251 end
16252
16253 # def decimal?: () -> bool
16254 def decimal?
16255 flags.anybits?(IntegerBaseFlags::DECIMAL)
16256 end
16257
16258 # def octal?: () -> bool
16259 def octal?
16260 flags.anybits?(IntegerBaseFlags::OCTAL)
16261 end
16262
16263 # def hexadecimal?: () -> bool
16264 def hexadecimal?
16265 flags.anybits?(IntegerBaseFlags::HEXADECIMAL)
16266 end
16267
16268 # The numerator of the rational number.
16269 #
16270 # 1.5r # numerator 3
16271 attr_reader :numerator
16272
16273 # The denominator of the rational number.
16274 #
16275 # 1.5r # denominator 2
16276 attr_reader :denominator
16277
16278 # def inspect -> String
16279 def inspect
16280 InspectVisitor.compose(self)
16281 end
16282
16283 # Return a symbol representation of this node type. See `Node#type`.
16284 def type
16285 :rational_node
16286 end
16287
16288 # Return a symbol representation of this node type. See `Node::type`.
16289 def self.type
16290 :rational_node
16291 end
16292
16293 # Implements case-equality for the node. This is effectively == but without
16294 # comparing the value of locations. Locations are checked only for presence.
16295 def ===(other)
16296 other.is_a?(RationalNode) &&
16297 (flags === other.flags) &&
16298 (numerator === other.numerator) &&
16299 (denominator === other.denominator)
16300 end
16301 end
16302
16303 # Represents the use of the `redo` keyword.
16304 #
16305 # redo
16306 # ^^^^
16307 class RedoNode < Node
16308 # Initialize a new RedoNode node.
16309 def initialize(source, node_id, location, flags)
16310 @source = source
16311 @node_id = node_id
16312 @location = location
16313 @flags = flags
16314 end
16315
16316 # def accept: (Visitor visitor) -> void
16317 def accept(visitor)
16318 visitor.visit_redo_node(self)
16319 end
16320
16321 # def child_nodes: () -> Array[Node?]
16322 def child_nodes
16323 []
16324 end
16325
16326 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16327 def each_child_node
16328 return to_enum(:each_child_node) unless block_given?
16329
16330 end
16331
16332 # def compact_child_nodes: () -> Array[Node]
16333 def compact_child_nodes
16334 []
16335 end
16336
16337 # def comment_targets: () -> Array[Node | Location]
16338 def comment_targets
16339 [] #: Array[Prism::node | Location]
16340 end
16341
16342 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> RedoNode
16343 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
16344 RedoNode.new(source, node_id, location, flags)
16345 end
16346
16347 # def deconstruct: () -> Array[Node?]
16348 alias deconstruct child_nodes
16349
16350 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
16351 def deconstruct_keys(keys)
16352 { node_id: node_id, location: location }
16353 end
16354
16355 # def inspect -> String
16356 def inspect
16357 InspectVisitor.compose(self)
16358 end
16359
16360 # Return a symbol representation of this node type. See `Node#type`.
16361 def type
16362 :redo_node
16363 end
16364
16365 # Return a symbol representation of this node type. See `Node::type`.
16366 def self.type
16367 :redo_node
16368 end
16369
16370 # Implements case-equality for the node. This is effectively == but without
16371 # comparing the value of locations. Locations are checked only for presence.
16372 def ===(other)
16373 other.is_a?(RedoNode)
16374 end
16375 end
16376
16377 # Represents a regular expression literal with no interpolation.
16378 #
16379 # /foo/i
16380 # ^^^^^^
16381 class RegularExpressionNode < Node
16382 # Initialize a new RegularExpressionNode node.
16383 def initialize(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped)
16384 @source = source
16385 @node_id = node_id
16386 @location = location
16387 @flags = flags
16388 @opening_loc = opening_loc
16389 @content_loc = content_loc
16390 @closing_loc = closing_loc
16391 @unescaped = unescaped
16392 end
16393
16394 # def accept: (Visitor visitor) -> void
16395 def accept(visitor)
16396 visitor.visit_regular_expression_node(self)
16397 end
16398
16399 # def child_nodes: () -> Array[Node?]
16400 def child_nodes
16401 []
16402 end
16403
16404 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16405 def each_child_node
16406 return to_enum(:each_child_node) unless block_given?
16407
16408 end
16409
16410 # def compact_child_nodes: () -> Array[Node]
16411 def compact_child_nodes
16412 []
16413 end
16414
16415 # def comment_targets: () -> Array[Node | Location]
16416 def comment_targets
16417 [opening_loc, content_loc, closing_loc] #: Array[Prism::node | Location]
16418 end
16419
16420 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?content_loc: Location, ?closing_loc: Location, ?unescaped: String) -> RegularExpressionNode
16421 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, content_loc: self.content_loc, closing_loc: self.closing_loc, unescaped: self.unescaped)
16422 RegularExpressionNode.new(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped)
16423 end
16424
16425 # def deconstruct: () -> Array[Node?]
16426 alias deconstruct child_nodes
16427
16428 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String }
16429 def deconstruct_keys(keys)
16430 { node_id: node_id, location: location, opening_loc: opening_loc, content_loc: content_loc, closing_loc: closing_loc, unescaped: unescaped }
16431 end
16432
16433 # def ignore_case?: () -> bool
16434 def ignore_case?
16435 flags.anybits?(RegularExpressionFlags::IGNORE_CASE)
16436 end
16437
16438 # def extended?: () -> bool
16439 def extended?
16440 flags.anybits?(RegularExpressionFlags::EXTENDED)
16441 end
16442
16443 # def multi_line?: () -> bool
16444 def multi_line?
16445 flags.anybits?(RegularExpressionFlags::MULTI_LINE)
16446 end
16447
16448 # def once?: () -> bool
16449 def once?
16450 flags.anybits?(RegularExpressionFlags::ONCE)
16451 end
16452
16453 # def euc_jp?: () -> bool
16454 def euc_jp?
16455 flags.anybits?(RegularExpressionFlags::EUC_JP)
16456 end
16457
16458 # def ascii_8bit?: () -> bool
16459 def ascii_8bit?
16460 flags.anybits?(RegularExpressionFlags::ASCII_8BIT)
16461 end
16462
16463 # def windows_31j?: () -> bool
16464 def windows_31j?
16465 flags.anybits?(RegularExpressionFlags::WINDOWS_31J)
16466 end
16467
16468 # def utf_8?: () -> bool
16469 def utf_8?
16470 flags.anybits?(RegularExpressionFlags::UTF_8)
16471 end
16472
16473 # def forced_utf8_encoding?: () -> bool
16474 def forced_utf8_encoding?
16475 flags.anybits?(RegularExpressionFlags::FORCED_UTF8_ENCODING)
16476 end
16477
16478 # def forced_binary_encoding?: () -> bool
16479 def forced_binary_encoding?
16480 flags.anybits?(RegularExpressionFlags::FORCED_BINARY_ENCODING)
16481 end
16482
16483 # def forced_us_ascii_encoding?: () -> bool
16484 def forced_us_ascii_encoding?
16485 flags.anybits?(RegularExpressionFlags::FORCED_US_ASCII_ENCODING)
16486 end
16487
16488 # attr_reader opening_loc: Location
16489 def opening_loc
16490 location = @opening_loc
16491 return location if location.is_a?(Location)
16492 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16493 end
16494
16495 # Save the opening_loc location using the given saved source so that
16496 # it can be retrieved later.
16497 def save_opening_loc(repository)
16498 repository.enter(node_id, :opening_loc)
16499 end
16500
16501 # attr_reader content_loc: Location
16502 def content_loc
16503 location = @content_loc
16504 return location if location.is_a?(Location)
16505 @content_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16506 end
16507
16508 # Save the content_loc location using the given saved source so that
16509 # it can be retrieved later.
16510 def save_content_loc(repository)
16511 repository.enter(node_id, :content_loc)
16512 end
16513
16514 # attr_reader closing_loc: Location
16515 def closing_loc
16516 location = @closing_loc
16517 return location if location.is_a?(Location)
16518 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16519 end
16520
16521 # Save the closing_loc location using the given saved source so that
16522 # it can be retrieved later.
16523 def save_closing_loc(repository)
16524 repository.enter(node_id, :closing_loc)
16525 end
16526
16527 # attr_reader unescaped: String
16528 attr_reader :unescaped
16529
16530 # def opening: () -> String
16531 def opening
16532 opening_loc.slice
16533 end
16534
16535 # def content: () -> String
16536 def content
16537 content_loc.slice
16538 end
16539
16540 # def closing: () -> String
16541 def closing
16542 closing_loc.slice
16543 end
16544
16545 # def inspect -> String
16546 def inspect
16547 InspectVisitor.compose(self)
16548 end
16549
16550 # Return a symbol representation of this node type. See `Node#type`.
16551 def type
16552 :regular_expression_node
16553 end
16554
16555 # Return a symbol representation of this node type. See `Node::type`.
16556 def self.type
16557 :regular_expression_node
16558 end
16559
16560 # Implements case-equality for the node. This is effectively == but without
16561 # comparing the value of locations. Locations are checked only for presence.
16562 def ===(other)
16563 other.is_a?(RegularExpressionNode) &&
16564 (flags === other.flags) &&
16565 (opening_loc.nil? == other.opening_loc.nil?) &&
16566 (content_loc.nil? == other.content_loc.nil?) &&
16567 (closing_loc.nil? == other.closing_loc.nil?) &&
16568 (unescaped === other.unescaped)
16569 end
16570 end
16571
16572 # Represents a required keyword parameter to a method, block, or lambda definition.
16573 #
16574 # def a(b: )
16575 # ^^
16576 # end
16577 class RequiredKeywordParameterNode < Node
16578 # Initialize a new RequiredKeywordParameterNode node.
16579 def initialize(source, node_id, location, flags, name, name_loc)
16580 @source = source
16581 @node_id = node_id
16582 @location = location
16583 @flags = flags
16584 @name = name
16585 @name_loc = name_loc
16586 end
16587
16588 # def accept: (Visitor visitor) -> void
16589 def accept(visitor)
16590 visitor.visit_required_keyword_parameter_node(self)
16591 end
16592
16593 # def child_nodes: () -> Array[Node?]
16594 def child_nodes
16595 []
16596 end
16597
16598 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16599 def each_child_node
16600 return to_enum(:each_child_node) unless block_given?
16601
16602 end
16603
16604 # def compact_child_nodes: () -> Array[Node]
16605 def compact_child_nodes
16606 []
16607 end
16608
16609 # def comment_targets: () -> Array[Node | Location]
16610 def comment_targets
16611 [name_loc] #: Array[Prism::node | Location]
16612 end
16613
16614 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location) -> RequiredKeywordParameterNode
16615 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc)
16616 RequiredKeywordParameterNode.new(source, node_id, location, flags, name, name_loc)
16617 end
16618
16619 # def deconstruct: () -> Array[Node?]
16620 alias deconstruct child_nodes
16621
16622 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location }
16623 def deconstruct_keys(keys)
16624 { node_id: node_id, location: location, name: name, name_loc: name_loc }
16625 end
16626
16627 # def repeated_parameter?: () -> bool
16628 def repeated_parameter?
16629 flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
16630 end
16631
16632 # attr_reader name: Symbol
16633 attr_reader :name
16634
16635 # attr_reader name_loc: Location
16636 def name_loc
16637 location = @name_loc
16638 return location if location.is_a?(Location)
16639 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16640 end
16641
16642 # Save the name_loc location using the given saved source so that
16643 # it can be retrieved later.
16644 def save_name_loc(repository)
16645 repository.enter(node_id, :name_loc)
16646 end
16647
16648 # def inspect -> String
16649 def inspect
16650 InspectVisitor.compose(self)
16651 end
16652
16653 # Return a symbol representation of this node type. See `Node#type`.
16654 def type
16655 :required_keyword_parameter_node
16656 end
16657
16658 # Return a symbol representation of this node type. See `Node::type`.
16659 def self.type
16660 :required_keyword_parameter_node
16661 end
16662
16663 # Implements case-equality for the node. This is effectively == but without
16664 # comparing the value of locations. Locations are checked only for presence.
16665 def ===(other)
16666 other.is_a?(RequiredKeywordParameterNode) &&
16667 (flags === other.flags) &&
16668 (name === other.name) &&
16669 (name_loc.nil? == other.name_loc.nil?)
16670 end
16671 end
16672
16673 # Represents a required parameter to a method, block, or lambda definition.
16674 #
16675 # def a(b)
16676 # ^
16677 # end
16678 class RequiredParameterNode < Node
16679 # Initialize a new RequiredParameterNode node.
16680 def initialize(source, node_id, location, flags, name)
16681 @source = source
16682 @node_id = node_id
16683 @location = location
16684 @flags = flags
16685 @name = name
16686 end
16687
16688 # def accept: (Visitor visitor) -> void
16689 def accept(visitor)
16690 visitor.visit_required_parameter_node(self)
16691 end
16692
16693 # def child_nodes: () -> Array[Node?]
16694 def child_nodes
16695 []
16696 end
16697
16698 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16699 def each_child_node
16700 return to_enum(:each_child_node) unless block_given?
16701
16702 end
16703
16704 # def compact_child_nodes: () -> Array[Node]
16705 def compact_child_nodes
16706 []
16707 end
16708
16709 # def comment_targets: () -> Array[Node | Location]
16710 def comment_targets
16711 [] #: Array[Prism::node | Location]
16712 end
16713
16714 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> RequiredParameterNode
16715 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
16716 RequiredParameterNode.new(source, node_id, location, flags, name)
16717 end
16718
16719 # def deconstruct: () -> Array[Node?]
16720 alias deconstruct child_nodes
16721
16722 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol }
16723 def deconstruct_keys(keys)
16724 { node_id: node_id, location: location, name: name }
16725 end
16726
16727 # def repeated_parameter?: () -> bool
16728 def repeated_parameter?
16729 flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
16730 end
16731
16732 # attr_reader name: Symbol
16733 attr_reader :name
16734
16735 # def inspect -> String
16736 def inspect
16737 InspectVisitor.compose(self)
16738 end
16739
16740 # Return a symbol representation of this node type. See `Node#type`.
16741 def type
16742 :required_parameter_node
16743 end
16744
16745 # Return a symbol representation of this node type. See `Node::type`.
16746 def self.type
16747 :required_parameter_node
16748 end
16749
16750 # Implements case-equality for the node. This is effectively == but without
16751 # comparing the value of locations. Locations are checked only for presence.
16752 def ===(other)
16753 other.is_a?(RequiredParameterNode) &&
16754 (flags === other.flags) &&
16755 (name === other.name)
16756 end
16757 end
16758
16759 # Represents an expression modified with a rescue.
16760 #
16761 # foo rescue nil
16762 # ^^^^^^^^^^^^^^
16763 class RescueModifierNode < Node
16764 # Initialize a new RescueModifierNode node.
16765 def initialize(source, node_id, location, flags, expression, keyword_loc, rescue_expression)
16766 @source = source
16767 @node_id = node_id
16768 @location = location
16769 @flags = flags
16770 @expression = expression
16771 @keyword_loc = keyword_loc
16772 @rescue_expression = rescue_expression
16773 end
16774
16775 # def accept: (Visitor visitor) -> void
16776 def accept(visitor)
16777 visitor.visit_rescue_modifier_node(self)
16778 end
16779
16780 # def child_nodes: () -> Array[Node?]
16781 def child_nodes
16782 [expression, rescue_expression]
16783 end
16784
16785 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16786 def each_child_node
16787 return to_enum(:each_child_node) unless block_given?
16788
16789 yield expression
16790 yield rescue_expression
16791 end
16792
16793 # def compact_child_nodes: () -> Array[Node]
16794 def compact_child_nodes
16795 [expression, rescue_expression]
16796 end
16797
16798 # def comment_targets: () -> Array[Node | Location]
16799 def comment_targets
16800 [expression, keyword_loc, rescue_expression] #: Array[Prism::node | Location]
16801 end
16802
16803 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?expression: Prism::node, ?keyword_loc: Location, ?rescue_expression: Prism::node) -> RescueModifierNode
16804 def copy(node_id: self.node_id, location: self.location, flags: self.flags, expression: self.expression, keyword_loc: self.keyword_loc, rescue_expression: self.rescue_expression)
16805 RescueModifierNode.new(source, node_id, location, flags, expression, keyword_loc, rescue_expression)
16806 end
16807
16808 # def deconstruct: () -> Array[Node?]
16809 alias deconstruct child_nodes
16810
16811 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, expression: Prism::node, keyword_loc: Location, rescue_expression: Prism::node }
16812 def deconstruct_keys(keys)
16813 { node_id: node_id, location: location, expression: expression, keyword_loc: keyword_loc, rescue_expression: rescue_expression }
16814 end
16815
16816 # attr_reader expression: Prism::node
16817 attr_reader :expression
16818
16819 # attr_reader keyword_loc: Location
16820 def keyword_loc
16821 location = @keyword_loc
16822 return location if location.is_a?(Location)
16823 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16824 end
16825
16826 # Save the keyword_loc location using the given saved source so that
16827 # it can be retrieved later.
16828 def save_keyword_loc(repository)
16829 repository.enter(node_id, :keyword_loc)
16830 end
16831
16832 # attr_reader rescue_expression: Prism::node
16833 attr_reader :rescue_expression
16834
16835 # def keyword: () -> String
16836 def keyword
16837 keyword_loc.slice
16838 end
16839
16840 # def inspect -> String
16841 def inspect
16842 InspectVisitor.compose(self)
16843 end
16844
16845 # Return a symbol representation of this node type. See `Node#type`.
16846 def type
16847 :rescue_modifier_node
16848 end
16849
16850 # Return a symbol representation of this node type. See `Node::type`.
16851 def self.type
16852 :rescue_modifier_node
16853 end
16854
16855 # Implements case-equality for the node. This is effectively == but without
16856 # comparing the value of locations. Locations are checked only for presence.
16857 def ===(other)
16858 other.is_a?(RescueModifierNode) &&
16859 (expression === other.expression) &&
16860 (keyword_loc.nil? == other.keyword_loc.nil?) &&
16861 (rescue_expression === other.rescue_expression)
16862 end
16863 end
16864
16865 # Represents a rescue statement.
16866 #
16867 # begin
16868 # rescue Foo, *splat, Bar => ex
16869 # foo
16870 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16871 # end
16872 #
16873 # `Foo, *splat, Bar` are in the `exceptions` field. `ex` is in the `reference` field.
16874 class RescueNode < Node
16875 # Initialize a new RescueNode node.
16876 def initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent)
16877 @source = source
16878 @node_id = node_id
16879 @location = location
16880 @flags = flags
16881 @keyword_loc = keyword_loc
16882 @exceptions = exceptions
16883 @operator_loc = operator_loc
16884 @reference = reference
16885 @then_keyword_loc = then_keyword_loc
16886 @statements = statements
16887 @subsequent = subsequent
16888 end
16889
16890 # def accept: (Visitor visitor) -> void
16891 def accept(visitor)
16892 visitor.visit_rescue_node(self)
16893 end
16894
16895 # def child_nodes: () -> Array[Node?]
16896 def child_nodes
16897 [*exceptions, reference, statements, subsequent]
16898 end
16899
16900 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16901 def each_child_node
16902 return to_enum(:each_child_node) unless block_given?
16903
16904 exceptions.each { |node| yield node }
16905 yield reference if reference
16906 yield statements if statements
16907 yield subsequent if subsequent
16908 end
16909
16910 # def compact_child_nodes: () -> Array[Node]
16911 def compact_child_nodes
16912 compact = [] #: Array[Prism::node]
16913 compact.concat(exceptions)
16914 compact << reference if reference
16915 compact << statements if statements
16916 compact << subsequent if subsequent
16917 compact
16918 end
16919
16920 # def comment_targets: () -> Array[Node | Location]
16921 def comment_targets
16922 [keyword_loc, *exceptions, *operator_loc, *reference, *then_keyword_loc, *statements, *subsequent] #: Array[Prism::node | Location]
16923 end
16924
16925 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?exceptions: Array[Prism::node], ?operator_loc: Location?, ?reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil, ?then_keyword_loc: Location?, ?statements: StatementsNode?, ?subsequent: RescueNode?) -> RescueNode
16926 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, exceptions: self.exceptions, operator_loc: self.operator_loc, reference: self.reference, then_keyword_loc: self.then_keyword_loc, statements: self.statements, subsequent: self.subsequent)
16927 RescueNode.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent)
16928 end
16929
16930 # def deconstruct: () -> Array[Node?]
16931 alias deconstruct child_nodes
16932
16933 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, exceptions: Array[Prism::node], operator_loc: Location?, reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil, then_keyword_loc: Location?, statements: StatementsNode?, subsequent: RescueNode? }
16934 def deconstruct_keys(keys)
16935 { node_id: node_id, location: location, keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, then_keyword_loc: then_keyword_loc, statements: statements, subsequent: subsequent }
16936 end
16937
16938 # attr_reader keyword_loc: Location
16939 def keyword_loc
16940 location = @keyword_loc
16941 return location if location.is_a?(Location)
16942 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16943 end
16944
16945 # Save the keyword_loc location using the given saved source so that
16946 # it can be retrieved later.
16947 def save_keyword_loc(repository)
16948 repository.enter(node_id, :keyword_loc)
16949 end
16950
16951 # attr_reader exceptions: Array[Prism::node]
16952 attr_reader :exceptions
16953
16954 # attr_reader operator_loc: Location?
16955 def operator_loc
16956 location = @operator_loc
16957 case location
16958 when nil
16959 nil
16960 when Location
16961 location
16962 else
16963 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16964 end
16965 end
16966
16967 # Save the operator_loc location using the given saved source so that
16968 # it can be retrieved later.
16969 def save_operator_loc(repository)
16970 repository.enter(node_id, :operator_loc) unless @operator_loc.nil?
16971 end
16972
16973 # attr_reader reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil
16974 attr_reader :reference
16975
16976 # attr_reader then_keyword_loc: Location?
16977 def then_keyword_loc
16978 location = @then_keyword_loc
16979 case location
16980 when nil
16981 nil
16982 when Location
16983 location
16984 else
16985 @then_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
16986 end
16987 end
16988
16989 # Save the then_keyword_loc location using the given saved source so that
16990 # it can be retrieved later.
16991 def save_then_keyword_loc(repository)
16992 repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil?
16993 end
16994
16995 # attr_reader statements: StatementsNode?
16996 attr_reader :statements
16997
16998 # attr_reader subsequent: RescueNode?
16999 attr_reader :subsequent
17000
17001 # def keyword: () -> String
17002 def keyword
17003 keyword_loc.slice
17004 end
17005
17006 # def operator: () -> String?
17007 def operator
17008 operator_loc&.slice
17009 end
17010
17011 # def then_keyword: () -> String?
17012 def then_keyword
17013 then_keyword_loc&.slice
17014 end
17015
17016 # def inspect -> String
17017 def inspect
17018 InspectVisitor.compose(self)
17019 end
17020
17021 # Return a symbol representation of this node type. See `Node#type`.
17022 def type
17023 :rescue_node
17024 end
17025
17026 # Return a symbol representation of this node type. See `Node::type`.
17027 def self.type
17028 :rescue_node
17029 end
17030
17031 # Implements case-equality for the node. This is effectively == but without
17032 # comparing the value of locations. Locations are checked only for presence.
17033 def ===(other)
17034 other.is_a?(RescueNode) &&
17035 (keyword_loc.nil? == other.keyword_loc.nil?) &&
17036 (exceptions.length == other.exceptions.length) &&
17037 exceptions.zip(other.exceptions).all? { |left, right| left === right } &&
17038 (operator_loc.nil? == other.operator_loc.nil?) &&
17039 (reference === other.reference) &&
17040 (then_keyword_loc.nil? == other.then_keyword_loc.nil?) &&
17041 (statements === other.statements) &&
17042 (subsequent === other.subsequent)
17043 end
17044 end
17045
17046 # Represents a rest parameter to a method, block, or lambda definition.
17047 #
17048 # def a(*b)
17049 # ^^
17050 # end
17051 class RestParameterNode < Node
17052 # Initialize a new RestParameterNode node.
17053 def initialize(source, node_id, location, flags, name, name_loc, operator_loc)
17054 @source = source
17055 @node_id = node_id
17056 @location = location
17057 @flags = flags
17058 @name = name
17059 @name_loc = name_loc
17060 @operator_loc = operator_loc
17061 end
17062
17063 # def accept: (Visitor visitor) -> void
17064 def accept(visitor)
17065 visitor.visit_rest_parameter_node(self)
17066 end
17067
17068 # def child_nodes: () -> Array[Node?]
17069 def child_nodes
17070 []
17071 end
17072
17073 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17074 def each_child_node
17075 return to_enum(:each_child_node) unless block_given?
17076
17077 end
17078
17079 # def compact_child_nodes: () -> Array[Node]
17080 def compact_child_nodes
17081 []
17082 end
17083
17084 # def comment_targets: () -> Array[Node | Location]
17085 def comment_targets
17086 [*name_loc, operator_loc] #: Array[Prism::node | Location]
17087 end
17088
17089 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol?, ?name_loc: Location?, ?operator_loc: Location) -> RestParameterNode
17090 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc)
17091 RestParameterNode.new(source, node_id, location, flags, name, name_loc, operator_loc)
17092 end
17093
17094 # def deconstruct: () -> Array[Node?]
17095 alias deconstruct child_nodes
17096
17097 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, name: Symbol?, name_loc: Location?, operator_loc: Location }
17098 def deconstruct_keys(keys)
17099 { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc }
17100 end
17101
17102 # def repeated_parameter?: () -> bool
17103 def repeated_parameter?
17104 flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
17105 end
17106
17107 # attr_reader name: Symbol?
17108 attr_reader :name
17109
17110 # attr_reader name_loc: Location?
17111 def name_loc
17112 location = @name_loc
17113 case location
17114 when nil
17115 nil
17116 when Location
17117 location
17118 else
17119 @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
17120 end
17121 end
17122
17123 # Save the name_loc location using the given saved source so that
17124 # it can be retrieved later.
17125 def save_name_loc(repository)
17126 repository.enter(node_id, :name_loc) unless @name_loc.nil?
17127 end
17128
17129 # attr_reader operator_loc: Location
17130 def operator_loc
17131 location = @operator_loc
17132 return location if location.is_a?(Location)
17133 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
17134 end
17135
17136 # Save the operator_loc location using the given saved source so that
17137 # it can be retrieved later.
17138 def save_operator_loc(repository)
17139 repository.enter(node_id, :operator_loc)
17140 end
17141
17142 # def operator: () -> String
17143 def operator
17144 operator_loc.slice
17145 end
17146
17147 # def inspect -> String
17148 def inspect
17149 InspectVisitor.compose(self)
17150 end
17151
17152 # Return a symbol representation of this node type. See `Node#type`.
17153 def type
17154 :rest_parameter_node
17155 end
17156
17157 # Return a symbol representation of this node type. See `Node::type`.
17158 def self.type
17159 :rest_parameter_node
17160 end
17161
17162 # Implements case-equality for the node. This is effectively == but without
17163 # comparing the value of locations. Locations are checked only for presence.
17164 def ===(other)
17165 other.is_a?(RestParameterNode) &&
17166 (flags === other.flags) &&
17167 (name === other.name) &&
17168 (name_loc.nil? == other.name_loc.nil?) &&
17169 (operator_loc.nil? == other.operator_loc.nil?)
17170 end
17171 end
17172
17173 # Represents the use of the `retry` keyword.
17174 #
17175 # retry
17176 # ^^^^^
17177 class RetryNode < Node
17178 # Initialize a new RetryNode node.
17179 def initialize(source, node_id, location, flags)
17180 @source = source
17181 @node_id = node_id
17182 @location = location
17183 @flags = flags
17184 end
17185
17186 # def accept: (Visitor visitor) -> void
17187 def accept(visitor)
17188 visitor.visit_retry_node(self)
17189 end
17190
17191 # def child_nodes: () -> Array[Node?]
17192 def child_nodes
17193 []
17194 end
17195
17196 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17197 def each_child_node
17198 return to_enum(:each_child_node) unless block_given?
17199
17200 end
17201
17202 # def compact_child_nodes: () -> Array[Node]
17203 def compact_child_nodes
17204 []
17205 end
17206
17207 # def comment_targets: () -> Array[Node | Location]
17208 def comment_targets
17209 [] #: Array[Prism::node | Location]
17210 end
17211
17212 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> RetryNode
17213 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
17214 RetryNode.new(source, node_id, location, flags)
17215 end
17216
17217 # def deconstruct: () -> Array[Node?]
17218 alias deconstruct child_nodes
17219
17220 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
17221 def deconstruct_keys(keys)
17222 { node_id: node_id, location: location }
17223 end
17224
17225 # def inspect -> String
17226 def inspect
17227 InspectVisitor.compose(self)
17228 end
17229
17230 # Return a symbol representation of this node type. See `Node#type`.
17231 def type
17232 :retry_node
17233 end
17234
17235 # Return a symbol representation of this node type. See `Node::type`.
17236 def self.type
17237 :retry_node
17238 end
17239
17240 # Implements case-equality for the node. This is effectively == but without
17241 # comparing the value of locations. Locations are checked only for presence.
17242 def ===(other)
17243 other.is_a?(RetryNode)
17244 end
17245 end
17246
17247 # Represents the use of the `return` keyword.
17248 #
17249 # return 1
17250 # ^^^^^^^^
17251 class ReturnNode < Node
17252 # Initialize a new ReturnNode node.
17253 def initialize(source, node_id, location, flags, keyword_loc, arguments)
17254 @source = source
17255 @node_id = node_id
17256 @location = location
17257 @flags = flags
17258 @keyword_loc = keyword_loc
17259 @arguments = arguments
17260 end
17261
17262 # def accept: (Visitor visitor) -> void
17263 def accept(visitor)
17264 visitor.visit_return_node(self)
17265 end
17266
17267 # def child_nodes: () -> Array[Node?]
17268 def child_nodes
17269 [arguments]
17270 end
17271
17272 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17273 def each_child_node
17274 return to_enum(:each_child_node) unless block_given?
17275
17276 yield arguments if arguments
17277 end
17278
17279 # def compact_child_nodes: () -> Array[Node]
17280 def compact_child_nodes
17281 compact = [] #: Array[Prism::node]
17282 compact << arguments if arguments
17283 compact
17284 end
17285
17286 # def comment_targets: () -> Array[Node | Location]
17287 def comment_targets
17288 [keyword_loc, *arguments] #: Array[Prism::node | Location]
17289 end
17290
17291 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?arguments: ArgumentsNode?) -> ReturnNode
17292 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, arguments: self.arguments)
17293 ReturnNode.new(source, node_id, location, flags, keyword_loc, arguments)
17294 end
17295
17296 # def deconstruct: () -> Array[Node?]
17297 alias deconstruct child_nodes
17298
17299 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, arguments: ArgumentsNode? }
17300 def deconstruct_keys(keys)
17301 { node_id: node_id, location: location, keyword_loc: keyword_loc, arguments: arguments }
17302 end
17303
17304 # attr_reader keyword_loc: Location
17305 def keyword_loc
17306 location = @keyword_loc
17307 return location if location.is_a?(Location)
17308 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
17309 end
17310
17311 # Save the keyword_loc location using the given saved source so that
17312 # it can be retrieved later.
17313 def save_keyword_loc(repository)
17314 repository.enter(node_id, :keyword_loc)
17315 end
17316
17317 # attr_reader arguments: ArgumentsNode?
17318 attr_reader :arguments
17319
17320 # def keyword: () -> String
17321 def keyword
17322 keyword_loc.slice
17323 end
17324
17325 # def inspect -> String
17326 def inspect
17327 InspectVisitor.compose(self)
17328 end
17329
17330 # Return a symbol representation of this node type. See `Node#type`.
17331 def type
17332 :return_node
17333 end
17334
17335 # Return a symbol representation of this node type. See `Node::type`.
17336 def self.type
17337 :return_node
17338 end
17339
17340 # Implements case-equality for the node. This is effectively == but without
17341 # comparing the value of locations. Locations are checked only for presence.
17342 def ===(other)
17343 other.is_a?(ReturnNode) &&
17344 (keyword_loc.nil? == other.keyword_loc.nil?) &&
17345 (arguments === other.arguments)
17346 end
17347 end
17348
17349 # Represents the `self` keyword.
17350 #
17351 # self
17352 # ^^^^
17353 class SelfNode < Node
17354 # Initialize a new SelfNode node.
17355 def initialize(source, node_id, location, flags)
17356 @source = source
17357 @node_id = node_id
17358 @location = location
17359 @flags = flags
17360 end
17361
17362 # def accept: (Visitor visitor) -> void
17363 def accept(visitor)
17364 visitor.visit_self_node(self)
17365 end
17366
17367 # def child_nodes: () -> Array[Node?]
17368 def child_nodes
17369 []
17370 end
17371
17372 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17373 def each_child_node
17374 return to_enum(:each_child_node) unless block_given?
17375
17376 end
17377
17378 # def compact_child_nodes: () -> Array[Node]
17379 def compact_child_nodes
17380 []
17381 end
17382
17383 # def comment_targets: () -> Array[Node | Location]
17384 def comment_targets
17385 [] #: Array[Prism::node | Location]
17386 end
17387
17388 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> SelfNode
17389 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
17390 SelfNode.new(source, node_id, location, flags)
17391 end
17392
17393 # def deconstruct: () -> Array[Node?]
17394 alias deconstruct child_nodes
17395
17396 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
17397 def deconstruct_keys(keys)
17398 { node_id: node_id, location: location }
17399 end
17400
17401 # def inspect -> String
17402 def inspect
17403 InspectVisitor.compose(self)
17404 end
17405
17406 # Return a symbol representation of this node type. See `Node#type`.
17407 def type
17408 :self_node
17409 end
17410
17411 # Return a symbol representation of this node type. See `Node::type`.
17412 def self.type
17413 :self_node
17414 end
17415
17416 # Implements case-equality for the node. This is effectively == but without
17417 # comparing the value of locations. Locations are checked only for presence.
17418 def ===(other)
17419 other.is_a?(SelfNode)
17420 end
17421 end
17422
17423 # This node wraps a constant write to indicate that when the value is written, it should have its shareability state modified.
17424 #
17425 # # shareable_constant_value: literal
17426 # C = { a: 1 }
17427 # ^^^^^^^^^^^^
17428 class ShareableConstantNode < Node
17429 # Initialize a new ShareableConstantNode node.
17430 def initialize(source, node_id, location, flags, write)
17431 @source = source
17432 @node_id = node_id
17433 @location = location
17434 @flags = flags
17435 @write = write
17436 end
17437
17438 # def accept: (Visitor visitor) -> void
17439 def accept(visitor)
17440 visitor.visit_shareable_constant_node(self)
17441 end
17442
17443 # def child_nodes: () -> Array[Node?]
17444 def child_nodes
17445 [write]
17446 end
17447
17448 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17449 def each_child_node
17450 return to_enum(:each_child_node) unless block_given?
17451
17452 yield write
17453 end
17454
17455 # def compact_child_nodes: () -> Array[Node]
17456 def compact_child_nodes
17457 [write]
17458 end
17459
17460 # def comment_targets: () -> Array[Node | Location]
17461 def comment_targets
17462 [write] #: Array[Prism::node | Location]
17463 end
17464
17465 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?write: ConstantWriteNode | ConstantAndWriteNode | ConstantOrWriteNode | ConstantOperatorWriteNode | ConstantPathWriteNode | ConstantPathAndWriteNode | ConstantPathOrWriteNode | ConstantPathOperatorWriteNode) -> ShareableConstantNode
17466 def copy(node_id: self.node_id, location: self.location, flags: self.flags, write: self.write)
17467 ShareableConstantNode.new(source, node_id, location, flags, write)
17468 end
17469
17470 # def deconstruct: () -> Array[Node?]
17471 alias deconstruct child_nodes
17472
17473 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, write: ConstantWriteNode | ConstantAndWriteNode | ConstantOrWriteNode | ConstantOperatorWriteNode | ConstantPathWriteNode | ConstantPathAndWriteNode | ConstantPathOrWriteNode | ConstantPathOperatorWriteNode }
17474 def deconstruct_keys(keys)
17475 { node_id: node_id, location: location, write: write }
17476 end
17477
17478 # def literal?: () -> bool
17479 def literal?
17480 flags.anybits?(ShareableConstantNodeFlags::LITERAL)
17481 end
17482
17483 # def experimental_everything?: () -> bool
17484 def experimental_everything?
17485 flags.anybits?(ShareableConstantNodeFlags::EXPERIMENTAL_EVERYTHING)
17486 end
17487
17488 # def experimental_copy?: () -> bool
17489 def experimental_copy?
17490 flags.anybits?(ShareableConstantNodeFlags::EXPERIMENTAL_COPY)
17491 end
17492
17493 # The constant write that should be modified with the shareability state.
17494 attr_reader :write
17495
17496 # def inspect -> String
17497 def inspect
17498 InspectVisitor.compose(self)
17499 end
17500
17501 # Return a symbol representation of this node type. See `Node#type`.
17502 def type
17503 :shareable_constant_node
17504 end
17505
17506 # Return a symbol representation of this node type. See `Node::type`.
17507 def self.type
17508 :shareable_constant_node
17509 end
17510
17511 # Implements case-equality for the node. This is effectively == but without
17512 # comparing the value of locations. Locations are checked only for presence.
17513 def ===(other)
17514 other.is_a?(ShareableConstantNode) &&
17515 (flags === other.flags) &&
17516 (write === other.write)
17517 end
17518 end
17519
17520 # Represents a singleton class declaration involving the `class` keyword.
17521 #
17522 # class << self end
17523 # ^^^^^^^^^^^^^^^^^
17524 class SingletonClassNode < Node
17525 # Initialize a new SingletonClassNode node.
17526 def initialize(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc)
17527 @source = source
17528 @node_id = node_id
17529 @location = location
17530 @flags = flags
17531 @locals = locals
17532 @class_keyword_loc = class_keyword_loc
17533 @operator_loc = operator_loc
17534 @expression = expression
17535 @body = body
17536 @end_keyword_loc = end_keyword_loc
17537 end
17538
17539 # def accept: (Visitor visitor) -> void
17540 def accept(visitor)
17541 visitor.visit_singleton_class_node(self)
17542 end
17543
17544 # def child_nodes: () -> Array[Node?]
17545 def child_nodes
17546 [expression, body]
17547 end
17548
17549 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17550 def each_child_node
17551 return to_enum(:each_child_node) unless block_given?
17552
17553 yield expression
17554 yield body if body
17555 end
17556
17557 # def compact_child_nodes: () -> Array[Node]
17558 def compact_child_nodes
17559 compact = [] #: Array[Prism::node]
17560 compact << expression
17561 compact << body if body
17562 compact
17563 end
17564
17565 # def comment_targets: () -> Array[Node | Location]
17566 def comment_targets
17567 [class_keyword_loc, operator_loc, expression, *body, end_keyword_loc] #: Array[Prism::node | Location]
17568 end
17569
17570 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array[Symbol], ?class_keyword_loc: Location, ?operator_loc: Location, ?expression: Prism::node, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location) -> SingletonClassNode
17571 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, operator_loc: self.operator_loc, expression: self.expression, body: self.body, end_keyword_loc: self.end_keyword_loc)
17572 SingletonClassNode.new(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc)
17573 end
17574
17575 # def deconstruct: () -> Array[Node?]
17576 alias deconstruct child_nodes
17577
17578 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, locals: Array[Symbol], class_keyword_loc: Location, operator_loc: Location, expression: Prism::node, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location }
17579 def deconstruct_keys(keys)
17580 { node_id: node_id, location: location, locals: locals, class_keyword_loc: class_keyword_loc, operator_loc: operator_loc, expression: expression, body: body, end_keyword_loc: end_keyword_loc }
17581 end
17582
17583 # attr_reader locals: Array[Symbol]
17584 attr_reader :locals
17585
17586 # attr_reader class_keyword_loc: Location
17587 def class_keyword_loc
17588 location = @class_keyword_loc
17589 return location if location.is_a?(Location)
17590 @class_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
17591 end
17592
17593 # Save the class_keyword_loc location using the given saved source so that
17594 # it can be retrieved later.
17595 def save_class_keyword_loc(repository)
17596 repository.enter(node_id, :class_keyword_loc)
17597 end
17598
17599 # attr_reader operator_loc: Location
17600 def operator_loc
17601 location = @operator_loc
17602 return location if location.is_a?(Location)
17603 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
17604 end
17605
17606 # Save the operator_loc location using the given saved source so that
17607 # it can be retrieved later.
17608 def save_operator_loc(repository)
17609 repository.enter(node_id, :operator_loc)
17610 end
17611
17612 # attr_reader expression: Prism::node
17613 attr_reader :expression
17614
17615 # attr_reader body: StatementsNode | BeginNode | nil
17616 attr_reader :body
17617
17618 # attr_reader end_keyword_loc: Location
17619 def end_keyword_loc
17620 location = @end_keyword_loc
17621 return location if location.is_a?(Location)
17622 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
17623 end
17624
17625 # Save the end_keyword_loc location using the given saved source so that
17626 # it can be retrieved later.
17627 def save_end_keyword_loc(repository)
17628 repository.enter(node_id, :end_keyword_loc)
17629 end
17630
17631 # def class_keyword: () -> String
17632 def class_keyword
17633 class_keyword_loc.slice
17634 end
17635
17636 # def operator: () -> String
17637 def operator
17638 operator_loc.slice
17639 end
17640
17641 # def end_keyword: () -> String
17642 def end_keyword
17643 end_keyword_loc.slice
17644 end
17645
17646 # def inspect -> String
17647 def inspect
17648 InspectVisitor.compose(self)
17649 end
17650
17651 # Return a symbol representation of this node type. See `Node#type`.
17652 def type
17653 :singleton_class_node
17654 end
17655
17656 # Return a symbol representation of this node type. See `Node::type`.
17657 def self.type
17658 :singleton_class_node
17659 end
17660
17661 # Implements case-equality for the node. This is effectively == but without
17662 # comparing the value of locations. Locations are checked only for presence.
17663 def ===(other)
17664 other.is_a?(SingletonClassNode) &&
17665 (locals.length == other.locals.length) &&
17666 locals.zip(other.locals).all? { |left, right| left === right } &&
17667 (class_keyword_loc.nil? == other.class_keyword_loc.nil?) &&
17668 (operator_loc.nil? == other.operator_loc.nil?) &&
17669 (expression === other.expression) &&
17670 (body === other.body) &&
17671 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
17672 end
17673 end
17674
17675 # Represents the use of the `__ENCODING__` keyword.
17676 #
17677 # __ENCODING__
17678 # ^^^^^^^^^^^^
17679 class SourceEncodingNode < Node
17680 # Initialize a new SourceEncodingNode node.
17681 def initialize(source, node_id, location, flags)
17682 @source = source
17683 @node_id = node_id
17684 @location = location
17685 @flags = flags
17686 end
17687
17688 # def accept: (Visitor visitor) -> void
17689 def accept(visitor)
17690 visitor.visit_source_encoding_node(self)
17691 end
17692
17693 # def child_nodes: () -> Array[Node?]
17694 def child_nodes
17695 []
17696 end
17697
17698 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17699 def each_child_node
17700 return to_enum(:each_child_node) unless block_given?
17701
17702 end
17703
17704 # def compact_child_nodes: () -> Array[Node]
17705 def compact_child_nodes
17706 []
17707 end
17708
17709 # def comment_targets: () -> Array[Node | Location]
17710 def comment_targets
17711 [] #: Array[Prism::node | Location]
17712 end
17713
17714 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> SourceEncodingNode
17715 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
17716 SourceEncodingNode.new(source, node_id, location, flags)
17717 end
17718
17719 # def deconstruct: () -> Array[Node?]
17720 alias deconstruct child_nodes
17721
17722 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
17723 def deconstruct_keys(keys)
17724 { node_id: node_id, location: location }
17725 end
17726
17727 # def inspect -> String
17728 def inspect
17729 InspectVisitor.compose(self)
17730 end
17731
17732 # Return a symbol representation of this node type. See `Node#type`.
17733 def type
17734 :source_encoding_node
17735 end
17736
17737 # Return a symbol representation of this node type. See `Node::type`.
17738 def self.type
17739 :source_encoding_node
17740 end
17741
17742 # Implements case-equality for the node. This is effectively == but without
17743 # comparing the value of locations. Locations are checked only for presence.
17744 def ===(other)
17745 other.is_a?(SourceEncodingNode)
17746 end
17747 end
17748
17749 # Represents the use of the `__FILE__` keyword.
17750 #
17751 # __FILE__
17752 # ^^^^^^^^
17753 class SourceFileNode < Node
17754 # Initialize a new SourceFileNode node.
17755 def initialize(source, node_id, location, flags, filepath)
17756 @source = source
17757 @node_id = node_id
17758 @location = location
17759 @flags = flags
17760 @filepath = filepath
17761 end
17762
17763 # def accept: (Visitor visitor) -> void
17764 def accept(visitor)
17765 visitor.visit_source_file_node(self)
17766 end
17767
17768 # def child_nodes: () -> Array[Node?]
17769 def child_nodes
17770 []
17771 end
17772
17773 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17774 def each_child_node
17775 return to_enum(:each_child_node) unless block_given?
17776
17777 end
17778
17779 # def compact_child_nodes: () -> Array[Node]
17780 def compact_child_nodes
17781 []
17782 end
17783
17784 # def comment_targets: () -> Array[Node | Location]
17785 def comment_targets
17786 [] #: Array[Prism::node | Location]
17787 end
17788
17789 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?filepath: String) -> SourceFileNode
17790 def copy(node_id: self.node_id, location: self.location, flags: self.flags, filepath: self.filepath)
17791 SourceFileNode.new(source, node_id, location, flags, filepath)
17792 end
17793
17794 # def deconstruct: () -> Array[Node?]
17795 alias deconstruct child_nodes
17796
17797 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, filepath: String }
17798 def deconstruct_keys(keys)
17799 { node_id: node_id, location: location, filepath: filepath }
17800 end
17801
17802 # def forced_utf8_encoding?: () -> bool
17803 def forced_utf8_encoding?
17804 flags.anybits?(StringFlags::FORCED_UTF8_ENCODING)
17805 end
17806
17807 # def forced_binary_encoding?: () -> bool
17808 def forced_binary_encoding?
17809 flags.anybits?(StringFlags::FORCED_BINARY_ENCODING)
17810 end
17811
17812 # def frozen?: () -> bool
17813 def frozen?
17814 flags.anybits?(StringFlags::FROZEN)
17815 end
17816
17817 # def mutable?: () -> bool
17818 def mutable?
17819 flags.anybits?(StringFlags::MUTABLE)
17820 end
17821
17822 # Represents the file path being parsed. This corresponds directly to the `filepath` option given to the various `Prism::parse*` APIs.
17823 attr_reader :filepath
17824
17825 # def inspect -> String
17826 def inspect
17827 InspectVisitor.compose(self)
17828 end
17829
17830 # Return a symbol representation of this node type. See `Node#type`.
17831 def type
17832 :source_file_node
17833 end
17834
17835 # Return a symbol representation of this node type. See `Node::type`.
17836 def self.type
17837 :source_file_node
17838 end
17839
17840 # Implements case-equality for the node. This is effectively == but without
17841 # comparing the value of locations. Locations are checked only for presence.
17842 def ===(other)
17843 other.is_a?(SourceFileNode) &&
17844 (flags === other.flags) &&
17845 (filepath === other.filepath)
17846 end
17847 end
17848
17849 # Represents the use of the `__LINE__` keyword.
17850 #
17851 # __LINE__
17852 # ^^^^^^^^
17853 class SourceLineNode < Node
17854 # Initialize a new SourceLineNode node.
17855 def initialize(source, node_id, location, flags)
17856 @source = source
17857 @node_id = node_id
17858 @location = location
17859 @flags = flags
17860 end
17861
17862 # def accept: (Visitor visitor) -> void
17863 def accept(visitor)
17864 visitor.visit_source_line_node(self)
17865 end
17866
17867 # def child_nodes: () -> Array[Node?]
17868 def child_nodes
17869 []
17870 end
17871
17872 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17873 def each_child_node
17874 return to_enum(:each_child_node) unless block_given?
17875
17876 end
17877
17878 # def compact_child_nodes: () -> Array[Node]
17879 def compact_child_nodes
17880 []
17881 end
17882
17883 # def comment_targets: () -> Array[Node | Location]
17884 def comment_targets
17885 [] #: Array[Prism::node | Location]
17886 end
17887
17888 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> SourceLineNode
17889 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
17890 SourceLineNode.new(source, node_id, location, flags)
17891 end
17892
17893 # def deconstruct: () -> Array[Node?]
17894 alias deconstruct child_nodes
17895
17896 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
17897 def deconstruct_keys(keys)
17898 { node_id: node_id, location: location }
17899 end
17900
17901 # def inspect -> String
17902 def inspect
17903 InspectVisitor.compose(self)
17904 end
17905
17906 # Return a symbol representation of this node type. See `Node#type`.
17907 def type
17908 :source_line_node
17909 end
17910
17911 # Return a symbol representation of this node type. See `Node::type`.
17912 def self.type
17913 :source_line_node
17914 end
17915
17916 # Implements case-equality for the node. This is effectively == but without
17917 # comparing the value of locations. Locations are checked only for presence.
17918 def ===(other)
17919 other.is_a?(SourceLineNode)
17920 end
17921 end
17922
17923 # Represents the use of the splat operator.
17924 #
17925 # [*a]
17926 # ^^
17927 class SplatNode < Node
17928 # Initialize a new SplatNode node.
17929 def initialize(source, node_id, location, flags, operator_loc, expression)
17930 @source = source
17931 @node_id = node_id
17932 @location = location
17933 @flags = flags
17934 @operator_loc = operator_loc
17935 @expression = expression
17936 end
17937
17938 # def accept: (Visitor visitor) -> void
17939 def accept(visitor)
17940 visitor.visit_splat_node(self)
17941 end
17942
17943 # def child_nodes: () -> Array[Node?]
17944 def child_nodes
17945 [expression]
17946 end
17947
17948 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
17949 def each_child_node
17950 return to_enum(:each_child_node) unless block_given?
17951
17952 yield expression if expression
17953 end
17954
17955 # def compact_child_nodes: () -> Array[Node]
17956 def compact_child_nodes
17957 compact = [] #: Array[Prism::node]
17958 compact << expression if expression
17959 compact
17960 end
17961
17962 # def comment_targets: () -> Array[Node | Location]
17963 def comment_targets
17964 [operator_loc, *expression] #: Array[Prism::node | Location]
17965 end
17966
17967 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?operator_loc: Location, ?expression: Prism::node?) -> SplatNode
17968 def copy(node_id: self.node_id, location: self.location, flags: self.flags, operator_loc: self.operator_loc, expression: self.expression)
17969 SplatNode.new(source, node_id, location, flags, operator_loc, expression)
17970 end
17971
17972 # def deconstruct: () -> Array[Node?]
17973 alias deconstruct child_nodes
17974
17975 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, operator_loc: Location, expression: Prism::node? }
17976 def deconstruct_keys(keys)
17977 { node_id: node_id, location: location, operator_loc: operator_loc, expression: expression }
17978 end
17979
17980 # attr_reader operator_loc: Location
17981 def operator_loc
17982 location = @operator_loc
17983 return location if location.is_a?(Location)
17984 @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
17985 end
17986
17987 # Save the operator_loc location using the given saved source so that
17988 # it can be retrieved later.
17989 def save_operator_loc(repository)
17990 repository.enter(node_id, :operator_loc)
17991 end
17992
17993 # attr_reader expression: Prism::node?
17994 attr_reader :expression
17995
17996 # def operator: () -> String
17997 def operator
17998 operator_loc.slice
17999 end
18000
18001 # def inspect -> String
18002 def inspect
18003 InspectVisitor.compose(self)
18004 end
18005
18006 # Return a symbol representation of this node type. See `Node#type`.
18007 def type
18008 :splat_node
18009 end
18010
18011 # Return a symbol representation of this node type. See `Node::type`.
18012 def self.type
18013 :splat_node
18014 end
18015
18016 # Implements case-equality for the node. This is effectively == but without
18017 # comparing the value of locations. Locations are checked only for presence.
18018 def ===(other)
18019 other.is_a?(SplatNode) &&
18020 (operator_loc.nil? == other.operator_loc.nil?) &&
18021 (expression === other.expression)
18022 end
18023 end
18024
18025 # Represents a set of statements contained within some scope.
18026 #
18027 # foo; bar; baz
18028 # ^^^^^^^^^^^^^
18029 class StatementsNode < Node
18030 # Initialize a new StatementsNode node.
18031 def initialize(source, node_id, location, flags, body)
18032 @source = source
18033 @node_id = node_id
18034 @location = location
18035 @flags = flags
18036 @body = body
18037 end
18038
18039 # def accept: (Visitor visitor) -> void
18040 def accept(visitor)
18041 visitor.visit_statements_node(self)
18042 end
18043
18044 # def child_nodes: () -> Array[Node?]
18045 def child_nodes
18046 [*body]
18047 end
18048
18049 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
18050 def each_child_node
18051 return to_enum(:each_child_node) unless block_given?
18052
18053 body.each { |node| yield node }
18054 end
18055
18056 # def compact_child_nodes: () -> Array[Node]
18057 def compact_child_nodes
18058 [*body]
18059 end
18060
18061 # def comment_targets: () -> Array[Node | Location]
18062 def comment_targets
18063 [*body] #: Array[Prism::node | Location]
18064 end
18065
18066 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?body: Array[Prism::node]) -> StatementsNode
18067 def copy(node_id: self.node_id, location: self.location, flags: self.flags, body: self.body)
18068 StatementsNode.new(source, node_id, location, flags, body)
18069 end
18070
18071 # def deconstruct: () -> Array[Node?]
18072 alias deconstruct child_nodes
18073
18074 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, body: Array[Prism::node] }
18075 def deconstruct_keys(keys)
18076 { node_id: node_id, location: location, body: body }
18077 end
18078
18079 # attr_reader body: Array[Prism::node]
18080 attr_reader :body
18081
18082 # def inspect -> String
18083 def inspect
18084 InspectVisitor.compose(self)
18085 end
18086
18087 # Return a symbol representation of this node type. See `Node#type`.
18088 def type
18089 :statements_node
18090 end
18091
18092 # Return a symbol representation of this node type. See `Node::type`.
18093 def self.type
18094 :statements_node
18095 end
18096
18097 # Implements case-equality for the node. This is effectively == but without
18098 # comparing the value of locations. Locations are checked only for presence.
18099 def ===(other)
18100 other.is_a?(StatementsNode) &&
18101 (body.length == other.body.length) &&
18102 body.zip(other.body).all? { |left, right| left === right }
18103 end
18104 end
18105
18106 # Represents a string literal, a string contained within a `%w` list, or plain string content within an interpolated string.
18107 #
18108 # "foo"
18109 # ^^^^^
18110 #
18111 # %w[foo]
18112 # ^^^
18113 #
18114 # "foo #{bar} baz"
18115 # ^^^^ ^^^^
18116 class StringNode < Node
18117 # Initialize a new StringNode node.
18118 def initialize(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped)
18119 @source = source
18120 @node_id = node_id
18121 @location = location
18122 @flags = flags
18123 @opening_loc = opening_loc
18124 @content_loc = content_loc
18125 @closing_loc = closing_loc
18126 @unescaped = unescaped
18127 end
18128
18129 # def accept: (Visitor visitor) -> void
18130 def accept(visitor)
18131 visitor.visit_string_node(self)
18132 end
18133
18134 # def child_nodes: () -> Array[Node?]
18135 def child_nodes
18136 []
18137 end
18138
18139 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
18140 def each_child_node
18141 return to_enum(:each_child_node) unless block_given?
18142
18143 end
18144
18145 # def compact_child_nodes: () -> Array[Node]
18146 def compact_child_nodes
18147 []
18148 end
18149
18150 # def comment_targets: () -> Array[Node | Location]
18151 def comment_targets
18152 [*opening_loc, content_loc, *closing_loc] #: Array[Prism::node | Location]
18153 end
18154
18155 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location?, ?content_loc: Location, ?closing_loc: Location?, ?unescaped: String) -> StringNode
18156 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, content_loc: self.content_loc, closing_loc: self.closing_loc, unescaped: self.unescaped)
18157 StringNode.new(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped)
18158 end
18159
18160 # def deconstruct: () -> Array[Node?]
18161 alias deconstruct child_nodes
18162
18163 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location?, content_loc: Location, closing_loc: Location?, unescaped: String }
18164 def deconstruct_keys(keys)
18165 { node_id: node_id, location: location, opening_loc: opening_loc, content_loc: content_loc, closing_loc: closing_loc, unescaped: unescaped }
18166 end
18167
18168 # def forced_utf8_encoding?: () -> bool
18169 def forced_utf8_encoding?
18170 flags.anybits?(StringFlags::FORCED_UTF8_ENCODING)
18171 end
18172
18173 # def forced_binary_encoding?: () -> bool
18174 def forced_binary_encoding?
18175 flags.anybits?(StringFlags::FORCED_BINARY_ENCODING)
18176 end
18177
18178 # def frozen?: () -> bool
18179 def frozen?
18180 flags.anybits?(StringFlags::FROZEN)
18181 end
18182
18183 # def mutable?: () -> bool
18184 def mutable?
18185 flags.anybits?(StringFlags::MUTABLE)
18186 end
18187
18188 # attr_reader opening_loc: Location?
18189 def opening_loc
18190 location = @opening_loc
18191 case location
18192 when nil
18193 nil
18194 when Location
18195 location
18196 else
18197 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18198 end
18199 end
18200
18201 # Save the opening_loc location using the given saved source so that
18202 # it can be retrieved later.
18203 def save_opening_loc(repository)
18204 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
18205 end
18206
18207 # attr_reader content_loc: Location
18208 def content_loc
18209 location = @content_loc
18210 return location if location.is_a?(Location)
18211 @content_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18212 end
18213
18214 # Save the content_loc location using the given saved source so that
18215 # it can be retrieved later.
18216 def save_content_loc(repository)
18217 repository.enter(node_id, :content_loc)
18218 end
18219
18220 # attr_reader closing_loc: Location?
18221 def closing_loc
18222 location = @closing_loc
18223 case location
18224 when nil
18225 nil
18226 when Location
18227 location
18228 else
18229 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18230 end
18231 end
18232
18233 # Save the closing_loc location using the given saved source so that
18234 # it can be retrieved later.
18235 def save_closing_loc(repository)
18236 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
18237 end
18238
18239 # attr_reader unescaped: String
18240 attr_reader :unescaped
18241
18242 # def opening: () -> String?
18243 def opening
18244 opening_loc&.slice
18245 end
18246
18247 # def content: () -> String
18248 def content
18249 content_loc.slice
18250 end
18251
18252 # def closing: () -> String?
18253 def closing
18254 closing_loc&.slice
18255 end
18256
18257 # def inspect -> String
18258 def inspect
18259 InspectVisitor.compose(self)
18260 end
18261
18262 # Return a symbol representation of this node type. See `Node#type`.
18263 def type
18264 :string_node
18265 end
18266
18267 # Return a symbol representation of this node type. See `Node::type`.
18268 def self.type
18269 :string_node
18270 end
18271
18272 # Implements case-equality for the node. This is effectively == but without
18273 # comparing the value of locations. Locations are checked only for presence.
18274 def ===(other)
18275 other.is_a?(StringNode) &&
18276 (flags === other.flags) &&
18277 (opening_loc.nil? == other.opening_loc.nil?) &&
18278 (content_loc.nil? == other.content_loc.nil?) &&
18279 (closing_loc.nil? == other.closing_loc.nil?) &&
18280 (unescaped === other.unescaped)
18281 end
18282 end
18283
18284 # Represents the use of the `super` keyword with parentheses or arguments.
18285 #
18286 # super()
18287 # ^^^^^^^
18288 #
18289 # super foo, bar
18290 # ^^^^^^^^^^^^^^
18291 #
18292 # If no arguments are provided (except for a block), it would be a `ForwardingSuperNode` instead.
18293 class SuperNode < Node
18294 # Initialize a new SuperNode node.
18295 def initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block)
18296 @source = source
18297 @node_id = node_id
18298 @location = location
18299 @flags = flags
18300 @keyword_loc = keyword_loc
18301 @lparen_loc = lparen_loc
18302 @arguments = arguments
18303 @rparen_loc = rparen_loc
18304 @block = block
18305 end
18306
18307 # def accept: (Visitor visitor) -> void
18308 def accept(visitor)
18309 visitor.visit_super_node(self)
18310 end
18311
18312 # def child_nodes: () -> Array[Node?]
18313 def child_nodes
18314 [arguments, block]
18315 end
18316
18317 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
18318 def each_child_node
18319 return to_enum(:each_child_node) unless block_given?
18320
18321 yield arguments if arguments
18322 yield block if block
18323 end
18324
18325 # def compact_child_nodes: () -> Array[Node]
18326 def compact_child_nodes
18327 compact = [] #: Array[Prism::node]
18328 compact << arguments if arguments
18329 compact << block if block
18330 compact
18331 end
18332
18333 # def comment_targets: () -> Array[Node | Location]
18334 def comment_targets
18335 [keyword_loc, *lparen_loc, *arguments, *rparen_loc, *block] #: Array[Prism::node | Location]
18336 end
18337
18338 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?lparen_loc: Location?, ?arguments: ArgumentsNode?, ?rparen_loc: Location?, ?block: BlockNode | BlockArgumentNode | nil) -> SuperNode
18339 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc, block: self.block)
18340 SuperNode.new(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block)
18341 end
18342
18343 # def deconstruct: () -> Array[Node?]
18344 alias deconstruct child_nodes
18345
18346 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, lparen_loc: Location?, arguments: ArgumentsNode?, rparen_loc: Location?, block: BlockNode | BlockArgumentNode | nil }
18347 def deconstruct_keys(keys)
18348 { node_id: node_id, location: location, keyword_loc: keyword_loc, lparen_loc: lparen_loc, arguments: arguments, rparen_loc: rparen_loc, block: block }
18349 end
18350
18351 # attr_reader keyword_loc: Location
18352 def keyword_loc
18353 location = @keyword_loc
18354 return location if location.is_a?(Location)
18355 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18356 end
18357
18358 # Save the keyword_loc location using the given saved source so that
18359 # it can be retrieved later.
18360 def save_keyword_loc(repository)
18361 repository.enter(node_id, :keyword_loc)
18362 end
18363
18364 # attr_reader lparen_loc: Location?
18365 def lparen_loc
18366 location = @lparen_loc
18367 case location
18368 when nil
18369 nil
18370 when Location
18371 location
18372 else
18373 @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18374 end
18375 end
18376
18377 # Save the lparen_loc location using the given saved source so that
18378 # it can be retrieved later.
18379 def save_lparen_loc(repository)
18380 repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil?
18381 end
18382
18383 # Can be only `nil` when there are empty parentheses, like `super()`.
18384 attr_reader :arguments
18385
18386 # attr_reader rparen_loc: Location?
18387 def rparen_loc
18388 location = @rparen_loc
18389 case location
18390 when nil
18391 nil
18392 when Location
18393 location
18394 else
18395 @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18396 end
18397 end
18398
18399 # Save the rparen_loc location using the given saved source so that
18400 # it can be retrieved later.
18401 def save_rparen_loc(repository)
18402 repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil?
18403 end
18404
18405 # attr_reader block: BlockNode | BlockArgumentNode | nil
18406 attr_reader :block
18407
18408 # def keyword: () -> String
18409 def keyword
18410 keyword_loc.slice
18411 end
18412
18413 # def lparen: () -> String?
18414 def lparen
18415 lparen_loc&.slice
18416 end
18417
18418 # def rparen: () -> String?
18419 def rparen
18420 rparen_loc&.slice
18421 end
18422
18423 # def inspect -> String
18424 def inspect
18425 InspectVisitor.compose(self)
18426 end
18427
18428 # Return a symbol representation of this node type. See `Node#type`.
18429 def type
18430 :super_node
18431 end
18432
18433 # Return a symbol representation of this node type. See `Node::type`.
18434 def self.type
18435 :super_node
18436 end
18437
18438 # Implements case-equality for the node. This is effectively == but without
18439 # comparing the value of locations. Locations are checked only for presence.
18440 def ===(other)
18441 other.is_a?(SuperNode) &&
18442 (keyword_loc.nil? == other.keyword_loc.nil?) &&
18443 (lparen_loc.nil? == other.lparen_loc.nil?) &&
18444 (arguments === other.arguments) &&
18445 (rparen_loc.nil? == other.rparen_loc.nil?) &&
18446 (block === other.block)
18447 end
18448 end
18449
18450 # Represents a symbol literal or a symbol contained within a `%i` list.
18451 #
18452 # :foo
18453 # ^^^^
18454 #
18455 # %i[foo]
18456 # ^^^
18457 class SymbolNode < Node
18458 # Initialize a new SymbolNode node.
18459 def initialize(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped)
18460 @source = source
18461 @node_id = node_id
18462 @location = location
18463 @flags = flags
18464 @opening_loc = opening_loc
18465 @value_loc = value_loc
18466 @closing_loc = closing_loc
18467 @unescaped = unescaped
18468 end
18469
18470 # def accept: (Visitor visitor) -> void
18471 def accept(visitor)
18472 visitor.visit_symbol_node(self)
18473 end
18474
18475 # def child_nodes: () -> Array[Node?]
18476 def child_nodes
18477 []
18478 end
18479
18480 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
18481 def each_child_node
18482 return to_enum(:each_child_node) unless block_given?
18483
18484 end
18485
18486 # def compact_child_nodes: () -> Array[Node]
18487 def compact_child_nodes
18488 []
18489 end
18490
18491 # def comment_targets: () -> Array[Node | Location]
18492 def comment_targets
18493 [*opening_loc, *value_loc, *closing_loc] #: Array[Prism::node | Location]
18494 end
18495
18496 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location?, ?value_loc: Location?, ?closing_loc: Location?, ?unescaped: String) -> SymbolNode
18497 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, value_loc: self.value_loc, closing_loc: self.closing_loc, unescaped: self.unescaped)
18498 SymbolNode.new(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped)
18499 end
18500
18501 # def deconstruct: () -> Array[Node?]
18502 alias deconstruct child_nodes
18503
18504 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location?, value_loc: Location?, closing_loc: Location?, unescaped: String }
18505 def deconstruct_keys(keys)
18506 { node_id: node_id, location: location, opening_loc: opening_loc, value_loc: value_loc, closing_loc: closing_loc, unescaped: unescaped }
18507 end
18508
18509 # def forced_utf8_encoding?: () -> bool
18510 def forced_utf8_encoding?
18511 flags.anybits?(SymbolFlags::FORCED_UTF8_ENCODING)
18512 end
18513
18514 # def forced_binary_encoding?: () -> bool
18515 def forced_binary_encoding?
18516 flags.anybits?(SymbolFlags::FORCED_BINARY_ENCODING)
18517 end
18518
18519 # def forced_us_ascii_encoding?: () -> bool
18520 def forced_us_ascii_encoding?
18521 flags.anybits?(SymbolFlags::FORCED_US_ASCII_ENCODING)
18522 end
18523
18524 # attr_reader opening_loc: Location?
18525 def opening_loc
18526 location = @opening_loc
18527 case location
18528 when nil
18529 nil
18530 when Location
18531 location
18532 else
18533 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18534 end
18535 end
18536
18537 # Save the opening_loc location using the given saved source so that
18538 # it can be retrieved later.
18539 def save_opening_loc(repository)
18540 repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
18541 end
18542
18543 # attr_reader value_loc: Location?
18544 def value_loc
18545 location = @value_loc
18546 case location
18547 when nil
18548 nil
18549 when Location
18550 location
18551 else
18552 @value_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18553 end
18554 end
18555
18556 # Save the value_loc location using the given saved source so that
18557 # it can be retrieved later.
18558 def save_value_loc(repository)
18559 repository.enter(node_id, :value_loc) unless @value_loc.nil?
18560 end
18561
18562 # attr_reader closing_loc: Location?
18563 def closing_loc
18564 location = @closing_loc
18565 case location
18566 when nil
18567 nil
18568 when Location
18569 location
18570 else
18571 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18572 end
18573 end
18574
18575 # Save the closing_loc location using the given saved source so that
18576 # it can be retrieved later.
18577 def save_closing_loc(repository)
18578 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
18579 end
18580
18581 # attr_reader unescaped: String
18582 attr_reader :unescaped
18583
18584 # def opening: () -> String?
18585 def opening
18586 opening_loc&.slice
18587 end
18588
18589 # def value: () -> String?
18590 def value
18591 value_loc&.slice
18592 end
18593
18594 # def closing: () -> String?
18595 def closing
18596 closing_loc&.slice
18597 end
18598
18599 # def inspect -> String
18600 def inspect
18601 InspectVisitor.compose(self)
18602 end
18603
18604 # Return a symbol representation of this node type. See `Node#type`.
18605 def type
18606 :symbol_node
18607 end
18608
18609 # Return a symbol representation of this node type. See `Node::type`.
18610 def self.type
18611 :symbol_node
18612 end
18613
18614 # Implements case-equality for the node. This is effectively == but without
18615 # comparing the value of locations. Locations are checked only for presence.
18616 def ===(other)
18617 other.is_a?(SymbolNode) &&
18618 (flags === other.flags) &&
18619 (opening_loc.nil? == other.opening_loc.nil?) &&
18620 (value_loc.nil? == other.value_loc.nil?) &&
18621 (closing_loc.nil? == other.closing_loc.nil?) &&
18622 (unescaped === other.unescaped)
18623 end
18624 end
18625
18626 # Represents the use of the literal `true` keyword.
18627 #
18628 # true
18629 # ^^^^
18630 class TrueNode < Node
18631 # Initialize a new TrueNode node.
18632 def initialize(source, node_id, location, flags)
18633 @source = source
18634 @node_id = node_id
18635 @location = location
18636 @flags = flags
18637 end
18638
18639 # def accept: (Visitor visitor) -> void
18640 def accept(visitor)
18641 visitor.visit_true_node(self)
18642 end
18643
18644 # def child_nodes: () -> Array[Node?]
18645 def child_nodes
18646 []
18647 end
18648
18649 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
18650 def each_child_node
18651 return to_enum(:each_child_node) unless block_given?
18652
18653 end
18654
18655 # def compact_child_nodes: () -> Array[Node]
18656 def compact_child_nodes
18657 []
18658 end
18659
18660 # def comment_targets: () -> Array[Node | Location]
18661 def comment_targets
18662 [] #: Array[Prism::node | Location]
18663 end
18664
18665 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer) -> TrueNode
18666 def copy(node_id: self.node_id, location: self.location, flags: self.flags)
18667 TrueNode.new(source, node_id, location, flags)
18668 end
18669
18670 # def deconstruct: () -> Array[Node?]
18671 alias deconstruct child_nodes
18672
18673 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location }
18674 def deconstruct_keys(keys)
18675 { node_id: node_id, location: location }
18676 end
18677
18678 # def inspect -> String
18679 def inspect
18680 InspectVisitor.compose(self)
18681 end
18682
18683 # Return a symbol representation of this node type. See `Node#type`.
18684 def type
18685 :true_node
18686 end
18687
18688 # Return a symbol representation of this node type. See `Node::type`.
18689 def self.type
18690 :true_node
18691 end
18692
18693 # Implements case-equality for the node. This is effectively == but without
18694 # comparing the value of locations. Locations are checked only for presence.
18695 def ===(other)
18696 other.is_a?(TrueNode)
18697 end
18698 end
18699
18700 # Represents the use of the `undef` keyword.
18701 #
18702 # undef :foo, :bar, :baz
18703 # ^^^^^^^^^^^^^^^^^^^^^^
18704 class UndefNode < Node
18705 # Initialize a new UndefNode node.
18706 def initialize(source, node_id, location, flags, names, keyword_loc)
18707 @source = source
18708 @node_id = node_id
18709 @location = location
18710 @flags = flags
18711 @names = names
18712 @keyword_loc = keyword_loc
18713 end
18714
18715 # def accept: (Visitor visitor) -> void
18716 def accept(visitor)
18717 visitor.visit_undef_node(self)
18718 end
18719
18720 # def child_nodes: () -> Array[Node?]
18721 def child_nodes
18722 [*names]
18723 end
18724
18725 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
18726 def each_child_node
18727 return to_enum(:each_child_node) unless block_given?
18728
18729 names.each { |node| yield node }
18730 end
18731
18732 # def compact_child_nodes: () -> Array[Node]
18733 def compact_child_nodes
18734 [*names]
18735 end
18736
18737 # def comment_targets: () -> Array[Node | Location]
18738 def comment_targets
18739 [*names, keyword_loc] #: Array[Prism::node | Location]
18740 end
18741
18742 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?names: Array[SymbolNode | InterpolatedSymbolNode], ?keyword_loc: Location) -> UndefNode
18743 def copy(node_id: self.node_id, location: self.location, flags: self.flags, names: self.names, keyword_loc: self.keyword_loc)
18744 UndefNode.new(source, node_id, location, flags, names, keyword_loc)
18745 end
18746
18747 # def deconstruct: () -> Array[Node?]
18748 alias deconstruct child_nodes
18749
18750 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, names: Array[SymbolNode | InterpolatedSymbolNode], keyword_loc: Location }
18751 def deconstruct_keys(keys)
18752 { node_id: node_id, location: location, names: names, keyword_loc: keyword_loc }
18753 end
18754
18755 # attr_reader names: Array[SymbolNode | InterpolatedSymbolNode]
18756 attr_reader :names
18757
18758 # attr_reader keyword_loc: Location
18759 def keyword_loc
18760 location = @keyword_loc
18761 return location if location.is_a?(Location)
18762 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18763 end
18764
18765 # Save the keyword_loc location using the given saved source so that
18766 # it can be retrieved later.
18767 def save_keyword_loc(repository)
18768 repository.enter(node_id, :keyword_loc)
18769 end
18770
18771 # def keyword: () -> String
18772 def keyword
18773 keyword_loc.slice
18774 end
18775
18776 # def inspect -> String
18777 def inspect
18778 InspectVisitor.compose(self)
18779 end
18780
18781 # Return a symbol representation of this node type. See `Node#type`.
18782 def type
18783 :undef_node
18784 end
18785
18786 # Return a symbol representation of this node type. See `Node::type`.
18787 def self.type
18788 :undef_node
18789 end
18790
18791 # Implements case-equality for the node. This is effectively == but without
18792 # comparing the value of locations. Locations are checked only for presence.
18793 def ===(other)
18794 other.is_a?(UndefNode) &&
18795 (names.length == other.names.length) &&
18796 names.zip(other.names).all? { |left, right| left === right } &&
18797 (keyword_loc.nil? == other.keyword_loc.nil?)
18798 end
18799 end
18800
18801 # Represents the use of the `unless` keyword, either in the block form or the modifier form.
18802 #
18803 # bar unless foo
18804 # ^^^^^^^^^^^^^^
18805 #
18806 # unless foo then bar end
18807 # ^^^^^^^^^^^^^^^^^^^^^^^
18808 class UnlessNode < Node
18809 # Initialize a new UnlessNode node.
18810 def initialize(source, node_id, location, flags, keyword_loc, predicate, then_keyword_loc, statements, else_clause, end_keyword_loc)
18811 @source = source
18812 @node_id = node_id
18813 @location = location
18814 @flags = flags
18815 @keyword_loc = keyword_loc
18816 @predicate = predicate
18817 @then_keyword_loc = then_keyword_loc
18818 @statements = statements
18819 @else_clause = else_clause
18820 @end_keyword_loc = end_keyword_loc
18821 end
18822
18823 # def accept: (Visitor visitor) -> void
18824 def accept(visitor)
18825 visitor.visit_unless_node(self)
18826 end
18827
18828 # def child_nodes: () -> Array[Node?]
18829 def child_nodes
18830 [predicate, statements, else_clause]
18831 end
18832
18833 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
18834 def each_child_node
18835 return to_enum(:each_child_node) unless block_given?
18836
18837 yield predicate
18838 yield statements if statements
18839 yield else_clause if else_clause
18840 end
18841
18842 # def compact_child_nodes: () -> Array[Node]
18843 def compact_child_nodes
18844 compact = [] #: Array[Prism::node]
18845 compact << predicate
18846 compact << statements if statements
18847 compact << else_clause if else_clause
18848 compact
18849 end
18850
18851 # def comment_targets: () -> Array[Node | Location]
18852 def comment_targets
18853 [keyword_loc, predicate, *then_keyword_loc, *statements, *else_clause, *end_keyword_loc] #: Array[Prism::node | Location]
18854 end
18855
18856 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?predicate: Prism::node, ?then_keyword_loc: Location?, ?statements: StatementsNode?, ?else_clause: ElseNode?, ?end_keyword_loc: Location?) -> UnlessNode
18857 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, predicate: self.predicate, then_keyword_loc: self.then_keyword_loc, statements: self.statements, else_clause: self.else_clause, end_keyword_loc: self.end_keyword_loc)
18858 UnlessNode.new(source, node_id, location, flags, keyword_loc, predicate, then_keyword_loc, statements, else_clause, end_keyword_loc)
18859 end
18860
18861 # def deconstruct: () -> Array[Node?]
18862 alias deconstruct child_nodes
18863
18864 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, predicate: Prism::node, then_keyword_loc: Location?, statements: StatementsNode?, else_clause: ElseNode?, end_keyword_loc: Location? }
18865 def deconstruct_keys(keys)
18866 { node_id: node_id, location: location, keyword_loc: keyword_loc, predicate: predicate, then_keyword_loc: then_keyword_loc, statements: statements, else_clause: else_clause, end_keyword_loc: end_keyword_loc }
18867 end
18868
18869 # The location of the `unless` keyword.
18870 #
18871 # unless cond then bar end
18872 # ^^^^^^
18873 #
18874 # bar unless cond
18875 # ^^^^^^
18876 def keyword_loc
18877 location = @keyword_loc
18878 return location if location.is_a?(Location)
18879 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18880 end
18881
18882 # Save the keyword_loc location using the given saved source so that
18883 # it can be retrieved later.
18884 def save_keyword_loc(repository)
18885 repository.enter(node_id, :keyword_loc)
18886 end
18887
18888 # The condition to be evaluated for the unless expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
18889 #
18890 # unless cond then bar end
18891 # ^^^^
18892 #
18893 # bar unless cond
18894 # ^^^^
18895 attr_reader :predicate
18896
18897 # The location of the `then` keyword, if present.
18898 #
18899 # unless cond then bar end
18900 # ^^^^
18901 def then_keyword_loc
18902 location = @then_keyword_loc
18903 case location
18904 when nil
18905 nil
18906 when Location
18907 location
18908 else
18909 @then_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18910 end
18911 end
18912
18913 # Save the then_keyword_loc location using the given saved source so that
18914 # it can be retrieved later.
18915 def save_then_keyword_loc(repository)
18916 repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil?
18917 end
18918
18919 # The body of statements that will executed if the unless condition is
18920 # falsey. Will be `nil` if no body is provided.
18921 #
18922 # unless cond then bar end
18923 # ^^^
18924 attr_reader :statements
18925
18926 # The else clause of the unless expression, if present.
18927 #
18928 # unless cond then bar else baz end
18929 # ^^^^^^^^
18930 attr_reader :else_clause
18931
18932 # The location of the `end` keyword, if present.
18933 #
18934 # unless cond then bar end
18935 # ^^^
18936 def end_keyword_loc
18937 location = @end_keyword_loc
18938 case location
18939 when nil
18940 nil
18941 when Location
18942 location
18943 else
18944 @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
18945 end
18946 end
18947
18948 # Save the end_keyword_loc location using the given saved source so that
18949 # it can be retrieved later.
18950 def save_end_keyword_loc(repository)
18951 repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil?
18952 end
18953
18954 # def keyword: () -> String
18955 def keyword
18956 keyword_loc.slice
18957 end
18958
18959 # def then_keyword: () -> String?
18960 def then_keyword
18961 then_keyword_loc&.slice
18962 end
18963
18964 # def end_keyword: () -> String?
18965 def end_keyword
18966 end_keyword_loc&.slice
18967 end
18968
18969 # def inspect -> String
18970 def inspect
18971 InspectVisitor.compose(self)
18972 end
18973
18974 # Return a symbol representation of this node type. See `Node#type`.
18975 def type
18976 :unless_node
18977 end
18978
18979 # Return a symbol representation of this node type. See `Node::type`.
18980 def self.type
18981 :unless_node
18982 end
18983
18984 # Implements case-equality for the node. This is effectively == but without
18985 # comparing the value of locations. Locations are checked only for presence.
18986 def ===(other)
18987 other.is_a?(UnlessNode) &&
18988 (keyword_loc.nil? == other.keyword_loc.nil?) &&
18989 (predicate === other.predicate) &&
18990 (then_keyword_loc.nil? == other.then_keyword_loc.nil?) &&
18991 (statements === other.statements) &&
18992 (else_clause === other.else_clause) &&
18993 (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
18994 end
18995 end
18996
18997 # Represents the use of the `until` keyword, either in the block form or the modifier form.
18998 #
18999 # bar until foo
19000 # ^^^^^^^^^^^^^
19001 #
19002 # until foo do bar end
19003 # ^^^^^^^^^^^^^^^^^^^^
19004 class UntilNode < Node
19005 # Initialize a new UntilNode node.
19006 def initialize(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements)
19007 @source = source
19008 @node_id = node_id
19009 @location = location
19010 @flags = flags
19011 @keyword_loc = keyword_loc
19012 @do_keyword_loc = do_keyword_loc
19013 @closing_loc = closing_loc
19014 @predicate = predicate
19015 @statements = statements
19016 end
19017
19018 # def accept: (Visitor visitor) -> void
19019 def accept(visitor)
19020 visitor.visit_until_node(self)
19021 end
19022
19023 # def child_nodes: () -> Array[Node?]
19024 def child_nodes
19025 [predicate, statements]
19026 end
19027
19028 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
19029 def each_child_node
19030 return to_enum(:each_child_node) unless block_given?
19031
19032 yield predicate
19033 yield statements if statements
19034 end
19035
19036 # def compact_child_nodes: () -> Array[Node]
19037 def compact_child_nodes
19038 compact = [] #: Array[Prism::node]
19039 compact << predicate
19040 compact << statements if statements
19041 compact
19042 end
19043
19044 # def comment_targets: () -> Array[Node | Location]
19045 def comment_targets
19046 [keyword_loc, *do_keyword_loc, *closing_loc, predicate, *statements] #: Array[Prism::node | Location]
19047 end
19048
19049 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?do_keyword_loc: Location?, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> UntilNode
19050 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, do_keyword_loc: self.do_keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements)
19051 UntilNode.new(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements)
19052 end
19053
19054 # def deconstruct: () -> Array[Node?]
19055 alias deconstruct child_nodes
19056
19057 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, do_keyword_loc: Location?, closing_loc: Location?, predicate: Prism::node, statements: StatementsNode? }
19058 def deconstruct_keys(keys)
19059 { node_id: node_id, location: location, keyword_loc: keyword_loc, do_keyword_loc: do_keyword_loc, closing_loc: closing_loc, predicate: predicate, statements: statements }
19060 end
19061
19062 # def begin_modifier?: () -> bool
19063 def begin_modifier?
19064 flags.anybits?(LoopFlags::BEGIN_MODIFIER)
19065 end
19066
19067 # attr_reader keyword_loc: Location
19068 def keyword_loc
19069 location = @keyword_loc
19070 return location if location.is_a?(Location)
19071 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19072 end
19073
19074 # Save the keyword_loc location using the given saved source so that
19075 # it can be retrieved later.
19076 def save_keyword_loc(repository)
19077 repository.enter(node_id, :keyword_loc)
19078 end
19079
19080 # attr_reader do_keyword_loc: Location?
19081 def do_keyword_loc
19082 location = @do_keyword_loc
19083 case location
19084 when nil
19085 nil
19086 when Location
19087 location
19088 else
19089 @do_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19090 end
19091 end
19092
19093 # Save the do_keyword_loc location using the given saved source so that
19094 # it can be retrieved later.
19095 def save_do_keyword_loc(repository)
19096 repository.enter(node_id, :do_keyword_loc) unless @do_keyword_loc.nil?
19097 end
19098
19099 # attr_reader closing_loc: Location?
19100 def closing_loc
19101 location = @closing_loc
19102 case location
19103 when nil
19104 nil
19105 when Location
19106 location
19107 else
19108 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19109 end
19110 end
19111
19112 # Save the closing_loc location using the given saved source so that
19113 # it can be retrieved later.
19114 def save_closing_loc(repository)
19115 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
19116 end
19117
19118 # attr_reader predicate: Prism::node
19119 attr_reader :predicate
19120
19121 # attr_reader statements: StatementsNode?
19122 attr_reader :statements
19123
19124 # def keyword: () -> String
19125 def keyword
19126 keyword_loc.slice
19127 end
19128
19129 # def do_keyword: () -> String?
19130 def do_keyword
19131 do_keyword_loc&.slice
19132 end
19133
19134 # def closing: () -> String?
19135 def closing
19136 closing_loc&.slice
19137 end
19138
19139 # def inspect -> String
19140 def inspect
19141 InspectVisitor.compose(self)
19142 end
19143
19144 # Return a symbol representation of this node type. See `Node#type`.
19145 def type
19146 :until_node
19147 end
19148
19149 # Return a symbol representation of this node type. See `Node::type`.
19150 def self.type
19151 :until_node
19152 end
19153
19154 # Implements case-equality for the node. This is effectively == but without
19155 # comparing the value of locations. Locations are checked only for presence.
19156 def ===(other)
19157 other.is_a?(UntilNode) &&
19158 (flags === other.flags) &&
19159 (keyword_loc.nil? == other.keyword_loc.nil?) &&
19160 (do_keyword_loc.nil? == other.do_keyword_loc.nil?) &&
19161 (closing_loc.nil? == other.closing_loc.nil?) &&
19162 (predicate === other.predicate) &&
19163 (statements === other.statements)
19164 end
19165 end
19166
19167 # Represents the use of the `when` keyword within a case statement.
19168 #
19169 # case true
19170 # when true
19171 # ^^^^^^^^^
19172 # end
19173 class WhenNode < Node
19174 # Initialize a new WhenNode node.
19175 def initialize(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements)
19176 @source = source
19177 @node_id = node_id
19178 @location = location
19179 @flags = flags
19180 @keyword_loc = keyword_loc
19181 @conditions = conditions
19182 @then_keyword_loc = then_keyword_loc
19183 @statements = statements
19184 end
19185
19186 # def accept: (Visitor visitor) -> void
19187 def accept(visitor)
19188 visitor.visit_when_node(self)
19189 end
19190
19191 # def child_nodes: () -> Array[Node?]
19192 def child_nodes
19193 [*conditions, statements]
19194 end
19195
19196 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
19197 def each_child_node
19198 return to_enum(:each_child_node) unless block_given?
19199
19200 conditions.each { |node| yield node }
19201 yield statements if statements
19202 end
19203
19204 # def compact_child_nodes: () -> Array[Node]
19205 def compact_child_nodes
19206 compact = [] #: Array[Prism::node]
19207 compact.concat(conditions)
19208 compact << statements if statements
19209 compact
19210 end
19211
19212 # def comment_targets: () -> Array[Node | Location]
19213 def comment_targets
19214 [keyword_loc, *conditions, *then_keyword_loc, *statements] #: Array[Prism::node | Location]
19215 end
19216
19217 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?conditions: Array[Prism::node], ?then_keyword_loc: Location?, ?statements: StatementsNode?) -> WhenNode
19218 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, conditions: self.conditions, then_keyword_loc: self.then_keyword_loc, statements: self.statements)
19219 WhenNode.new(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements)
19220 end
19221
19222 # def deconstruct: () -> Array[Node?]
19223 alias deconstruct child_nodes
19224
19225 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, conditions: Array[Prism::node], then_keyword_loc: Location?, statements: StatementsNode? }
19226 def deconstruct_keys(keys)
19227 { node_id: node_id, location: location, keyword_loc: keyword_loc, conditions: conditions, then_keyword_loc: then_keyword_loc, statements: statements }
19228 end
19229
19230 # attr_reader keyword_loc: Location
19231 def keyword_loc
19232 location = @keyword_loc
19233 return location if location.is_a?(Location)
19234 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19235 end
19236
19237 # Save the keyword_loc location using the given saved source so that
19238 # it can be retrieved later.
19239 def save_keyword_loc(repository)
19240 repository.enter(node_id, :keyword_loc)
19241 end
19242
19243 # attr_reader conditions: Array[Prism::node]
19244 attr_reader :conditions
19245
19246 # attr_reader then_keyword_loc: Location?
19247 def then_keyword_loc
19248 location = @then_keyword_loc
19249 case location
19250 when nil
19251 nil
19252 when Location
19253 location
19254 else
19255 @then_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19256 end
19257 end
19258
19259 # Save the then_keyword_loc location using the given saved source so that
19260 # it can be retrieved later.
19261 def save_then_keyword_loc(repository)
19262 repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil?
19263 end
19264
19265 # attr_reader statements: StatementsNode?
19266 attr_reader :statements
19267
19268 # def keyword: () -> String
19269 def keyword
19270 keyword_loc.slice
19271 end
19272
19273 # def then_keyword: () -> String?
19274 def then_keyword
19275 then_keyword_loc&.slice
19276 end
19277
19278 # def inspect -> String
19279 def inspect
19280 InspectVisitor.compose(self)
19281 end
19282
19283 # Return a symbol representation of this node type. See `Node#type`.
19284 def type
19285 :when_node
19286 end
19287
19288 # Return a symbol representation of this node type. See `Node::type`.
19289 def self.type
19290 :when_node
19291 end
19292
19293 # Implements case-equality for the node. This is effectively == but without
19294 # comparing the value of locations. Locations are checked only for presence.
19295 def ===(other)
19296 other.is_a?(WhenNode) &&
19297 (keyword_loc.nil? == other.keyword_loc.nil?) &&
19298 (conditions.length == other.conditions.length) &&
19299 conditions.zip(other.conditions).all? { |left, right| left === right } &&
19300 (then_keyword_loc.nil? == other.then_keyword_loc.nil?) &&
19301 (statements === other.statements)
19302 end
19303 end
19304
19305 # Represents the use of the `while` keyword, either in the block form or the modifier form.
19306 #
19307 # bar while foo
19308 # ^^^^^^^^^^^^^
19309 #
19310 # while foo do bar end
19311 # ^^^^^^^^^^^^^^^^^^^^
19312 class WhileNode < Node
19313 # Initialize a new WhileNode node.
19314 def initialize(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements)
19315 @source = source
19316 @node_id = node_id
19317 @location = location
19318 @flags = flags
19319 @keyword_loc = keyword_loc
19320 @do_keyword_loc = do_keyword_loc
19321 @closing_loc = closing_loc
19322 @predicate = predicate
19323 @statements = statements
19324 end
19325
19326 # def accept: (Visitor visitor) -> void
19327 def accept(visitor)
19328 visitor.visit_while_node(self)
19329 end
19330
19331 # def child_nodes: () -> Array[Node?]
19332 def child_nodes
19333 [predicate, statements]
19334 end
19335
19336 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
19337 def each_child_node
19338 return to_enum(:each_child_node) unless block_given?
19339
19340 yield predicate
19341 yield statements if statements
19342 end
19343
19344 # def compact_child_nodes: () -> Array[Node]
19345 def compact_child_nodes
19346 compact = [] #: Array[Prism::node]
19347 compact << predicate
19348 compact << statements if statements
19349 compact
19350 end
19351
19352 # def comment_targets: () -> Array[Node | Location]
19353 def comment_targets
19354 [keyword_loc, *do_keyword_loc, *closing_loc, predicate, *statements] #: Array[Prism::node | Location]
19355 end
19356
19357 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?do_keyword_loc: Location?, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> WhileNode
19358 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, do_keyword_loc: self.do_keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements)
19359 WhileNode.new(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements)
19360 end
19361
19362 # def deconstruct: () -> Array[Node?]
19363 alias deconstruct child_nodes
19364
19365 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, do_keyword_loc: Location?, closing_loc: Location?, predicate: Prism::node, statements: StatementsNode? }
19366 def deconstruct_keys(keys)
19367 { node_id: node_id, location: location, keyword_loc: keyword_loc, do_keyword_loc: do_keyword_loc, closing_loc: closing_loc, predicate: predicate, statements: statements }
19368 end
19369
19370 # def begin_modifier?: () -> bool
19371 def begin_modifier?
19372 flags.anybits?(LoopFlags::BEGIN_MODIFIER)
19373 end
19374
19375 # attr_reader keyword_loc: Location
19376 def keyword_loc
19377 location = @keyword_loc
19378 return location if location.is_a?(Location)
19379 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19380 end
19381
19382 # Save the keyword_loc location using the given saved source so that
19383 # it can be retrieved later.
19384 def save_keyword_loc(repository)
19385 repository.enter(node_id, :keyword_loc)
19386 end
19387
19388 # attr_reader do_keyword_loc: Location?
19389 def do_keyword_loc
19390 location = @do_keyword_loc
19391 case location
19392 when nil
19393 nil
19394 when Location
19395 location
19396 else
19397 @do_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19398 end
19399 end
19400
19401 # Save the do_keyword_loc location using the given saved source so that
19402 # it can be retrieved later.
19403 def save_do_keyword_loc(repository)
19404 repository.enter(node_id, :do_keyword_loc) unless @do_keyword_loc.nil?
19405 end
19406
19407 # attr_reader closing_loc: Location?
19408 def closing_loc
19409 location = @closing_loc
19410 case location
19411 when nil
19412 nil
19413 when Location
19414 location
19415 else
19416 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19417 end
19418 end
19419
19420 # Save the closing_loc location using the given saved source so that
19421 # it can be retrieved later.
19422 def save_closing_loc(repository)
19423 repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
19424 end
19425
19426 # attr_reader predicate: Prism::node
19427 attr_reader :predicate
19428
19429 # attr_reader statements: StatementsNode?
19430 attr_reader :statements
19431
19432 # def keyword: () -> String
19433 def keyword
19434 keyword_loc.slice
19435 end
19436
19437 # def do_keyword: () -> String?
19438 def do_keyword
19439 do_keyword_loc&.slice
19440 end
19441
19442 # def closing: () -> String?
19443 def closing
19444 closing_loc&.slice
19445 end
19446
19447 # def inspect -> String
19448 def inspect
19449 InspectVisitor.compose(self)
19450 end
19451
19452 # Return a symbol representation of this node type. See `Node#type`.
19453 def type
19454 :while_node
19455 end
19456
19457 # Return a symbol representation of this node type. See `Node::type`.
19458 def self.type
19459 :while_node
19460 end
19461
19462 # Implements case-equality for the node. This is effectively == but without
19463 # comparing the value of locations. Locations are checked only for presence.
19464 def ===(other)
19465 other.is_a?(WhileNode) &&
19466 (flags === other.flags) &&
19467 (keyword_loc.nil? == other.keyword_loc.nil?) &&
19468 (do_keyword_loc.nil? == other.do_keyword_loc.nil?) &&
19469 (closing_loc.nil? == other.closing_loc.nil?) &&
19470 (predicate === other.predicate) &&
19471 (statements === other.statements)
19472 end
19473 end
19474
19475 # Represents an xstring literal with no interpolation.
19476 #
19477 # `foo`
19478 # ^^^^^
19479 class XStringNode < Node
19480 # Initialize a new XStringNode node.
19481 def initialize(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped)
19482 @source = source
19483 @node_id = node_id
19484 @location = location
19485 @flags = flags
19486 @opening_loc = opening_loc
19487 @content_loc = content_loc
19488 @closing_loc = closing_loc
19489 @unescaped = unescaped
19490 end
19491
19492 # def accept: (Visitor visitor) -> void
19493 def accept(visitor)
19494 visitor.visit_x_string_node(self)
19495 end
19496
19497 # def child_nodes: () -> Array[Node?]
19498 def child_nodes
19499 []
19500 end
19501
19502 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
19503 def each_child_node
19504 return to_enum(:each_child_node) unless block_given?
19505
19506 end
19507
19508 # def compact_child_nodes: () -> Array[Node]
19509 def compact_child_nodes
19510 []
19511 end
19512
19513 # def comment_targets: () -> Array[Node | Location]
19514 def comment_targets
19515 [opening_loc, content_loc, closing_loc] #: Array[Prism::node | Location]
19516 end
19517
19518 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?content_loc: Location, ?closing_loc: Location, ?unescaped: String) -> XStringNode
19519 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, content_loc: self.content_loc, closing_loc: self.closing_loc, unescaped: self.unescaped)
19520 XStringNode.new(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped)
19521 end
19522
19523 # def deconstruct: () -> Array[Node?]
19524 alias deconstruct child_nodes
19525
19526 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String }
19527 def deconstruct_keys(keys)
19528 { node_id: node_id, location: location, opening_loc: opening_loc, content_loc: content_loc, closing_loc: closing_loc, unescaped: unescaped }
19529 end
19530
19531 # def forced_utf8_encoding?: () -> bool
19532 def forced_utf8_encoding?
19533 flags.anybits?(EncodingFlags::FORCED_UTF8_ENCODING)
19534 end
19535
19536 # def forced_binary_encoding?: () -> bool
19537 def forced_binary_encoding?
19538 flags.anybits?(EncodingFlags::FORCED_BINARY_ENCODING)
19539 end
19540
19541 # attr_reader opening_loc: Location
19542 def opening_loc
19543 location = @opening_loc
19544 return location if location.is_a?(Location)
19545 @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19546 end
19547
19548 # Save the opening_loc location using the given saved source so that
19549 # it can be retrieved later.
19550 def save_opening_loc(repository)
19551 repository.enter(node_id, :opening_loc)
19552 end
19553
19554 # attr_reader content_loc: Location
19555 def content_loc
19556 location = @content_loc
19557 return location if location.is_a?(Location)
19558 @content_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19559 end
19560
19561 # Save the content_loc location using the given saved source so that
19562 # it can be retrieved later.
19563 def save_content_loc(repository)
19564 repository.enter(node_id, :content_loc)
19565 end
19566
19567 # attr_reader closing_loc: Location
19568 def closing_loc
19569 location = @closing_loc
19570 return location if location.is_a?(Location)
19571 @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19572 end
19573
19574 # Save the closing_loc location using the given saved source so that
19575 # it can be retrieved later.
19576 def save_closing_loc(repository)
19577 repository.enter(node_id, :closing_loc)
19578 end
19579
19580 # attr_reader unescaped: String
19581 attr_reader :unescaped
19582
19583 # def opening: () -> String
19584 def opening
19585 opening_loc.slice
19586 end
19587
19588 # def content: () -> String
19589 def content
19590 content_loc.slice
19591 end
19592
19593 # def closing: () -> String
19594 def closing
19595 closing_loc.slice
19596 end
19597
19598 # def inspect -> String
19599 def inspect
19600 InspectVisitor.compose(self)
19601 end
19602
19603 # Return a symbol representation of this node type. See `Node#type`.
19604 def type
19605 :x_string_node
19606 end
19607
19608 # Return a symbol representation of this node type. See `Node::type`.
19609 def self.type
19610 :x_string_node
19611 end
19612
19613 # Implements case-equality for the node. This is effectively == but without
19614 # comparing the value of locations. Locations are checked only for presence.
19615 def ===(other)
19616 other.is_a?(XStringNode) &&
19617 (flags === other.flags) &&
19618 (opening_loc.nil? == other.opening_loc.nil?) &&
19619 (content_loc.nil? == other.content_loc.nil?) &&
19620 (closing_loc.nil? == other.closing_loc.nil?) &&
19621 (unescaped === other.unescaped)
19622 end
19623 end
19624
19625 # Represents the use of the `yield` keyword.
19626 #
19627 # yield 1
19628 # ^^^^^^^
19629 class YieldNode < Node
19630 # Initialize a new YieldNode node.
19631 def initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc)
19632 @source = source
19633 @node_id = node_id
19634 @location = location
19635 @flags = flags
19636 @keyword_loc = keyword_loc
19637 @lparen_loc = lparen_loc
19638 @arguments = arguments
19639 @rparen_loc = rparen_loc
19640 end
19641
19642 # def accept: (Visitor visitor) -> void
19643 def accept(visitor)
19644 visitor.visit_yield_node(self)
19645 end
19646
19647 # def child_nodes: () -> Array[Node?]
19648 def child_nodes
19649 [arguments]
19650 end
19651
19652 # def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
19653 def each_child_node
19654 return to_enum(:each_child_node) unless block_given?
19655
19656 yield arguments if arguments
19657 end
19658
19659 # def compact_child_nodes: () -> Array[Node]
19660 def compact_child_nodes
19661 compact = [] #: Array[Prism::node]
19662 compact << arguments if arguments
19663 compact
19664 end
19665
19666 # def comment_targets: () -> Array[Node | Location]
19667 def comment_targets
19668 [keyword_loc, *lparen_loc, *arguments, *rparen_loc] #: Array[Prism::node | Location]
19669 end
19670
19671 # def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?lparen_loc: Location?, ?arguments: ArgumentsNode?, ?rparen_loc: Location?) -> YieldNode
19672 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc)
19673 YieldNode.new(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc)
19674 end
19675
19676 # def deconstruct: () -> Array[Node?]
19677 alias deconstruct child_nodes
19678
19679 # def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, lparen_loc: Location?, arguments: ArgumentsNode?, rparen_loc: Location? }
19680 def deconstruct_keys(keys)
19681 { node_id: node_id, location: location, keyword_loc: keyword_loc, lparen_loc: lparen_loc, arguments: arguments, rparen_loc: rparen_loc }
19682 end
19683
19684 # attr_reader keyword_loc: Location
19685 def keyword_loc
19686 location = @keyword_loc
19687 return location if location.is_a?(Location)
19688 @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19689 end
19690
19691 # Save the keyword_loc location using the given saved source so that
19692 # it can be retrieved later.
19693 def save_keyword_loc(repository)
19694 repository.enter(node_id, :keyword_loc)
19695 end
19696
19697 # attr_reader lparen_loc: Location?
19698 def lparen_loc
19699 location = @lparen_loc
19700 case location
19701 when nil
19702 nil
19703 when Location
19704 location
19705 else
19706 @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19707 end
19708 end
19709
19710 # Save the lparen_loc location using the given saved source so that
19711 # it can be retrieved later.
19712 def save_lparen_loc(repository)
19713 repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil?
19714 end
19715
19716 # attr_reader arguments: ArgumentsNode?
19717 attr_reader :arguments
19718
19719 # attr_reader rparen_loc: Location?
19720 def rparen_loc
19721 location = @rparen_loc
19722 case location
19723 when nil
19724 nil
19725 when Location
19726 location
19727 else
19728 @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
19729 end
19730 end
19731
19732 # Save the rparen_loc location using the given saved source so that
19733 # it can be retrieved later.
19734 def save_rparen_loc(repository)
19735 repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil?
19736 end
19737
19738 # def keyword: () -> String
19739 def keyword
19740 keyword_loc.slice
19741 end
19742
19743 # def lparen: () -> String?
19744 def lparen
19745 lparen_loc&.slice
19746 end
19747
19748 # def rparen: () -> String?
19749 def rparen
19750 rparen_loc&.slice
19751 end
19752
19753 # def inspect -> String
19754 def inspect
19755 InspectVisitor.compose(self)
19756 end
19757
19758 # Return a symbol representation of this node type. See `Node#type`.
19759 def type
19760 :yield_node
19761 end
19762
19763 # Return a symbol representation of this node type. See `Node::type`.
19764 def self.type
19765 :yield_node
19766 end
19767
19768 # Implements case-equality for the node. This is effectively == but without
19769 # comparing the value of locations. Locations are checked only for presence.
19770 def ===(other)
19771 other.is_a?(YieldNode) &&
19772 (keyword_loc.nil? == other.keyword_loc.nil?) &&
19773 (lparen_loc.nil? == other.lparen_loc.nil?) &&
19774 (arguments === other.arguments) &&
19775 (rparen_loc.nil? == other.rparen_loc.nil?)
19776 end
19777 end
19778
19779 # Flags for arguments nodes.
19780 module ArgumentsNodeFlags
19781 # if the arguments contain forwarding
19782 CONTAINS_FORWARDING = 1 << 2
19783
19784 # if the arguments contain keywords
19785 CONTAINS_KEYWORDS = 1 << 3
19786
19787 # if the arguments contain a keyword splat
19788 CONTAINS_KEYWORD_SPLAT = 1 << 4
19789
19790 # if the arguments contain a splat
19791 CONTAINS_SPLAT = 1 << 5
19792
19793 # if the arguments contain multiple splats
19794 CONTAINS_MULTIPLE_SPLATS = 1 << 6
19795 end
19796
19797 # Flags for array nodes.
19798 module ArrayNodeFlags
19799 # if array contains splat nodes
19800 CONTAINS_SPLAT = 1 << 2
19801 end
19802
19803 # Flags for call nodes.
19804 module CallNodeFlags
19805 # &. operator
19806 SAFE_NAVIGATION = 1 << 2
19807
19808 # a call that could have been a local variable
19809 VARIABLE_CALL = 1 << 3
19810
19811 # a call that is an attribute write, so the value being written should be returned
19812 ATTRIBUTE_WRITE = 1 << 4
19813
19814 # a call that ignores method visibility
19815 IGNORE_VISIBILITY = 1 << 5
19816 end
19817
19818 # Flags for nodes that have unescaped content.
19819 module EncodingFlags
19820 # internal bytes forced the encoding to UTF-8
19821 FORCED_UTF8_ENCODING = 1 << 2
19822
19823 # internal bytes forced the encoding to binary
19824 FORCED_BINARY_ENCODING = 1 << 3
19825 end
19826
19827 # Flags for integer nodes that correspond to the base of the integer.
19828 module IntegerBaseFlags
19829 # 0b prefix
19830 BINARY = 1 << 2
19831
19832 # 0d or no prefix
19833 DECIMAL = 1 << 3
19834
19835 # 0o or 0 prefix
19836 OCTAL = 1 << 4
19837
19838 # 0x prefix
19839 HEXADECIMAL = 1 << 5
19840 end
19841
19842 # Flags for interpolated string nodes that indicated mutability if they are also marked as literals.
19843 module InterpolatedStringNodeFlags
19844 # frozen by virtue of a `frozen_string_literal: true` comment or `--enable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'`
19845 FROZEN = 1 << 2
19846
19847 # mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'`
19848 MUTABLE = 1 << 3
19849 end
19850
19851 # Flags for keyword hash nodes.
19852 module KeywordHashNodeFlags
19853 # a keyword hash which only has `AssocNode` elements all with symbol keys, which means the elements can be treated as keyword arguments
19854 SYMBOL_KEYS = 1 << 2
19855 end
19856
19857 # Flags for while and until loop nodes.
19858 module LoopFlags
19859 # a loop after a begin statement, so the body is executed first before the condition
19860 BEGIN_MODIFIER = 1 << 2
19861 end
19862
19863 # Flags for parameter nodes.
19864 module ParameterFlags
19865 # a parameter name that has been repeated in the method signature
19866 REPEATED_PARAMETER = 1 << 2
19867 end
19868
19869 # Flags for parentheses nodes.
19870 module ParenthesesNodeFlags
19871 # parentheses that contain multiple potentially void statements
19872 MULTIPLE_STATEMENTS = 1 << 2
19873 end
19874
19875 # Flags for range and flip-flop nodes.
19876 module RangeFlags
19877 # ... operator
19878 EXCLUDE_END = 1 << 2
19879 end
19880
19881 # Flags for regular expression and match last line nodes.
19882 module RegularExpressionFlags
19883 # i - ignores the case of characters when matching
19884 IGNORE_CASE = 1 << 2
19885
19886 # x - ignores whitespace and allows comments in regular expressions
19887 EXTENDED = 1 << 3
19888
19889 # m - allows $ to match the end of lines within strings
19890 MULTI_LINE = 1 << 4
19891
19892 # o - only interpolates values into the regular expression once
19893 ONCE = 1 << 5
19894
19895 # e - forces the EUC-JP encoding
19896 EUC_JP = 1 << 6
19897
19898 # n - forces the ASCII-8BIT encoding
19899 ASCII_8BIT = 1 << 7
19900
19901 # s - forces the Windows-31J encoding
19902 WINDOWS_31J = 1 << 8
19903
19904 # u - forces the UTF-8 encoding
19905 UTF_8 = 1 << 9
19906
19907 # internal bytes forced the encoding to UTF-8
19908 FORCED_UTF8_ENCODING = 1 << 10
19909
19910 # internal bytes forced the encoding to binary
19911 FORCED_BINARY_ENCODING = 1 << 11
19912
19913 # internal bytes forced the encoding to US-ASCII
19914 FORCED_US_ASCII_ENCODING = 1 << 12
19915 end
19916
19917 # Flags for shareable constant nodes.
19918 module ShareableConstantNodeFlags
19919 # constant writes that should be modified with shareable constant value literal
19920 LITERAL = 1 << 2
19921
19922 # constant writes that should be modified with shareable constant value experimental everything
19923 EXPERIMENTAL_EVERYTHING = 1 << 3
19924
19925 # constant writes that should be modified with shareable constant value experimental copy
19926 EXPERIMENTAL_COPY = 1 << 4
19927 end
19928
19929 # Flags for string nodes.
19930 module StringFlags
19931 # internal bytes forced the encoding to UTF-8
19932 FORCED_UTF8_ENCODING = 1 << 2
19933
19934 # internal bytes forced the encoding to binary
19935 FORCED_BINARY_ENCODING = 1 << 3
19936
19937 # frozen by virtue of a `frozen_string_literal: true` comment or `--enable-frozen-string-literal`
19938 FROZEN = 1 << 4
19939
19940 # mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal`
19941 MUTABLE = 1 << 5
19942 end
19943
19944 # Flags for symbol nodes.
19945 module SymbolFlags
19946 # internal bytes forced the encoding to UTF-8
19947 FORCED_UTF8_ENCODING = 1 << 2
19948
19949 # internal bytes forced the encoding to binary
19950 FORCED_BINARY_ENCODING = 1 << 3
19951
19952 # internal bytes forced the encoding to US-ASCII
19953 FORCED_US_ASCII_ENCODING = 1 << 4
19954 end
19955
19956 # The flags that are common to all nodes.
19957 module NodeFlags
19958 # A flag to indicate that the node is a candidate to emit a :line event
19959 # through tracepoint when compiled.
19960 NEWLINE = 1
19961
19962 # A flag to indicate that the value that the node represents is a value that
19963 # can be determined at parse-time.
19964 STATIC_LITERAL = 2
19965 end
19966 end