Skip to content

Instantly share code, notes, and snippets.

@gosukiwi
Last active January 13, 2019 15:43
Show Gist options
  • Save gosukiwi/4c1847206032189ecc2ca8f2388d57b7 to your computer and use it in GitHub Desktop.
Save gosukiwi/4c1847206032189ecc2ca8f2388d57b7 to your computer and use it in GitHub Desktop.
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