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.



9164
9165
9166
9167
9168
9169
# File 'lib/syntax_tree/node.rb', line 9164

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



9162
9163
9164
# File 'lib/syntax_tree/node.rb', line 9162

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9156
9157
9158
# File 'lib/syntax_tree/node.rb', line 9156

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



9159
9160
9161
# File 'lib/syntax_tree/node.rb', line 9159

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



9171
9172
9173
# File 'lib/syntax_tree/node.rb', line 9171

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

#child_nodesObject Also known as: deconstruct



9175
9176
9177
# File 'lib/syntax_tree/node.rb', line 9175

def child_nodes
  [predicate, statements]
end

#deconstruct_keys(_keys) ⇒ Object



9181
9182
9183
9184
9185
9186
9187
9188
# File 'lib/syntax_tree/node.rb', line 9181

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

#format(q) ⇒ Object



9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
# File 'lib/syntax_tree/node.rb', line 9190

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