Class: YARP::WhileNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::WhileNode
- 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
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location?.
-
#flags ⇒ Object
readonly
attr_reader flags: Integer.
-
#keyword_loc ⇒ Object
readonly
attr_reader keyword_loc: Location.
-
#predicate ⇒ Object
readonly
attr_reader predicate: Node.
-
#statements ⇒ Object
readonly
attr_reader statements: StatementsNode?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#begin_modifier? ⇒ Boolean
def begin_modifier?: () -> bool.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> WhileNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(keyword_loc, closing_loc, predicate, statements, flags, location) ⇒ WhileNode
constructor
def initialize: (keyword_loc: Location, closing_loc: Location?, predicate: Node, statements: StatementsNode?, flags: Integer, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#keyword ⇒ Object
def keyword: () -> String.
- #set_newline_flag(newline_marked) ⇒ Object
Constructor Details
#initialize(keyword_loc, closing_loc, predicate, statements, flags, location) ⇒ WhileNode
def initialize: (keyword_loc: Location, closing_loc: Location?, predicate: Node, statements: StatementsNode?, flags: Integer, location: Location) -> void
10302 10303 10304 10305 10306 10307 10308 10309 |
# File 'lib/yarp/node.rb', line 10302 def initialize(keyword_loc, closing_loc, predicate, statements, flags, location) @keyword_loc = keyword_loc @closing_loc = closing_loc @predicate = predicate @statements = statements @flags = flags @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location?
10290 10291 10292 |
# File 'lib/yarp/node.rb', line 10290 def closing_loc @closing_loc end |
#flags ⇒ Object (readonly)
attr_reader flags: Integer
10299 10300 10301 |
# File 'lib/yarp/node.rb', line 10299 def flags @flags end |
#keyword_loc ⇒ Object (readonly)
attr_reader keyword_loc: Location
10287 10288 10289 |
# File 'lib/yarp/node.rb', line 10287 def keyword_loc @keyword_loc end |
#predicate ⇒ Object (readonly)
attr_reader predicate: Node
10293 10294 10295 |
# File 'lib/yarp/node.rb', line 10293 def predicate @predicate end |
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode?
10296 10297 10298 |
# File 'lib/yarp/node.rb', line 10296 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
10312 10313 10314 |
# File 'lib/yarp/node.rb', line 10312 def accept(visitor) visitor.visit_while_node(self) end |
#begin_modifier? ⇒ Boolean
def begin_modifier?: () -> bool
10361 10362 10363 |
# File 'lib/yarp/node.rb', line 10361 def begin_modifier? flags.anybits?(LoopFlags::BEGIN_MODIFIER) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
10321 10322 10323 |
# File 'lib/yarp/node.rb', line 10321 def child_nodes [predicate, statements] end |
#closing ⇒ Object
def closing: () -> String?
10356 10357 10358 |
# File 'lib/yarp/node.rb', line 10356 def closing closing_loc&.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
10326 10327 10328 |
# File 'lib/yarp/node.rb', line 10326 def comment_targets [keyword_loc, *closing_loc, predicate, *statements] end |
#copy(**params) ⇒ Object
def copy: (**params) -> WhileNode
10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 |
# File 'lib/yarp/node.rb', line 10331 def copy(**params) WhileNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:predicate) { predicate }, params.fetch(:statements) { statements }, params.fetch(:flags) { flags }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
10346 10347 10348 |
# File 'lib/yarp/node.rb', line 10346 def deconstruct_keys(keys) { keyword_loc: keyword_loc, closing_loc: closing_loc, predicate: predicate, statements: statements, flags: flags, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 |
# File 'lib/yarp/node.rb', line 10365 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 |
#keyword ⇒ Object
def keyword: () -> String
10351 10352 10353 |
# File 'lib/yarp/node.rb', line 10351 def keyword keyword_loc.slice end |
#set_newline_flag(newline_marked) ⇒ Object
10316 10317 10318 |
# File 'lib/yarp/node.rb', line 10316 def set_newline_flag(newline_marked) predicate.set_newline_flag(newline_marked) end |