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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(predicate:, statements:, location:) ⇒ UntilNode

Returns a new instance of UntilNode.



11464
11465
11466
11467
11468
11469
# File 'lib/syntax_tree/node.rb', line 11464

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



11462
11463
11464
# File 'lib/syntax_tree/node.rb', line 11462

def comments
  @comments
end

#predicateObject (readonly)

Node

the expression to be checked



11456
11457
11458
# File 'lib/syntax_tree/node.rb', line 11456

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



11459
11460
11461
# File 'lib/syntax_tree/node.rb', line 11459

def statements
  @statements
end

Instance Method Details

#===(other) ⇒ Object



11506
11507
11508
11509
# File 'lib/syntax_tree/node.rb', line 11506

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

#accept(visitor) ⇒ Object



11471
11472
11473
# File 'lib/syntax_tree/node.rb', line 11471

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

#child_nodesObject Also known as: deconstruct



11475
11476
11477
# File 'lib/syntax_tree/node.rb', line 11475

def child_nodes
  [predicate, statements]
end

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



11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
# File 'lib/syntax_tree/node.rb', line 11479

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



11493
11494
11495
11496
11497
11498
11499
11500
# File 'lib/syntax_tree/node.rb', line 11493

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

#format(q) ⇒ Object



11502
11503
11504
# File 'lib/syntax_tree/node.rb', line 11502

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

#modifier?Boolean

Returns:

  • (Boolean)


11511
11512
11513
# File 'lib/syntax_tree/node.rb', line 11511

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