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.



8913
8914
8915
8916
8917
# File 'lib/syntax_tree/node.rb', line 8913

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8911
8912
8913
# File 'lib/syntax_tree/node.rb', line 8911

def comments
  @comments
end

#valueObject (readonly)

String

the content of the string



8908
8909
8910
# File 'lib/syntax_tree/node.rb', line 8908

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



8923
8924
8925
# File 'lib/syntax_tree/node.rb', line 8923

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

#child_nodesObject Also known as: deconstruct



8927
8928
8929
# File 'lib/syntax_tree/node.rb', line 8927

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



8933
8934
8935
# File 'lib/syntax_tree/node.rb', line 8933

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

#format(q) ⇒ Object



8937
8938
8939
# File 'lib/syntax_tree/node.rb', line 8937

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

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


8919
8920
8921
# File 'lib/syntax_tree/node.rb', line 8919

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