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.



8237
8238
8239
8240
8241
8242
# File 'lib/syntax_tree/node.rb', line 8237

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



8235
8236
8237
# File 'lib/syntax_tree/node.rb', line 8235

def comments
  @comments
end

#left ⇒ Object (readonly)

[StringConcat | StringLiteral] the left side of the concatenation



8229
8230
8231
# File 'lib/syntax_tree/node.rb', line 8229

def left
  @left
end

#right ⇒ Object (readonly)

[StringLiteral] the right side of the concatenation



8232
8233
8234
# File 'lib/syntax_tree/node.rb', line 8232

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



8244
8245
8246
# File 'lib/syntax_tree/node.rb', line 8244

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

#child_nodes ⇒ Object Also known as: deconstruct



8248
8249
8250
# File 'lib/syntax_tree/node.rb', line 8248

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



8254
8255
8256
# File 'lib/syntax_tree/node.rb', line 8254

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

#format(q) ⇒ Object



8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
# File 'lib/syntax_tree/node.rb', line 8258

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