mirror of
https://github.com/RoBaertschi/tt.git
synced 2025-04-18 23:13:29 +00:00
44 lines
570 B
Go
44 lines
570 B
Go
package token
|
|
|
|
type Loc struct {
|
|
Line int
|
|
Col int
|
|
Pos int
|
|
File string
|
|
}
|
|
|
|
type TokenType string
|
|
|
|
type Token struct {
|
|
Type TokenType
|
|
Literal string
|
|
Loc Loc
|
|
}
|
|
|
|
var keywords = map[string]TokenType{
|
|
"fn": FN,
|
|
}
|
|
|
|
const (
|
|
ILLEGAL TokenType = "ILLEGAL"
|
|
EOF TokenType = "EOF"
|
|
|
|
IDENT TokenType = "IDENT"
|
|
INT TokenType = "INT"
|
|
|
|
SEMICOLON = ";"
|
|
EQUAL = "="
|
|
OPEN_PAREN = "("
|
|
CLOSE_PAREN = ")"
|
|
|
|
// Keywords
|
|
FN = "FN"
|
|
)
|
|
|
|
func LookupKeyword(literal string) TokenType {
|
|
if value, ok := keywords[literal]; ok {
|
|
return value
|
|
}
|
|
return IDENT
|
|
}
|