Class: SyntaxTree::WhileMod

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

Overview

WhileMod represents the modifier form of a while loop.

expression while predicate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of WhileMod.



12675
12676
12677
12678
12679
12680
# File 'lib/syntax_tree.rb', line 12675

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



12673
12674
12675
# File 'lib/syntax_tree.rb', line 12673

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12670
12671
12672
# File 'lib/syntax_tree.rb', line 12670

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



12667
12668
12669
# File 'lib/syntax_tree.rb', line 12667

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



12664
12665
12666
# File 'lib/syntax_tree.rb', line 12664

def statement
  @statement
end

Instance Method Details

#child_nodesObject



12682
12683
12684
# File 'lib/syntax_tree.rb', line 12682

def child_nodes
  [statement, predicate]
end

#format(q) ⇒ Object



12686
12687
12688
# File 'lib/syntax_tree.rb', line 12686

def format(q)
  LoopFormatter.new("while", self, statement).format(q)
end

#pretty_print(q) ⇒ Object



12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
# File 'lib/syntax_tree.rb', line 12690

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

    q.breakable
    q.pp(statement)

    q.breakable
    q.pp(predicate)

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

#to_json(*opts) ⇒ Object



12704
12705
12706
12707
12708
12709
12710
12711
12712
# File 'lib/syntax_tree.rb', line 12704

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