Class: SyntaxTree::UntilNode

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:) ⇒ UntilNode



11297
11298
11299
11300
11301
11302
# File 'lib/syntax_tree/node.rb', line 11297

def initialize(predicate:, statements:, location:)
  @predicate = predicate
  @statements = statements
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11295
11296
11297
# File 'lib/syntax_tree/node.rb', line 11295

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



11289
11290
11291
# File 'lib/syntax_tree/node.rb', line 11289

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



11292
11293
11294
# File 'lib/syntax_tree/node.rb', line 11292

def statements
  @statements
end

Instance Method Details

#===(other) ⇒ Object



11339
11340
11341
11342
# File 'lib/syntax_tree/node.rb', line 11339

def ===(other)
  other.is_a?(UntilNode) && predicate === other.predicate &&
    statements === other.statements
end

#accept(visitor) ⇒ Object



11304
11305
11306
# File 'lib/syntax_tree/node.rb', line 11304

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

#child_nodesObject Also known as: deconstruct



11308
11309
11310
# File 'lib/syntax_tree/node.rb', line 11308

def child_nodes
  [predicate, statements]
end

#copy(predicate: nil, statements: nil, location: nil) ⇒ Object



11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
# File 'lib/syntax_tree/node.rb', line 11312

def copy(predicate: nil, statements: nil, location: nil)
  node =
    UntilNode.new(
      predicate: predicate || self.predicate,
      statements: statements || self.statements,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



11326
11327
11328
11329
11330
11331
11332
11333
# File 'lib/syntax_tree/node.rb', line 11326

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

#format(q) ⇒ Object



11335
11336
11337
# File 'lib/syntax_tree/node.rb', line 11335

def format(q)
  LoopFormatter.new("until", self).format(q)
end

#modifier?Boolean



11344
11345
11346
# File 'lib/syntax_tree/node.rb', line 11344

def modifier?
  predicate.location.start_char > statements.location.start_char
end