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.



11067
11068
11069
11070
11071
11072
# File 'lib/syntax_tree.rb', line 11067

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



11065
11066
11067
# File 'lib/syntax_tree.rb', line 11065

def comments
  @comments
end

#leftObject (readonly)

StringConcat | StringLiteral

the left side of the concatenation



11056
11057
11058
# File 'lib/syntax_tree.rb', line 11056

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



11062
11063
11064
# File 'lib/syntax_tree.rb', line 11062

def location
  @location
end

#rightObject (readonly)

StringLiteral

the right side of the concatenation



11059
11060
11061
# File 'lib/syntax_tree.rb', line 11059

def right
  @right
end

Instance Method Details

#child_nodesObject



11074
11075
11076
# File 'lib/syntax_tree.rb', line 11074

def child_nodes
  [left, right]
end

#format(q) ⇒ Object



11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
# File 'lib/syntax_tree.rb', line 11078

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



11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
# File 'lib/syntax_tree.rb', line 11089

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



11103
11104
11105
11106
11107
11108
11109
11110
11111
# File 'lib/syntax_tree.rb', line 11103

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