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.
9286 9287 9288 9289 9290 9291 |
# File 'lib/syntax_tree/node.rb', line 9286 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
9284 9285 9286 |
# File 'lib/syntax_tree/node.rb', line 9284 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
9278 9279 9280 |
# File 'lib/syntax_tree/node.rb', line 9278 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
9281 9282 9283 |
# File 'lib/syntax_tree/node.rb', line 9281 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
9293 9294 9295 |
# File 'lib/syntax_tree/node.rb', line 9293 def accept(visitor) visitor.visit_until(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9297 9298 9299 |
# File 'lib/syntax_tree/node.rb', line 9297 def child_nodes [predicate, statements] end |
#deconstruct_keys(_keys) ⇒ Object
9303 9304 9305 9306 9307 9308 9309 9310 |
# File 'lib/syntax_tree/node.rb', line 9303 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 |
# File 'lib/syntax_tree/node.rb', line 9312 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 |