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.



8019
8020
8021
8022
8023
8024
# File 'lib/syntax_tree/node.rb', line 8019

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



8017
8018
8019
# File 'lib/syntax_tree/node.rb', line 8017

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



8011
8012
8013
# File 'lib/syntax_tree/node.rb', line 8011

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



8014
8015
8016
# File 'lib/syntax_tree/node.rb', line 8014

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



8026
8027
8028
# File 'lib/syntax_tree/node.rb', line 8026

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

#child_nodesObject Also known as: deconstruct



8030
8031
8032
# File 'lib/syntax_tree/node.rb', line 8030

def child_nodes
  [left, right]
end

#deconstruct_keys(keys) ⇒ Object



8036
8037
8038
# File 'lib/syntax_tree/node.rb', line 8036

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

#format(q) ⇒ Object



8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
# File 'lib/syntax_tree/node.rb', line 8040

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