-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtoken.go
48 lines (42 loc) · 1021 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
// Package token contains the token-types which our lexer produces,
// and which our parser understands.
package token
// Type is a string
type Type string
// Token struct represent the lexer token
type Token struct {
Type Type
Literal string
}
// pre-defined TokenTypes
const (
EOF = "EOF"
IDENT = "IDENT"
ILLEGAL = "ILLEGAL"
STRING = "STRING"
// Our keywords.
COPYFILE = "CopyFile"
COPYTEMPLATE = "CopyTemplate"
DEPLOYTO = "DeployTo"
IFCHANGED = "IfChanged"
RUN = "Run"
SET = "Set"
SUDO = "Sudo"
)
// keywords holds our reversed keywords
var keywords = map[string]Type{
"CopyFile": COPYFILE,
"CopyTemplate": COPYTEMPLATE,
"DeployTo": DEPLOYTO,
"IfChanged": IFCHANGED,
"Run": RUN,
"Set": SET,
"Sudo": SUDO,
}
// LookupIdentifier used to determinate whether identifier is keyword nor not
func LookupIdentifier(identifier string) Type {
if tok, ok := keywords[identifier]; ok {
return tok
}
return IDENT
}