Class: SyntaxTree::BEGINBlock
- Inherits:
-
Object
- Object
- SyntaxTree::BEGINBlock
- Defined in:
- lib/syntax_tree.rb
Overview
BEGINBlock represents the use of the BEGIN keyword, which hooks into the lifecycle of the interpreter. Whatever is inside the block will get executed when the program starts.
BEGIN {
}
Interestingly, the BEGIN keyword doesn’t allow the do and end keywords for the block. Only braces are permitted.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#lbrace ⇒ Object
readonly
- LBrace
-
the left brace that is seen after the keyword.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lbrace:, statements:, location:, comments: []) ⇒ BEGINBlock
constructor
A new instance of BEGINBlock.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(lbrace:, statements:, location:, comments: []) ⇒ BEGINBlock
Returns a new instance of BEGINBlock.
418 419 420 421 422 423 |
# File 'lib/syntax_tree.rb', line 418 def initialize(lbrace:, statements:, location:, comments: []) @lbrace = lbrace @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
416 417 418 |
# File 'lib/syntax_tree.rb', line 416 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that is seen after the keyword
407 408 409 |
# File 'lib/syntax_tree.rb', line 407 def lbrace @lbrace end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
413 414 415 |
# File 'lib/syntax_tree.rb', line 413 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
410 411 412 |
# File 'lib/syntax_tree.rb', line 410 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
425 426 427 |
# File 'lib/syntax_tree.rb', line 425 def child_nodes [lbrace, statements] end |
#format(q) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/syntax_tree.rb', line 429 def format(q) q.group do q.text("BEGIN ") q.format(lbrace) q.indent do q.breakable q.format(statements) end q.breakable q.text("}") end end |
#pretty_print(q) ⇒ Object
442 443 444 445 446 447 448 449 450 451 |
# File 'lib/syntax_tree.rb', line 442 def pretty_print(q) q.group(2, "(", ")") do q.text("BEGIN") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
453 454 455 456 457 458 459 460 461 |
# File 'lib/syntax_tree.rb', line 453 def to_json(*opts) { type: :BEGIN, lbrace: lbrace, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |