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.



11989
11990
11991
11992
11993
# File 'lib/syntax_tree.rb', line 11989

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



11987
11988
11989
# File 'lib/syntax_tree.rb', line 11987

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11984
11985
11986
# File 'lib/syntax_tree.rb', line 11984

def location
  @location
end

#valueObject (readonly)

String

the content of the string



11981
11982
11983
# File 'lib/syntax_tree.rb', line 11981

def value
  @value
end

Instance Method Details

#child_nodesObject



11999
12000
12001
# File 'lib/syntax_tree.rb', line 11999

def child_nodes
  []
end

#format(q) ⇒ Object



12003
12004
12005
# File 'lib/syntax_tree.rb', line 12003

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

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


11995
11996
11997
# File 'lib/syntax_tree.rb', line 11995

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

#pretty_print(q) ⇒ Object



12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
# File 'lib/syntax_tree.rb', line 12007

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



12018
12019
12020
12021
12022
12023
12024
12025
# File 'lib/syntax_tree.rb', line 12018

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