-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gal.go
57 lines (50 loc) · 1.02 KB
/
gal.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
package gal
import "fmt"
type exprType int
const (
unknownType exprType = iota
blankType
numericalType
operatorType
stringType
variableType
functionType
boolType
)
type Value interface {
// Calculation
Add(Value) Value
Sub(Value) Value
Multiply(Value) Value
Divide(Value) Value
PowerOf(Value) Value
Mod(Value) Value
LShift(Value) Value
RShift(Value) Value
// Logical
LessThan(Value) Bool
LessThanOrEqual(Value) Bool
EqualTo(Value) Bool
NotEqualTo(Value) Bool
GreaterThan(Value) Bool
GreaterThanOrEqual(Value) Bool
And(Value) Bool
Or(Value) Bool
// Helpers
Stringer
fmt.Stringer
entry
}
// Example: Parse("blah").Eval(WithVariables(...), WithFunctions(...), WithObjects(...))
// This allows to parse an expression and then use the resulting Tree for multiple
// evaluations with different variables provided.
func Parse(expr string) Tree {
treeBuilder := NewTreeBuilder()
tree, err := treeBuilder.FromExpr(expr)
if err != nil {
return Tree{
NewUndefinedWithReasonf(err.Error()),
}
}
return tree
}