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.



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

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

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments being sent to the keyword



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

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2631
2632
2633
# File 'lib/syntax_tree/node.rb', line 2631

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



2668
2669
2670
# File 'lib/syntax_tree/node.rb', line 2668

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

#accept(visitor) ⇒ Object



2639
2640
2641
# File 'lib/syntax_tree/node.rb', line 2639

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

#child_nodesObject Also known as: deconstruct



2643
2644
2645
# File 'lib/syntax_tree/node.rb', line 2643

def child_nodes
  [arguments]
end

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



2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
# File 'lib/syntax_tree/node.rb', line 2647

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



2660
2661
2662
# File 'lib/syntax_tree/node.rb', line 2660

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

#format(q) ⇒ Object



2664
2665
2666
# File 'lib/syntax_tree/node.rb', line 2664

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