Class: SyntaxTree::StringConcat

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

StringConcat represents concatenating two strings together using a backward slash.

"first" \
  "second"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of StringConcat.



11199
11200
11201
11202
11203
11204
# File 'lib/syntax_tree.rb', line 11199

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



11197
11198
11199
# File 'lib/syntax_tree.rb', line 11197

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



11188
11189
11190
# File 'lib/syntax_tree.rb', line 11188

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



11194
11195
11196
# File 'lib/syntax_tree.rb', line 11194

def location
  @location
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



11191
11192
11193
# File 'lib/syntax_tree.rb', line 11191

def right
  @right
end

Instance Method Details

#child_nodesObject



11206
11207
11208
# File 'lib/syntax_tree.rb', line 11206

def child_nodes
  [left, right]
end

#format(q) ⇒ Object



11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
# File 'lib/syntax_tree.rb', line 11210

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



11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
# File 'lib/syntax_tree.rb', line 11221

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



11235
11236
11237
11238
11239
11240
11241
11242
11243
# File 'lib/syntax_tree.rb', line 11235

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