-
Notifications
You must be signed in to change notification settings - Fork 46
/
token.go
67 lines (55 loc) · 1.35 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package fuzztag
import (
"github.com/yaklang/yaklang/common/utils"
)
type token struct {
Raw []byte
Verbose string
Type TokenType
}
type TokenType string
const (
TokenType_TAG_OPEN = "TAG_OPEN"
TokenType_TAG_CLOSE = "TAG_CLOSE"
TokenType_DATA = "DATA"
TokenType_METHOND = "Method"
TokenType_LEFT_PAREN = "LEFT_PAREN"
TokenType_RIGHT_PAREN = "RIGHT_PAREN"
)
const (
TAG_OPEN = "{{"
TAG_OPEN_VERBOSE = "TAG_OPEN"
TAG_CLOSE = "}}"
TAG_CLOSE_VERBOSE = "TAG_CLOSE"
LEFT_PAREN = '('
LEFT_PAREN_VERBOSE = "LEFT_PAREN"
RIGHT_PAREN = ')'
RIGHT_PAREN_VERBOSE = "RIGHT_PAREN"
)
func isIdentifyFirstByte(b byte) bool {
if (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' {
return true
}
return false
}
var blankByteTable = make(map[byte]byte)
func isBlank(b byte) bool {
_, ok := blankByteTable[b]
return ok
}
var identifyRestByteTable = make(map[byte]byte)
func init() {
for _, b := range "abcdefghijklmnopqrstuvwzxy_1234567890ABCDEFGHJIKLMNOPQRSTUVWXYZ:-" {
identifyRestByteTable[byte(b)] = byte(b)
}
for _, b := range " \n\r\v\t" {
blankByteTable[byte(b)] = byte(b)
}
}
func isIdentifyString(s string) bool {
return utils.MatchAllOfRegexp(s, "^[a-zA-Z_][a-zA-Z0-9_:-]*$")
}
func isIdentifyRestByte(b byte) bool {
_, ok := identifyRestByteTable[b]
return ok
}