Class: SyntaxTree::TStringContent

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ TStringContent

Returns a new instance of TStringContent.



11909
11910
11911
11912
11913
# File 'lib/syntax_tree.rb', line 11909

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



11907
11908
11909
# File 'lib/syntax_tree.rb', line 11907

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11904
11905
11906
# File 'lib/syntax_tree.rb', line 11904

def location
  @location
end

#valueObject (readonly)

String

the content of the string



11901
11902
11903
# File 'lib/syntax_tree.rb', line 11901

def value
  @value
end

Instance Method Details

#child_nodesObject



11919
11920
11921
# File 'lib/syntax_tree.rb', line 11919

def child_nodes
  []
end

#format(q) ⇒ Object



11923
11924
11925
# File 'lib/syntax_tree.rb', line 11923

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

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


11915
11916
11917
# File 'lib/syntax_tree.rb', line 11915

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

#pretty_print(q) ⇒ Object



11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
# File 'lib/syntax_tree.rb', line 11927

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("tstring_content")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



11938
11939
11940
11941
11942
11943
11944
11945
# File 'lib/syntax_tree.rb', line 11938

def to_json(*opts)
  {
    type: :tstring_content,
    value: value.force_encoding("UTF-8"),
    loc: location,
    cmts: comments
  }.to_json(*opts)
end