2021-11-30 19:02:01 +00:00
|
|
|
package token
|
|
|
|
|
|
|
|
type TokenType string
|
|
|
|
|
|
|
|
type Token struct {
|
2021-11-30 20:27:22 +00:00
|
|
|
Type TokenType
|
|
|
|
Literal string
|
2021-11-30 19:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2021-11-30 20:27:22 +00:00
|
|
|
ILLEGAL = "ILLEGAL"
|
|
|
|
EOF = "EOF"
|
2021-11-30 19:02:01 +00:00
|
|
|
|
2021-11-30 20:27:22 +00:00
|
|
|
//Identifiers and literals
|
|
|
|
IDENT = "IDENT" //add, foo, bar, a, b, c...
|
|
|
|
INT = "INT" /// 1 2 3 4 5
|
2021-11-30 19:02:01 +00:00
|
|
|
|
2021-11-30 20:27:22 +00:00
|
|
|
//OPERATORS
|
|
|
|
ASSIGN = "="
|
|
|
|
PLUS = "+"
|
2021-11-30 19:02:01 +00:00
|
|
|
|
2021-11-30 20:27:22 +00:00
|
|
|
//DELIM
|
|
|
|
COMMA = ""
|
|
|
|
SEMICOLON = ";"
|
2021-11-30 19:02:01 +00:00
|
|
|
|
2021-11-30 20:27:22 +00:00
|
|
|
LPAREN = "("
|
|
|
|
RPAREN = ")"
|
|
|
|
LBRACE = "{"
|
|
|
|
RBRACE = "}"
|
2021-11-30 19:02:01 +00:00
|
|
|
|
2021-11-30 20:27:22 +00:00
|
|
|
// KEYWORDS
|
|
|
|
FUNCTION = "FUNCTION"
|
|
|
|
LET = "LET"
|
2021-11-30 19:02:01 +00:00
|
|
|
)
|
2021-11-30 20:27:22 +00:00
|
|
|
|
|
|
|
var keywords = map[string]TokenType{
|
|
|
|
"fn": FUNCTION,
|
|
|
|
"let": LET,
|
|
|
|
}
|
|
|
|
|
|
|
|
func LookupIdent(ident string) TokenType {
|
|
|
|
if tok, ok := keywords[ident]; ok {
|
|
|
|
return tok
|
|
|
|
}
|
|
|
|
return IDENT
|
|
|
|
}
|