Class: Prism::Token
- Inherits:
-
Object
- Object
- Prism::Token
- Defined in:
- lib/prism/parse_result.rb,
ext/prism/extension.c
Overview
This represents a token from the Ruby source.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
The type of token that this token is.
-
#value ⇒ Object
readonly
A byteslice of the source that this token represents.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns true if the given other token is equal to this token.
-
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for Token.
-
#deep_freeze ⇒ Object
Freeze this object and the objects it contains.
-
#initialize(source, type, value, location) ⇒ Token
constructor
Create a new token object with the given type, value, and location.
-
#inspect ⇒ Object
Returns a string representation of this token.
-
#location ⇒ Object
A Location object representing the location of this token in the source.
-
#pretty_print(q) ⇒ Object
Implement the pretty print interface for Token.
Constructor Details
#initialize(source, type, value, location) ⇒ Token
Create a new token object with the given type, value, and location.
828 829 830 831 832 833 |
# File 'lib/prism/parse_result.rb', line 828 def initialize(source, type, value, location) @source = source @type = type @value = value @location = location end |
Instance Attribute Details
#type ⇒ Object (readonly)
The type of token that this token is.
822 823 824 |
# File 'lib/prism/parse_result.rb', line 822 def type @type end |
#value ⇒ Object (readonly)
A byteslice of the source that this token represents.
825 826 827 |
# File 'lib/prism/parse_result.rb', line 825 def value @value end |
Instance Method Details
#==(other) ⇒ Object
Returns true if the given other token is equal to this token.
863 864 865 866 867 |
# File 'lib/prism/parse_result.rb', line 863 def ==(other) Token === other && other.type == type && other.value == value end |
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for Token.
836 837 838 |
# File 'lib/prism/parse_result.rb', line 836 def deconstruct_keys(keys) { type: type, value: value, location: location } end |
#deep_freeze ⇒ Object
Freeze this object and the objects it contains.
876 877 878 879 880 |
# File 'lib/prism/parse_result.rb', line 876 def deep_freeze value.freeze location.freeze freeze end |
#inspect ⇒ Object
Returns a string representation of this token.
870 871 872 873 |
# File 'lib/prism/parse_result.rb', line 870 def inspect location super end |
#location ⇒ Object
A Location object representing the location of this token in the source.
841 842 843 844 845 |
# File 'lib/prism/parse_result.rb', line 841 def location location = @location return location if location.is_a?(Location) @location = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#pretty_print(q) ⇒ Object
Implement the pretty print interface for Token.
848 849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/prism/parse_result.rb', line 848 def pretty_print(q) q.group do q.text(type.to_s) self.location.pretty_print(q) q.text("(") q.nest(2) do q.breakable("") q.pp(value) end q.breakable("") q.text(")") end end |