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