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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of XStringLiteral.



11767
11768
11769
11770
11771
# File 'lib/syntax_tree/node.rb', line 11767

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



11765
11766
11767
# File 'lib/syntax_tree/node.rb', line 11765

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11762
11763
11764
# File 'lib/syntax_tree/node.rb', line 11762

def location
  @location
end

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

xstring



11759
11760
11761
# File 'lib/syntax_tree/node.rb', line 11759

def parts
  @parts
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



11773
11774
11775
# File 'lib/syntax_tree/node.rb', line 11773

def child_nodes
  parts
end

#deconstruct_keys(keys) ⇒ Object



11779
11780
11781
# File 'lib/syntax_tree/node.rb', line 11779

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

#format(q) ⇒ Object



11783
11784
11785
11786
11787
# File 'lib/syntax_tree/node.rb', line 11783

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

#pretty_print(q) ⇒ Object



11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
# File 'lib/syntax_tree/node.rb', line 11789

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



11800
11801
11802
11803
11804
11805
11806
11807
# File 'lib/syntax_tree/node.rb', line 11800

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