forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
53 lines (46 loc) · 1019 Bytes
/
token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package token
// Type is a specific type of int which describes the symbols.
type Type int
// Token describes the letter(s) or symbol, is a result of the lexer.
type Token struct {
Type Type
Literal string
Start int // including the first char
End int // including the last char
}
// /about/{fullname:alphabetical}
// /profile/{anySpecialName:string}
// {id:int range(1,5) else 404}
// /admin/{id:int eq(1) else 402}
// /file/{filepath:file else 405}
const (
EOF = iota // 0
ILLEGAL
// Identifiers + literals
LBRACE // {
RBRACE // }
// PARAM_IDENTIFIER // id
COLON // :
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]Type{
"else": ELSE,
}
// LookupIdent receives a series of chars
// and tries to resolves the token type.
func LookupIdent(ident string) Type {
if tok, ok := keywords[ident]; ok {
return tok
}
return IDENT
}