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
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, location:, comments: []) ⇒ Until
constructor
A new instance of Until.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(predicate:, statements:, location:, comments: []) ⇒ Until
Returns a new instance of Until.
10379 10380 10381 10382 10383 10384 |
# File 'lib/syntax_tree/node.rb', line 10379 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
10377 10378 10379 |
# File 'lib/syntax_tree/node.rb', line 10377 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
10371 10372 10373 |
# File 'lib/syntax_tree/node.rb', line 10371 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
10374 10375 10376 |
# File 'lib/syntax_tree/node.rb', line 10374 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10386 10387 10388 |
# File 'lib/syntax_tree/node.rb', line 10386 def child_nodes [predicate, statements] end |
#deconstruct_keys(keys) ⇒ Object
10392 10393 10394 10395 10396 10397 10398 10399 |
# File 'lib/syntax_tree/node.rb', line 10392 def deconstruct_keys(keys) { predicate: predicate, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 |
# File 'lib/syntax_tree/node.rb', line 10401 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 |
#pretty_print(q) ⇒ Object
10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 |
# File 'lib/syntax_tree/node.rb', line 10416 def pretty_print(q) q.group(2, "(", ")") do q.text("until") q.breakable q.pp(predicate) q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
10430 10431 10432 10433 10434 10435 10436 10437 10438 |
# File 'lib/syntax_tree/node.rb', line 10430 def to_json(*opts) { type: :until, pred: predicate, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |