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



12964
12965
12966
12967
12968
# File 'lib/syntax_tree.rb', line 12964

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



12962
12963
12964
# File 'lib/syntax_tree.rb', line 12962

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12959
12960
12961
# File 'lib/syntax_tree.rb', line 12959

def location
  @location
end

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

xstring



12956
12957
12958
# File 'lib/syntax_tree.rb', line 12956

def parts
  @parts
end

Instance Method Details

#child_nodesObject



12970
12971
12972
# File 'lib/syntax_tree.rb', line 12970

def child_nodes
  parts
end

#format(q) ⇒ Object



12974
12975
12976
12977
12978
# File 'lib/syntax_tree.rb', line 12974

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

#pretty_print(q) ⇒ Object



12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
# File 'lib/syntax_tree.rb', line 12980

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



12991
12992
12993
12994
12995
12996
12997
12998
# File 'lib/syntax_tree.rb', line 12991

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