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

Constructor Details

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

Returns a new instance of StringConcat.



9204
9205
9206
9207
9208
9209
# File 'lib/syntax_tree/node.rb', line 9204

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



9202
9203
9204
# File 'lib/syntax_tree/node.rb', line 9202

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



9196
9197
9198
# File 'lib/syntax_tree/node.rb', line 9196

def left
  @left
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



9199
9200
9201
# File 'lib/syntax_tree/node.rb', line 9199

def right
  @right
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



9211
9212
9213
# File 'lib/syntax_tree/node.rb', line 9211

def child_nodes
  [left, right]
end

#deconstruct_keys(keys) ⇒ Object



9217
9218
9219
# File 'lib/syntax_tree/node.rb', line 9217

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

#format(q) ⇒ Object



9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
# File 'lib/syntax_tree/node.rb', line 9221

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

#pretty_print(q) ⇒ Object



9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
# File 'lib/syntax_tree/node.rb', line 9232

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("string_concat")

    q.breakable
    q.pp(left)

    q.breakable
    q.pp(right)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



9246
9247
9248
9249
9250
9251
9252
9253
9254
# File 'lib/syntax_tree/node.rb', line 9246

def to_json(*opts)
  {
    type: :string_concat,
    left: left,
    right: right,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end