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.
9164 9165 9166 9167 9168 9169 |
# File 'lib/syntax_tree/node.rb', line 9164 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
9162 9163 9164 |
# File 'lib/syntax_tree/node.rb', line 9162 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
9156 9157 9158 |
# File 'lib/syntax_tree/node.rb', line 9156 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
9159 9160 9161 |
# File 'lib/syntax_tree/node.rb', line 9159 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
9171 9172 9173 |
# File 'lib/syntax_tree/node.rb', line 9171 def accept(visitor) visitor.visit_until(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9175 9176 9177 |
# File 'lib/syntax_tree/node.rb', line 9175 def child_nodes [predicate, statements] end |
#deconstruct_keys(_keys) ⇒ Object
9181 9182 9183 9184 9185 9186 9187 9188 |
# File 'lib/syntax_tree/node.rb', line 9181 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 |
# File 'lib/syntax_tree/node.rb', line 9190 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 |