107 lines
3.1 KiB
Go
107 lines
3.1 KiB
Go
package lang
|
|
|
|
type tokenKind string
|
|
|
|
const (
|
|
tokenEOF tokenKind = "EOF"
|
|
tokenIdent tokenKind = "IDENT"
|
|
tokenInt tokenKind = "INT"
|
|
tokenFloat tokenKind = "FLOAT"
|
|
tokenString tokenKind = "STRING"
|
|
tokenTrue tokenKind = "TRUE"
|
|
tokenFalse tokenKind = "FALSE"
|
|
tokenNull tokenKind = "NULL"
|
|
tokenImport tokenKind = "IMPORT"
|
|
tokenPackage tokenKind = "PACKAGE"
|
|
tokenClass tokenKind = "CLASS"
|
|
tokenData tokenKind = "DATA"
|
|
tokenWorker tokenKind = "WORKER"
|
|
tokenInterface tokenKind = "INTERFACE"
|
|
tokenEnum tokenKind = "ENUM"
|
|
tokenMatch tokenKind = "MATCH"
|
|
tokenFun tokenKind = "FUN"
|
|
tokenOverride tokenKind = "OVERRIDE"
|
|
tokenPrivate tokenKind = "PRIVATE"
|
|
tokenVal tokenKind = "VAL"
|
|
tokenVar tokenKind = "VAR"
|
|
tokenIf tokenKind = "IF"
|
|
tokenElse tokenKind = "ELSE"
|
|
tokenWhile tokenKind = "WHILE"
|
|
tokenFor tokenKind = "FOR"
|
|
tokenIn tokenKind = "IN"
|
|
tokenSelect tokenKind = "SELECT"
|
|
tokenReturn tokenKind = "RETURN"
|
|
tokenGo tokenKind = "GO"
|
|
tokenDefer tokenKind = "DEFER"
|
|
tokenTry tokenKind = "TRY"
|
|
tokenCatch tokenKind = "CATCH"
|
|
tokenThrow tokenKind = "THROW"
|
|
tokenLParen tokenKind = "("
|
|
tokenRParen tokenKind = ")"
|
|
tokenLBrace tokenKind = "{"
|
|
tokenRBrace tokenKind = "}"
|
|
tokenLBracket tokenKind = "["
|
|
tokenRBracket tokenKind = "]"
|
|
tokenComma tokenKind = ","
|
|
tokenDot tokenKind = "."
|
|
tokenColon tokenKind = ":"
|
|
tokenDoubleColon tokenKind = "::"
|
|
tokenSemicolon tokenKind = ";"
|
|
tokenPlus tokenKind = "+"
|
|
tokenMinus tokenKind = "-"
|
|
tokenStar tokenKind = "*"
|
|
tokenSlash tokenKind = "/"
|
|
tokenPercent tokenKind = "%"
|
|
tokenBang tokenKind = "!"
|
|
tokenAssign tokenKind = "="
|
|
tokenPlusAssign tokenKind = "+="
|
|
tokenEq tokenKind = "=="
|
|
tokenNeq tokenKind = "!="
|
|
tokenLt tokenKind = "<"
|
|
tokenLte tokenKind = "<="
|
|
tokenGt tokenKind = ">"
|
|
tokenGte tokenKind = ">="
|
|
tokenAnd tokenKind = "&&"
|
|
tokenAmp tokenKind = "&"
|
|
tokenAt tokenKind = "@"
|
|
tokenQuestion tokenKind = "?"
|
|
tokenOr tokenKind = "||"
|
|
tokenArrow tokenKind = "->"
|
|
)
|
|
|
|
var keywords = map[string]tokenKind{
|
|
"fun": tokenFun,
|
|
"import": tokenImport,
|
|
"package": tokenPackage,
|
|
"class": tokenClass,
|
|
"data": tokenData,
|
|
"worker": tokenWorker,
|
|
"interface": tokenInterface,
|
|
"enum": tokenEnum,
|
|
"match": tokenMatch,
|
|
"val": tokenVal,
|
|
"var": tokenVar,
|
|
"override": tokenOverride,
|
|
"private": tokenPrivate,
|
|
"if": tokenIf,
|
|
"else": tokenElse,
|
|
"while": tokenWhile,
|
|
"for": tokenFor,
|
|
"in": tokenIn,
|
|
"select": tokenSelect,
|
|
"return": tokenReturn,
|
|
"go": tokenGo,
|
|
"defer": tokenDefer,
|
|
"try": tokenTry,
|
|
"catch": tokenCatch,
|
|
"throw": tokenThrow,
|
|
"true": tokenTrue,
|
|
"false": tokenFalse,
|
|
"null": tokenNull,
|
|
}
|
|
|
|
type token struct {
|
|
kind tokenKind
|
|
lexeme string
|
|
pos int
|
|
}
|