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.



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

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



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

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



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

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



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

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [left, right]
end

#deconstruct_keys(keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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