* Deejay files, split them to achieve go-style project layout * Replace logrus with log/slog module to reduce dependencies * Replace gopkg.in/ini.v1 with github.com/wlevene/ini to make sure all modules BSD licensed * Update linter config && fix tons of linter warnings * Update .gitignore * Update README.md
53 lines
852 B
Go
53 lines
852 B
Go
package token
|
|
|
|
import "fmt"
|
|
|
|
type TokenType string
|
|
|
|
const (
|
|
TokenType_ILLEGAL = "ILLEGAL"
|
|
TokenType_EOF = "EOF"
|
|
Ident = "Ident"
|
|
|
|
TokenType_SECTION = "SECTION"
|
|
TokenType_KEY = "KEY"
|
|
TokenType_VALUE = "VALUE"
|
|
TokenType_COMMENT = "#"
|
|
TokenType_COMMENT2 = "#"
|
|
|
|
TokenType_ASSIGN = "="
|
|
TokenType_LBRACKET = "["
|
|
TokenType_RBRACKET = "]"
|
|
|
|
RETURN = "RETURN"
|
|
)
|
|
|
|
type Token struct {
|
|
Type TokenType
|
|
Literal string
|
|
Line int
|
|
}
|
|
|
|
var keywords = map[string]TokenType{
|
|
"return": RETURN,
|
|
}
|
|
|
|
func LookupIdent(ident string) TokenType {
|
|
if tok, ok := keywords[ident]; ok {
|
|
return tok
|
|
}
|
|
return Ident
|
|
}
|
|
|
|
func (t Token) String() string {
|
|
return fmt.Sprintf("{Type:%s,Literal:\"%s\" Linie:%d}",
|
|
t.Type,
|
|
t.Literal,
|
|
t.Line)
|
|
}
|
|
|
|
//Is check type of a token
|
|
func (t Token) Is(typ TokenType) bool {
|
|
return t.Type == typ
|
|
}
|