Last active
January 13, 2019 15:43
-
-
Save gosukiwi/4c1847206032189ecc2ca8f2388d57b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Token | |
attr_reader :type, :value | |
def initialize(type:, value:) | |
@type = type | |
@value = value | |
raise InvalidTokenError if value.nil? || type.nil? | |
end | |
def self.null | |
NullToken.new | |
end | |
def self.end_of_file | |
Token.new(type: 'EOF', value: '') | |
end | |
def length | |
value.length | |
end | |
def null? | |
false | |
end | |
def present? | |
true | |
end | |
def to_s | |
"<type: #{type}, value: #{value}>" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment