Class: SyntaxTree::CHAR
Overview
CHAR irepresents a single codepoint in the script encoding.
?a
In the example above, the CHAR node represents the string literal “a”. You can use control characters with this as well, as in ?C-a.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the value of the character literal.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ CHAR
constructor
A new instance of CHAR.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:, comments: []) ⇒ CHAR
Returns a new instance of CHAR.
202 203 204 205 206 |
# File 'lib/syntax_tree/node.rb', line 202 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
200 201 202 |
# File 'lib/syntax_tree/node.rb', line 200 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the value of the character literal
197 198 199 |
# File 'lib/syntax_tree/node.rb', line 197 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
208 209 210 |
# File 'lib/syntax_tree/node.rb', line 208 def accept(visitor) visitor.visit_CHAR(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
212 213 214 |
# File 'lib/syntax_tree/node.rb', line 212 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
218 219 220 |
# File 'lib/syntax_tree/node.rb', line 218 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
222 223 224 225 226 227 228 229 230 |
# File 'lib/syntax_tree/node.rb', line 222 def format(q) if value.length != 2 q.text(value) else q.text(q.quote) q.text(value[1] == "\"" ? "\\\"" : value[1]) q.text(q.quote) end end |