You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB
Go

package token
type TokenType int
const (
// Special tokens
EOF TokenType = iota // Represents the end of the file/input
ILLEGAL // Represents any character or sequence of characters that doesn't form a valid token in JSON
// Symbols and structure tokens
BEGIN_ARRAY // [
END_ARRAY // ]
BEGIN_OBJECT // {
END_OBJECT // }
NAME_SEPARATOR // :
VALUE_SEPARATOR // ,
// Whitespace
WHITESPACE // Represents whitespace (spaces, tabs, line feeds, carriage returns).
// Literal types
STRING // Represents a string literal
NUMBER // Represents a number
TRUE // Represents the boolean value "true"
FALSE // Represents the boolean value "false"
NULL // Represents the "null" value
)
type Token struct {
Type TokenType
Value string
}
func NewToken(tokenType TokenType, ch byte) Token {
return Token{Type: tokenType, Value: string(ch)}
}
var keywords = map[string]TokenType{
"true": TRUE,
"false": FALSE,
"null": NULL,
}
func LookupIdent(ident string) TokenType {
if tok, ok := keywords[ident]; ok {
return tok
}
return ILLEGAL
}