Class: SyntaxTree::CHAR
- Inherits:
-
Object
- Object
- SyntaxTree::CHAR
- Defined in:
- lib/syntax_tree.rb
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
- #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.
500 501 502 503 504 |
# File 'lib/syntax_tree.rb', line 500 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
498 499 500 |
# File 'lib/syntax_tree.rb', line 498 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
495 496 497 |
# File 'lib/syntax_tree.rb', line 495 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the character literal
492 493 494 |
# File 'lib/syntax_tree.rb', line 492 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
506 507 508 |
# File 'lib/syntax_tree.rb', line 506 def child_nodes [] end |
#format(q) ⇒ Object
510 511 512 513 514 515 516 517 518 |
# File 'lib/syntax_tree.rb', line 510 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
520 521 522 523 524 525 526 527 528 529 |
# File 'lib/syntax_tree.rb', line 520 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
531 532 533 534 535 |
# File 'lib/syntax_tree.rb', line 531 def to_json(*opts) { type: :CHAR, value: value, loc: location, cmts: comments }.to_json( *opts ) end |