Class: SyntaxTree::If
- Inherits:
-
Object
- Object
- SyntaxTree::If
- Defined in:
- lib/syntax_tree.rb
Overview
If represents the first clause in an if chain.
if predicate
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- nil, Elsif, Else
-
the next clause in the chain.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ If
constructor
A new instance of If.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ If
Returns a new instance of If.
6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 |
# File 'lib/syntax_tree.rb', line 6501 def initialize( predicate:, statements:, consequent:, location:, comments: [] ) @predicate = predicate @statements = statements @consequent = consequent @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6499 6500 6501 |
# File 'lib/syntax_tree.rb', line 6499 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
6493 6494 6495 |
# File 'lib/syntax_tree.rb', line 6493 def consequent @consequent end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
6496 6497 6498 |
# File 'lib/syntax_tree.rb', line 6496 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
6487 6488 6489 |
# File 'lib/syntax_tree.rb', line 6487 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
6490 6491 6492 |
# File 'lib/syntax_tree.rb', line 6490 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
6515 6516 6517 |
# File 'lib/syntax_tree.rb', line 6515 def child_nodes [predicate, statements, consequent] end |
#format(q) ⇒ Object
6519 6520 6521 |
# File 'lib/syntax_tree.rb', line 6519 def format(q) ConditionalFormatter.new("if", self).format(q) end |
#pretty_print(q) ⇒ Object
6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 |
# File 'lib/syntax_tree.rb', line 6523 def pretty_print(q) q.group(2, "(", ")") do q.text("if") q.breakable q.pp(predicate) q.breakable q.pp(statements) if consequent q.breakable q.pp(consequent) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 |
# File 'lib/syntax_tree.rb', line 6542 def to_json(*opts) { type: :if, pred: predicate, stmts: statements, cons: consequent, loc: location, cmts: comments }.to_json(*opts) end |