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



6731
6732
6733
6734
6735
6736
# File 'lib/syntax_tree.rb', line 6731

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



6729
6730
6731
# File 'lib/syntax_tree.rb', line 6729

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6726
6727
6728
# File 'lib/syntax_tree.rb', line 6726

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



6723
6724
6725
# File 'lib/syntax_tree.rb', line 6723

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



6720
6721
6722
# File 'lib/syntax_tree.rb', line 6720

def statement
  @statement
end

Instance Method Details

#child_nodesObject



6738
6739
6740
# File 'lib/syntax_tree.rb', line 6738

def child_nodes
  [statement, predicate]
end

#format(q) ⇒ Object



6742
6743
6744
# File 'lib/syntax_tree.rb', line 6742

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

#pretty_print(q) ⇒ Object



6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
# File 'lib/syntax_tree.rb', line 6746

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



6760
6761
6762
6763
6764
6765
6766
6767
6768
# File 'lib/syntax_tree.rb', line 6760

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