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.



9286
9287
9288
9289
9290
9291
# File 'lib/syntax_tree/node.rb', line 9286

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



9284
9285
9286
# File 'lib/syntax_tree/node.rb', line 9284

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9278
9279
9280
# File 'lib/syntax_tree/node.rb', line 9278

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



9281
9282
9283
# File 'lib/syntax_tree/node.rb', line 9281

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



9293
9294
9295
# File 'lib/syntax_tree/node.rb', line 9293

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

#child_nodesObject Also known as: deconstruct



9297
9298
9299
# File 'lib/syntax_tree/node.rb', line 9297

def child_nodes
  [predicate, statements]
end

#deconstruct_keys(_keys) ⇒ Object



9303
9304
9305
9306
9307
9308
9309
9310
# File 'lib/syntax_tree/node.rb', line 9303

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

#format(q) ⇒ Object



9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
# File 'lib/syntax_tree/node.rb', line 9312

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