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

Returns a new instance of UntilNode.



11323
11324
11325
11326
11327
11328
# File 'lib/syntax_tree/node.rb', line 11323

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



11321
11322
11323
# File 'lib/syntax_tree/node.rb', line 11321

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



11315
11316
11317
# File 'lib/syntax_tree/node.rb', line 11315

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



11318
11319
11320
# File 'lib/syntax_tree/node.rb', line 11318

def statements
  @statements
end

Instance Method Details

#===(other) ⇒ Object



11365
11366
11367
11368
# File 'lib/syntax_tree/node.rb', line 11365

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

#accept(visitor) ⇒ Object



11330
11331
11332
# File 'lib/syntax_tree/node.rb', line 11330

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [predicate, statements]
end

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



11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
# File 'lib/syntax_tree/node.rb', line 11338

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



11352
11353
11354
11355
11356
11357
11358
11359
# File 'lib/syntax_tree/node.rb', line 11352

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

#format(q) ⇒ Object



11361
11362
11363
# File 'lib/syntax_tree/node.rb', line 11361

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

#modifier?Boolean

Returns:

  • (Boolean)


11370
11371
11372
# File 'lib/syntax_tree/node.rb', line 11370

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