Class: SyntaxTree::Break

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Break represents using the break keyword.

break

It can also optionally accept arguments, as in:

break 1

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(arguments:, location:) ⇒ Break

Returns a new instance of Break.



2602
2603
2604
2605
2606
# File 'lib/syntax_tree/node.rb', line 2602

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

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments being sent to the keyword



2597
2598
2599
# File 'lib/syntax_tree/node.rb', line 2597

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2600
2601
2602
# File 'lib/syntax_tree/node.rb', line 2600

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



2637
2638
2639
# File 'lib/syntax_tree/node.rb', line 2637

def ===(other)
  other.is_a?(Break) && arguments === other.arguments
end

#accept(visitor) ⇒ Object



2608
2609
2610
# File 'lib/syntax_tree/node.rb', line 2608

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

#child_nodesObject Also known as: deconstruct



2612
2613
2614
# File 'lib/syntax_tree/node.rb', line 2612

def child_nodes
  [arguments]
end

#copy(arguments: nil, location: nil) ⇒ Object



2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
# File 'lib/syntax_tree/node.rb', line 2616

def copy(arguments: nil, location: nil)
  node =
    Break.new(
      arguments: arguments || self.arguments,
      location: location || self.location
    )

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

#deconstruct_keys(_keys) ⇒ Object



2629
2630
2631
# File 'lib/syntax_tree/node.rb', line 2629

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

#format(q) ⇒ Object



2633
2634
2635
# File 'lib/syntax_tree/node.rb', line 2633

def format(q)
  FlowControlFormatter.new("break", self).format(q)
end