Skip to content

Commit d87968c

Browse files
committed
cleaned up parsing & set math
1 parent ceaf8bd commit d87968c

21 files changed

Lines changed: 417 additions & 187 deletions

dfl/Equal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func (e Equal) Evaluate(ctx interface{}, funcs FunctionMap) (interface{}, error)
6161
case string:
6262
lvs := lv.(string)
6363
switch rv.(type) {
64+
case Null:
65+
return false, nil
6466
case string:
6567
return lvs == rv.(string), nil
6668
case int:

dfl/FunctionMap.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type FunctionMap map[string]func(FunctionMap, interface{}, []interface{}) (inter
2323
func NewFuntionMapWithDefaults() FunctionMap {
2424
funcs := FunctionMap{}
2525

26+
funcs["intersects"] = intersects
2627
funcs["flatten"] = flattenArray
2728
funcs["filter"] = filterArray
2829
funcs["map"] = mapArray

dfl/In.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ func (i In) Evaluate(ctx interface{}, funcs FunctionMap) (interface{}, error) {
152152
lvs := fmt.Sprint(lv)
153153

154154
switch rv.(type) {
155+
case Null:
156+
return false, nil
157+
case StringSet:
158+
return rv.(StringSet).Contains(lvs), nil
155159
case string:
156160
return strings.Contains(rv.(string), lvs), nil
157161
case int:

dfl/In_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestIn(t *testing.T) {
4141
if err != nil {
4242
t.Errorf(errors.Wrap(err, "Error evaluating expression \""+testCase.Expression+"\"").Error())
4343
} else if got != testCase.Result {
44-
t.Errorf("TestILike(%q) == %v (%q), want %v (%q)", testCase.Expression, got, reflect.TypeOf(got), testCase.Result, reflect.TypeOf(testCase.Result))
44+
t.Errorf("TestIn(%q) == %v (%q), want %v (%q)", testCase.Expression, got, reflect.TypeOf(got), testCase.Result, reflect.TypeOf(testCase.Result))
4545
}
4646
}
4747

dfl/IsArray.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dfl
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func IsArray(s string) bool {
8+
return len(s) >= 2 && strings.HasPrefix(s, "[") && strings.HasSuffix(s, "]")
9+
}

dfl/IsAttribute.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dfl
2+
3+
import (
4+
"strings"
5+
"unicode"
6+
)
7+
8+
func IsAttribute(s string) bool {
9+
return strings.HasPrefix(strings.TrimLeftFunc(s, unicode.IsSpace), "@")
10+
}

dfl/IsFunction.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dfl
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func IsFunction(s string) bool {
8+
return len(s) >= 3 && strings.Contains(s, "(") && strings.HasSuffix(s, ")")
9+
}

dfl/IsQuoted.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dfl
2+
3+
func IsQuoted(s string) bool {
4+
if len(s) < 2 {
5+
return false
6+
}
7+
return (s[0] == '\'' && s[len(s)-1] == '\'') || (s[0] == '"' && s[len(s)-1] == '"') || (s[0] == '`' && s[len(s)-1] == '`')
8+
}

dfl/IsSet.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dfl
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func IsSet(s string) bool {
8+
return len(s) >= 2 && strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}")
9+
}

dfl/IsSub.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dfl
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func IsSub(s string) bool {
8+
return len(s) >= 2 && strings.HasPrefix(s, "(") && strings.HasSuffix(s, ")")
9+
}

0 commit comments

Comments
 (0)