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:, comments: []) ⇒ TStringContent

Returns a new instance of TStringContent.



8863
8864
8865
8866
8867
# File 'lib/syntax_tree/node.rb', line 8863

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



8861
8862
8863
# File 'lib/syntax_tree/node.rb', line 8861

def comments
  @comments
end

#value ⇒ Object (readonly)

[String] the content of the string



8858
8859
8860
# File 'lib/syntax_tree/node.rb', line 8858

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



8873
8874
8875
# File 'lib/syntax_tree/node.rb', line 8873

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

#child_nodes ⇒ Object Also known as: deconstruct



8877
8878
8879
# File 'lib/syntax_tree/node.rb', line 8877

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



8883
8884
8885
# File 'lib/syntax_tree/node.rb', line 8883

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

#format(q) ⇒ Object



8887
8888
8889
# File 'lib/syntax_tree/node.rb', line 8887

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

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


8869
8870
8871
# File 'lib/syntax_tree/node.rb', line 8869

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