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.



8287
8288
8289
8290
8291
8292
# File 'lib/syntax_tree/node.rb', line 8287

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



8285
8286
8287
# File 'lib/syntax_tree/node.rb', line 8285

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



8279
8280
8281
# File 'lib/syntax_tree/node.rb', line 8279

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



8282
8283
8284
# File 'lib/syntax_tree/node.rb', line 8282

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



8294
8295
8296
# File 'lib/syntax_tree/node.rb', line 8294

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

#child_nodesObject Also known as: deconstruct



8298
8299
8300
# File 'lib/syntax_tree/node.rb', line 8298

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



8304
8305
8306
# File 'lib/syntax_tree/node.rb', line 8304

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

#format(q) ⇒ Object



8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
# File 'lib/syntax_tree/node.rb', line 8308

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