lib/yarp/node.rb in yarp-0.10.0 vs lib/yarp/node.rb in yarp-0.11.0

- old
+ new

@@ -36,10 +36,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [new_name, old_name] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [new_name, old_name, keyword_loc] + end + # def copy: (**params) -> AliasNode def copy(**params) AliasNode.new( params.fetch(:new_name) { new_name }, params.fetch(:old_name) { old_name }, @@ -58,10 +63,20 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── new_name:\n" + inspector << inspector.child_node(new_name, "│ ") + inspector << "├── old_name:\n" + inspector << inspector.child_node(old_name, "│ ") + inspector << "└── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector.to_str + end end # Represents an alternation pattern in pattern matching. # # foo => bar | baz @@ -92,10 +107,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [left, right] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [left, right, operator_loc] + end + # def copy: (**params) -> AlternationPatternNode def copy(**params) AlternationPatternNode.new( params.fetch(:left) { left }, params.fetch(:right) { right }, @@ -114,10 +134,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── left:\n" + inspector << inspector.child_node(left, "│ ") + inspector << "├── right:\n" + inspector << inspector.child_node(right, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents the use of the `&&` operator or the `and` keyword. # # left and right @@ -148,10 +178,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [left, right] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [left, right, operator_loc] + end + # def copy: (**params) -> AndNode def copy(**params) AndNode.new( params.fetch(:left) { left }, params.fetch(:right) { right }, @@ -170,10 +205,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── left:\n" + inspector << inspector.child_node(left, "│ ") + inspector << "├── right:\n" + inspector << inspector.child_node(right, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents a set of arguments to a method or a keyword. # # return foo, bar, baz @@ -196,10 +241,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*arguments] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*arguments] + end + # def copy: (**params) -> ArgumentsNode def copy(**params) ArgumentsNode.new( params.fetch(:arguments) { arguments }, params.fetch(:location) { location }, @@ -211,10 +261,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { arguments: arguments, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── arguments: #{inspector.list("#{inspector.prefix} ", arguments)}" + inspector.to_str + end end # Represents an array literal. This can be a regular array using brackets or # a special array using % like %w or %i. # @@ -246,10 +302,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*elements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*elements, *opening_loc, *closing_loc] + end + # def copy: (**params) -> ArrayNode def copy(**params) ArrayNode.new( params.fetch(:elements) { elements }, params.fetch(:opening_loc) { opening_loc }, @@ -273,10 +334,18 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── elements: #{inspector.list("#{inspector.prefix}│ ", elements)}" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents an array pattern in pattern matching. # # foo in 1, 2 @@ -331,10 +400,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [constant, *requireds, rest, *posts] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*constant, *requireds, *rest, *posts, *opening_loc, *closing_loc] + end + # def copy: (**params) -> ArrayPatternNode def copy(**params) ArrayPatternNode.new( params.fetch(:constant) { constant }, params.fetch(:requireds) { requireds }, @@ -361,10 +435,31 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (constant = self.constant).nil? + inspector << "├── constant: ∅\n" + else + inspector << "├── constant:\n" + inspector << constant.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── requireds: #{inspector.list("#{inspector.prefix}│ ", requireds)}" + if (rest = self.rest).nil? + inspector << "├── rest: ∅\n" + else + inspector << "├── rest:\n" + inspector << rest.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── posts: #{inspector.list("#{inspector.prefix}│ ", posts)}" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents a hash key/value pair. # # { a => b } @@ -395,10 +490,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [key, value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [key, *value, *operator_loc] + end + # def copy: (**params) -> AssocNode def copy(**params) AssocNode.new( params.fetch(:key) { key }, params.fetch(:value) { value }, @@ -417,10 +517,24 @@ # def operator: () -> String? def operator operator_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── key:\n" + inspector << inspector.child_node(key, "│ ") + if (value = self.value).nil? + inspector << "├── value: ∅\n" + else + inspector << "├── value:\n" + inspector << value.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents a splat in a hash literal. # # { **foo } @@ -447,10 +561,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*value, operator_loc] + end + # def copy: (**params) -> AssocSplatNode def copy(**params) AssocSplatNode.new( params.fetch(:value) { value }, params.fetch(:operator_loc) { operator_loc }, @@ -468,10 +587,22 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (value = self.value).nil? + inspector << "├── value: ∅\n" + else + inspector << "├── value:\n" + inspector << value.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents reading a reference to a field in the previous match. # # $' @@ -490,10 +621,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> BackReferenceReadNode def copy(**params) BackReferenceReadNode.new( params.fetch(:location) { location }, ) @@ -504,10 +640,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents a begin statement. # # begin @@ -556,10 +697,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [statements, rescue_clause, else_clause, ensure_clause] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*begin_keyword_loc, *statements, *rescue_clause, *else_clause, *ensure_clause, *end_keyword_loc] + end + # def copy: (**params) -> BeginNode def copy(**params) BeginNode.new( params.fetch(:begin_keyword_loc) { begin_keyword_loc }, params.fetch(:statements) { statements }, @@ -586,10 +732,41 @@ # def end_keyword: () -> String? def end_keyword end_keyword_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── begin_keyword_loc: #{inspector.location(begin_keyword_loc)}\n" + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (rescue_clause = self.rescue_clause).nil? + inspector << "├── rescue_clause: ∅\n" + else + inspector << "├── rescue_clause:\n" + inspector << rescue_clause.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (else_clause = self.else_clause).nil? + inspector << "├── else_clause: ∅\n" + else + inspector << "├── else_clause:\n" + inspector << else_clause.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (ensure_clause = self.ensure_clause).nil? + inspector << "├── ensure_clause: ∅\n" + else + inspector << "├── ensure_clause:\n" + inspector << ensure_clause.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents block method arguments. # # bar(&args) @@ -616,10 +793,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [expression] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*expression, operator_loc] + end + # def copy: (**params) -> BlockArgumentNode def copy(**params) BlockArgumentNode.new( params.fetch(:expression) { expression }, params.fetch(:operator_loc) { operator_loc }, @@ -637,12 +819,76 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (expression = self.expression).nil? + inspector << "├── expression: ∅\n" + else + inspector << "├── expression:\n" + inspector << expression.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end + # Represents a block local variable. + # + # a { |; b| } + # ^ + class BlockLocalVariableNode < Node + # attr_reader name: Symbol + attr_reader :name + + # def initialize: (name: Symbol, location: Location) -> void + def initialize(name, location) + @name = name + @location = location + end + + # def accept: (visitor: Visitor) -> void + def accept(visitor) + visitor.visit_block_local_variable_node(self) + end + + # def child_nodes: () -> Array[nil | Node] + def child_nodes + [] + end + + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + + # def copy: (**params) -> BlockLocalVariableNode + def copy(**params) + BlockLocalVariableNode.new( + params.fetch(:name) { name }, + params.fetch(:location) { location }, + ) + end + + # def deconstruct: () -> Array[nil | Node] + alias deconstruct child_nodes + + # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] + def deconstruct_keys(keys) + { name: name, location: location } + end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end + end + # Represents a block of ruby code. # # [1, 2, 3].each { |i| puts x } # ^^^^^^^^^^^^^^ class BlockNode < Node @@ -679,10 +925,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [parameters, body] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*parameters, *body, opening_loc, closing_loc] + end + # def copy: (**params) -> BlockNode def copy(**params) BlockNode.new( params.fetch(:locals) { locals }, params.fetch(:parameters) { parameters }, @@ -708,26 +959,50 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── locals: #{locals.inspect}\n" + if (parameters = self.parameters).nil? + inspector << "├── parameters: ∅\n" + else + inspector << "├── parameters:\n" + inspector << parameters.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (body = self.body).nil? + inspector << "├── body: ∅\n" + else + inspector << "├── body:\n" + inspector << body.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents a block parameter to a method, block, or lambda definition. # # def a(&b) # ^^ # end class BlockParameterNode < Node + # attr_reader name: Symbol? + attr_reader :name + # attr_reader name_loc: Location? attr_reader :name_loc # attr_reader operator_loc: Location attr_reader :operator_loc - # def initialize: (name_loc: Location?, operator_loc: Location, location: Location) -> void - def initialize(name_loc, operator_loc, location) + # def initialize: (name: Symbol?, name_loc: Location?, operator_loc: Location, location: Location) -> void + def initialize(name, name_loc, operator_loc, location) + @name = name @name_loc = name_loc @operator_loc = operator_loc @location = location end @@ -739,13 +1014,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*name_loc, operator_loc] + end + # def copy: (**params) -> BlockParameterNode def copy(**params) BlockParameterNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:location) { location }, ) end @@ -753,22 +1034,25 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, location: location } end - # def name: () -> String? - def name - name_loc&.slice - end - # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents a block's parameters declaration. # # -> (a, b = 1; local) { } @@ -779,20 +1063,20 @@ # end class BlockParametersNode < Node # attr_reader parameters: ParametersNode? attr_reader :parameters - # attr_reader locals: Array[Location] + # attr_reader locals: Array[Node] attr_reader :locals # attr_reader opening_loc: Location? attr_reader :opening_loc # attr_reader closing_loc: Location? attr_reader :closing_loc - # def initialize: (parameters: ParametersNode?, locals: Array[Location], opening_loc: Location?, closing_loc: Location?, location: Location) -> void + # def initialize: (parameters: ParametersNode?, locals: Array[Node], opening_loc: Location?, closing_loc: Location?, location: Location) -> void def initialize(parameters, locals, opening_loc, closing_loc, location) @parameters = parameters @locals = locals @opening_loc = opening_loc @closing_loc = closing_loc @@ -804,13 +1088,18 @@ visitor.visit_block_parameters_node(self) end # def child_nodes: () -> Array[nil | Node] def child_nodes - [parameters] + [parameters, *locals] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*parameters, *locals, *opening_loc, *closing_loc] + end + # def copy: (**params) -> BlockParametersNode def copy(**params) BlockParametersNode.new( params.fetch(:parameters) { parameters }, params.fetch(:locals) { locals }, @@ -835,10 +1124,24 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (parameters = self.parameters).nil? + inspector << "├── parameters: ∅\n" + else + inspector << "├── parameters:\n" + inspector << parameters.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── locals: #{inspector.list("#{inspector.prefix}│ ", locals)}" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents the use of the `break` keyword. # # break foo @@ -865,10 +1168,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [arguments] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*arguments, keyword_loc] + end + # def copy: (**params) -> BreakNode def copy(**params) BreakNode.new( params.fetch(:arguments) { arguments }, params.fetch(:keyword_loc) { keyword_loc }, @@ -886,12 +1194,182 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (arguments = self.arguments).nil? + inspector << "├── arguments: ∅\n" + else + inspector << "├── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector.to_str + end end + # Represents the use of the `&&=` operator on a call. + # + # foo.bar &&= value + # ^^^^^^^^^^^^^^^^^ + class CallAndWriteNode < Node + # attr_reader receiver: Node? + attr_reader :receiver + + # attr_reader call_operator_loc: Location? + attr_reader :call_operator_loc + + # attr_reader message_loc: Location? + attr_reader :message_loc + + # attr_reader opening_loc: Location? + attr_reader :opening_loc + + # attr_reader arguments: ArgumentsNode? + attr_reader :arguments + + # attr_reader closing_loc: Location? + attr_reader :closing_loc + + # attr_reader flags: Integer + attr_reader :flags + + # attr_reader read_name: String + attr_reader :read_name + + # attr_reader write_name: String + attr_reader :write_name + + # attr_reader operator_loc: Location + attr_reader :operator_loc + + # attr_reader value: Node + attr_reader :value + + # def initialize: (receiver: Node?, call_operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, flags: Integer, read_name: String, write_name: String, operator_loc: Location, value: Node, location: Location) -> void + def initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location) + @receiver = receiver + @call_operator_loc = call_operator_loc + @message_loc = message_loc + @opening_loc = opening_loc + @arguments = arguments + @closing_loc = closing_loc + @flags = flags + @read_name = read_name + @write_name = write_name + @operator_loc = operator_loc + @value = value + @location = location + end + + # def accept: (visitor: Visitor) -> void + def accept(visitor) + visitor.visit_call_and_write_node(self) + end + + # def child_nodes: () -> Array[nil | Node] + def child_nodes + [receiver, arguments, value] + end + + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*receiver, *call_operator_loc, *message_loc, *opening_loc, *arguments, *closing_loc, operator_loc, value] + end + + # def copy: (**params) -> CallAndWriteNode + def copy(**params) + CallAndWriteNode.new( + params.fetch(:receiver) { receiver }, + params.fetch(:call_operator_loc) { call_operator_loc }, + params.fetch(:message_loc) { message_loc }, + params.fetch(:opening_loc) { opening_loc }, + params.fetch(:arguments) { arguments }, + params.fetch(:closing_loc) { closing_loc }, + params.fetch(:flags) { flags }, + params.fetch(:read_name) { read_name }, + params.fetch(:write_name) { write_name }, + params.fetch(:operator_loc) { operator_loc }, + params.fetch(:value) { value }, + params.fetch(:location) { location }, + ) + end + + # def deconstruct: () -> Array[nil | Node] + alias deconstruct child_nodes + + # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] + def deconstruct_keys(keys) + { receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, flags: flags, read_name: read_name, write_name: write_name, operator_loc: operator_loc, value: value, location: location } + end + + # def call_operator: () -> String? + def call_operator + call_operator_loc&.slice + end + + # def message: () -> String? + def message + message_loc&.slice + end + + # def opening: () -> String? + def opening + opening_loc&.slice + end + + # def closing: () -> String? + def closing + closing_loc&.slice + end + + # def safe_navigation?: () -> bool + def safe_navigation? + flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) + end + + # def variable_call?: () -> bool + def variable_call? + flags.anybits?(CallNodeFlags::VARIABLE_CALL) + end + + # def operator: () -> String + def operator + operator_loc.slice + end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (receiver = self.receiver).nil? + inspector << "├── receiver: ∅\n" + else + inspector << "├── receiver:\n" + inspector << receiver.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── call_operator_loc: #{inspector.location(call_operator_loc)}\n" + inspector << "├── message_loc: #{inspector.location(message_loc)}\n" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + if (arguments = self.arguments).nil? + inspector << "├── arguments: ∅\n" + else + inspector << "├── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "├── flags: #{[("safe_navigation" if safe_navigation?), ("variable_call" if variable_call?)].compact.join(", ")}\n" + inspector << "├── read_name: #{read_name.inspect}\n" + inspector << "├── write_name: #{write_name.inspect}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end + end + # Represents a method call, in all of the various forms that can take. # # foo # ^^^ # @@ -911,12 +1389,12 @@ # ^^^^^^^^ class CallNode < Node # attr_reader receiver: Node? attr_reader :receiver - # attr_reader operator_loc: Location? - attr_reader :operator_loc + # attr_reader call_operator_loc: Location? + attr_reader :call_operator_loc # attr_reader message_loc: Location? attr_reader :message_loc # attr_reader opening_loc: Location? @@ -935,14 +1413,14 @@ attr_reader :flags # attr_reader name: String attr_reader :name - # def initialize: (receiver: Node?, operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, block: BlockNode?, flags: Integer, name: String, location: Location) -> void - def initialize(receiver, operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location) + # def initialize: (receiver: Node?, call_operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, block: BlockNode?, flags: Integer, name: String, location: Location) -> void + def initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location) @receiver = receiver - @operator_loc = operator_loc + @call_operator_loc = call_operator_loc @message_loc = message_loc @opening_loc = opening_loc @arguments = arguments @closing_loc = closing_loc @block = block @@ -959,15 +1437,20 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [receiver, arguments, block] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*receiver, *call_operator_loc, *message_loc, *opening_loc, *arguments, *closing_loc, *block] + end + # def copy: (**params) -> CallNode def copy(**params) CallNode.new( params.fetch(:receiver) { receiver }, - params.fetch(:operator_loc) { operator_loc }, + params.fetch(:call_operator_loc) { call_operator_loc }, params.fetch(:message_loc) { message_loc }, params.fetch(:opening_loc) { opening_loc }, params.fetch(:arguments) { arguments }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:block) { block }, @@ -980,16 +1463,16 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { receiver: receiver, operator_loc: operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block, flags: flags, name: name, location: location } + { receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block, flags: flags, name: name, location: location } end - # def operator: () -> String? - def operator - operator_loc&.slice + # def call_operator: () -> String? + def call_operator + call_operator_loc&.slice end # def message: () -> String? def message message_loc&.slice @@ -1012,48 +1495,127 @@ # def variable_call?: () -> bool def variable_call? flags.anybits?(CallNodeFlags::VARIABLE_CALL) end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (receiver = self.receiver).nil? + inspector << "├── receiver: ∅\n" + else + inspector << "├── receiver:\n" + inspector << receiver.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── call_operator_loc: #{inspector.location(call_operator_loc)}\n" + inspector << "├── message_loc: #{inspector.location(message_loc)}\n" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + if (arguments = self.arguments).nil? + inspector << "├── arguments: ∅\n" + else + inspector << "├── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + if (block = self.block).nil? + inspector << "├── block: ∅\n" + else + inspector << "├── block:\n" + inspector << block.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── flags: #{[("safe_navigation" if safe_navigation?), ("variable_call" if variable_call?)].compact.join(", ")}\n" + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end - # Represents the use of the `&&=` operator on a call. + # Represents the use of an assignment operator on a call. # - # foo.bar &&= value - # ^^^^^^^^^^^^^^^^^ - class CallOperatorAndWriteNode < Node - # attr_reader target: CallNode - attr_reader :target + # foo.bar += baz + # ^^^^^^^^^^^^^^ + class CallOperatorWriteNode < Node + # attr_reader receiver: Node? + attr_reader :receiver + # attr_reader call_operator_loc: Location? + attr_reader :call_operator_loc + + # attr_reader message_loc: Location? + attr_reader :message_loc + + # attr_reader opening_loc: Location? + attr_reader :opening_loc + + # attr_reader arguments: ArgumentsNode? + attr_reader :arguments + + # attr_reader closing_loc: Location? + attr_reader :closing_loc + + # attr_reader flags: Integer + attr_reader :flags + + # attr_reader read_name: String + attr_reader :read_name + + # attr_reader write_name: String + attr_reader :write_name + + # attr_reader operator: Symbol + attr_reader :operator + # attr_reader operator_loc: Location attr_reader :operator_loc # attr_reader value: Node attr_reader :value - # def initialize: (target: CallNode, operator_loc: Location, value: Node, location: Location) -> void - def initialize(target, operator_loc, value, location) - @target = target + # def initialize: (receiver: Node?, call_operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, flags: Integer, read_name: String, write_name: String, operator: Symbol, operator_loc: Location, value: Node, location: Location) -> void + def initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator, operator_loc, value, location) + @receiver = receiver + @call_operator_loc = call_operator_loc + @message_loc = message_loc + @opening_loc = opening_loc + @arguments = arguments + @closing_loc = closing_loc + @flags = flags + @read_name = read_name + @write_name = write_name + @operator = operator @operator_loc = operator_loc @value = value @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) - visitor.visit_call_operator_and_write_node(self) + visitor.visit_call_operator_write_node(self) end # def child_nodes: () -> Array[nil | Node] def child_nodes - [target, value] + [receiver, arguments, value] end - # def copy: (**params) -> CallOperatorAndWriteNode + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*receiver, *call_operator_loc, *message_loc, *opening_loc, *arguments, *closing_loc, operator_loc, value] + end + + # def copy: (**params) -> CallOperatorWriteNode def copy(**params) - CallOperatorAndWriteNode.new( - params.fetch(:target) { target }, + CallOperatorWriteNode.new( + params.fetch(:receiver) { receiver }, + params.fetch(:call_operator_loc) { call_operator_loc }, + params.fetch(:message_loc) { message_loc }, + params.fetch(:opening_loc) { opening_loc }, + params.fetch(:arguments) { arguments }, + params.fetch(:closing_loc) { closing_loc }, + params.fetch(:flags) { flags }, + params.fetch(:read_name) { read_name }, + params.fetch(:write_name) { write_name }, + params.fetch(:operator) { operator }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) end @@ -1061,128 +1623,227 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { target: target, operator_loc: operator_loc, value: value, location: location } + { receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, flags: flags, read_name: read_name, write_name: write_name, operator: operator, operator_loc: operator_loc, value: value, location: location } end - # def operator: () -> String - def operator - operator_loc.slice + # def call_operator: () -> String? + def call_operator + call_operator_loc&.slice end + + # def message: () -> String? + def message + message_loc&.slice + end + + # def opening: () -> String? + def opening + opening_loc&.slice + end + + # def closing: () -> String? + def closing + closing_loc&.slice + end + + # def safe_navigation?: () -> bool + def safe_navigation? + flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) + end + + # def variable_call?: () -> bool + def variable_call? + flags.anybits?(CallNodeFlags::VARIABLE_CALL) + end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (receiver = self.receiver).nil? + inspector << "├── receiver: ∅\n" + else + inspector << "├── receiver:\n" + inspector << receiver.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── call_operator_loc: #{inspector.location(call_operator_loc)}\n" + inspector << "├── message_loc: #{inspector.location(message_loc)}\n" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + if (arguments = self.arguments).nil? + inspector << "├── arguments: ∅\n" + else + inspector << "├── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "├── flags: #{[("safe_navigation" if safe_navigation?), ("variable_call" if variable_call?)].compact.join(", ")}\n" + inspector << "├── read_name: #{read_name.inspect}\n" + inspector << "├── write_name: #{write_name.inspect}\n" + inspector << "├── operator: #{operator.inspect}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents the use of the `||=` operator on a call. # # foo.bar ||= value # ^^^^^^^^^^^^^^^^^ - class CallOperatorOrWriteNode < Node - # attr_reader target: CallNode - attr_reader :target + class CallOrWriteNode < Node + # attr_reader receiver: Node? + attr_reader :receiver - # attr_reader value: Node - attr_reader :value + # attr_reader call_operator_loc: Location? + attr_reader :call_operator_loc + # attr_reader message_loc: Location? + attr_reader :message_loc + + # attr_reader opening_loc: Location? + attr_reader :opening_loc + + # attr_reader arguments: ArgumentsNode? + attr_reader :arguments + + # attr_reader closing_loc: Location? + attr_reader :closing_loc + + # attr_reader flags: Integer + attr_reader :flags + + # attr_reader read_name: String + attr_reader :read_name + + # attr_reader write_name: String + attr_reader :write_name + # attr_reader operator_loc: Location attr_reader :operator_loc - # def initialize: (target: CallNode, value: Node, operator_loc: Location, location: Location) -> void - def initialize(target, value, operator_loc, location) - @target = target - @value = value + # attr_reader value: Node + attr_reader :value + + # def initialize: (receiver: Node?, call_operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, flags: Integer, read_name: String, write_name: String, operator_loc: Location, value: Node, location: Location) -> void + def initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location) + @receiver = receiver + @call_operator_loc = call_operator_loc + @message_loc = message_loc + @opening_loc = opening_loc + @arguments = arguments + @closing_loc = closing_loc + @flags = flags + @read_name = read_name + @write_name = write_name @operator_loc = operator_loc + @value = value @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) - visitor.visit_call_operator_or_write_node(self) + visitor.visit_call_or_write_node(self) end # def child_nodes: () -> Array[nil | Node] def child_nodes - [target, value] + [receiver, arguments, value] end - # def copy: (**params) -> CallOperatorOrWriteNode + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*receiver, *call_operator_loc, *message_loc, *opening_loc, *arguments, *closing_loc, operator_loc, value] + end + + # def copy: (**params) -> CallOrWriteNode def copy(**params) - CallOperatorOrWriteNode.new( - params.fetch(:target) { target }, - params.fetch(:value) { value }, + CallOrWriteNode.new( + params.fetch(:receiver) { receiver }, + params.fetch(:call_operator_loc) { call_operator_loc }, + params.fetch(:message_loc) { message_loc }, + params.fetch(:opening_loc) { opening_loc }, + params.fetch(:arguments) { arguments }, + params.fetch(:closing_loc) { closing_loc }, + params.fetch(:flags) { flags }, + params.fetch(:read_name) { read_name }, + params.fetch(:write_name) { write_name }, params.fetch(:operator_loc) { operator_loc }, + params.fetch(:value) { value }, params.fetch(:location) { location }, ) end # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { target: target, value: value, operator_loc: operator_loc, location: location } + { receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, flags: flags, read_name: read_name, write_name: write_name, operator_loc: operator_loc, value: value, location: location } end - # def operator: () -> String - def operator - operator_loc.slice + # def call_operator: () -> String? + def call_operator + call_operator_loc&.slice end - end - # Represents the use of an assignment operator on a call. - # - # foo.bar += baz - # ^^^^^^^^^^^^^^ - class CallOperatorWriteNode < Node - # attr_reader target: CallNode - attr_reader :target + # def message: () -> String? + def message + message_loc&.slice + end - # attr_reader operator_loc: Location - attr_reader :operator_loc + # def opening: () -> String? + def opening + opening_loc&.slice + end - # attr_reader value: Node - attr_reader :value - - # attr_reader operator: Symbol - attr_reader :operator - - # def initialize: (target: CallNode, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void - def initialize(target, operator_loc, value, operator, location) - @target = target - @operator_loc = operator_loc - @value = value - @operator = operator - @location = location + # def closing: () -> String? + def closing + closing_loc&.slice end - # def accept: (visitor: Visitor) -> void - def accept(visitor) - visitor.visit_call_operator_write_node(self) + # def safe_navigation?: () -> bool + def safe_navigation? + flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) end - # def child_nodes: () -> Array[nil | Node] - def child_nodes - [target, value] + # def variable_call?: () -> bool + def variable_call? + flags.anybits?(CallNodeFlags::VARIABLE_CALL) end - # def copy: (**params) -> CallOperatorWriteNode - def copy(**params) - CallOperatorWriteNode.new( - params.fetch(:target) { target }, - params.fetch(:operator_loc) { operator_loc }, - params.fetch(:value) { value }, - params.fetch(:operator) { operator }, - params.fetch(:location) { location }, - ) + # def operator: () -> String + def operator + operator_loc.slice end - # def deconstruct: () -> Array[nil | Node] - alias deconstruct child_nodes - - # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] - def deconstruct_keys(keys) - { target: target, operator_loc: operator_loc, value: value, operator: operator, location: location } + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (receiver = self.receiver).nil? + inspector << "├── receiver: ∅\n" + else + inspector << "├── receiver:\n" + inspector << receiver.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── call_operator_loc: #{inspector.location(call_operator_loc)}\n" + inspector << "├── message_loc: #{inspector.location(message_loc)}\n" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + if (arguments = self.arguments).nil? + inspector << "├── arguments: ∅\n" + else + inspector << "├── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "├── flags: #{[("safe_navigation" if safe_navigation?), ("variable_call" if variable_call?)].compact.join(", ")}\n" + inspector << "├── read_name: #{read_name.inspect}\n" + inspector << "├── write_name: #{write_name.inspect}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str end end # Represents assigning to a local variable in pattern matching. # @@ -1214,10 +1875,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value, target] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [value, target, operator_loc] + end + # def copy: (**params) -> CapturePatternNode def copy(**params) CapturePatternNode.new( params.fetch(:value) { value }, params.fetch(:target) { target }, @@ -1236,10 +1902,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "├── target:\n" + inspector << inspector.child_node(target, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents the use of a case statement. # # case true @@ -1280,10 +1956,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [predicate, *conditions, consequent] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*predicate, *conditions, *consequent, case_keyword_loc, end_keyword_loc] + end + # def copy: (**params) -> CaseNode def copy(**params) CaseNode.new( params.fetch(:predicate) { predicate }, params.fetch(:conditions) { conditions }, @@ -1309,10 +1990,30 @@ # def end_keyword: () -> String def end_keyword end_keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (predicate = self.predicate).nil? + inspector << "├── predicate: ∅\n" + else + inspector << "├── predicate:\n" + inspector << predicate.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── conditions: #{inspector.list("#{inspector.prefix}│ ", conditions)}" + if (consequent = self.consequent).nil? + inspector << "├── consequent: ∅\n" + else + inspector << "├── consequent:\n" + inspector << consequent.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── case_keyword_loc: #{inspector.location(case_keyword_loc)}\n" + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents a class declaration involving the `class` keyword. # # class Foo end @@ -1337,14 +2038,14 @@ attr_reader :body # attr_reader end_keyword_loc: Location attr_reader :end_keyword_loc - # attr_reader name: String + # attr_reader name: Symbol attr_reader :name - # def initialize: (locals: Array[Symbol], class_keyword_loc: Location, constant_path: Node, inheritance_operator_loc: Location?, superclass: Node?, body: Node?, end_keyword_loc: Location, name: String, location: Location) -> void + # def initialize: (locals: Array[Symbol], class_keyword_loc: Location, constant_path: Node, inheritance_operator_loc: Location?, superclass: Node?, body: Node?, end_keyword_loc: Location, name: Symbol, location: Location) -> void def initialize(locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name, location) @locals = locals @class_keyword_loc = class_keyword_loc @constant_path = constant_path @inheritance_operator_loc = inheritance_operator_loc @@ -1363,10 +2064,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [constant_path, superclass, body] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [class_keyword_loc, constant_path, *inheritance_operator_loc, *superclass, *body, end_keyword_loc] + end + # def copy: (**params) -> ClassNode def copy(**params) ClassNode.new( params.fetch(:locals) { locals }, params.fetch(:class_keyword_loc) { class_keyword_loc }, @@ -1400,10 +2106,34 @@ # def end_keyword: () -> String def end_keyword end_keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── locals: #{locals.inspect}\n" + inspector << "├── class_keyword_loc: #{inspector.location(class_keyword_loc)}\n" + inspector << "├── constant_path:\n" + inspector << inspector.child_node(constant_path, "│ ") + inspector << "├── inheritance_operator_loc: #{inspector.location(inheritance_operator_loc)}\n" + if (superclass = self.superclass).nil? + inspector << "├── superclass: ∅\n" + else + inspector << "├── superclass:\n" + inspector << superclass.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (body = self.body).nil? + inspector << "├── body: ∅\n" + else + inspector << "├── body:\n" + inspector << body.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents the use of the `&&=` operator for assignment to a class variable. # # @@target &&= value @@ -1438,10 +2168,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> ClassVariableAndWriteNode def copy(**params) ClassVariableAndWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -1461,10 +2196,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents assigning to a class variable using an operator that isn't `=`. # # @@target += value @@ -1503,10 +2248,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> ClassVariableOperatorWriteNode def copy(**params) ClassVariableOperatorWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -1522,10 +2272,21 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator: #{operator.inspect}\n" + inspector.to_str + end end # Represents the use of the `||=` operator for assignment to a class variable. # # @@target ||= value @@ -1560,10 +2321,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> ClassVariableOrWriteNode def copy(**params) ClassVariableOrWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -1583,10 +2349,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents referencing a class variable. # # @@foo @@ -1609,10 +2385,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> ClassVariableReadNode def copy(**params) ClassVariableReadNode.new( params.fetch(:name) { name }, params.fetch(:location) { location }, @@ -1624,10 +2405,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents writing to a class variable in a context that doesn't have an explicit value. # # @@foo, @@bar = baz @@ -1650,10 +2437,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> ClassVariableTargetNode def copy(**params) ClassVariableTargetNode.new( params.fetch(:name) { name }, params.fetch(:location) { location }, @@ -1665,10 +2457,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents writing to a class variable. # # @@foo = 1 @@ -1678,17 +2476,17 @@ attr_reader :name # attr_reader name_loc: Location attr_reader :name_loc - # attr_reader value: Node? + # attr_reader value: Node attr_reader :value # attr_reader operator_loc: Location? attr_reader :operator_loc - # def initialize: (name: Symbol, name_loc: Location, value: Node?, operator_loc: Location?, location: Location) -> void + # def initialize: (name: Symbol, name_loc: Location, value: Node, operator_loc: Location?, location: Location) -> void def initialize(name, name_loc, value, operator_loc, location) @name = name @name_loc = name_loc @value = value @operator_loc = operator_loc @@ -1703,10 +2501,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, value, *operator_loc] + end + # def copy: (**params) -> ClassVariableWriteNode def copy(**params) ClassVariableWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -1726,28 +2529,42 @@ # def operator: () -> String? def operator operator_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents the use of the `&&=` operator for assignment to a constant. # # Target &&= value # ^^^^^^^^^^^^^^^^ class ConstantAndWriteNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader operator_loc: Location attr_reader :operator_loc # attr_reader value: Node attr_reader :value - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) + # def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void + def initialize(name, name_loc, operator_loc, value, location) + @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value @location = location end @@ -1760,13 +2577,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> ConstantAndWriteNode def copy(**params) ConstantAndWriteNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) @@ -1775,29 +2598,37 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } end - # def name: () -> String - def name - name_loc.slice - end - # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents assigning to a constant using an operator that isn't `=`. # # Target += value # ^^^^^^^^^^^^^^^ class ConstantOperatorWriteNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader operator_loc: Location attr_reader :operator_loc @@ -1806,12 +2637,13 @@ attr_reader :value # attr_reader operator: Symbol attr_reader :operator - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, operator, location) + # def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void + def initialize(name, name_loc, operator_loc, value, operator, location) + @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value @operator = operator @location = location @@ -1825,13 +2657,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> ConstantOperatorWriteNode def copy(**params) ConstantOperatorWriteNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:operator) { operator }, params.fetch(:location) { location }, @@ -1841,35 +2679,45 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } end - # def name: () -> String - def name - name_loc.slice + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator: #{operator.inspect}\n" + inspector.to_str end end # Represents the use of the `||=` operator for assignment to a constant. # # Target ||= value # ^^^^^^^^^^^^^^^^ class ConstantOrWriteNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader operator_loc: Location attr_reader :operator_loc # attr_reader value: Node attr_reader :value - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) + # def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void + def initialize(name, name_loc, operator_loc, value, location) + @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value @location = location end @@ -1882,13 +2730,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> ConstantOrWriteNode def copy(**params) ConstantOrWriteNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) @@ -1897,22 +2751,27 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } end - # def name: () -> String - def name - name_loc.slice - end - # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents the use of the `&&=` operator for assignment to a constant path. # # Parent::Child &&= value @@ -1943,10 +2802,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [target, value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [target, operator_loc, value] + end + # def copy: (**params) -> ConstantPathAndWriteNode def copy(**params) ConstantPathAndWriteNode.new( params.fetch(:target) { target }, params.fetch(:operator_loc) { operator_loc }, @@ -1965,10 +2829,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── target:\n" + inspector << inspector.child_node(target, "│ ") + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents accessing a constant through a path of `::` operators. # # Foo::Bar @@ -1999,10 +2873,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [parent, child] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*parent, child, delimiter_loc] + end + # def copy: (**params) -> ConstantPathNode def copy(**params) ConstantPathNode.new( params.fetch(:parent) { parent }, params.fetch(:child) { child }, @@ -2021,10 +2900,24 @@ # def delimiter: () -> String def delimiter delimiter_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (parent = self.parent).nil? + inspector << "├── parent: ∅\n" + else + inspector << "├── parent:\n" + inspector << parent.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── child:\n" + inspector << inspector.child_node(child, "│ ") + inspector << "└── delimiter_loc: #{inspector.location(delimiter_loc)}\n" + inspector.to_str + end end # Represents assigning to a constant path using an operator that isn't `=`. # # Parent::Child += value @@ -2059,10 +2952,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [target, value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [target, operator_loc, value] + end + # def copy: (**params) -> ConstantPathOperatorWriteNode def copy(**params) ConstantPathOperatorWriteNode.new( params.fetch(:target) { target }, params.fetch(:operator_loc) { operator_loc }, @@ -2077,10 +2975,21 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { target: target, operator_loc: operator_loc, value: value, operator: operator, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── target:\n" + inspector << inspector.child_node(target, "│ ") + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator: #{operator.inspect}\n" + inspector.to_str + end end # Represents the use of the `||=` operator for assignment to a constant path. # # Parent::Child ||= value @@ -2111,10 +3020,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [target, value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [target, operator_loc, value] + end + # def copy: (**params) -> ConstantPathOrWriteNode def copy(**params) ConstantPathOrWriteNode.new( params.fetch(:target) { target }, params.fetch(:operator_loc) { operator_loc }, @@ -2133,10 +3047,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── target:\n" + inspector << inspector.child_node(target, "│ ") + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents writing to a constant path in a context that doesn't have an explicit value. # # Foo::Foo, Bar::Bar = baz @@ -2167,10 +3091,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [parent, child] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*parent, child, delimiter_loc] + end + # def copy: (**params) -> ConstantPathTargetNode def copy(**params) ConstantPathTargetNode.new( params.fetch(:parent) { parent }, params.fetch(:child) { child }, @@ -2189,10 +3118,24 @@ # def delimiter: () -> String def delimiter delimiter_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (parent = self.parent).nil? + inspector << "├── parent: ∅\n" + else + inspector << "├── parent:\n" + inspector << parent.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── child:\n" + inspector << inspector.child_node(child, "│ ") + inspector << "└── delimiter_loc: #{inspector.location(delimiter_loc)}\n" + inspector.to_str + end end # Represents writing to a constant path. # # ::Foo = 1 @@ -2229,10 +3172,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [target, value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [target, operator_loc, value] + end + # def copy: (**params) -> ConstantPathWriteNode def copy(**params) ConstantPathWriteNode.new( params.fetch(:target) { target }, params.fetch(:operator_loc) { operator_loc }, @@ -2251,19 +3199,33 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── target:\n" + inspector << inspector.child_node(target, "│ ") + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents referencing a constant. # # Foo # ^^^ class ConstantReadNode < Node - # def initialize: (location: Location) -> void - def initialize(location) + # attr_reader name: Symbol + attr_reader :name + + # def initialize: (name: Symbol, location: Location) -> void + def initialize(name, location) + @name = name @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) @@ -2273,33 +3235,49 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> ConstantReadNode def copy(**params) ConstantReadNode.new( + params.fetch(:name) { name }, params.fetch(:location) { location }, ) end # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { location: location } + { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents writing to a constant in a context that doesn't have an explicit value. # # Foo, Bar = baz # ^^^ ^^^ class ConstantTargetNode < Node - # def initialize: (location: Location) -> void - def initialize(location) + # attr_reader name: Symbol + attr_reader :name + + # def initialize: (name: Symbol, location: Location) -> void + def initialize(name, location) + @name = name @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) @@ -2309,42 +3287,58 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> ConstantTargetNode def copy(**params) ConstantTargetNode.new( + params.fetch(:name) { name }, params.fetch(:location) { location }, ) end # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { location: location } + { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents writing to a constant. # # Foo = 1 # ^^^^^^^ class ConstantWriteNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader value: Node attr_reader :value # attr_reader operator_loc: Location attr_reader :operator_loc - # def initialize: (name_loc: Location, value: Node, operator_loc: Location, location: Location) -> void - def initialize(name_loc, value, operator_loc, location) + # def initialize: (name: Symbol, name_loc: Location, value: Node, operator_loc: Location, location: Location) -> void + def initialize(name, name_loc, value, operator_loc, location) + @name = name @name_loc = name_loc @value = value @operator_loc = operator_loc @location = location end @@ -2357,13 +3351,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, value, operator_loc] + end + # def copy: (**params) -> ConstantWriteNode def copy(**params) ConstantWriteNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:value) { value }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:location) { location }, ) @@ -2372,30 +3372,38 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, value: value, operator_loc: operator_loc, location: location } + { name: name, name_loc: name_loc, value: value, operator_loc: operator_loc, location: location } end - # def name: () -> String - def name - name_loc.slice - end - # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents a method definition. # # def method # end # ^^^^^^^^^^ class DefNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader receiver: Node? attr_reader :receiver @@ -2425,12 +3433,13 @@ attr_reader :equal_loc # attr_reader end_keyword_loc: Location? attr_reader :end_keyword_loc - # def initialize: (name_loc: Location, receiver: Node?, parameters: ParametersNode?, body: Node?, locals: Array[Symbol], def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location?, location: Location) -> void - def initialize(name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) + # def initialize: (name: Symbol, name_loc: Location, receiver: Node?, parameters: ParametersNode?, body: Node?, locals: Array[Symbol], def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location?, location: Location) -> void + def initialize(name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) + @name = name @name_loc = name_loc @receiver = receiver @parameters = parameters @body = body @locals = locals @@ -2451,13 +3460,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [receiver, parameters, body] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, *receiver, *parameters, *body, def_keyword_loc, *operator_loc, *lparen_loc, *rparen_loc, *equal_loc, *end_keyword_loc] + end + # def copy: (**params) -> DefNode def copy(**params) DefNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:receiver) { receiver }, params.fetch(:parameters) { parameters }, params.fetch(:body) { body }, params.fetch(:locals) { locals }, @@ -2474,18 +3489,13 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { 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, 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, location: location } end - # def name: () -> String - def name - name_loc.slice - end - # def def_keyword: () -> String def def_keyword def_keyword_loc.slice end @@ -2511,10 +3521,42 @@ # def end_keyword: () -> String? def end_keyword end_keyword_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + if (receiver = self.receiver).nil? + inspector << "├── receiver: ∅\n" + else + inspector << "├── receiver:\n" + inspector << receiver.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (parameters = self.parameters).nil? + inspector << "├── parameters: ∅\n" + else + inspector << "├── parameters:\n" + inspector << parameters.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (body = self.body).nil? + inspector << "├── body: ∅\n" + else + inspector << "├── body:\n" + inspector << body.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── locals: #{locals.inspect}\n" + inspector << "├── def_keyword_loc: #{inspector.location(def_keyword_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n" + inspector << "├── rparen_loc: #{inspector.location(rparen_loc)}\n" + inspector << "├── equal_loc: #{inspector.location(equal_loc)}\n" + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents the use of the `defined?` keyword. # # defined?(a) @@ -2549,10 +3591,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*lparen_loc, value, *rparen_loc, keyword_loc] + end + # def copy: (**params) -> DefinedNode def copy(**params) DefinedNode.new( params.fetch(:lparen_loc) { lparen_loc }, params.fetch(:value) { value }, @@ -2582,10 +3629,20 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "├── rparen_loc: #{inspector.location(rparen_loc)}\n" + inspector << "└── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector.to_str + end end # Represents an `else` clause in a `case`, `if`, or `unless` statement. # # if a then b else c end @@ -2616,10 +3673,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [else_keyword_loc, *statements, *end_keyword_loc] + end + # def copy: (**params) -> ElseNode def copy(**params) ElseNode.new( params.fetch(:else_keyword_loc) { else_keyword_loc }, params.fetch(:statements) { statements }, @@ -2643,10 +3705,23 @@ # def end_keyword: () -> String? def end_keyword end_keyword_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── else_keyword_loc: #{inspector.location(else_keyword_loc)}\n" + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents an interpolated set of statements. # # "foo #{bar}" @@ -2677,10 +3752,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [opening_loc, *statements, closing_loc] + end + # def copy: (**params) -> EmbeddedStatementsNode def copy(**params) EmbeddedStatementsNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:statements) { statements }, @@ -2704,10 +3784,23 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents an interpolated variable. # # "foo #@bar" @@ -2734,10 +3827,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [variable] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [operator_loc, variable] + end + # def copy: (**params) -> EmbeddedVariableNode def copy(**params) EmbeddedVariableNode.new( params.fetch(:operator_loc) { operator_loc }, params.fetch(:variable) { variable }, @@ -2755,10 +3853,18 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── variable:\n" + inspector << inspector.child_node(variable, " ") + inspector.to_str + end end # Represents an `ensure` clause in a `begin` statement. # # begin @@ -2793,10 +3899,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [ensure_keyword_loc, *statements, end_keyword_loc] + end + # def copy: (**params) -> EnsureNode def copy(**params) EnsureNode.new( params.fetch(:ensure_keyword_loc) { ensure_keyword_loc }, params.fetch(:statements) { statements }, @@ -2820,10 +3931,23 @@ # def end_keyword: () -> String def end_keyword end_keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── ensure_keyword_loc: #{inspector.location(ensure_keyword_loc)}\n" + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents the use of the literal `false` keyword. # # false @@ -2842,10 +3966,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> FalseNode def copy(**params) FalseNode.new( params.fetch(:location) { location }, ) @@ -2856,10 +3985,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents a find pattern in pattern matching. # # foo in *bar, baz, *qux @@ -2908,10 +4042,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [constant, left, *requireds, right] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*constant, left, *requireds, right, *opening_loc, *closing_loc] + end + # def copy: (**params) -> FindPatternNode def copy(**params) FindPatternNode.new( params.fetch(:constant) { constant }, params.fetch(:left) { left }, @@ -2938,10 +4077,28 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (constant = self.constant).nil? + inspector << "├── constant: ∅\n" + else + inspector << "├── constant:\n" + inspector << constant.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── left:\n" + inspector << inspector.child_node(left, "│ ") + inspector << "├── requireds: #{inspector.list("#{inspector.prefix}│ ", requireds)}" + inspector << "├── right:\n" + inspector << inspector.child_node(right, "│ ") + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents the use of the `..` or `...` operators to create flip flops. # # baz if foo .. bar @@ -2976,10 +4133,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [left, right] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*left, *right, operator_loc] + end + # def copy: (**params) -> FlipFlopNode def copy(**params) FlipFlopNode.new( params.fetch(:left) { left }, params.fetch(:right) { right }, @@ -3004,10 +4166,29 @@ # def exclude_end?: () -> bool def exclude_end? flags.anybits?(RangeFlags::EXCLUDE_END) end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (left = self.left).nil? + inspector << "├── left: ∅\n" + else + inspector << "├── left:\n" + inspector << left.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (right = self.right).nil? + inspector << "├── right: ∅\n" + else + inspector << "├── right:\n" + inspector << right.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── flags: #{[("exclude_end" if exclude_end?)].compact.join(", ")}\n" + inspector.to_str + end end # Represents a floating point number literal. # # 1.0 @@ -3026,10 +4207,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> FloatNode def copy(**params) FloatNode.new( params.fetch(:location) { location }, ) @@ -3040,10 +4226,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents the use of the `for` keyword. # # for i in a end @@ -3090,10 +4281,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [index, collection, statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [index, collection, *statements, for_keyword_loc, in_keyword_loc, *do_keyword_loc, end_keyword_loc] + end + # def copy: (**params) -> ForNode def copy(**params) ForNode.new( params.fetch(:index) { index }, params.fetch(:collection) { collection }, @@ -3131,10 +4327,29 @@ # def end_keyword: () -> String def end_keyword end_keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── index:\n" + inspector << inspector.child_node(index, "│ ") + inspector << "├── collection:\n" + inspector << inspector.child_node(collection, "│ ") + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── for_keyword_loc: #{inspector.location(for_keyword_loc)}\n" + inspector << "├── in_keyword_loc: #{inspector.location(in_keyword_loc)}\n" + inspector << "├── do_keyword_loc: #{inspector.location(do_keyword_loc)}\n" + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents forwarding all arguments to this method to another method. # # def foo(...) @@ -3155,10 +4370,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> ForwardingArgumentsNode def copy(**params) ForwardingArgumentsNode.new( params.fetch(:location) { location }, ) @@ -3169,10 +4389,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents the use of the forwarding parameter in a method, block, or lambda declaration. # # def foo(...) @@ -3192,10 +4417,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> ForwardingParameterNode def copy(**params) ForwardingParameterNode.new( params.fetch(:location) { location }, ) @@ -3206,10 +4436,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents the use of the `super` keyword without parentheses or arguments. # # super @@ -3232,10 +4467,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [block] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*block] + end + # def copy: (**params) -> ForwardingSuperNode def copy(**params) ForwardingSuperNode.new( params.fetch(:block) { block }, params.fetch(:location) { location }, @@ -3247,28 +4487,43 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { block: block, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (block = self.block).nil? + inspector << "└── block: ∅\n" + else + inspector << "└── block:\n" + inspector << block.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str + end end # Represents the use of the `&&=` operator for assignment to a global variable. # # $target &&= value # ^^^^^^^^^^^^^^^^^ class GlobalVariableAndWriteNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader operator_loc: Location attr_reader :operator_loc # attr_reader value: Node attr_reader :value - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) + # def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void + def initialize(name, name_loc, operator_loc, value, location) + @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value @location = location end @@ -3281,13 +4536,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> GlobalVariableAndWriteNode def copy(**params) GlobalVariableAndWriteNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) @@ -3296,29 +4557,37 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } end - # def name: () -> String - def name - name_loc.slice - end - # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents assigning to a global variable using an operator that isn't `=`. # # $target += value # ^^^^^^^^^^^^^^^^ class GlobalVariableOperatorWriteNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader operator_loc: Location attr_reader :operator_loc @@ -3327,12 +4596,13 @@ attr_reader :value # attr_reader operator: Symbol attr_reader :operator - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void - def initialize(name_loc, operator_loc, value, operator, location) + # def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, operator: Symbol, location: Location) -> void + def initialize(name, name_loc, operator_loc, value, operator, location) + @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value @operator = operator @location = location @@ -3346,13 +4616,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> GlobalVariableOperatorWriteNode def copy(**params) GlobalVariableOperatorWriteNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:operator) { operator }, params.fetch(:location) { location }, @@ -3362,35 +4638,45 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } end - # def name: () -> String - def name - name_loc.slice + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator: #{operator.inspect}\n" + inspector.to_str end end # Represents the use of the `||=` operator for assignment to a global variable. # # $target ||= value # ^^^^^^^^^^^^^^^^^ class GlobalVariableOrWriteNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader operator_loc: Location attr_reader :operator_loc # attr_reader value: Node attr_reader :value - # def initialize: (name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void - def initialize(name_loc, operator_loc, value, location) + # def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void + def initialize(name, name_loc, operator_loc, value, location) + @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value @location = location end @@ -3403,13 +4689,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> GlobalVariableOrWriteNode def copy(**params) GlobalVariableOrWriteNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) @@ -3418,31 +4710,40 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } end - # def name: () -> String - def name - name_loc.slice - end - # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents referencing a global variable. # # $foo # ^^^^ class GlobalVariableReadNode < Node - # def initialize: (location: Location) -> void - def initialize(location) + # attr_reader name: Symbol + attr_reader :name + + # def initialize: (name: Symbol, location: Location) -> void + def initialize(name, location) + @name = name @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) @@ -3452,33 +4753,49 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> GlobalVariableReadNode def copy(**params) GlobalVariableReadNode.new( + params.fetch(:name) { name }, params.fetch(:location) { location }, ) end # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { location: location } + { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents writing to a global variable in a context that doesn't have an explicit value. # # $foo, $bar = baz # ^^^^ ^^^^ class GlobalVariableTargetNode < Node - # def initialize: (location: Location) -> void - def initialize(location) + # attr_reader name: Symbol + attr_reader :name + + # def initialize: (name: Symbol, location: Location) -> void + def initialize(name, location) + @name = name @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) @@ -3488,42 +4805,58 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> GlobalVariableTargetNode def copy(**params) GlobalVariableTargetNode.new( + params.fetch(:name) { name }, params.fetch(:location) { location }, ) end # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { location: location } + { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents writing to a global variable. # # $foo = 1 # ^^^^^^^^ class GlobalVariableWriteNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader value: Node attr_reader :value # attr_reader operator_loc: Location attr_reader :operator_loc - # def initialize: (name_loc: Location, value: Node, operator_loc: Location, location: Location) -> void - def initialize(name_loc, value, operator_loc, location) + # def initialize: (name: Symbol, name_loc: Location, value: Node, operator_loc: Location, location: Location) -> void + def initialize(name, name_loc, value, operator_loc, location) + @name = name @name_loc = name_loc @value = value @operator_loc = operator_loc @location = location end @@ -3536,13 +4869,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, value, operator_loc] + end + # def copy: (**params) -> GlobalVariableWriteNode def copy(**params) GlobalVariableWriteNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:value) { value }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:location) { location }, ) @@ -3551,22 +4890,27 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, value: value, operator_loc: operator_loc, location: location } + { name: name, name_loc: name_loc, value: value, operator_loc: operator_loc, location: location } end - # def name: () -> String - def name - name_loc.slice - end - # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents a hash literal. # # { a => b } @@ -3597,10 +4941,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*elements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [opening_loc, *elements, closing_loc] + end + # def copy: (**params) -> HashNode def copy(**params) HashNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:elements) { elements }, @@ -3624,10 +4973,18 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── elements: #{inspector.list("#{inspector.prefix}│ ", elements)}" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents a hash pattern in pattern matching. # # foo => { a: 1, b: 2 } @@ -3669,10 +5026,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [constant, *assocs, kwrest] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*constant, *assocs, *kwrest, *opening_loc, *closing_loc] + end + # def copy: (**params) -> HashPatternNode def copy(**params) HashPatternNode.new( params.fetch(:constant) { constant }, params.fetch(:assocs) { assocs }, @@ -3698,10 +5060,30 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (constant = self.constant).nil? + inspector << "├── constant: ∅\n" + else + inspector << "├── constant:\n" + inspector << constant.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── assocs: #{inspector.list("#{inspector.prefix}│ ", assocs)}" + if (kwrest = self.kwrest).nil? + inspector << "├── kwrest: ∅\n" + else + inspector << "├── kwrest:\n" + inspector << kwrest.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents the use of the `if` keyword, either in the block form or the modifier form. # # bar if foo @@ -3747,10 +5129,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [predicate, statements, consequent] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*if_keyword_loc, predicate, *statements, *consequent, *end_keyword_loc] + end + # def copy: (**params) -> IfNode def copy(**params) IfNode.new( params.fetch(:if_keyword_loc) { if_keyword_loc }, params.fetch(:predicate) { predicate }, @@ -3776,10 +5163,31 @@ # def end_keyword: () -> String? def end_keyword end_keyword_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── if_keyword_loc: #{inspector.location(if_keyword_loc)}\n" + inspector << "├── predicate:\n" + inspector << inspector.child_node(predicate, "│ ") + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (consequent = self.consequent).nil? + inspector << "├── consequent: ∅\n" + else + inspector << "├── consequent:\n" + inspector << consequent.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents an imaginary number literal. # # 1.0i @@ -3802,10 +5210,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [numeric] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [numeric] + end + # def copy: (**params) -> ImaginaryNode def copy(**params) ImaginaryNode.new( params.fetch(:numeric) { numeric }, params.fetch(:location) { location }, @@ -3817,10 +5230,17 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { numeric: numeric, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── numeric:\n" + inspector << inspector.child_node(numeric, " ") + inspector.to_str + end end # Represents the use of the `in` keyword in a case statement. # # case a; in b then c end @@ -3855,10 +5275,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [pattern, statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [pattern, *statements, in_loc, *then_loc] + end + # def copy: (**params) -> InNode def copy(**params) InNode.new( params.fetch(:pattern) { pattern }, params.fetch(:statements) { statements }, @@ -3883,10 +5308,25 @@ # def then: () -> String? def then then_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── pattern:\n" + inspector << inspector.child_node(pattern, "│ ") + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── in_loc: #{inspector.location(in_loc)}\n" + inspector << "└── then_loc: #{inspector.location(then_loc)}\n" + inspector.to_str + end end # Represents the use of the `&&=` operator for assignment to an instance variable. # # @target &&= value @@ -3921,10 +5361,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> InstanceVariableAndWriteNode def copy(**params) InstanceVariableAndWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -3944,10 +5389,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents assigning to an instance variable using an operator that isn't `=`. # # @target += value @@ -3986,10 +5441,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> InstanceVariableOperatorWriteNode def copy(**params) InstanceVariableOperatorWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -4005,10 +5465,21 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, operator: operator, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator: #{operator.inspect}\n" + inspector.to_str + end end # Represents the use of the `||=` operator for assignment to an instance variable. # # @target ||= value @@ -4043,10 +5514,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> InstanceVariableOrWriteNode def copy(**params) InstanceVariableOrWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -4066,10 +5542,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents referencing an instance variable. # # @foo @@ -4092,10 +5578,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> InstanceVariableReadNode def copy(**params) InstanceVariableReadNode.new( params.fetch(:name) { name }, params.fetch(:location) { location }, @@ -4107,10 +5598,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents writing to an instance variable in a context that doesn't have an explicit value. # # @foo, @bar = baz @@ -4133,10 +5630,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> InstanceVariableTargetNode def copy(**params) InstanceVariableTargetNode.new( params.fetch(:name) { name }, params.fetch(:location) { location }, @@ -4148,10 +5650,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents writing to an instance variable. # # @foo = 1 @@ -4186,10 +5694,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, value, operator_loc] + end + # def copy: (**params) -> InstanceVariableWriteNode def copy(**params) InstanceVariableWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -4209,10 +5722,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents an integer number literal. # # 1 @@ -4231,10 +5754,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> IntegerNode def copy(**params) IntegerNode.new( params.fetch(:location) { location }, ) @@ -4245,10 +5773,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents a regular expression literal that contains interpolation. # # /foo #{bar} baz/ @@ -4288,10 +5821,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*parts] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [opening_loc, *parts, closing_loc] + end + # def copy: (**params) -> InterpolatedRegularExpressionNode def copy(**params) InterpolatedRegularExpressionNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:parts) { parts }, @@ -4356,10 +5894,19 @@ # def once?: () -> bool def once? flags.anybits?(RegularExpressionFlags::ONCE) end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── parts: #{inspector.list("#{inspector.prefix}│ ", parts)}" + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "└── flags: #{[("ignore_case" if ignore_case?), ("multi_line" if multi_line?), ("extended" if extended?), ("euc_jp" if euc_jp?), ("ascii_8bit" if ascii_8bit?), ("windows_31j" if windows_31j?), ("utf_8" if utf_8?), ("once" if once?)].compact.join(", ")}\n" + inspector.to_str + end end # Represents a string literal that contains interpolation. # # "foo #{bar} baz" @@ -4395,10 +5942,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*parts] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*opening_loc, *parts, *closing_loc] + end + # def copy: (**params) -> InterpolatedStringNode def copy(**params) InterpolatedStringNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:parts) { parts }, @@ -4422,10 +5974,18 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── parts: #{inspector.list("#{inspector.prefix}│ ", parts)}" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents a symbol literal that contains interpolation. # # :"foo #{bar} baz" @@ -4461,10 +6021,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*parts] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*opening_loc, *parts, *closing_loc] + end + # def copy: (**params) -> InterpolatedSymbolNode def copy(**params) InterpolatedSymbolNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:parts) { parts }, @@ -4488,10 +6053,18 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── parts: #{inspector.list("#{inspector.prefix}│ ", parts)}" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents an xstring literal that contains interpolation. # # `foo #{bar} baz` @@ -4527,10 +6100,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*parts] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [opening_loc, *parts, closing_loc] + end + # def copy: (**params) -> InterpolatedXStringNode def copy(**params) InterpolatedXStringNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:parts) { parts }, @@ -4554,10 +6132,18 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── parts: #{inspector.list("#{inspector.prefix}│ ", parts)}" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents a hash literal without opening and closing braces. # # foo(a: b) @@ -4580,10 +6166,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*elements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*elements] + end + # def copy: (**params) -> KeywordHashNode def copy(**params) KeywordHashNode.new( params.fetch(:elements) { elements }, params.fetch(:location) { location }, @@ -4595,10 +6186,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { elements: elements, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── elements: #{inspector.list("#{inspector.prefix} ", elements)}" + inspector.to_str + end end # Represents a keyword parameter to a method, block, or lambda definition. # # def a(b:) @@ -4607,18 +6204,22 @@ # # def a(b: 1) # ^^^^ # end class KeywordParameterNode < Node + # attr_reader name: Symbol + attr_reader :name + # attr_reader name_loc: Location attr_reader :name_loc # attr_reader value: Node? attr_reader :value - # def initialize: (name_loc: Location, value: Node?, location: Location) -> void - def initialize(name_loc, value, location) + # def initialize: (name: Symbol, name_loc: Location, value: Node?, location: Location) -> void + def initialize(name, name_loc, value, location) + @name = name @name_loc = name_loc @value = value @location = location end @@ -4630,13 +6231,19 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, *value] + end + # def copy: (**params) -> KeywordParameterNode def copy(**params) KeywordParameterNode.new( + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) end @@ -4644,35 +6251,47 @@ # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { name_loc: name_loc, value: value, location: location } + { name: name, name_loc: name_loc, value: value, location: location } end - # def name: () -> String - def name - name_loc.slice + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + if (value = self.value).nil? + inspector << "└── value: ∅\n" + else + inspector << "└── value:\n" + inspector << value.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str end end # Represents a keyword rest parameter to a method, block, or lambda definition. # # def a(**b) # ^^^ # end class KeywordRestParameterNode < Node - # attr_reader operator_loc: Location - attr_reader :operator_loc + # attr_reader name: Symbol? + attr_reader :name # attr_reader name_loc: Location? attr_reader :name_loc - # def initialize: (operator_loc: Location, name_loc: Location?, location: Location) -> void - def initialize(operator_loc, name_loc, location) - @operator_loc = operator_loc + # attr_reader operator_loc: Location + attr_reader :operator_loc + + # def initialize: (name: Symbol?, name_loc: Location?, operator_loc: Location, location: Location) -> void + def initialize(name, name_loc, operator_loc, location) + @name = name @name_loc = name_loc + @operator_loc = operator_loc @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) @@ -4682,35 +6301,44 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*name_loc, operator_loc] + end + # def copy: (**params) -> KeywordRestParameterNode def copy(**params) KeywordRestParameterNode.new( - params.fetch(:operator_loc) { operator_loc }, + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, + params.fetch(:operator_loc) { operator_loc }, params.fetch(:location) { location }, ) end # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { operator_loc: operator_loc, name_loc: name_loc, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, location: location } end # def operator: () -> String def operator operator_loc.slice end - # def name: () -> String? - def name - name_loc&.slice + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str end end # Represents using a lambda literal (not the lambda method call). # @@ -4754,10 +6382,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [parameters, body] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [operator_loc, opening_loc, closing_loc, *parameters, *body] + end + # def copy: (**params) -> LambdaNode def copy(**params) LambdaNode.new( params.fetch(:locals) { locals }, params.fetch(:operator_loc) { operator_loc }, @@ -4789,10 +6422,31 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── locals: #{locals.inspect}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + if (parameters = self.parameters).nil? + inspector << "├── parameters: ∅\n" + else + inspector << "├── parameters:\n" + inspector << parameters.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (body = self.body).nil? + inspector << "└── body: ∅\n" + else + inspector << "└── body:\n" + inspector << body.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str + end end # Represents the use of the `&&=` operator for assignment to a local variable. # # target &&= value @@ -4831,10 +6485,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> LocalVariableAndWriteNode def copy(**params) LocalVariableAndWriteNode.new( params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, @@ -4855,10 +6514,21 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "├── name: #{name.inspect}\n" + inspector << "└── depth: #{depth.inspect}\n" + inspector.to_str + end end # Represents assigning to a local variable using an operator that isn't `=`. # # target += value @@ -4901,10 +6571,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> LocalVariableOperatorWriteNode def copy(**params) LocalVariableOperatorWriteNode.new( params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, @@ -4921,10 +6596,22 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name_loc: name_loc, operator_loc: operator_loc, value: value, name: name, operator: operator, depth: depth, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "├── name: #{name.inspect}\n" + inspector << "├── operator: #{operator.inspect}\n" + inspector << "└── depth: #{depth.inspect}\n" + inspector.to_str + end end # Represents the use of the `||=` operator for assignment to a local variable. # # target ||= value @@ -4963,10 +6650,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> LocalVariableOrWriteNode def copy(**params) LocalVariableOrWriteNode.new( params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, @@ -4987,10 +6679,21 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "├── name: #{name.inspect}\n" + inspector << "└── depth: #{depth.inspect}\n" + inspector.to_str + end end # 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. @@ -5019,10 +6722,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> LocalVariableReadNode def copy(**params) LocalVariableReadNode.new( params.fetch(:name) { name }, params.fetch(:depth) { depth }, @@ -5035,10 +6743,17 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, depth: depth, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "└── depth: #{depth.inspect}\n" + inspector.to_str + end end # Represents writing to a local variable in a context that doesn't have an explicit value. # # foo, bar = baz @@ -5065,10 +6780,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> LocalVariableTargetNode def copy(**params) LocalVariableTargetNode.new( params.fetch(:name) { name }, params.fetch(:depth) { depth }, @@ -5081,10 +6801,17 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, depth: depth, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "└── depth: #{depth.inspect}\n" + inspector.to_str + end end # Represents writing to a local variable. # # foo = 1 @@ -5123,10 +6850,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, value, operator_loc] + end + # def copy: (**params) -> LocalVariableWriteNode def copy(**params) LocalVariableWriteNode.new( params.fetch(:name) { name }, params.fetch(:depth) { depth }, @@ -5147,10 +6879,21 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── depth: #{depth.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents the use of the modifier `in` operator. # # foo in bar @@ -5181,10 +6924,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value, pattern] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [value, pattern, operator_loc] + end + # def copy: (**params) -> MatchPredicateNode def copy(**params) MatchPredicateNode.new( params.fetch(:value) { value }, params.fetch(:pattern) { pattern }, @@ -5203,10 +6951,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "├── pattern:\n" + inspector << inspector.child_node(pattern, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents the use of the `=>` operator. # # foo => bar @@ -5237,10 +6995,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value, pattern] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [value, pattern, operator_loc] + end + # def copy: (**params) -> MatchRequiredNode def copy(**params) MatchRequiredNode.new( params.fetch(:value) { value }, params.fetch(:pattern) { pattern }, @@ -5259,10 +7022,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── value:\n" + inspector << inspector.child_node(value, "│ ") + inspector << "├── pattern:\n" + inspector << inspector.child_node(pattern, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents a node that is missing from the source and results in a syntax # error. class MissingNode < Node @@ -5279,10 +7052,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> MissingNode def copy(**params) MissingNode.new( params.fetch(:location) { location }, ) @@ -5293,10 +7071,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents a module declaration involving the `module` keyword. # # module Foo end @@ -5315,14 +7098,14 @@ attr_reader :body # attr_reader end_keyword_loc: Location attr_reader :end_keyword_loc - # attr_reader name: String + # attr_reader name: Symbol attr_reader :name - # def initialize: (locals: Array[Symbol], module_keyword_loc: Location, constant_path: Node, body: Node?, end_keyword_loc: Location, name: String, location: Location) -> void + # def initialize: (locals: Array[Symbol], module_keyword_loc: Location, constant_path: Node, body: Node?, end_keyword_loc: Location, name: Symbol, location: Location) -> void def initialize(locals, module_keyword_loc, constant_path, body, end_keyword_loc, name, location) @locals = locals @module_keyword_loc = module_keyword_loc @constant_path = constant_path @body = body @@ -5339,10 +7122,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [constant_path, body] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [module_keyword_loc, constant_path, *body, end_keyword_loc] + end + # def copy: (**params) -> ModuleNode def copy(**params) ModuleNode.new( params.fetch(:locals) { locals }, params.fetch(:module_keyword_loc) { module_keyword_loc }, @@ -5369,39 +7157,130 @@ # def end_keyword: () -> String def end_keyword end_keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── locals: #{locals.inspect}\n" + inspector << "├── module_keyword_loc: #{inspector.location(module_keyword_loc)}\n" + inspector << "├── constant_path:\n" + inspector << inspector.child_node(constant_path, "│ ") + if (body = self.body).nil? + inspector << "├── body: ∅\n" + else + inspector << "├── body:\n" + inspector << body.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents a multi-target expression. # # a, b, c = 1, 2, 3 - # ^^^^^^^^^^^^^^^^^ - class MultiWriteNode < Node + # ^^^^^^^ + class MultiTargetNode < Node # attr_reader targets: Array[Node] attr_reader :targets - # attr_reader operator_loc: Location? - attr_reader :operator_loc + # attr_reader lparen_loc: Location? + attr_reader :lparen_loc - # attr_reader value: Node? - attr_reader :value + # attr_reader rparen_loc: Location? + attr_reader :rparen_loc + # def initialize: (targets: Array[Node], lparen_loc: Location?, rparen_loc: Location?, location: Location) -> void + def initialize(targets, lparen_loc, rparen_loc, location) + @targets = targets + @lparen_loc = lparen_loc + @rparen_loc = rparen_loc + @location = location + end + + # def accept: (visitor: Visitor) -> void + def accept(visitor) + visitor.visit_multi_target_node(self) + end + + # def child_nodes: () -> Array[nil | Node] + def child_nodes + [*targets] + end + + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*targets, *lparen_loc, *rparen_loc] + end + + # def copy: (**params) -> MultiTargetNode + def copy(**params) + MultiTargetNode.new( + params.fetch(:targets) { targets }, + params.fetch(:lparen_loc) { lparen_loc }, + params.fetch(:rparen_loc) { rparen_loc }, + params.fetch(:location) { location }, + ) + end + + # def deconstruct: () -> Array[nil | Node] + alias deconstruct child_nodes + + # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] + def deconstruct_keys(keys) + { targets: targets, lparen_loc: lparen_loc, rparen_loc: rparen_loc, location: location } + end + + # def lparen: () -> String? + def lparen + lparen_loc&.slice + end + + # def rparen: () -> String? + def rparen + rparen_loc&.slice + end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── targets: #{inspector.list("#{inspector.prefix}│ ", targets)}" + inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n" + inspector << "└── rparen_loc: #{inspector.location(rparen_loc)}\n" + inspector.to_str + end + end + + # Represents a write to a multi-target expression. + # + # a, b, c = 1, 2, 3 + # ^^^^^^^^^^^^^^^^^ + class MultiWriteNode < Node + # attr_reader targets: Array[Node] + attr_reader :targets + # attr_reader lparen_loc: Location? attr_reader :lparen_loc # attr_reader rparen_loc: Location? attr_reader :rparen_loc - # def initialize: (targets: Array[Node], operator_loc: Location?, value: Node?, lparen_loc: Location?, rparen_loc: Location?, location: Location) -> void - def initialize(targets, operator_loc, value, lparen_loc, rparen_loc, location) + # attr_reader operator_loc: Location + attr_reader :operator_loc + + # attr_reader value: Node + attr_reader :value + + # def initialize: (targets: Array[Node], lparen_loc: Location?, rparen_loc: Location?, operator_loc: Location, value: Node, location: Location) -> void + def initialize(targets, lparen_loc, rparen_loc, operator_loc, value, location) @targets = targets - @operator_loc = operator_loc - @value = value @lparen_loc = lparen_loc @rparen_loc = rparen_loc + @operator_loc = operator_loc + @value = value @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) @@ -5411,44 +7290,60 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*targets, value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*targets, *lparen_loc, *rparen_loc, operator_loc, value] + end + # def copy: (**params) -> MultiWriteNode def copy(**params) MultiWriteNode.new( params.fetch(:targets) { targets }, - params.fetch(:operator_loc) { operator_loc }, - params.fetch(:value) { value }, params.fetch(:lparen_loc) { lparen_loc }, params.fetch(:rparen_loc) { rparen_loc }, + params.fetch(:operator_loc) { operator_loc }, + params.fetch(:value) { value }, params.fetch(:location) { location }, ) end # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { targets: targets, operator_loc: operator_loc, value: value, lparen_loc: lparen_loc, rparen_loc: rparen_loc, location: location } + { targets: targets, lparen_loc: lparen_loc, rparen_loc: rparen_loc, operator_loc: operator_loc, value: value, location: location } end - # def operator: () -> String? - def operator - operator_loc&.slice - end - # def lparen: () -> String? def lparen lparen_loc&.slice end # def rparen: () -> String? def rparen rparen_loc&.slice end + + # def operator: () -> String + def operator + operator_loc.slice + end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── targets: #{inspector.list("#{inspector.prefix}│ ", targets)}" + inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n" + inspector << "├── rparen_loc: #{inspector.location(rparen_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents the use of the `next` keyword. # # next 1 @@ -5475,10 +7370,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [arguments] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*arguments, keyword_loc] + end + # def copy: (**params) -> NextNode def copy(**params) NextNode.new( params.fetch(:arguments) { arguments }, params.fetch(:keyword_loc) { keyword_loc }, @@ -5496,10 +7396,22 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (arguments = self.arguments).nil? + inspector << "├── arguments: ∅\n" + else + inspector << "├── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector.to_str + end end # Represents the use of the `nil` keyword. # # nil @@ -5518,10 +7430,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> NilNode def copy(**params) NilNode.new( params.fetch(:location) { location }, ) @@ -5532,10 +7449,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents the use of `**nil` inside method arguments. # # def a(**nil) @@ -5563,10 +7485,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [operator_loc, keyword_loc] + end + # def copy: (**params) -> NoKeywordsParameterNode def copy(**params) NoKeywordsParameterNode.new( params.fetch(:operator_loc) { operator_loc }, params.fetch(:keyword_loc) { keyword_loc }, @@ -5589,10 +7516,17 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector.to_str + end end # Represents reading a numbered reference to a capture in the previous match. # # $1 @@ -5615,10 +7549,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> NumberedReferenceReadNode def copy(**params) NumberedReferenceReadNode.new( params.fetch(:number) { number }, params.fetch(:location) { location }, @@ -5630,10 +7569,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { number: number, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── number: #{number.inspect}\n" + inspector.to_str + end end # Represents an optional parameter to a method, block, or lambda definition. # # def a(b = 1) @@ -5669,10 +7614,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [value] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [name_loc, operator_loc, value] + end + # def copy: (**params) -> OptionalParameterNode def copy(**params) OptionalParameterNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, @@ -5692,10 +7642,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── value:\n" + inspector << inspector.child_node(value, " ") + inspector.to_str + end end # Represents the use of the `||` operator or the `or` keyword. # # left or right @@ -5726,10 +7686,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [left, right] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [left, right, operator_loc] + end + # def copy: (**params) -> OrNode def copy(**params) OrNode.new( params.fetch(:left) { left }, params.fetch(:right) { right }, @@ -5748,10 +7713,20 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── left:\n" + inspector << inspector.child_node(left, "│ ") + inspector << "├── right:\n" + inspector << inspector.child_node(right, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents the list of parameters on a method, block, or lambda definition. # # def a(b, c, d) @@ -5799,10 +7774,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*requireds, *optionals, *posts, rest, *keywords, keyword_rest, block] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*requireds, *optionals, *posts, *rest, *keywords, *keyword_rest, *block] + end + # def copy: (**params) -> ParametersNode def copy(**params) ParametersNode.new( params.fetch(:requireds) { requireds }, params.fetch(:optionals) { optionals }, @@ -5820,10 +7800,37 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { requireds: requireds, optionals: optionals, posts: posts, rest: rest, keywords: keywords, keyword_rest: keyword_rest, block: block, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── requireds: #{inspector.list("#{inspector.prefix}│ ", requireds)}" + inspector << "├── optionals: #{inspector.list("#{inspector.prefix}│ ", optionals)}" + inspector << "├── posts: #{inspector.list("#{inspector.prefix}│ ", posts)}" + if (rest = self.rest).nil? + inspector << "├── rest: ∅\n" + else + inspector << "├── rest:\n" + inspector << rest.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── keywords: #{inspector.list("#{inspector.prefix}│ ", keywords)}" + if (keyword_rest = self.keyword_rest).nil? + inspector << "├── keyword_rest: ∅\n" + else + inspector << "├── keyword_rest:\n" + inspector << keyword_rest.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (block = self.block).nil? + inspector << "└── block: ∅\n" + else + inspector << "└── block:\n" + inspector << block.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str + end end # Represents a parenthesized expression # # (10 + 34) @@ -5858,10 +7865,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [body] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*body, opening_loc, closing_loc] + end + # def copy: (**params) -> ParenthesesNode def copy(**params) ParenthesesNode.new( params.fetch(:body) { body }, params.fetch(:opening_loc) { opening_loc }, @@ -5885,10 +7897,23 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (body = self.body).nil? + inspector << "├── body: ∅\n" + else + inspector << "├── body:\n" + inspector << body.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents the use of the `^` operator for pinning an expression in a # pattern matching expression. # @@ -5924,10 +7949,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [expression] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [expression, operator_loc, lparen_loc, rparen_loc] + end + # def copy: (**params) -> PinnedExpressionNode def copy(**params) PinnedExpressionNode.new( params.fetch(:expression) { expression }, params.fetch(:operator_loc) { operator_loc }, @@ -5957,10 +7987,20 @@ # def rparen: () -> String def rparen rparen_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── expression:\n" + inspector << inspector.child_node(expression, "│ ") + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n" + inspector << "└── rparen_loc: #{inspector.location(rparen_loc)}\n" + inspector.to_str + end end # Represents the use of the `^` operator for pinning a variable in a pattern # matching expression. # @@ -5988,10 +8028,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [variable] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [variable, operator_loc] + end + # def copy: (**params) -> PinnedVariableNode def copy(**params) PinnedVariableNode.new( params.fetch(:variable) { variable }, params.fetch(:operator_loc) { operator_loc }, @@ -6009,10 +8054,18 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── variable:\n" + inspector << inspector.child_node(variable, "│ ") + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str + end end # Represents the use of the `END` keyword. # # END { foo } @@ -6047,10 +8100,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*statements, keyword_loc, opening_loc, closing_loc] + end + # def copy: (**params) -> PostExecutionNode def copy(**params) PostExecutionNode.new( params.fetch(:statements) { statements }, params.fetch(:keyword_loc) { keyword_loc }, @@ -6080,10 +8138,24 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents the use of the `BEGIN` keyword. # # BEGIN { foo } @@ -6118,10 +8190,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*statements, keyword_loc, opening_loc, closing_loc] + end + # def copy: (**params) -> PreExecutionNode def copy(**params) PreExecutionNode.new( params.fetch(:statements) { statements }, params.fetch(:keyword_loc) { keyword_loc }, @@ -6151,10 +8228,24 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # The top level node of any parse tree. class ProgramNode < Node # attr_reader locals: Array[Symbol] @@ -6178,10 +8269,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [statements] + end + # def copy: (**params) -> ProgramNode def copy(**params) ProgramNode.new( params.fetch(:locals) { locals }, params.fetch(:statements) { statements }, @@ -6194,10 +8290,18 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { locals: locals, statements: statements, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── locals: #{locals.inspect}\n" + inspector << "└── statements:\n" + inspector << inspector.child_node(statements, " ") + inspector.to_str + end end # Represents the use of the `..` or `...` operators. # # 1..2 @@ -6235,10 +8339,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [left, right] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*left, *right, operator_loc] + end + # def copy: (**params) -> RangeNode def copy(**params) RangeNode.new( params.fetch(:left) { left }, params.fetch(:right) { right }, @@ -6263,10 +8372,29 @@ # def exclude_end?: () -> bool def exclude_end? flags.anybits?(RangeFlags::EXCLUDE_END) end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + if (left = self.left).nil? + inspector << "├── left: ∅\n" + else + inspector << "├── left:\n" + inspector << left.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (right = self.right).nil? + inspector << "├── right: ∅\n" + else + inspector << "├── right:\n" + inspector << right.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "└── flags: #{[("exclude_end" if exclude_end?)].compact.join(", ")}\n" + inspector.to_str + end end # Represents a rational number literal. # # 1.0r @@ -6289,10 +8417,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [numeric] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [numeric] + end + # def copy: (**params) -> RationalNode def copy(**params) RationalNode.new( params.fetch(:numeric) { numeric }, params.fetch(:location) { location }, @@ -6304,10 +8437,17 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { numeric: numeric, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── numeric:\n" + inspector << inspector.child_node(numeric, " ") + inspector.to_str + end end # Represents the use of the `redo` keyword. # # redo @@ -6326,10 +8466,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> RedoNode def copy(**params) RedoNode.new( params.fetch(:location) { location }, ) @@ -6340,10 +8485,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents a regular expression literal with no interpolation. # # /foo/i @@ -6382,10 +8532,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [opening_loc, content_loc, closing_loc] + end + # def copy: (**params) -> RegularExpressionNode def copy(**params) RegularExpressionNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:content_loc) { content_loc }, @@ -6456,10 +8611,20 @@ # def once?: () -> bool def once? flags.anybits?(RegularExpressionFlags::ONCE) end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── content_loc: #{inspector.location(content_loc)}\n" + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "├── unescaped: #{unescaped.inspect}\n" + inspector << "└── flags: #{[("ignore_case" if ignore_case?), ("multi_line" if multi_line?), ("extended" if extended?), ("euc_jp" if euc_jp?), ("ascii_8bit" if ascii_8bit?), ("windows_31j" if windows_31j?), ("utf_8" if utf_8?), ("once" if once?)].compact.join(", ")}\n" + inspector.to_str + end end # Represents a destructured required parameter node. # # def foo((bar, baz)) @@ -6491,10 +8656,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*parameters] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*parameters, opening_loc, closing_loc] + end + # def copy: (**params) -> RequiredDestructuredParameterNode def copy(**params) RequiredDestructuredParameterNode.new( params.fetch(:parameters) { parameters }, params.fetch(:opening_loc) { opening_loc }, @@ -6518,10 +8688,18 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── parameters: #{inspector.list("#{inspector.prefix}│ ", parameters)}" + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" + inspector.to_str + end end # Represents a required parameter to a method, block, or lambda definition. # # def a(b) @@ -6545,10 +8723,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> RequiredParameterNode def copy(**params) RequiredParameterNode.new( params.fetch(:name) { name }, params.fetch(:location) { location }, @@ -6560,10 +8743,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { name: name, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── name: #{name.inspect}\n" + inspector.to_str + end end # Represents an expression modified with a rescue. # # foo rescue nil @@ -6598,10 +8787,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [expression, rescue_expression] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [expression, keyword_loc, rescue_expression] + end + # def copy: (**params) -> RescueModifierNode def copy(**params) RescueModifierNode.new( params.fetch(:expression) { expression }, params.fetch(:keyword_loc) { keyword_loc }, @@ -6620,10 +8814,20 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── expression:\n" + inspector << inspector.child_node(expression, "│ ") + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "└── rescue_expression:\n" + inspector << inspector.child_node(rescue_expression, " ") + inspector.to_str + end end # Represents a rescue statement. # # begin @@ -6672,10 +8876,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*exceptions, reference, statements, consequent] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [keyword_loc, *exceptions, *operator_loc, *reference, *statements, *consequent] + end + # def copy: (**params) -> RescueNode def copy(**params) RescueNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:exceptions) { exceptions }, @@ -6702,28 +8911,58 @@ # def operator: () -> String? def operator operator_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── exceptions: #{inspector.list("#{inspector.prefix}│ ", exceptions)}" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + if (reference = self.reference).nil? + inspector << "├── reference: ∅\n" + else + inspector << "├── reference:\n" + inspector << reference.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (consequent = self.consequent).nil? + inspector << "└── consequent: ∅\n" + else + inspector << "└── consequent:\n" + inspector << consequent.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str + end end # Represents a rest parameter to a method, block, or lambda definition. # # def a(*b) # ^^ # end class RestParameterNode < Node - # attr_reader operator_loc: Location - attr_reader :operator_loc + # attr_reader name: Symbol? + attr_reader :name # attr_reader name_loc: Location? attr_reader :name_loc - # def initialize: (operator_loc: Location, name_loc: Location?, location: Location) -> void - def initialize(operator_loc, name_loc, location) - @operator_loc = operator_loc + # attr_reader operator_loc: Location + attr_reader :operator_loc + + # def initialize: (name: Symbol?, name_loc: Location?, operator_loc: Location, location: Location) -> void + def initialize(name, name_loc, operator_loc, location) + @name = name @name_loc = name_loc + @operator_loc = operator_loc @location = location end # def accept: (visitor: Visitor) -> void def accept(visitor) @@ -6733,35 +8972,44 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*name_loc, operator_loc] + end + # def copy: (**params) -> RestParameterNode def copy(**params) RestParameterNode.new( - params.fetch(:operator_loc) { operator_loc }, + params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, + params.fetch(:operator_loc) { operator_loc }, params.fetch(:location) { location }, ) end # def deconstruct: () -> Array[nil | Node] alias deconstruct child_nodes # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) - { operator_loc: operator_loc, name_loc: name_loc, location: location } + { name: name, name_loc: name_loc, operator_loc: operator_loc, location: location } end # def operator: () -> String def operator operator_loc.slice end - # def name: () -> String? - def name - name_loc&.slice + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── name: #{name.inspect}\n" + inspector << "├── name_loc: #{inspector.location(name_loc)}\n" + inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" + inspector.to_str end end # Represents the use of the `retry` keyword. # @@ -6781,10 +9029,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> RetryNode def copy(**params) RetryNode.new( params.fetch(:location) { location }, ) @@ -6795,10 +9048,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents the use of the `return` keyword. # # return 1 @@ -6825,10 +9083,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [arguments] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [keyword_loc, *arguments] + end + # def copy: (**params) -> ReturnNode def copy(**params) ReturnNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:arguments) { arguments }, @@ -6846,10 +9109,22 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + if (arguments = self.arguments).nil? + inspector << "└── arguments: ∅\n" + else + inspector << "└── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str + end end # Represents the `self` keyword. # # self @@ -6868,10 +9143,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> SelfNode def copy(**params) SelfNode.new( params.fetch(:location) { location }, ) @@ -6882,10 +9162,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents a singleton class declaration involving the `class` keyword. # # class << self end @@ -6928,10 +9213,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [expression, body] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [class_keyword_loc, operator_loc, expression, *body, end_keyword_loc] + end + # def copy: (**params) -> SingletonClassNode def copy(**params) SingletonClassNode.new( params.fetch(:locals) { locals }, params.fetch(:class_keyword_loc) { class_keyword_loc }, @@ -6963,10 +9253,27 @@ # def end_keyword: () -> String def end_keyword end_keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── locals: #{locals.inspect}\n" + inspector << "├── class_keyword_loc: #{inspector.location(class_keyword_loc)}\n" + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + inspector << "├── expression:\n" + inspector << inspector.child_node(expression, "│ ") + if (body = self.body).nil? + inspector << "├── body: ∅\n" + else + inspector << "├── body:\n" + inspector << body.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents the use of the `__ENCODING__` keyword. # # __ENCODING__ @@ -6985,10 +9292,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> SourceEncodingNode def copy(**params) SourceEncodingNode.new( params.fetch(:location) { location }, ) @@ -6999,10 +9311,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents the use of the `__FILE__` keyword. # # __FILE__ @@ -7025,10 +9342,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> SourceFileNode def copy(**params) SourceFileNode.new( params.fetch(:filepath) { filepath }, params.fetch(:location) { location }, @@ -7040,10 +9362,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { filepath: filepath, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── filepath: #{filepath.inspect}\n" + inspector.to_str + end end # Represents the use of the `__LINE__` keyword. # # __LINE__ @@ -7062,10 +9390,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> SourceLineNode def copy(**params) SourceLineNode.new( params.fetch(:location) { location }, ) @@ -7076,10 +9409,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents the use of the splat operator. # # [*a] @@ -7106,10 +9444,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [expression] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [operator_loc, *expression] + end + # def copy: (**params) -> SplatNode def copy(**params) SplatNode.new( params.fetch(:operator_loc) { operator_loc }, params.fetch(:expression) { expression }, @@ -7127,10 +9470,22 @@ # def operator: () -> String def operator operator_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" + if (expression = self.expression).nil? + inspector << "└── expression: ∅\n" + else + inspector << "└── expression:\n" + inspector << expression.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str + end end # Represents a set of statements contained within some scope. # # foo; bar; baz @@ -7153,10 +9508,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*body] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*body] + end + # def copy: (**params) -> StatementsNode def copy(**params) StatementsNode.new( params.fetch(:body) { body }, params.fetch(:location) { location }, @@ -7168,10 +9528,16 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { body: body, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "└── body: #{inspector.list("#{inspector.prefix} ", body)}" + inspector.to_str + end end # Represents the use of compile-time string concatenation. # # "foo" "bar" @@ -7198,10 +9564,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [left, right] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [left, right] + end + # def copy: (**params) -> StringConcatNode def copy(**params) StringConcatNode.new( params.fetch(:left) { left }, params.fetch(:right) { right }, @@ -7214,10 +9585,19 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { left: left, right: right, location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── left:\n" + inspector << inspector.child_node(left, "│ ") + inspector << "└── right:\n" + inspector << inspector.child_node(right, " ") + inspector.to_str + end end # Represents a string literal, a string contained within a `%w` list, or # plain string content within an interpolated string. # @@ -7259,10 +9639,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*opening_loc, content_loc, *closing_loc] + end + # def copy: (**params) -> StringNode def copy(**params) StringNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:content_loc) { content_loc }, @@ -7292,10 +9677,19 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── content_loc: #{inspector.location(content_loc)}\n" + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "└── unescaped: #{unescaped.inspect}\n" + inspector.to_str + end end # Represents the use of the `super` keyword with parentheses or arguments. # # super() @@ -7337,10 +9731,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [arguments, block] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [keyword_loc, *lparen_loc, *arguments, *rparen_loc, *block] + end + # def copy: (**params) -> SuperNode def copy(**params) SuperNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:lparen_loc) { lparen_loc }, @@ -7371,10 +9770,30 @@ # def rparen: () -> String? def rparen rparen_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n" + if (arguments = self.arguments).nil? + inspector << "├── arguments: ∅\n" + else + inspector << "├── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "├── rparen_loc: #{inspector.location(rparen_loc)}\n" + if (block = self.block).nil? + inspector << "└── block: ∅\n" + else + inspector << "└── block:\n" + inspector << block.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str + end end # Represents a symbol literal or a symbol contained within a `%i` list. # # :foo @@ -7412,10 +9831,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*opening_loc, *value_loc, *closing_loc] + end + # def copy: (**params) -> SymbolNode def copy(**params) SymbolNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:value_loc) { value_loc }, @@ -7445,10 +9869,19 @@ # def closing: () -> String? def closing closing_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── value_loc: #{inspector.location(value_loc)}\n" + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "└── unescaped: #{unescaped.inspect}\n" + inspector.to_str + end end # Represents the use of the literal `true` keyword. # # true @@ -7467,10 +9900,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [] + end + # def copy: (**params) -> TrueNode def copy(**params) TrueNode.new( params.fetch(:location) { location }, ) @@ -7481,10 +9919,15 @@ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location] def deconstruct_keys(keys) { location: location } end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector.to_str + end end # Represents the use of the `undef` keyword. # # undef :foo, :bar, :baz @@ -7511,10 +9954,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*names] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [*names, keyword_loc] + end + # def copy: (**params) -> UndefNode def copy(**params) UndefNode.new( params.fetch(:names) { names }, params.fetch(:keyword_loc) { keyword_loc }, @@ -7532,10 +9980,17 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── names: #{inspector.list("#{inspector.prefix}│ ", names)}" + inspector << "└── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector.to_str + end end # Represents the use of the `unless` keyword, either in the block form or the modifier form. # # bar unless foo @@ -7581,10 +10036,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [predicate, statements, consequent] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [keyword_loc, predicate, *statements, *consequent, *end_keyword_loc] + end + # def copy: (**params) -> UnlessNode def copy(**params) UnlessNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:predicate) { predicate }, @@ -7610,10 +10070,31 @@ # def end_keyword: () -> String? def end_keyword end_keyword_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── predicate:\n" + inspector << inspector.child_node(predicate, "│ ") + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + if (consequent = self.consequent).nil? + inspector << "├── consequent: ∅\n" + else + inspector << "├── consequent:\n" + inspector << consequent.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" + inspector.to_str + end end # Represents the use of the `until` keyword, either in the block form or the modifier form. # # bar until foo @@ -7659,10 +10140,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [predicate, statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [keyword_loc, *closing_loc, predicate, *statements] + end + # def copy: (**params) -> UntilNode def copy(**params) UntilNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:closing_loc) { closing_loc }, @@ -7693,10 +10179,26 @@ # def begin_modifier?: () -> bool def begin_modifier? flags.anybits?(LoopFlags::BEGIN_MODIFIER) end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "├── predicate:\n" + inspector << inspector.child_node(predicate, "│ ") + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── flags: #{[("begin_modifier" if begin_modifier?)].compact.join(", ")}\n" + inspector.to_str + end end # Represents the use of the `when` keyword within a case statement. # # case true @@ -7729,10 +10231,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [*conditions, statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [keyword_loc, *conditions, *statements] + end + # def copy: (**params) -> WhenNode def copy(**params) WhenNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:conditions) { conditions }, @@ -7751,10 +10258,23 @@ # def keyword: () -> String def keyword keyword_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── conditions: #{inspector.list("#{inspector.prefix}│ ", conditions)}" + if (statements = self.statements).nil? + inspector << "└── statements: ∅\n" + else + inspector << "└── statements:\n" + inspector << statements.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) + end + inspector.to_str + end end # Represents the use of the `while` keyword, either in the block form or the modifier form. # # bar while foo @@ -7800,10 +10320,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [predicate, statements] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [keyword_loc, *closing_loc, predicate, *statements] + end + # def copy: (**params) -> WhileNode def copy(**params) WhileNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:closing_loc) { closing_loc }, @@ -7834,10 +10359,26 @@ # def begin_modifier?: () -> bool def begin_modifier? flags.anybits?(LoopFlags::BEGIN_MODIFIER) end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "├── predicate:\n" + inspector << inspector.child_node(predicate, "│ ") + if (statements = self.statements).nil? + inspector << "├── statements: ∅\n" + else + inspector << "├── statements:\n" + inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── flags: #{[("begin_modifier" if begin_modifier?)].compact.join(", ")}\n" + inspector.to_str + end end # Represents an xstring literal with no interpolation. # # `foo` @@ -7872,10 +10413,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [opening_loc, content_loc, closing_loc] + end + # def copy: (**params) -> XStringNode def copy(**params) XStringNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:content_loc) { content_loc }, @@ -7905,10 +10451,19 @@ # def closing: () -> String def closing closing_loc.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" + inspector << "├── content_loc: #{inspector.location(content_loc)}\n" + inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" + inspector << "└── unescaped: #{unescaped.inspect}\n" + inspector.to_str + end end # Represents the use of the `yield` keyword. # # yield 1 @@ -7943,10 +10498,15 @@ # def child_nodes: () -> Array[nil | Node] def child_nodes [arguments] end + # def comment_targets: () -> Array[Node | Location] + def comment_targets + [keyword_loc, *lparen_loc, *arguments, *rparen_loc] + end + # def copy: (**params) -> YieldNode def copy(**params) YieldNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:lparen_loc) { lparen_loc }, @@ -7976,10 +10536,24 @@ # def rparen: () -> String? def rparen rparen_loc&.slice end + + def inspect(inspector = NodeInspector.new) + inspector << inspector.header(self) + inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" + inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n" + if (arguments = self.arguments).nil? + inspector << "├── arguments: ∅\n" + else + inspector << "├── arguments:\n" + inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) + end + inspector << "└── rparen_loc: #{inspector.location(rparen_loc)}\n" + inspector.to_str + end end module CallNodeFlags # &. operator SAFE_NAVIGATION = 1 << 0 @@ -8056,10 +10630,13 @@ alias visit_begin_node visit_child_nodes # Visit a BlockArgumentNode node alias visit_block_argument_node visit_child_nodes + # Visit a BlockLocalVariableNode node + alias visit_block_local_variable_node visit_child_nodes + # Visit a BlockNode node alias visit_block_node visit_child_nodes # Visit a BlockParameterNode node alias visit_block_parameter_node visit_child_nodes @@ -8068,22 +10645,22 @@ alias visit_block_parameters_node visit_child_nodes # Visit a BreakNode node alias visit_break_node visit_child_nodes + # Visit a CallAndWriteNode node + alias visit_call_and_write_node visit_child_nodes + # Visit a CallNode node alias visit_call_node visit_child_nodes - # Visit a CallOperatorAndWriteNode node - alias visit_call_operator_and_write_node visit_child_nodes - - # Visit a CallOperatorOrWriteNode node - alias visit_call_operator_or_write_node visit_child_nodes - # Visit a CallOperatorWriteNode node alias visit_call_operator_write_node visit_child_nodes + # Visit a CallOrWriteNode node + alias visit_call_or_write_node visit_child_nodes + # Visit a CapturePatternNode node alias visit_capture_pattern_node visit_child_nodes # Visit a CaseNode node alias visit_case_node visit_child_nodes @@ -8293,10 +10870,13 @@ alias visit_missing_node visit_child_nodes # Visit a ModuleNode node alias visit_module_node visit_child_nodes + # Visit a MultiTargetNode node + alias visit_multi_target_node visit_child_nodes + # Visit a MultiWriteNode node alias visit_multi_write_node visit_child_nodes # Visit a NextNode node alias visit_next_node visit_child_nodes @@ -8489,18 +11069,23 @@ # Create a new BlockArgumentNode node def BlockArgumentNode(expression, operator_loc, location = Location()) BlockArgumentNode.new(expression, operator_loc, location) end + # Create a new BlockLocalVariableNode node + def BlockLocalVariableNode(name, location = Location()) + BlockLocalVariableNode.new(name, location) + end + # Create a new BlockNode node def BlockNode(locals, parameters, body, opening_loc, closing_loc, location = Location()) BlockNode.new(locals, parameters, body, opening_loc, closing_loc, location) end # Create a new BlockParameterNode node - def BlockParameterNode(name_loc, operator_loc, location = Location()) - BlockParameterNode.new(name_loc, operator_loc, location) + def BlockParameterNode(name, name_loc, operator_loc, location = Location()) + BlockParameterNode.new(name, name_loc, operator_loc, location) end # Create a new BlockParametersNode node def BlockParametersNode(parameters, locals, opening_loc, closing_loc, location = Location()) BlockParametersNode.new(parameters, locals, opening_loc, closing_loc, location) @@ -8509,28 +11094,28 @@ # Create a new BreakNode node def BreakNode(arguments, keyword_loc, location = Location()) BreakNode.new(arguments, keyword_loc, location) end - # Create a new CallNode node - def CallNode(receiver, operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location = Location()) - CallNode.new(receiver, operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location) + # Create a new CallAndWriteNode node + def CallAndWriteNode(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location = Location()) + CallAndWriteNode.new(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location) end - # Create a new CallOperatorAndWriteNode node - def CallOperatorAndWriteNode(target, operator_loc, value, location = Location()) - CallOperatorAndWriteNode.new(target, operator_loc, value, location) + # Create a new CallNode node + def CallNode(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location = Location()) + CallNode.new(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location) end - # Create a new CallOperatorOrWriteNode node - def CallOperatorOrWriteNode(target, value, operator_loc, location = Location()) - CallOperatorOrWriteNode.new(target, value, operator_loc, location) + # Create a new CallOperatorWriteNode node + def CallOperatorWriteNode(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator, operator_loc, value, location = Location()) + CallOperatorWriteNode.new(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator, operator_loc, value, location) end - # Create a new CallOperatorWriteNode node - def CallOperatorWriteNode(target, operator_loc, value, operator, location = Location()) - CallOperatorWriteNode.new(target, operator_loc, value, operator, location) + # Create a new CallOrWriteNode node + def CallOrWriteNode(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location = Location()) + CallOrWriteNode.new(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location) end # Create a new CapturePatternNode node def CapturePatternNode(value, target, operator_loc, location = Location()) CapturePatternNode.new(value, target, operator_loc, location) @@ -8575,22 +11160,22 @@ def ClassVariableWriteNode(name, name_loc, value, operator_loc, location = Location()) ClassVariableWriteNode.new(name, name_loc, value, operator_loc, location) end # Create a new ConstantAndWriteNode node - def ConstantAndWriteNode(name_loc, operator_loc, value, location = Location()) - ConstantAndWriteNode.new(name_loc, operator_loc, value, location) + def ConstantAndWriteNode(name, name_loc, operator_loc, value, location = Location()) + ConstantAndWriteNode.new(name, name_loc, operator_loc, value, location) end # Create a new ConstantOperatorWriteNode node - def ConstantOperatorWriteNode(name_loc, operator_loc, value, operator, location = Location()) - ConstantOperatorWriteNode.new(name_loc, operator_loc, value, operator, location) + def ConstantOperatorWriteNode(name, name_loc, operator_loc, value, operator, location = Location()) + ConstantOperatorWriteNode.new(name, name_loc, operator_loc, value, operator, location) end # Create a new ConstantOrWriteNode node - def ConstantOrWriteNode(name_loc, operator_loc, value, location = Location()) - ConstantOrWriteNode.new(name_loc, operator_loc, value, location) + def ConstantOrWriteNode(name, name_loc, operator_loc, value, location = Location()) + ConstantOrWriteNode.new(name, name_loc, operator_loc, value, location) end # Create a new ConstantPathAndWriteNode node def ConstantPathAndWriteNode(target, operator_loc, value, location = Location()) ConstantPathAndWriteNode.new(target, operator_loc, value, location) @@ -8620,27 +11205,27 @@ def ConstantPathWriteNode(target, operator_loc, value, location = Location()) ConstantPathWriteNode.new(target, operator_loc, value, location) end # Create a new ConstantReadNode node - def ConstantReadNode(location = Location()) - ConstantReadNode.new(location) + def ConstantReadNode(name, location = Location()) + ConstantReadNode.new(name, location) end # Create a new ConstantTargetNode node - def ConstantTargetNode(location = Location()) - ConstantTargetNode.new(location) + def ConstantTargetNode(name, location = Location()) + ConstantTargetNode.new(name, location) end # Create a new ConstantWriteNode node - def ConstantWriteNode(name_loc, value, operator_loc, location = Location()) - ConstantWriteNode.new(name_loc, value, operator_loc, location) + def ConstantWriteNode(name, name_loc, value, operator_loc, location = Location()) + ConstantWriteNode.new(name, name_loc, value, operator_loc, location) end # Create a new DefNode node - def DefNode(name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location = Location()) - DefNode.new(name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) + def DefNode(name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location = Location()) + DefNode.new(name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc, location) end # Create a new DefinedNode node def DefinedNode(lparen_loc, value, rparen_loc, keyword_loc, location = Location()) DefinedNode.new(lparen_loc, value, rparen_loc, keyword_loc, location) @@ -8705,37 +11290,37 @@ def ForwardingSuperNode(block, location = Location()) ForwardingSuperNode.new(block, location) end # Create a new GlobalVariableAndWriteNode node - def GlobalVariableAndWriteNode(name_loc, operator_loc, value, location = Location()) - GlobalVariableAndWriteNode.new(name_loc, operator_loc, value, location) + def GlobalVariableAndWriteNode(name, name_loc, operator_loc, value, location = Location()) + GlobalVariableAndWriteNode.new(name, name_loc, operator_loc, value, location) end # Create a new GlobalVariableOperatorWriteNode node - def GlobalVariableOperatorWriteNode(name_loc, operator_loc, value, operator, location = Location()) - GlobalVariableOperatorWriteNode.new(name_loc, operator_loc, value, operator, location) + def GlobalVariableOperatorWriteNode(name, name_loc, operator_loc, value, operator, location = Location()) + GlobalVariableOperatorWriteNode.new(name, name_loc, operator_loc, value, operator, location) end # Create a new GlobalVariableOrWriteNode node - def GlobalVariableOrWriteNode(name_loc, operator_loc, value, location = Location()) - GlobalVariableOrWriteNode.new(name_loc, operator_loc, value, location) + def GlobalVariableOrWriteNode(name, name_loc, operator_loc, value, location = Location()) + GlobalVariableOrWriteNode.new(name, name_loc, operator_loc, value, location) end # Create a new GlobalVariableReadNode node - def GlobalVariableReadNode(location = Location()) - GlobalVariableReadNode.new(location) + def GlobalVariableReadNode(name, location = Location()) + GlobalVariableReadNode.new(name, location) end # Create a new GlobalVariableTargetNode node - def GlobalVariableTargetNode(location = Location()) - GlobalVariableTargetNode.new(location) + def GlobalVariableTargetNode(name, location = Location()) + GlobalVariableTargetNode.new(name, location) end # Create a new GlobalVariableWriteNode node - def GlobalVariableWriteNode(name_loc, value, operator_loc, location = Location()) - GlobalVariableWriteNode.new(name_loc, value, operator_loc, location) + def GlobalVariableWriteNode(name, name_loc, value, operator_loc, location = Location()) + GlobalVariableWriteNode.new(name, name_loc, value, operator_loc, location) end # Create a new HashNode node def HashNode(opening_loc, elements, closing_loc, location = Location()) HashNode.new(opening_loc, elements, closing_loc, location) @@ -8820,17 +11405,17 @@ def KeywordHashNode(elements, location = Location()) KeywordHashNode.new(elements, location) end # Create a new KeywordParameterNode node - def KeywordParameterNode(name_loc, value, location = Location()) - KeywordParameterNode.new(name_loc, value, location) + def KeywordParameterNode(name, name_loc, value, location = Location()) + KeywordParameterNode.new(name, name_loc, value, location) end # Create a new KeywordRestParameterNode node - def KeywordRestParameterNode(operator_loc, name_loc, location = Location()) - KeywordRestParameterNode.new(operator_loc, name_loc, location) + def KeywordRestParameterNode(name, name_loc, operator_loc, location = Location()) + KeywordRestParameterNode.new(name, name_loc, operator_loc, location) end # Create a new LambdaNode node def LambdaNode(locals, operator_loc, opening_loc, closing_loc, parameters, body, location = Location()) LambdaNode.new(locals, operator_loc, opening_loc, closing_loc, parameters, body, location) @@ -8884,13 +11469,18 @@ # Create a new ModuleNode node def ModuleNode(locals, module_keyword_loc, constant_path, body, end_keyword_loc, name, location = Location()) ModuleNode.new(locals, module_keyword_loc, constant_path, body, end_keyword_loc, name, location) end + # Create a new MultiTargetNode node + def MultiTargetNode(targets, lparen_loc, rparen_loc, location = Location()) + MultiTargetNode.new(targets, lparen_loc, rparen_loc, location) + end + # Create a new MultiWriteNode node - def MultiWriteNode(targets, operator_loc, value, lparen_loc, rparen_loc, location = Location()) - MultiWriteNode.new(targets, operator_loc, value, lparen_loc, rparen_loc, location) + def MultiWriteNode(targets, lparen_loc, rparen_loc, operator_loc, value, location = Location()) + MultiWriteNode.new(targets, lparen_loc, rparen_loc, operator_loc, value, location) end # Create a new NextNode node def NextNode(arguments, keyword_loc, location = Location()) NextNode.new(arguments, keyword_loc, location) @@ -8995,11 +11585,11 @@ def RescueNode(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location = Location()) RescueNode.new(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location) end # Create a new RestParameterNode node - def RestParameterNode(operator_loc, name_loc, location = Location()) - RestParameterNode.new(operator_loc, name_loc, location) + def RestParameterNode(name, name_loc, operator_loc, location = Location()) + RestParameterNode.new(name, name_loc, operator_loc, location) end # Create a new RetryNode node def RetryNode(location = Location()) RetryNode.new(location)