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

#pretty_print, #to_json

Constructor Details

#initialize(left:, right:, location:, comments: []) ⇒ StringConcat

Returns a new instance of StringConcat.



7476
7477
7478
7479
7480
7481
# File 'lib/syntax_tree/node.rb', line 7476

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



7474
7475
7476
# File 'lib/syntax_tree/node.rb', line 7474

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



7468
7469
7470
# File 'lib/syntax_tree/node.rb', line 7468

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



7471
7472
7473
# File 'lib/syntax_tree/node.rb', line 7471

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



7483
7484
7485
# File 'lib/syntax_tree/node.rb', line 7483

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

#child_nodesObject Also known as: deconstruct



7487
7488
7489
# File 'lib/syntax_tree/node.rb', line 7487

def child_nodes
  [left, right]
end

#deconstruct_keys(keys) ⇒ Object



7493
7494
7495
# File 'lib/syntax_tree/node.rb', line 7493

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

#format(q) ⇒ Object



7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
# File 'lib/syntax_tree/node.rb', line 7497

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