class SyntaxTree::Program

Program represents the overall syntax tree.

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

statements[R]
Statements

the top-level expressions of the program

Public Class Methods

new(statements:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 8608
def initialize(statements:, location:)
  @statements = statements
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 8648
def ===(other)
  other.is_a?(Program) && statements === other.statements
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 8614
def accept(visitor)
  visitor.visit_program(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 8618
def child_nodes
  [statements]
end
Also aliased as: deconstruct
copy(statements: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 8622
def copy(statements: nil, location: nil)
  node =
    Program.new(
      statements: statements || self.statements,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 8635
def deconstruct_keys(_keys)
  { statements: statements, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 8639
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 unless statements.body.last.is_a?(EndContent)
end