Class: SyntaxTree::Until

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

Overview

Until represents an until loop.

until predicate
end

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of Until.



8491
8492
8493
8494
8495
8496
# File 'lib/syntax_tree/node.rb', line 8491

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



8489
8490
8491
# File 'lib/syntax_tree/node.rb', line 8489

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



8483
8484
8485
# File 'lib/syntax_tree/node.rb', line 8483

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



8486
8487
8488
# File 'lib/syntax_tree/node.rb', line 8486

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



8498
8499
8500
# File 'lib/syntax_tree/node.rb', line 8498

def accept(visitor)
  visitor.visit_until(self)
end

#child_nodesObject Also known as: deconstruct



8502
8503
8504
# File 'lib/syntax_tree/node.rb', line 8502

def child_nodes
  [predicate, statements]
end

#deconstruct_keys(keys) ⇒ Object



8508
8509
8510
8511
8512
8513
8514
8515
# File 'lib/syntax_tree/node.rb', line 8508

def deconstruct_keys(keys)
  {
    predicate: predicate,
    statements: statements,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
# File 'lib/syntax_tree/node.rb', line 8517

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