mirror of
https://github.com/kataras/iris.git
synced 2025-12-26 14:27:04 +00:00
Nothing special here (yet)
Former-commit-id: 826d7c370481b78afd9ba92f4ae8bef1fb85a567
This commit is contained in:
62
_future/ipel/token/token.go
Normal file
62
_future/ipel/token/token.go
Normal file
@@ -0,0 +1,62 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user