Class: Markbridge::AST::Text
Overview
Represents a text node (leaf node) in the AST. Text nodes contain the actual text content and cannot have children.
Instance Attribute Summary collapse
-
#text ⇒ String
readonly
The text content of this node.
Instance Method Summary collapse
-
#initialize(text) ⇒ Text
constructor
Create a new text node with the given content.
-
#merge(other) ⇒ Text
Merge another text node's content into this one.
Constructor Details
#initialize(text) ⇒ Text
Create a new text node with the given content.
Frozen input is shared as-is (copy-on-write: #merge dups before its first append) — the parser hot path always passes frozen token text, so no copy is made per text node. Mutable input is copied so that in-place mutations cannot leak in either direction between the caller's string and this node.
29 30 31 |
# File 'lib/markbridge/ast/text.rb', line 29 def initialize(text) @text = text.frozen? ? text : text.dup end |
Instance Attribute Details
#text ⇒ String (readonly)
Returns the text content of this node.
18 19 20 |
# File 'lib/markbridge/ast/text.rb', line 18 def text @text end |
Instance Method Details
#merge(other) ⇒ Text
Merge another text node's content into this one. This mutates the current text node by appending the other's text.
38 39 40 41 42 |
# File 'lib/markbridge/ast/text.rb', line 38 def merge(other) @text = @text.dup if @text.frozen? @text << other.text self end |