Class: SyntaxTree::WhileMod
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.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statement ⇒ Object
readonly
- untyped
-
the expression 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(statement:, predicate:, location:, comments: []) ⇒ WhileMod
constructor
A new instance of WhileMod.
Methods inherited from Node
Constructor Details
#initialize(statement:, predicate:, location:, comments: []) ⇒ WhileMod
Returns a new instance of WhileMod.
9000 9001 9002 9003 9004 9005 |
# File 'lib/syntax_tree/node.rb', line 9000 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
8998 8999 9000 |
# File 'lib/syntax_tree/node.rb', line 8998 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
8995 8996 8997 |
# File 'lib/syntax_tree/node.rb', line 8995 def predicate @predicate end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed
8992 8993 8994 |
# File 'lib/syntax_tree/node.rb', line 8992 def statement @statement end |
Instance Method Details
#accept(visitor) ⇒ Object
9007 9008 9009 |
# File 'lib/syntax_tree/node.rb', line 9007 def accept(visitor) visitor.visit_while_mod(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9011 9012 9013 |
# File 'lib/syntax_tree/node.rb', line 9011 def child_nodes [statement, predicate] end |
#deconstruct_keys(keys) ⇒ Object
9017 9018 9019 9020 9021 9022 9023 9024 |
# File 'lib/syntax_tree/node.rb', line 9017 def deconstruct_keys(keys) { statement: statement, predicate: predicate, location: location, comments: comments } end |
#format(q) ⇒ Object
9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 |
# File 'lib/syntax_tree/node.rb', line 9026 def format(q) # If we're in the modifier form and we're modifying a `begin`, then this # is a special case where we need to explicitly use the modifier form # because otherwise the semantic meaning changes. This looks like: # # begin # foo # end while bar # # Also, if the statement of the modifier includes an assignment, then we # can't know for certain that it won't impact the predicate, so we need to # force it to stay as it is. This looks like: # # foo = bar while foo # if statement.is_a?(Begin) || ContainsAssignment.call(statement) q.format(statement) q.text(" while ") q.format(predicate) else LoopFormatter.new("while", self, statement).format(q) end end |