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.
8591
8592
8593
8594
8595
|
# File 'lib/syntax_tree/node.rb', line 8591
def initialize(statements:, location:)
@statements = statements
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8589
8590
8591
|
# File 'lib/syntax_tree/node.rb', line 8589
def
@comments
end
|
#statements ⇒ Object
- Statements
-
the top-level expressions of the program
8586
8587
8588
|
# File 'lib/syntax_tree/node.rb', line 8586
def statements
@statements
end
|
Instance Method Details
#===(other) ⇒ Object
8631
8632
8633
|
# File 'lib/syntax_tree/node.rb', line 8631
def ===(other)
other.is_a?(Program) && statements === other.statements
end
|
#accept(visitor) ⇒ Object
8597
8598
8599
|
# File 'lib/syntax_tree/node.rb', line 8597
def accept(visitor)
visitor.visit_program(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
8601
8602
8603
|
# File 'lib/syntax_tree/node.rb', line 8601
def child_nodes
[statements]
end
|
#copy(statements: nil, location: nil) ⇒ Object
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
|
# File 'lib/syntax_tree/node.rb', line 8605
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
8618
8619
8620
|
# File 'lib/syntax_tree/node.rb', line 8618
def deconstruct_keys(_keys)
{ statements: statements, location: location, comments: }
end
|
8622
8623
8624
8625
8626
8627
8628
8629
|
# File 'lib/syntax_tree/node.rb', line 8622
def format(q)
q.format(statements)
q.breakable_force unless statements.body.last.is_a?(EndContent)
end
|