Class: SyntaxTree::Program
- Inherits:
-
Object
- Object
- SyntaxTree::Program
- Defined in:
- lib/syntax_tree.rb
Overview
Program represents the overall syntax tree.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#statements ⇒ Object
readonly
- Statements
-
the top-level expressions of the program.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statements:, location:, comments: []) ⇒ Program
constructor
A new instance of Program.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ Program
Returns a new instance of Program.
8887 8888 8889 8890 8891 |
# File 'lib/syntax_tree.rb', line 8887 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
8885 8886 8887 |
# File 'lib/syntax_tree.rb', line 8885 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8882 8883 8884 |
# File 'lib/syntax_tree.rb', line 8882 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the top-level expressions of the program
8879 8880 8881 |
# File 'lib/syntax_tree.rb', line 8879 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
8893 8894 8895 |
# File 'lib/syntax_tree.rb', line 8893 def child_nodes [statements] end |
#format(q) ⇒ Object
8897 8898 8899 8900 |
# File 'lib/syntax_tree.rb', line 8897 def format(q) q.format(statements) q.breakable(force: true) end |
#pretty_print(q) ⇒ Object
8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 |
# File 'lib/syntax_tree.rb', line 8902 def pretty_print(q) q.group(2, "(", ")") do q.text("program") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8913 8914 8915 8916 8917 8918 8919 8920 8921 |
# File 'lib/syntax_tree.rb', line 8913 def to_json(*opts) { type: :program, stmts: statements, comments: comments, loc: location, cmts: comments }.to_json(*opts) end |