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.



9052
9053
9054
9055
9056
9057
# File 'lib/syntax_tree/node.rb', line 9052

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



9050
9051
9052
# File 'lib/syntax_tree/node.rb', line 9050

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9044
9045
9046
# File 'lib/syntax_tree/node.rb', line 9044

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



9047
9048
9049
# File 'lib/syntax_tree/node.rb', line 9047

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



9059
9060
9061
# File 'lib/syntax_tree/node.rb', line 9059

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

#child_nodesObject Also known as: deconstruct



9063
9064
9065
# File 'lib/syntax_tree/node.rb', line 9063

def child_nodes
  [predicate, statements]
end

#deconstruct_keys(keys) ⇒ Object



9069
9070
9071
9072
9073
9074
9075
9076
# File 'lib/syntax_tree/node.rb', line 9069

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

#format(q) ⇒ Object



9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
# File 'lib/syntax_tree/node.rb', line 9078

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