Class: SyntaxTree::IfMod

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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.



6321
6322
6323
6324
6325
6326
# File 'lib/syntax_tree/node.rb', line 6321

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



6319
6320
6321
# File 'lib/syntax_tree/node.rb', line 6319

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6316
6317
6318
# File 'lib/syntax_tree/node.rb', line 6316

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



6313
6314
6315
# File 'lib/syntax_tree/node.rb', line 6313

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



6310
6311
6312
# File 'lib/syntax_tree/node.rb', line 6310

def statement
  @statement
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



6328
6329
6330
# File 'lib/syntax_tree/node.rb', line 6328

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(keys) ⇒ Object



6334
6335
6336
6337
6338
6339
6340
6341
# File 'lib/syntax_tree/node.rb', line 6334

def deconstruct_keys(keys)
  {
    statement: statement,
    predicate: predicate,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



6343
6344
6345
# File 'lib/syntax_tree/node.rb', line 6343

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

#pretty_print(q) ⇒ Object



6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
# File 'lib/syntax_tree/node.rb', line 6347

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



6361
6362
6363
6364
6365
6366
6367
6368
6369
# File 'lib/syntax_tree/node.rb', line 6361

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