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:, comments: []) ⇒ StringConcat

Returns a new instance of StringConcat.



8126
8127
8128
8129
8130
8131
# File 'lib/syntax_tree/node.rb', line 8126

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8124
8125
8126
# File 'lib/syntax_tree/node.rb', line 8124

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



8118
8119
8120
# File 'lib/syntax_tree/node.rb', line 8118

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



8121
8122
8123
# File 'lib/syntax_tree/node.rb', line 8121

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



8133
8134
8135
# File 'lib/syntax_tree/node.rb', line 8133

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

#child_nodesObject Also known as: deconstruct



8137
8138
8139
# File 'lib/syntax_tree/node.rb', line 8137

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



8143
8144
8145
# File 'lib/syntax_tree/node.rb', line 8143

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

#format(q) ⇒ Object



8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
# File 'lib/syntax_tree/node.rb', line 8147

def format(q)
  q.group do
    q.format(left)
    q.text(" \\")
    q.indent do
      q.breakable(force: true)
      q.format(right)
    end
  end
end