Class: SyntaxTree::UnlessMod

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

Overview

UnlessMod represents the modifier form of an unless statement.

expression unless predicate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



11847
11848
11849
11850
11851
11852
# File 'lib/syntax_tree.rb', line 11847

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



11845
11846
11847
# File 'lib/syntax_tree.rb', line 11845

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11842
11843
11844
# File 'lib/syntax_tree.rb', line 11842

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



11839
11840
11841
# File 'lib/syntax_tree.rb', line 11839

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



11836
11837
11838
# File 'lib/syntax_tree.rb', line 11836

def statement
  @statement
end

Instance Method Details

#child_nodesObject



11854
11855
11856
# File 'lib/syntax_tree.rb', line 11854

def child_nodes
  [statement, predicate]
end

#format(q) ⇒ Object



11858
11859
11860
# File 'lib/syntax_tree.rb', line 11858

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

#pretty_print(q) ⇒ Object



11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
# File 'lib/syntax_tree.rb', line 11862

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

    q.breakable
    q.pp(statement)

    q.breakable
    q.pp(predicate)

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

#to_json(*opts) ⇒ Object



11876
11877
11878
11879
11880
11881
11882
11883
11884
# File 'lib/syntax_tree.rb', line 11876

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