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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
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.
10802 10803 10804 10805 10806 10807 |
# File 'lib/syntax_tree/node.rb', line 10802 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
10800 10801 10802 |
# File 'lib/syntax_tree/node.rb', line 10800 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10797 10798 10799 |
# File 'lib/syntax_tree/node.rb', line 10797 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
10791 10792 10793 |
# File 'lib/syntax_tree/node.rb', line 10791 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
10794 10795 10796 |
# File 'lib/syntax_tree/node.rb', line 10794 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10809 10810 10811 |
# File 'lib/syntax_tree/node.rb', line 10809 def child_nodes [predicate, statements] end |
#deconstruct_keys(keys) ⇒ Object
10815 10816 10817 10818 10819 10820 10821 10822 |
# File 'lib/syntax_tree/node.rb', line 10815 def deconstruct_keys(keys) { predicate: predicate, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 |
# File 'lib/syntax_tree/node.rb', line 10824 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
10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 |
# File 'lib/syntax_tree/node.rb', line 10839 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
10853 10854 10855 10856 10857 10858 10859 10860 10861 |
# File 'lib/syntax_tree/node.rb', line 10853 def to_json(*opts) { type: :until, pred: predicate, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |