Class: Prism::ForNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ForNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents the use of the ‘for` keyword.
for i in a end
^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
The collection to iterate over.
-
#index ⇒ Object
readonly
The index expression for ‘for` loops.
-
#statements ⇒ Object
readonly
Represents the body of statements to execute for each iteration of the loop.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, index: self.index, collection: self.collection, statements: self.statements, for_keyword_loc: self.for_keyword_loc, in_keyword_loc: self.in_keyword_loc, do_keyword_loc: self.do_keyword_loc, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?index: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode, ?collection: Prism::node, ?statements: StatementsNode?, ?for_keyword_loc: Location, ?in_keyword_loc: Location, ?do_keyword_loc: Location?, ?end_keyword_loc: Location) -> ForNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, index: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode, collection: Prism::node, statements: StatementsNode?, for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: Location?, end_keyword_loc: Location }.
-
#do_keyword ⇒ Object
def do_keyword: () -> String?.
-
#do_keyword_loc ⇒ Object
The location of the ‘do` keyword, if present.
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
The location of the ‘end` keyword.
-
#for_keyword ⇒ Object
def for_keyword: () -> String.
-
#for_keyword_loc ⇒ Object
The location of the ‘for` keyword.
-
#in_keyword ⇒ Object
def in_keyword: () -> String.
-
#in_keyword_loc ⇒ Object
The location of the ‘in` keyword.
-
#initialize(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc) ⇒ ForNode
constructor
Initialize a new ForNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#save_do_keyword_loc(repository) ⇒ Object
Save the do_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_for_keyword_loc(repository) ⇒ Object
Save the for_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_in_keyword_loc(repository) ⇒ Object
Save the in_keyword_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc) ⇒ ForNode
Initialize a new ForNode node.
7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 |
# File 'lib/prism/node.rb', line 7210 def initialize(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @index = index @collection = collection @statements = statements @for_keyword_loc = for_keyword_loc @in_keyword_loc = in_keyword_loc @do_keyword_loc = do_keyword_loc @end_keyword_loc = end_keyword_loc end |
Instance Attribute Details
#collection ⇒ Object (readonly)
The collection to iterate over.
for i in a end
^
7271 7272 7273 |
# File 'lib/prism/node.rb', line 7271 def collection @collection end |
#index ⇒ Object (readonly)
The index expression for ‘for` loops.
for i in a end
^
7265 7266 7267 |
# File 'lib/prism/node.rb', line 7265 def index @index end |
#statements ⇒ Object (readonly)
Represents the body of statements to execute for each iteration of the loop.
for i in a
foo(i)
^^^^^^
end
7279 7280 7281 |
# File 'lib/prism/node.rb', line 7279 def statements @statements end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
7382 7383 7384 |
# File 'lib/prism/node.rb', line 7382 def self.type :for_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 |
# File 'lib/prism/node.rb', line 7388 def ===(other) other.is_a?(ForNode) && (index === other.index) && (collection === other.collection) && (statements === other.statements) && (for_keyword_loc.nil? == other.for_keyword_loc.nil?) && (in_keyword_loc.nil? == other.in_keyword_loc.nil?) && (do_keyword_loc.nil? == other.do_keyword_loc.nil?) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
7225 7226 7227 |
# File 'lib/prism/node.rb', line 7225 def accept(visitor) visitor.visit_for_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
7230 7231 7232 |
# File 'lib/prism/node.rb', line 7230 def child_nodes [index, collection, statements] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
7244 7245 7246 |
# File 'lib/prism/node.rb', line 7244 def comment_targets [index, collection, *statements, for_keyword_loc, in_keyword_loc, *do_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
7235 7236 7237 7238 7239 7240 7241 |
# File 'lib/prism/node.rb', line 7235 def compact_child_nodes compact = [] #: Array[Prism::node] compact << index compact << collection compact << statements if statements compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, index: self.index, collection: self.collection, statements: self.statements, for_keyword_loc: self.for_keyword_loc, in_keyword_loc: self.in_keyword_loc, do_keyword_loc: self.do_keyword_loc, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?index: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode, ?collection: Prism::node, ?statements: StatementsNode?, ?for_keyword_loc: Location, ?in_keyword_loc: Location, ?do_keyword_loc: Location?, ?end_keyword_loc: Location) -> ForNode
7249 7250 7251 |
# File 'lib/prism/node.rb', line 7249 def copy(node_id: self.node_id, location: self.location, flags: self.flags, index: self.index, collection: self.collection, statements: self.statements, for_keyword_loc: self.for_keyword_loc, in_keyword_loc: self.in_keyword_loc, do_keyword_loc: self.do_keyword_loc, end_keyword_loc: self.end_keyword_loc) ForNode.new(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, index: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode, collection: Prism::node, statements: StatementsNode?, for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: Location?, end_keyword_loc: Location }
7257 7258 7259 |
# File 'lib/prism/node.rb', line 7257 def deconstruct_keys(keys) { node_id: node_id, location: location, index: index, collection: collection, statements: statements, for_keyword_loc: for_keyword_loc, in_keyword_loc: in_keyword_loc, do_keyword_loc: do_keyword_loc, end_keyword_loc: end_keyword_loc } end |
#do_keyword ⇒ Object
def do_keyword: () -> String?
7362 7363 7364 |
# File 'lib/prism/node.rb', line 7362 def do_keyword do_keyword_loc&.slice end |
#do_keyword_loc ⇒ Object
The location of the ‘do` keyword, if present.
for i in a do end
^^
7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 |
# File 'lib/prism/node.rb', line 7317 def do_keyword_loc location = @do_keyword_loc case location when nil nil when Location location else @do_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#end_keyword ⇒ Object
def end_keyword: () -> String
7367 7368 7369 |
# File 'lib/prism/node.rb', line 7367 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
The location of the ‘end` keyword.
for i in a end
^^^
7339 7340 7341 7342 7343 |
# File 'lib/prism/node.rb', line 7339 def end_keyword_loc location = @end_keyword_loc return location if location.is_a?(Location) @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#for_keyword ⇒ Object
def for_keyword: () -> String
7352 7353 7354 |
# File 'lib/prism/node.rb', line 7352 def for_keyword for_keyword_loc.slice end |
#for_keyword_loc ⇒ Object
The location of the ‘for` keyword.
for i in a end
^^^
7285 7286 7287 7288 7289 |
# File 'lib/prism/node.rb', line 7285 def for_keyword_loc location = @for_keyword_loc return location if location.is_a?(Location) @for_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#in_keyword ⇒ Object
def in_keyword: () -> String
7357 7358 7359 |
# File 'lib/prism/node.rb', line 7357 def in_keyword in_keyword_loc.slice end |
#in_keyword_loc ⇒ Object
The location of the ‘in` keyword.
for i in a end
^^
7301 7302 7303 7304 7305 |
# File 'lib/prism/node.rb', line 7301 def in_keyword_loc location = @in_keyword_loc return location if location.is_a?(Location) @in_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#inspect ⇒ Object
def inspect -> String
7372 7373 7374 |
# File 'lib/prism/node.rb', line 7372 def inspect InspectVisitor.compose(self) end |
#save_do_keyword_loc(repository) ⇒ Object
Save the do_keyword_loc location using the given saved source so that it can be retrieved later.
7331 7332 7333 |
# File 'lib/prism/node.rb', line 7331 def save_do_keyword_loc(repository) repository.enter(node_id, :do_keyword_loc) unless @do_keyword_loc.nil? end |
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
7347 7348 7349 |
# File 'lib/prism/node.rb', line 7347 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) end |
#save_for_keyword_loc(repository) ⇒ Object
Save the for_keyword_loc location using the given saved source so that it can be retrieved later.
7293 7294 7295 |
# File 'lib/prism/node.rb', line 7293 def save_for_keyword_loc(repository) repository.enter(node_id, :for_keyword_loc) end |
#save_in_keyword_loc(repository) ⇒ Object
Save the in_keyword_loc location using the given saved source so that it can be retrieved later.
7309 7310 7311 |
# File 'lib/prism/node.rb', line 7309 def save_in_keyword_loc(repository) repository.enter(node_id, :in_keyword_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
7377 7378 7379 |
# File 'lib/prism/node.rb', line 7377 def type :for_node end |