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.
6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 |
# File 'lib/syntax_tree.rb', line 6851 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
6849 6850 6851 |
# File 'lib/syntax_tree.rb', line 6849 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
6843 6844 6845 |
# File 'lib/syntax_tree.rb', line 6843 def consequent @consequent end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
6846 6847 6848 |
# File 'lib/syntax_tree.rb', line 6846 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
6837 6838 6839 |
# File 'lib/syntax_tree.rb', line 6837 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
6840 6841 6842 |
# File 'lib/syntax_tree.rb', line 6840 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
6865 6866 6867 |
# File 'lib/syntax_tree.rb', line 6865 def child_nodes [predicate, statements, consequent] end |
#format(q) ⇒ Object
6869 6870 6871 |
# File 'lib/syntax_tree.rb', line 6869 def format(q) ConditionalFormatter.new("if", self).format(q) end |
#pretty_print(q) ⇒ Object
6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 |
# File 'lib/syntax_tree.rb', line 6873 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
6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 |
# File 'lib/syntax_tree.rb', line 6892 def to_json(*opts) { type: :if, pred: predicate, stmts: statements, cons: consequent, loc: location, cmts: comments }.to_json(*opts) end |