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.



8205
8206
8207
8208
8209
8210
# File 'lib/syntax_tree/node.rb', line 8205

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



8203
8204
8205
# File 'lib/syntax_tree/node.rb', line 8203

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



8197
8198
8199
# File 'lib/syntax_tree/node.rb', line 8197

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



8200
8201
8202
# File 'lib/syntax_tree/node.rb', line 8200

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



8212
8213
8214
# File 'lib/syntax_tree/node.rb', line 8212

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

#child_nodesObject Also known as: deconstruct



8216
8217
8218
# File 'lib/syntax_tree/node.rb', line 8216

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



8222
8223
8224
# File 'lib/syntax_tree/node.rb', line 8222

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

#format(q) ⇒ Object



8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
# File 'lib/syntax_tree/node.rb', line 8226

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