thorgot/token/token.go
Robin Bärtschi 5db30a2a84
All checks were successful
Go / build (push) Successful in 20s
added statement parsing, missing tests and expression
2024-11-14 15:42:39 +01:00

50 lines
761 B
Go

package token
type TokenType string
type Loc struct {
Line int
Col int
}
type Token struct {
Type TokenType
Literal string
Loc Loc
}
const (
Illegal TokenType = "Illegal"
Eof = "Eof"
NewLine = "NewLine"
Semicolon = "Semicolon" // ;
Colon = "Colon" // :
Comma = "," // ,
Equal = "Equal" // =
LBrace = "LBrace" // {
RBrace = "RBrace" // }
LParen = "LParen" // (
RParen = "RParen" // )
Identifier = "Identifier"
Integer = "Integer" // 19232
// Keywords
Fn = "Fn" // fn
)
var stringToToken = map[string]TokenType{
"fn": Fn,
}
func LookupKeyword(literal string) TokenType {
if token, ok := stringToToken[literal]; ok {
return token
}
return Identifier
}