Class: SyntaxTree::IfMod

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

IfMod represents the modifier form of an if statement.

expression if predicate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statement:, predicate:, location:, comments: []) ⇒ IfMod

Returns a new instance of IfMod.



7169
7170
7171
7172
7173
7174
# File 'lib/syntax_tree.rb', line 7169

def initialize(statement:, predicate:, location:, comments: [])
  @statement = statement
  @predicate = predicate
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7167
7168
7169
# File 'lib/syntax_tree.rb', line 7167

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7164
7165
7166
# File 'lib/syntax_tree.rb', line 7164

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



7161
7162
7163
# File 'lib/syntax_tree.rb', line 7161

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



7158
7159
7160
# File 'lib/syntax_tree.rb', line 7158

def statement
  @statement
end

Instance Method Details

#child_nodesObject



7176
7177
7178
# File 'lib/syntax_tree.rb', line 7176

def child_nodes
  [statement, predicate]
end

#format(q) ⇒ Object



7180
7181
7182
# File 'lib/syntax_tree.rb', line 7180

def format(q)
  ConditionalModFormatter.new("if", self).format(q)
end

#pretty_print(q) ⇒ Object



7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
# File 'lib/syntax_tree.rb', line 7184

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("if_mod")

    q.breakable
    q.pp(statement)

    q.breakable
    q.pp(predicate)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



7198
7199
7200
7201
7202
7203
7204
7205
7206
# File 'lib/syntax_tree.rb', line 7198

def to_json(*opts)
  {
    type: :if_mod,
    stmt: statement,
    pred: predicate,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end