Class: SyntaxTree::Until

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

Overview

Until represents an until loop.

until predicate
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicate:, statements:, location:, comments: []) ⇒ Until

Returns a new instance of Until.



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

def initialize(predicate:, statements:, location:, comments: [])
  @predicate = predicate
  @statements = statements
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



12680
12681
12682
# File 'lib/syntax_tree.rb', line 12680

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



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

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



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

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



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

def statements
  @statements
end

Instance Method Details

#child_nodesObject



12689
12690
12691
# File 'lib/syntax_tree.rb', line 12689

def child_nodes
  [predicate, statements]
end

#format(q) ⇒ Object



12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
# File 'lib/syntax_tree.rb', line 12693

def format(q)
  if statements.empty?
    keyword = "until "

    q.group do
      q.text(keyword)
      q.nest(keyword.length) { q.format(predicate) }
      q.breakable(force: true)
      q.text("end")
    end
  else
    LoopFormatter.new("until", self, statements).format(q)
  end
end

#pretty_print(q) ⇒ Object



12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
# File 'lib/syntax_tree.rb', line 12708

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

    q.breakable
    q.pp(predicate)

    q.breakable
    q.pp(statements)

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

#to_json(*opts) ⇒ Object



12722
12723
12724
12725
12726
12727
12728
12729
12730
# File 'lib/syntax_tree.rb', line 12722

def to_json(*opts)
  {
    type: :until,
    pred: predicate,
    stmts: statements,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end