Class: SyntaxTree::TStringContent
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
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the content of the string.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ TStringContent
constructor
A new instance of TStringContent.
- #match?(pattern) ⇒ Boolean
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ TStringContent
Returns a new instance of TStringContent.
10295 10296 10297 10298 10299 |
# File 'lib/syntax_tree/node.rb', line 10295 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
10293 10294 10295 |
# File 'lib/syntax_tree/node.rb', line 10293 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10290 10291 10292 |
# File 'lib/syntax_tree/node.rb', line 10290 def location @location end |
#value ⇒ Object (readonly)
- String
-
the content of the string
10287 10288 10289 |
# File 'lib/syntax_tree/node.rb', line 10287 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10305 10306 10307 |
# File 'lib/syntax_tree/node.rb', line 10305 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
10311 10312 10313 |
# File 'lib/syntax_tree/node.rb', line 10311 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
10315 10316 10317 |
# File 'lib/syntax_tree/node.rb', line 10315 def format(q) q.text(value) end |
#match?(pattern) ⇒ Boolean
10301 10302 10303 |
# File 'lib/syntax_tree/node.rb', line 10301 def match?(pattern) value.match?(pattern) end |
#pretty_print(q) ⇒ Object
10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 |
# File 'lib/syntax_tree/node.rb', line 10319 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
10330 10331 10332 10333 10334 10335 10336 10337 |
# File 'lib/syntax_tree/node.rb', line 10330 def to_json(*opts) { type: :tstring_content, value: value.force_encoding("UTF-8"), loc: location, cmts: comments }.to_json(*opts) end |