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.



12550
12551
12552
12553
12554
12555
# File 'lib/syntax_tree.rb', line 12550

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



12548
12549
12550
# File 'lib/syntax_tree.rb', line 12548

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12545
12546
12547
# File 'lib/syntax_tree.rb', line 12545

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



12539
12540
12541
# File 'lib/syntax_tree.rb', line 12539

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



12542
12543
12544
# File 'lib/syntax_tree.rb', line 12542

def statements
  @statements
end

Instance Method Details

#child_nodesObject



12557
12558
12559
# File 'lib/syntax_tree.rb', line 12557

def child_nodes
  [predicate, statements]
end

#format(q) ⇒ Object



12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
# File 'lib/syntax_tree.rb', line 12561

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



12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
# File 'lib/syntax_tree.rb', line 12576

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



12590
12591
12592
12593
12594
12595
12596
12597
12598
# File 'lib/syntax_tree.rb', line 12590

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