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.



7101
7102
7103
7104
7105
7106
# File 'lib/syntax_tree.rb', line 7101

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



7099
7100
7101
# File 'lib/syntax_tree.rb', line 7099

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7096
7097
7098
# File 'lib/syntax_tree.rb', line 7096

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



7093
7094
7095
# File 'lib/syntax_tree.rb', line 7093

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



7090
7091
7092
# File 'lib/syntax_tree.rb', line 7090

def statement
  @statement
end

Instance Method Details

#child_nodesObject



7108
7109
7110
# File 'lib/syntax_tree.rb', line 7108

def child_nodes
  [statement, predicate]
end

#format(q) ⇒ Object



7112
7113
7114
# File 'lib/syntax_tree.rb', line 7112

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

#pretty_print(q) ⇒ Object



7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
# File 'lib/syntax_tree.rb', line 7116

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



7130
7131
7132
7133
7134
7135
7136
7137
7138
# File 'lib/syntax_tree.rb', line 7130

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