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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of Until.



9325
9326
9327
9328
9329
9330
# File 'lib/syntax_tree/node.rb', line 9325

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



9323
9324
9325
# File 'lib/syntax_tree/node.rb', line 9323

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9317
9318
9319
# File 'lib/syntax_tree/node.rb', line 9317

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



9320
9321
9322
# File 'lib/syntax_tree/node.rb', line 9320

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



9332
9333
9334
# File 'lib/syntax_tree/node.rb', line 9332

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

#child_nodesObject Also known as: deconstruct



9336
9337
9338
# File 'lib/syntax_tree/node.rb', line 9336

def child_nodes
  [predicate, statements]
end

#deconstruct_keys(_keys) ⇒ Object



9342
9343
9344
9345
9346
9347
9348
9349
# File 'lib/syntax_tree/node.rb', line 9342

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

#format(q) ⇒ Object



9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
# File 'lib/syntax_tree/node.rb', line 9351

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