Class: SyntaxTree::WhileMod
- Inherits:
-
Object
- Object
- SyntaxTree::WhileMod
- Defined in:
- lib/syntax_tree.rb
Overview
WhileMod represents the modifier form of a while loop.
expression while predicate
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.
-
#statement ⇒ Object
readonly
- untyped
-
the expression to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, predicate:, location:, comments: []) ⇒ WhileMod
constructor
A new instance of WhileMod.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statement:, predicate:, location:, comments: []) ⇒ WhileMod
Returns a new instance of WhileMod.
12675 12676 12677 12678 12679 12680 |
# File 'lib/syntax_tree.rb', line 12675 def initialize(statement:, predicate:, location:, comments: []) @statement = statement @predicate = predicate @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12673 12674 12675 |
# File 'lib/syntax_tree.rb', line 12673 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12670 12671 12672 |
# File 'lib/syntax_tree.rb', line 12670 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
12667 12668 12669 |
# File 'lib/syntax_tree.rb', line 12667 def predicate @predicate end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed
12664 12665 12666 |
# File 'lib/syntax_tree.rb', line 12664 def statement @statement end |
Instance Method Details
#child_nodes ⇒ Object
12682 12683 12684 |
# File 'lib/syntax_tree.rb', line 12682 def child_nodes [statement, predicate] end |
#format(q) ⇒ Object
12686 12687 12688 |
# File 'lib/syntax_tree.rb', line 12686 def format(q) LoopFormatter.new("while", self, statement).format(q) end |
#pretty_print(q) ⇒ Object
12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 12701 12702 |
# File 'lib/syntax_tree.rb', line 12690 def pretty_print(q) q.group(2, "(", ")") do q.text("while_mod") q.breakable q.pp(statement) q.breakable q.pp(predicate) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
12704 12705 12706 12707 12708 12709 12710 12711 12712 |
# File 'lib/syntax_tree.rb', line 12704 def to_json(*opts) { type: :while_mod, stmt: statement, pred: predicate, loc: location, cmts: comments }.to_json(*opts) end |