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.



12121
12122
12123
12124
12125
# File 'lib/syntax_tree.rb', line 12121

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



12119
12120
12121
# File 'lib/syntax_tree.rb', line 12119

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12116
12117
12118
# File 'lib/syntax_tree.rb', line 12116

def location
  @location
end

#valueObject (readonly)

String

the content of the string



12113
12114
12115
# File 'lib/syntax_tree.rb', line 12113

def value
  @value
end

Instance Method Details

#child_nodesObject



12131
12132
12133
# File 'lib/syntax_tree.rb', line 12131

def child_nodes
  []
end

#format(q) ⇒ Object



12135
12136
12137
# File 'lib/syntax_tree.rb', line 12135

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

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


12127
12128
12129
# File 'lib/syntax_tree.rb', line 12127

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

#pretty_print(q) ⇒ Object



12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
# File 'lib/syntax_tree.rb', line 12139

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



12150
12151
12152
12153
12154
12155
12156
12157
# File 'lib/syntax_tree.rb', line 12150

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