Class: SyntaxTree::Program
Overview
Program represents the overall syntax tree.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#statements ⇒ Object
readonly
- Statements
-
the top-level expressions of the program.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statements:, location:, comments: []) ⇒ Program
constructor
A new instance of Program.
Methods inherited from Node
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ Program
Returns a new instance of Program.
6806 6807 6808 6809 6810 |
# File 'lib/syntax_tree/node.rb', line 6806 def initialize(statements:, location:, comments: []) @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6804 6805 6806 |
# File 'lib/syntax_tree/node.rb', line 6804 def comments @comments end |
#statements ⇒ Object (readonly)
- Statements
-
the top-level expressions of the program
6801 6802 6803 |
# File 'lib/syntax_tree/node.rb', line 6801 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
6812 6813 6814 |
# File 'lib/syntax_tree/node.rb', line 6812 def accept(visitor) visitor.visit_program(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6816 6817 6818 |
# File 'lib/syntax_tree/node.rb', line 6816 def child_nodes [statements] end |
#deconstruct_keys(keys) ⇒ Object
6822 6823 6824 |
# File 'lib/syntax_tree/node.rb', line 6822 def deconstruct_keys(keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
6826 6827 6828 6829 6830 6831 6832 6833 |
# File 'lib/syntax_tree/node.rb', line 6826 def format(q) q.format(statements) # We're going to put a newline on the end so that it always has one unless # it ends with the special __END__ syntax. In that case we want to # replicate the text exactly so we will just let it be. q.breakable(force: true) unless statements.body.last.is_a?(EndContent) end |