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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the value of the character literal.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ CHAR
constructor
A new instance of CHAR.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ CHAR
Returns a new instance of CHAR.
176 177 178 179 180 |
# File 'lib/syntax_tree/node.rb', line 176 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
174 175 176 |
# File 'lib/syntax_tree/node.rb', line 174 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
171 172 173 |
# File 'lib/syntax_tree/node.rb', line 171 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the character literal
168 169 170 |
# File 'lib/syntax_tree/node.rb', line 168 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
182 183 184 |
# File 'lib/syntax_tree/node.rb', line 182 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
188 189 190 |
# File 'lib/syntax_tree/node.rb', line 188 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/syntax_tree/node.rb', line 192 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 |
#pretty_print(q) ⇒ Object
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/syntax_tree/node.rb', line 202 def pretty_print(q) q.group(2, "(", ")") do q.text("CHAR") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
213 214 215 216 217 |
# File 'lib/syntax_tree/node.rb', line 213 def to_json(*opts) { type: :CHAR, value: value, loc: location, cmts: comments }.to_json( *opts ) end |