Class: SyntaxTree::XStringLiteral

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

Overview

XStringLiteral represents a string that gets executed.

`ls`

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

#initialize(parts:, location:, comments: []) ⇒ XStringLiteral

Returns a new instance of XStringLiteral.



11302
11303
11304
11305
11306
# File 'lib/syntax_tree/node.rb', line 11302

def initialize(parts:, location:, comments: [])
  @parts = parts
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



11300
11301
11302
# File 'lib/syntax_tree/node.rb', line 11300

def comments
  @comments
end

#partsObject (readonly)

[Array[ StringEmbExpr | StringDVar | TStringContent ]] the parts of the xstring



11297
11298
11299
# File 'lib/syntax_tree/node.rb', line 11297

def parts
  @parts
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



11308
11309
11310
# File 'lib/syntax_tree/node.rb', line 11308

def child_nodes
  parts
end

#deconstruct_keys(keys) ⇒ Object



11314
11315
11316
# File 'lib/syntax_tree/node.rb', line 11314

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

#format(q) ⇒ Object



11318
11319
11320
11321
11322
# File 'lib/syntax_tree/node.rb', line 11318

def format(q)
  q.text("`")
  q.format_each(parts)
  q.text("`")
end

#pretty_print(q) ⇒ Object



11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
# File 'lib/syntax_tree/node.rb', line 11324

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

    q.breakable
    q.group(2, "(", ")") { q.seplist(parts) { |part| q.pp(part) } }

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

#to_json(*opts) ⇒ Object



11335
11336
11337
11338
11339
11340
11341
11342
# File 'lib/syntax_tree/node.rb', line 11335

def to_json(*opts)
  {
    type: :xstring_literal,
    parts: parts,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end