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.
6264 6265 6266 6267 6268 |
# File 'lib/syntax_tree/node.rb', line 6264 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
6262 6263 6264 |
# File 'lib/syntax_tree/node.rb', line 6262 def comments @comments end |
#statements ⇒ Object (readonly)
- Statements
-
the top-level expressions of the program
6259 6260 6261 |
# File 'lib/syntax_tree/node.rb', line 6259 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
6270 6271 6272 |
# File 'lib/syntax_tree/node.rb', line 6270 def accept(visitor) visitor.visit_program(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6274 6275 6276 |
# File 'lib/syntax_tree/node.rb', line 6274 def child_nodes [statements] end |
#deconstruct_keys(keys) ⇒ Object
6280 6281 6282 |
# File 'lib/syntax_tree/node.rb', line 6280 def deconstruct_keys(keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
6284 6285 6286 6287 6288 6289 6290 6291 |
# File 'lib/syntax_tree/node.rb', line 6284 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 |