Class: SyntaxTree::XStringLiteral

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

Overview

XStringLiteral represents a string that gets executed.

`ls`

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of XStringLiteral.



13474
13475
13476
13477
13478
# File 'lib/syntax_tree.rb', line 13474

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



13472
13473
13474
# File 'lib/syntax_tree.rb', line 13472

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



13469
13470
13471
# File 'lib/syntax_tree.rb', line 13469

def location
  @location
end

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

xstring



13466
13467
13468
# File 'lib/syntax_tree.rb', line 13466

def parts
  @parts
end

Instance Method Details

#child_nodesObject



13480
13481
13482
# File 'lib/syntax_tree.rb', line 13480

def child_nodes
  parts
end

#format(q) ⇒ Object



13484
13485
13486
13487
13488
# File 'lib/syntax_tree.rb', line 13484

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

#pretty_print(q) ⇒ Object



13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
# File 'lib/syntax_tree.rb', line 13490

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



13501
13502
13503
13504
13505
13506
13507
13508
# File 'lib/syntax_tree.rb', line 13501

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