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, #pretty_print, #to_json

Constructor Details

#initialize(parts:, location:) ⇒ XStringLiteral

Returns a new instance of XStringLiteral.



12088
12089
12090
12091
12092
# File 'lib/syntax_tree/node.rb', line 12088

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



12086
12087
12088
# File 'lib/syntax_tree/node.rb', line 12086

def comments
  @comments
end

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

xstring



12083
12084
12085
# File 'lib/syntax_tree/node.rb', line 12083

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



12125
12126
12127
# File 'lib/syntax_tree/node.rb', line 12125

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

#accept(visitor) ⇒ Object



12094
12095
12096
# File 'lib/syntax_tree/node.rb', line 12094

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

#child_nodesObject Also known as: deconstruct



12098
12099
12100
# File 'lib/syntax_tree/node.rb', line 12098

def child_nodes
  parts
end

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



12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
# File 'lib/syntax_tree/node.rb', line 12102

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



12115
12116
12117
# File 'lib/syntax_tree/node.rb', line 12115

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

#format(q) ⇒ Object



12119
12120
12121
12122
12123
# File 'lib/syntax_tree/node.rb', line 12119

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