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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ Program
Returns a new instance of Program.
7029 7030 7031 7032 7033 |
# File 'lib/syntax_tree/node.rb', line 7029 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
7027 7028 7029 |
# File 'lib/syntax_tree/node.rb', line 7027 def comments @comments end |
#statements ⇒ Object (readonly)
- Statements
-
the top-level expressions of the program
7024 7025 7026 |
# File 'lib/syntax_tree/node.rb', line 7024 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
7035 7036 7037 |
# File 'lib/syntax_tree/node.rb', line 7035 def accept(visitor) visitor.visit_program(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7039 7040 7041 |
# File 'lib/syntax_tree/node.rb', line 7039 def child_nodes [statements] end |
#deconstruct_keys(_keys) ⇒ Object
7045 7046 7047 |
# File 'lib/syntax_tree/node.rb', line 7045 def deconstruct_keys(_keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
7049 7050 7051 7052 7053 7054 7055 7056 |
# File 'lib/syntax_tree/node.rb', line 7049 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 |