-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.go
129 lines (116 loc) · 2.75 KB
/
constants.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package rule_engine
import (
"fmt"
)
var VALID_CHAR_SET = map[rune]struct{}{
'(': {},
')': {},
'+': {},
'-': {},
'*': {},
'/': {},
'%': {},
'>': {},
'<': {},
',': {},
'.': {},
}
const L = `[a-zA-Z_]`
const H = `[a-fA-F0-9]`
const E = `([Ee][+-]?[0-9]+)`
const P = `([Pp][+-]?[0-9]+)`
const FS = `(f|F|l|L)`
const IS = `((u|U)|(u|U)?(l|L|ll|LL)|(l|L|ll|LL)(u|U))`
type tokenRule struct {
token int
reStr string
}
var TOKEN_RULE_LIST = [...]tokenRule{
{LE, "<="},
{GE, ">="},
{EQ, "=="},
{NE, "!="},
{AND, "&&"},
{NOT, "!"},
{OR, `\|\|`},
{IDLEFT, "{{"},
{IDRIGHT, "}}"},
{STRING, `\"(\\.|[^\\"\n])*\"`},
{STRING, `\'(\\.|[^\\'\n])*\'`},
{FLOAT, fmt.Sprintf(`[0-9]+%v%v?`, E, FS)},
{FLOAT, fmt.Sprintf(`[0-9]+\.[0-9]+%v?%v?`, E, FS)},
{FLOAT, fmt.Sprintf(`[0-9]+\.[0-9]*%v?%v?`, E, FS)},
{INTEGER, fmt.Sprintf(`0[xX]%v+%v?`, H, IS)},
{INTEGER, fmt.Sprintf(`0[0-7]*%v?`, IS)},
{INTEGER, fmt.Sprintf(`[1-9][0-9]*%v?`, IS)},
{IDENTIFIER, fmt.Sprintf(`%v(%v|[0-9])*`, L, L)},
}
var KEY_WORD_LIST = [...]tokenRule{
{AND, "AND"},
{AND, "[A|a]nd"},
{OR, "OR"},
{OR, "[o|O]r"},
{NOT, "[N|n]ot"},
{NOT, "NOT"},
{TRUE, "TRUE"},
{TRUE, "[T|t]rue"},
{FALSE, "FALSE"},
{FALSE, "[F|f]alse"},
{IF, "[I|i]f"},
{IF, "IF"},
{ELSE, "[E|e]lse"},
{ELSE, "ELSE"},
}
type ValueType int
const (
ValueTypeNone ValueType = iota
ValueTypeInteger
ValueTypeFloat
ValueTypeBool
ValueTypeString
ValueTypeDecimal
valueTypeArgs
)
var valueTypeNameDict = map[ValueType]string{
ValueTypeNone: "null",
ValueTypeBool: "bool",
ValueTypeFloat: "float",
ValueTypeString: "string",
ValueTypeInteger: "integer",
valueTypeArgs: "args",
ValueTypeDecimal: "decimal",
}
var valueTokenToValueType = map[int]ValueType{
INTEGER: ValueTypeInteger,
FLOAT: ValueTypeFloat,
STRING: ValueTypeString,
TRUE: ValueTypeBool,
FALSE: ValueTypeBool,
BOOL: ValueTypeBool,
IDENTIFIER: ValueTypeString,
}
type operType int
const (
operTypeMath operType = 1 + iota
operTypeMod
operTypeMinus
operTypeRelation
operTypeEqual
operTypeLogic
operTypeString
operTypeArgument
operTypeRegex
operTypeChangeTo
)
var operValidType = map[operType][]ValueType{
operTypeMath: {ValueTypeInteger, ValueTypeFloat, ValueTypeDecimal},
operTypeMod: {ValueTypeInteger},
operTypeMinus: {ValueTypeInteger, ValueTypeFloat, ValueTypeDecimal},
operTypeRelation: {ValueTypeInteger, ValueTypeFloat, ValueTypeDecimal},
operTypeEqual: {ValueTypeInteger, ValueTypeFloat, ValueTypeBool, ValueTypeString, ValueTypeDecimal},
operTypeLogic: {ValueTypeBool},
operTypeString: {ValueTypeString},
operTypeArgument: {valueTypeArgs},
operTypeRegex: {ValueTypeString},
operTypeChangeTo: {ValueTypeInteger, ValueTypeFloat, ValueTypeDecimal, ValueTypeString},
}