Class: SyntaxTree::Program
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Program
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Program represents the overall syntax tree.
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(statements:, location:) ⇒ Program
Returns a new instance of Program.
8623
8624
8625
8626
8627
|
# File 'lib/syntax_tree/node.rb', line 8623
def initialize(statements:, location:)
@statements = statements
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8621
8622
8623
|
# File 'lib/syntax_tree/node.rb', line 8621
def
@comments
end
|
#statements ⇒ Object
- Statements
-
the top-level expressions of the program
8618
8619
8620
|
# File 'lib/syntax_tree/node.rb', line 8618
def statements
@statements
end
|
Instance Method Details
#===(other) ⇒ Object
8663
8664
8665
|
# File 'lib/syntax_tree/node.rb', line 8663
def ===(other)
other.is_a?(Program) && statements === other.statements
end
|
#accept(visitor) ⇒ Object
8629
8630
8631
|
# File 'lib/syntax_tree/node.rb', line 8629
def accept(visitor)
visitor.visit_program(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
8633
8634
8635
|
# File 'lib/syntax_tree/node.rb', line 8633
def child_nodes
[statements]
end
|
#copy(statements: nil, location: nil) ⇒ Object
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
|
# File 'lib/syntax_tree/node.rb', line 8637
def copy(statements: nil, location: nil)
node =
Program.new(
statements: statements || self.statements,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
8650
8651
8652
|
# File 'lib/syntax_tree/node.rb', line 8650
def deconstruct_keys(_keys)
{ statements: statements, location: location, comments: }
end
|
8654
8655
8656
8657
8658
8659
8660
8661
|
# File 'lib/syntax_tree/node.rb', line 8654
def format(q)
q.format(statements)
q.breakable_force unless statements.body.last.is_a?(EndContent)
end
|