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.



10991
10992
10993
10994
10995
10996
# File 'lib/syntax_tree.rb', line 10991

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



10989
10990
10991
# File 'lib/syntax_tree.rb', line 10989

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



10980
10981
10982
# File 'lib/syntax_tree.rb', line 10980

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



10986
10987
10988
# File 'lib/syntax_tree.rb', line 10986

def location
  @location
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



10983
10984
10985
# File 'lib/syntax_tree.rb', line 10983

def right
  @right
end

Instance Method Details

#child_nodesObject



10998
10999
11000
# File 'lib/syntax_tree.rb', line 10998

def child_nodes
  [left, right]
end

#format(q) ⇒ Object



11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
# File 'lib/syntax_tree.rb', line 11002

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



11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
# File 'lib/syntax_tree.rb', line 11013

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



11027
11028
11029
11030
11031
11032
11033
11034
11035
# File 'lib/syntax_tree.rb', line 11027

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