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, #pretty_print, #to_json
Constructor Details
#initialize(statements:, location:) ⇒ Program
8469
8470
8471
8472
8473
|
# File 'lib/syntax_tree/node.rb', line 8469
def initialize(statements:, location:)
@statements = statements
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8467
8468
8469
|
# File 'lib/syntax_tree/node.rb', line 8467
def
end
|
#statements ⇒ Object
- Statements
-
the top-level expressions of the program
8464
8465
8466
|
# File 'lib/syntax_tree/node.rb', line 8464
def statements
@statements
end
|
Instance Method Details
#===(other) ⇒ Object
8509
8510
8511
|
# File 'lib/syntax_tree/node.rb', line 8509
def ===(other)
other.is_a?(Program) && statements === other.statements
end
|
#accept(visitor) ⇒ Object
8475
8476
8477
|
# File 'lib/syntax_tree/node.rb', line 8475
def accept(visitor)
visitor.visit_program(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
8479
8480
8481
|
# File 'lib/syntax_tree/node.rb', line 8479
def child_nodes
[statements]
end
|
#copy(statements: nil, location: nil) ⇒ Object
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
|
# File 'lib/syntax_tree/node.rb', line 8483
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
8496
8497
8498
|
# File 'lib/syntax_tree/node.rb', line 8496
def deconstruct_keys(_keys)
{ statements: statements, location: location, comments: }
end
|
8500
8501
8502
8503
8504
8505
8506
8507
|
# File 'lib/syntax_tree/node.rb', line 8500
def format(q)
q.format(statements)
q.breakable_force unless statements.body.last.is_a?(EndContent)
end
|