Class: YARP::ForNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents the use of the ‘for` keyword.

for i in a end
^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc, location) ⇒ ForNode

def initialize: (index: Node, collection: Node, statements: StatementsNode?, for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: Location?, end_keyword_loc: Location, location: Location) -> void



4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
# File 'lib/yarp/node.rb', line 4265

def initialize(index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc, 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
  @location = location
end

Instance Attribute Details

#collectionObject (readonly)

attr_reader collection: Node



4247
4248
4249
# File 'lib/yarp/node.rb', line 4247

def collection
  @collection
end

#do_keyword_locObject (readonly)

attr_reader do_keyword_loc: Location?



4259
4260
4261
# File 'lib/yarp/node.rb', line 4259

def do_keyword_loc
  @do_keyword_loc
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location



4262
4263
4264
# File 'lib/yarp/node.rb', line 4262

def end_keyword_loc
  @end_keyword_loc
end

#for_keyword_locObject (readonly)

attr_reader for_keyword_loc: Location



4253
4254
4255
# File 'lib/yarp/node.rb', line 4253

def for_keyword_loc
  @for_keyword_loc
end

#in_keyword_locObject (readonly)

attr_reader in_keyword_loc: Location



4256
4257
4258
# File 'lib/yarp/node.rb', line 4256

def in_keyword_loc
  @in_keyword_loc
end

#indexObject (readonly)

attr_reader index: Node



4244
4245
4246
# File 'lib/yarp/node.rb', line 4244

def index
  @index
end

#statementsObject (readonly)

attr_reader statements: StatementsNode?



4250
4251
4252
# File 'lib/yarp/node.rb', line 4250

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



4277
4278
4279
# File 'lib/yarp/node.rb', line 4277

def accept(visitor)
  visitor.visit_for_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



4282
4283
4284
# File 'lib/yarp/node.rb', line 4282

def child_nodes
  [index, collection, statements]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



4287
4288
4289
# File 'lib/yarp/node.rb', line 4287

def comment_targets
  [index, collection, *statements, for_keyword_loc, in_keyword_loc, *do_keyword_loc, end_keyword_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ForNode



4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
# File 'lib/yarp/node.rb', line 4292

def copy(**params)
  ForNode.new(
    params.fetch(:index) { index },
    params.fetch(:collection) { collection },
    params.fetch(:statements) { statements },
    params.fetch(:for_keyword_loc) { for_keyword_loc },
    params.fetch(:in_keyword_loc) { in_keyword_loc },
    params.fetch(:do_keyword_loc) { do_keyword_loc },
    params.fetch(:end_keyword_loc) { end_keyword_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



4309
4310
4311
# File 'lib/yarp/node.rb', line 4309

def deconstruct_keys(keys)
  { 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, location: location }
end

#do_keywordObject

def do_keyword: () -> String?



4324
4325
4326
# File 'lib/yarp/node.rb', line 4324

def do_keyword
  do_keyword_loc&.slice
end

#end_keywordObject

def end_keyword: () -> String



4329
4330
4331
# File 'lib/yarp/node.rb', line 4329

def end_keyword
  end_keyword_loc.slice
end

#for_keywordObject

def for_keyword: () -> String



4314
4315
4316
# File 'lib/yarp/node.rb', line 4314

def for_keyword
  for_keyword_loc.slice
end

#in_keywordObject

def in_keyword: () -> String



4319
4320
4321
# File 'lib/yarp/node.rb', line 4319

def in_keyword
  in_keyword_loc.slice
end

#inspect(inspector = NodeInspector.new) ⇒ Object



4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
# File 'lib/yarp/node.rb', line 4333

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