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

Constructor Details

#initialize(value:, location:) ⇒ TStringContent

Returns a new instance of TStringContent.



10936
10937
10938
10939
10940
# File 'lib/syntax_tree/node.rb', line 10936

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10934
10935
10936
# File 'lib/syntax_tree/node.rb', line 10934

def comments
  @comments
end

#valueObject (readonly)

String

the content of the string



10931
10932
10933
# File 'lib/syntax_tree/node.rb', line 10931

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



10975
10976
10977
# File 'lib/syntax_tree/node.rb', line 10975

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

#accept(visitor) ⇒ Object



10946
10947
10948
# File 'lib/syntax_tree/node.rb', line 10946

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

#child_nodesObject Also known as: deconstruct



10950
10951
10952
# File 'lib/syntax_tree/node.rb', line 10950

def child_nodes
  []
end

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



10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
# File 'lib/syntax_tree/node.rb', line 10954

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



10967
10968
10969
# File 'lib/syntax_tree/node.rb', line 10967

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

#format(q) ⇒ Object



10971
10972
10973
# File 'lib/syntax_tree/node.rb', line 10971

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

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


10942
10943
10944
# File 'lib/syntax_tree/node.rb', line 10942

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