Class: Brandish::Parser::Node::Text
- Inherits:
-
Brandish::Parser::Node
- Object
- Brandish::Parser::Node
- Brandish::Parser::Node::Text
- Defined in:
- lib/brandish/parser/node/text.rb
Overview
A text node. This contains only text, and has no other node
decendants. This node automatically merges the contents of the text
into a single value, and places it in the value
attribute.
Direct Known Subclasses
Constant Summary collapse
- TOKENS =
A set of tokens kinds that are allowed to be in a text node.
::Set[:SPACE, :TEXT, :LINE, :NUMERIC, :ESCAPE, :/, :'"', :'='].freeze
Instance Attribute Summary collapse
-
#value ⇒ ::String
readonly
The value of the text node.
Attributes inherited from Brandish::Parser::Node
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Determines if this object equals another object.
-
#initialize(tokens: nil, value: nil, location: nil) ⇒ Text
constructor
Initialize the node.
-
#inspect ⇒ ::String
Pretty inspect.
Methods inherited from Brandish::Parser::Node
#prevent_update, #update, #update_prevented?
Constructor Details
#initialize(tokens: , location: nil) ⇒ Text #initialize(value: , location: ) ⇒ Text
Initialize the node.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/brandish/parser/node/text.rb', line 43 def initialize(tokens: nil, value: nil, location: nil) unless tokens || (value && location) fail ::ArgumentError, "Expected either a set of tokens or a " \ "value and a location, got neither" end @value = value || derive_value(tokens) @location = location || derive_location(tokens) freeze end |
Instance Attribute Details
#value ⇒ ::String (readonly)
The value of the text node. This is the string value of the source text that this node is based off of.
23 24 25 |
# File 'lib/brandish/parser/node/text.rb', line 23 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean
Determines if this object equals another object. If the other object is this object, it returns true; otherwise, if the other object is a Brandish::Parser::Node::Text, and all of the properties are equal, it returns true; otherwise, it returns false.
69 70 71 72 |
# File 'lib/brandish/parser/node/text.rb', line 69 def ==(other) equal?(other) || other.is_a?(self.class) && @value == other.value && @location == other.location end |
#inspect ⇒ ::String
Pretty inspect.
57 58 59 60 |
# File 'lib/brandish/parser/node/text.rb', line 57 def inspect "#<#{self.class} value=#{@value.inspect} " \ "location=#{@location.inspect}>" end |