Class: SyntaxTree::Until
Overview
Until represents an until loop.
until predicate
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, location:, comments: []) ⇒ Until
constructor
A new instance of Until.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(predicate:, statements:, location:, comments: []) ⇒ Until
Returns a new instance of Until.
9328 9329 9330 9331 9332 9333 |
# File 'lib/syntax_tree/node.rb', line 9328 def initialize(predicate:, statements:, location:, comments: []) @predicate = predicate @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9326 9327 9328 |
# File 'lib/syntax_tree/node.rb', line 9326 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
9320 9321 9322 |
# File 'lib/syntax_tree/node.rb', line 9320 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
9323 9324 9325 |
# File 'lib/syntax_tree/node.rb', line 9323 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
9335 9336 9337 |
# File 'lib/syntax_tree/node.rb', line 9335 def accept(visitor) visitor.visit_until(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9339 9340 9341 |
# File 'lib/syntax_tree/node.rb', line 9339 def child_nodes [predicate, statements] end |
#deconstruct_keys(_keys) ⇒ Object
9345 9346 9347 9348 9349 9350 9351 9352 |
# File 'lib/syntax_tree/node.rb', line 9345 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 |
# File 'lib/syntax_tree/node.rb', line 9354 def format(q) if statements.empty? keyword = "until " q.group do q.text(keyword) q.nest(keyword.length) { q.format(predicate) } q.breakable(force: true) q.text("end") end else LoopFormatter.new("until", self, statements).format(q) end end |