Class: SyntaxTree::TStringContent

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

Overview

TStringContent represents plain characters inside of an entity that accepts string content like a string, heredoc, command string, or regular expression.

"string"

In the example above, TStringContent represents the string token contained within the string.

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(value:, location:) ⇒ TStringContent



10817
10818
10819
10820
10821
# File 'lib/syntax_tree/node.rb', line 10817

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10815
10816
10817
# File 'lib/syntax_tree/node.rb', line 10815

def comments
  @comments
end

#valueObject (readonly)

String

the content of the string



10812
10813
10814
# File 'lib/syntax_tree/node.rb', line 10812

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



10856
10857
10858
# File 'lib/syntax_tree/node.rb', line 10856

def ===(other)
  other.is_a?(TStringContent) && value === other.value
end

#accept(visitor) ⇒ Object



10827
10828
10829
# File 'lib/syntax_tree/node.rb', line 10827

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

#child_nodesObject Also known as: deconstruct



10831
10832
10833
# File 'lib/syntax_tree/node.rb', line 10831

def child_nodes
  []
end

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



10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
# File 'lib/syntax_tree/node.rb', line 10835

def copy(value: nil, location: nil)
  node =
    TStringContent.new(
      value: value || self.value,
      location: location || self.location
    )

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

#deconstruct_keys(_keys) ⇒ Object



10848
10849
10850
# File 'lib/syntax_tree/node.rb', line 10848

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

#format(q) ⇒ Object



10852
10853
10854
# File 'lib/syntax_tree/node.rb', line 10852

def format(q)
  q.text(value)
end

#match?(pattern) ⇒ Boolean



10823
10824
10825
# File 'lib/syntax_tree/node.rb', line 10823

def match?(pattern)
  value.match?(pattern)
end