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.



8501
8502
8503
8504
8505
8506
# File 'lib/syntax_tree/node.rb', line 8501

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



8499
8500
8501
# File 'lib/syntax_tree/node.rb', line 8499

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



8493
8494
8495
# File 'lib/syntax_tree/node.rb', line 8493

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



8496
8497
8498
# File 'lib/syntax_tree/node.rb', line 8496

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



8508
8509
8510
# File 'lib/syntax_tree/node.rb', line 8508

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

#child_nodesObject Also known as: deconstruct



8512
8513
8514
# File 'lib/syntax_tree/node.rb', line 8512

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



8518
8519
8520
# File 'lib/syntax_tree/node.rb', line 8518

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

#format(q) ⇒ Object



8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
# File 'lib/syntax_tree/node.rb', line 8522

def format(q)
  q.group do
    q.format(left)
    q.text(" \\")
    q.indent do
      q.breakable_force
      q.format(right)
    end
  end
end