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.
-
#value ⇒ Object
readonly
- String
-
the content of the string.
Attributes inherited from Node
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.
9893 9894 9895 9896 9897 |
# File 'lib/syntax_tree/node.rb', line 9893 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
9891 9892 9893 |
# File 'lib/syntax_tree/node.rb', line 9891 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the content of the string
9888 9889 9890 |
# File 'lib/syntax_tree/node.rb', line 9888 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
9903 9904 9905 |
# File 'lib/syntax_tree/node.rb', line 9903 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
9909 9910 9911 |
# File 'lib/syntax_tree/node.rb', line 9909 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
9913 9914 9915 |
# File 'lib/syntax_tree/node.rb', line 9913 def format(q) q.text(value) end |
#match?(pattern) ⇒ Boolean
9899 9900 9901 |
# File 'lib/syntax_tree/node.rb', line 9899 def match?(pattern) value.match?(pattern) end |
#pretty_print(q) ⇒ Object
9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 |
# File 'lib/syntax_tree/node.rb', line 9917 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
9928 9929 9930 9931 9932 9933 9934 9935 |
# File 'lib/syntax_tree/node.rb', line 9928 def to_json(*opts) { type: :tstring_content, value: value.force_encoding("UTF-8"), loc: location, cmts: comments }.to_json(*opts) end |