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.



11479
11480
11481
11482
11483
11484
# File 'lib/syntax_tree/node.rb', line 11479

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



11477
11478
11479
# File 'lib/syntax_tree/node.rb', line 11477

def comments
  @comments
end

#predicateObject (readonly)

Node

the expression to be checked



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

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



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

def statements
  @statements
end

Instance Method Details

#===(other) ⇒ Object



11521
11522
11523
11524
# File 'lib/syntax_tree/node.rb', line 11521

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

#accept(visitor) ⇒ Object



11486
11487
11488
# File 'lib/syntax_tree/node.rb', line 11486

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

#child_nodesObject Also known as: deconstruct



11490
11491
11492
# File 'lib/syntax_tree/node.rb', line 11490

def child_nodes
  [predicate, statements]
end

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



11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
# File 'lib/syntax_tree/node.rb', line 11494

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



11508
11509
11510
11511
11512
11513
11514
11515
# File 'lib/syntax_tree/node.rb', line 11508

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

#format(q) ⇒ Object



11517
11518
11519
# File 'lib/syntax_tree/node.rb', line 11517

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

#modifier?Boolean

Returns:

  • (Boolean)


11526
11527
11528
# File 'lib/syntax_tree/node.rb', line 11526

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