iris/_future/ipel/token/token.go
Gerasimos (Makis) Maropoulos a95a02a16a Nothing special here (yet)
Former-commit-id: 826d7c370481b78afd9ba92f4ae8bef1fb85a567
2017-03-27 04:09:44 +03:00

63 lines
1020 B
Go

package token
type TokenType int
type Token struct {
Type TokenType
Literal string
Start int // excluding, useful for user
End int // excluding, useful for user and index
}
func (t Token) StartIndex() int {
if t.Start > 0 {
return t.Start + 1
}
return t.Start
}
func (t Token) EndIndex() int {
return t.End
}
// {id:int range(1,5) else 404}
// /admin/{id:int eq(1) else 402}
// /file/{filepath:tail else 405}
const (
EOF = iota // 0
ILLEGAL
// Identifiers + literals
LBRACE // {
RBRACE // }
// PARAM_IDENTIFIER // id
COLON // :
// let's take them in parser
// PARAM_TYPE // int, string, alphabetic, tail
// PARAM_FUNC // range
LPAREN // (
RPAREN // )
// PARAM_FUNC_ARG // 1
COMMA
IDENT // string or keyword
// Keywords
keywords_start
ELSE // else
keywords_end
INT // 42
)
const eof rune = 0
var keywords = map[string]TokenType{
"else": ELSE,
}
func LookupIdent(ident string) TokenType {
if tok, ok := keywords[ident]; ok {
return tok
}
return IDENT
}