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
Constructor Details
#initialize(value:, location:, comments: []) ⇒ CHAR
Returns a new instance of CHAR.
164 165 166 167 168 |
# File 'lib/syntax_tree/node.rb', line 164 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
162 163 164 |
# File 'lib/syntax_tree/node.rb', line 162 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the value of the character literal
159 160 161 |
# File 'lib/syntax_tree/node.rb', line 159 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
170 171 172 |
# File 'lib/syntax_tree/node.rb', line 170 def accept(visitor) visitor.visit_CHAR(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
174 175 176 |
# File 'lib/syntax_tree/node.rb', line 174 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
180 181 182 |
# File 'lib/syntax_tree/node.rb', line 180 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'lib/syntax_tree/node.rb', line 184 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 |