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.



7301
7302
7303
7304
7305
7306
# File 'lib/syntax_tree.rb', line 7301

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



7299
7300
7301
# File 'lib/syntax_tree.rb', line 7299

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7296
7297
7298
# File 'lib/syntax_tree.rb', line 7296

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



7293
7294
7295
# File 'lib/syntax_tree.rb', line 7293

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



7290
7291
7292
# File 'lib/syntax_tree.rb', line 7290

def statement
  @statement
end

Instance Method Details

#child_nodesObject



7308
7309
7310
# File 'lib/syntax_tree.rb', line 7308

def child_nodes
  [statement, predicate]
end

#format(q) ⇒ Object



7312
7313
7314
# File 'lib/syntax_tree.rb', line 7312

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

#pretty_print(q) ⇒ Object



7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
# File 'lib/syntax_tree.rb', line 7316

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



7330
7331
7332
7333
7334
7335
7336
7337
7338
# File 'lib/syntax_tree.rb', line 7330

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