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

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(parts:, location:) ⇒ XStringLiteral

Returns a new instance of XStringLiteral.



12210
12211
12212
12213
12214
# File 'lib/syntax_tree/node.rb', line 12210

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



12208
12209
12210
# File 'lib/syntax_tree/node.rb', line 12208

def comments
  @comments
end

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

xstring



12205
12206
12207
# File 'lib/syntax_tree/node.rb', line 12205

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



12247
12248
12249
# File 'lib/syntax_tree/node.rb', line 12247

def ===(other)
  other.is_a?(XStringLiteral) && ArrayMatch.call(parts, other.parts)
end

#accept(visitor) ⇒ Object



12216
12217
12218
# File 'lib/syntax_tree/node.rb', line 12216

def accept(visitor)
  visitor.visit_xstring_literal(self)
end

#child_nodesObject Also known as: deconstruct



12220
12221
12222
# File 'lib/syntax_tree/node.rb', line 12220

def child_nodes
  parts
end

#copy(parts: nil, location: nil) ⇒ Object



12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
# File 'lib/syntax_tree/node.rb', line 12224

def copy(parts: nil, location: nil)
  node =
    XStringLiteral.new(
      parts: parts || self.parts,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



12237
12238
12239
# File 'lib/syntax_tree/node.rb', line 12237

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

#format(q) ⇒ Object



12241
12242
12243
12244
12245
# File 'lib/syntax_tree/node.rb', line 12241

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