Class: SyntaxTree::WhileNode
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::WhileNode
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
While represents a while
loop.
while predicate
end
Instance Attribute Summary collapse
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(predicate:, statements:, location:) ⇒ WhileNode
Returns a new instance of WhileNode.
11945
11946
11947
11948
11949
11950
|
# File 'lib/syntax_tree/node.rb', line 11945
def initialize(predicate:, statements:, location:)
@predicate = predicate
@statements = statements
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11943
11944
11945
|
# File 'lib/syntax_tree/node.rb', line 11943
def
@comments
end
|
#predicate ⇒ Object
- Node
-
the expression to be checked
11937
11938
11939
|
# File 'lib/syntax_tree/node.rb', line 11937
def predicate
@predicate
end
|
#statements ⇒ Object
- Statements
-
the expressions to be executed
11940
11941
11942
|
# File 'lib/syntax_tree/node.rb', line 11940
def statements
@statements
end
|
Instance Method Details
#===(other) ⇒ Object
11987
11988
11989
11990
|
# File 'lib/syntax_tree/node.rb', line 11987
def ===(other)
other.is_a?(WhileNode) && predicate === other.predicate &&
statements === other.statements
end
|
#accept(visitor) ⇒ Object
11952
11953
11954
|
# File 'lib/syntax_tree/node.rb', line 11952
def accept(visitor)
visitor.visit_while(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
11956
11957
11958
|
# File 'lib/syntax_tree/node.rb', line 11956
def child_nodes
[predicate, statements]
end
|
#copy(predicate: nil, statements: nil, location: nil) ⇒ Object
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
|
# File 'lib/syntax_tree/node.rb', line 11960
def copy(predicate: nil, statements: nil, location: nil)
node =
WhileNode.new(
predicate: predicate || self.predicate,
statements: statements || self.statements,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
11974
11975
11976
11977
11978
11979
11980
11981
|
# File 'lib/syntax_tree/node.rb', line 11974
def deconstruct_keys(_keys)
{
predicate: predicate,
statements: statements,
location: location,
comments:
}
end
|
11983
11984
11985
|
# File 'lib/syntax_tree/node.rb', line 11983
def format(q)
LoopFormatter.new("while", self).format(q)
end
|
#modifier? ⇒ Boolean
11992
11993
11994
|
# File 'lib/syntax_tree/node.rb', line 11992
def modifier?
predicate.location.start_char > statements.location.start_char
end
|