mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 20:07:04 +00:00
partial cleanup of the macro pkg and move it from /core/router to the root because it may be used by the end-developers now to ammend the available macros per application
Former-commit-id: 951a5e7a401af25ecaa904ff6463b0def2c87afb
This commit is contained in:
53
macro/interpreter/token/token.go
Normal file
53
macro/interpreter/token/token.go
Normal file
@@ -0,0 +1,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:uint64 range(1,5) else 404}
|
||||
// /admin/{id:number 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
|
||||
}
|
||||
Reference in New Issue
Block a user