Class: SyntaxTree::StringConcat

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

Overview

StringConcat represents concatenating two strings together using a backward slash.

"first" \
  "second"

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(left:, right:, location:) ⇒ StringConcat

Returns a new instance of StringConcat.



9995
9996
9997
9998
9999
10000
# File 'lib/syntax_tree/node.rb', line 9995

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9993
9994
9995
# File 'lib/syntax_tree/node.rb', line 9993

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



9987
9988
9989
# File 'lib/syntax_tree/node.rb', line 9987

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



9990
9991
9992
# File 'lib/syntax_tree/node.rb', line 9990

def right
  @right
end

Instance Method Details

#===(other) ⇒ Object



10039
10040
10041
# File 'lib/syntax_tree/node.rb', line 10039

def ===(other)
  other.is_a?(StringConcat) && left === other.left && right === other.right
end

#accept(visitor) ⇒ Object



10002
10003
10004
# File 'lib/syntax_tree/node.rb', line 10002

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

#child_nodesObject Also known as: deconstruct



10006
10007
10008
# File 'lib/syntax_tree/node.rb', line 10006

def child_nodes
  [left, right]
end

#copy(left: nil, right: nil, location: nil) ⇒ Object



10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
# File 'lib/syntax_tree/node.rb', line 10010

def copy(left: nil, right: nil, location: nil)
  node =
    StringConcat.new(
      left: left || self.left,
      right: right || self.right,
      location: location || self.location
    )

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

#deconstruct_keys(_keys) ⇒ Object



10024
10025
10026
# File 'lib/syntax_tree/node.rb', line 10024

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

#format(q) ⇒ Object



10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
# File 'lib/syntax_tree/node.rb', line 10028

def format(q)
  q.group do
    q.format(left)
    q.text(" \\")
    q.indent do
      q.breakable_force
      q.format(right)
    end
  end
end