Class: YARP::WhileNode

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

Overview

Represents the use of the ‘while` keyword, either in the block form or the modifier form.

bar while foo
^^^^^^^^^^^^^

while foo do bar end
^^^^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword_loc, predicate, statements, flags, location) ⇒ WhileNode

def initialize: (keyword_loc: Location, predicate: Node, statements: Node?, flags: Integer, location: Location) -> void



6241
6242
6243
6244
6245
6246
6247
# File 'lib/yarp/node.rb', line 6241

def initialize(keyword_loc, predicate, statements, flags, location)
  @keyword_loc = keyword_loc
  @predicate = predicate
  @statements = statements
  @flags = flags
  @location = location
end

Instance Attribute Details

#flagsObject (readonly)

attr_reader flags: Integer



6238
6239
6240
# File 'lib/yarp/node.rb', line 6238

def flags
  @flags
end

#keyword_locObject (readonly)

attr_reader keyword_loc: Location



6229
6230
6231
# File 'lib/yarp/node.rb', line 6229

def keyword_loc
  @keyword_loc
end

#predicateObject (readonly)

attr_reader predicate: Node



6232
6233
6234
# File 'lib/yarp/node.rb', line 6232

def predicate
  @predicate
end

#statementsObject (readonly)

attr_reader statements: Node?



6235
6236
6237
# File 'lib/yarp/node.rb', line 6235

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6250
6251
6252
# File 'lib/yarp/node.rb', line 6250

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

#begin_modifier?Boolean

def begin_modifier?: () -> bool

Returns:

  • (Boolean)


6277
6278
6279
# File 'lib/yarp/node.rb', line 6277

def begin_modifier?
  flags.anybits?(LoopFlags::BEGIN_MODIFIER)
end

#child_nodesObject Also known as: deconstruct

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



6259
6260
6261
# File 'lib/yarp/node.rb', line 6259

def child_nodes
  [predicate, statements]
end

#deconstruct_keys(keys) ⇒ Object

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



6267
6268
6269
# File 'lib/yarp/node.rb', line 6267

def deconstruct_keys(keys)
  { keyword_loc: keyword_loc, predicate: predicate, statements: statements, flags: flags, location: location }
end

#keywordObject

def keyword: () -> String



6272
6273
6274
# File 'lib/yarp/node.rb', line 6272

def keyword
  keyword_loc.slice
end

#set_newline_flag(newline_marked) ⇒ Object



6254
6255
6256
# File 'lib/yarp/node.rb', line 6254

def set_newline_flag(newline_marked)
  predicate.set_newline_flag(newline_marked)
end