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.
6807 6808 6809 6810 6811 |
# File 'lib/syntax_tree/node.rb', line 6807 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
6805 6806 6807 |
# File 'lib/syntax_tree/node.rb', line 6805 def comments @comments end |
#statements ⇒ Object (readonly)
- Statements
-
the top-level expressions of the program
6802 6803 6804 |
# File 'lib/syntax_tree/node.rb', line 6802 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
6813 6814 6815 |
# File 'lib/syntax_tree/node.rb', line 6813 def accept(visitor) visitor.visit_program(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6817 6818 6819 |
# File 'lib/syntax_tree/node.rb', line 6817 def child_nodes [statements] end |
#deconstruct_keys(keys) ⇒ Object
6823 6824 6825 |
# File 'lib/syntax_tree/node.rb', line 6823 def deconstruct_keys(keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
6827 6828 6829 6830 6831 6832 6833 6834 |
# File 'lib/syntax_tree/node.rb', line 6827 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 |