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.
9244 9245 9246 9247 9248 9249 |
# File 'lib/syntax_tree/node.rb', line 9244 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
9242 9243 9244 |
# File 'lib/syntax_tree/node.rb', line 9242 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
9236 9237 9238 |
# File 'lib/syntax_tree/node.rb', line 9236 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
9239 9240 9241 |
# File 'lib/syntax_tree/node.rb', line 9239 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
9251 9252 9253 |
# File 'lib/syntax_tree/node.rb', line 9251 def accept(visitor) visitor.visit_until(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9255 9256 9257 |
# File 'lib/syntax_tree/node.rb', line 9255 def child_nodes [predicate, statements] end |
#deconstruct_keys(_keys) ⇒ Object
9261 9262 9263 9264 9265 9266 9267 9268 |
# File 'lib/syntax_tree/node.rb', line 9261 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 |
# File 'lib/syntax_tree/node.rb', line 9270 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 |