Skip to content

Commit 4b52bd4

Browse files
committed
0.0.11 release
1 parent fb14af7 commit 4b52bd4

107 files changed

Lines changed: 1609 additions & 718 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
version: 2.1
2+
executors:
3+
base:
4+
docker:
5+
- image: circleci/golang:1.11
6+
working_directory: /go/src/github.com/spatialcurrent/go-dfl
7+
jobs:
8+
pre_deps_golang:
9+
executor: base
10+
steps:
11+
- checkout
12+
- run: go get -d ./...
13+
- run: sudo chown -R circleci /go/src
14+
- save_cache:
15+
key: v1-go-src-{{ .Branch }}-{{ .Revision }}
16+
paths:
17+
- /go/src
18+
test:
19+
executor: base
20+
steps:
21+
- run: sudo chown -R circleci /go/src
22+
- restore_cache:
23+
keys:
24+
- v1-go-src-{{ .Branch }}-{{ .Revision }}
25+
- run:
26+
name: Install gometalinter
27+
command: |
28+
go get -u github.com/alecthomas/gometalinter
29+
gometalinter --install
30+
- run:
31+
name: Test
32+
command: bash scripts/test.sh
33+
build_cli:
34+
executor: base
35+
steps:
36+
- run: sudo chown -R circleci /go/src
37+
- restore_cache:
38+
keys:
39+
- v1-go-src-{{ .Branch }}-{{ .Revision }}
40+
- run: bash scripts/build_cli.sh
41+
- store_artifacts:
42+
path: bin
43+
destination: /
44+
build_javascript:
45+
executor: base
46+
steps:
47+
- run: sudo chown -R circleci /go/src
48+
- restore_cache:
49+
keys:
50+
- v1-go-src-{{ .Branch }}-{{ .Revision }}
51+
- run:
52+
name: Install GopherJS
53+
command: go get -u github.com/gopherjs/gopherjs
54+
- run: bash scripts/build_javascript.sh
55+
- store_artifacts:
56+
path: bin
57+
destination: /
58+
build_so:
59+
executor: base
60+
steps:
61+
- run: sudo chown -R circleci /go/src
62+
- restore_cache:
63+
keys:
64+
- v1-go-src-{{ .Branch }}-{{ .Revision }}
65+
- run: bash scripts/build_so.sh
66+
- store_artifacts:
67+
path: bin
68+
destination: /
69+
workflows:
70+
main:
71+
jobs:
72+
- pre_deps_golang
73+
- test:
74+
requires:
75+
- pre_deps_golang
76+
- build_cli:
77+
requires:
78+
- pre_deps_golang
79+
- build_javascript:
80+
requires:
81+
- pre_deps_golang
82+
- build_so:
83+
requires:
84+
- pre_deps_golang
85+

.travis.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/spatialcurrent/go-dfl.svg)](https://travis-ci.org/spatialcurrent/go-dfl) [![Go Report Card](https://goreportcard.com/badge/spatialcurrent/go-dfl)](https://goreportcard.com/report/spatialcurrent/go-dfl) [![GoDoc](https://godoc.org/github.com/spatialcurrent/go-dfl?status.svg)](https://godoc.org/github.com/spatialcurrent/go-dfl) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/spatialcurrent/go-dfl/blob/master/LICENSE.md)
1+
[![CircleCI](https://circleci.com/gh/spatialcurrent/go-dfl/tree/master.svg?style=svg)](https://circleci.com/gh/spatialcurrent/go-dfl/tree/master) [![Go Report Card](https://goreportcard.com/badge/spatialcurrent/go-dfl)](https://goreportcard.com/report/spatialcurrent/go-dfl) [![GoDoc](https://godoc.org/github.com/spatialcurrent/go-dfl?status.svg)](https://godoc.org/github.com/spatialcurrent/go-dfl) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/spatialcurrent/go-dfl/blob/master/LICENSE.md)
22

33
# go-dfl
44

@@ -7,6 +7,7 @@
77
**go-dfl** is a Go implementation of the Dynamic Filter Language (DFL). **go-dfl** depends on:
88
- [go-adaptive-functions](https://github.com/spatialcurrent/go-adaptive-functions) for many of the basic functions.
99
- [go-counter](https://github.com/spatialcurrent/go-counter) for counting for statistical functions.
10+
- [go-try-get](https://github.com/spatialcurrent/go-try-get) for abstracting how to get values by name from unknown objects.
1011

1112
Using cross compilers, this library can also be called by other languages. This library is cross compiled into a Shared Object file (`*.so`). The Shared Object file can be called by `C`, `C++`, and `Python` on Linux machines. See the examples folder for patterns that you can use. This library is also compiled to pure `JavaScript` using [GopherJS](https://github.com/gopherjs/gopherjs).
1213

cmd/dfl.js/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
func main() {
2727
js.Global.Set("dfl", map[string]interface{}{
28-
"version": dfl.VERSION,
28+
"version": dfl.Version,
2929
"Parse": dfljs.Parse,
3030
"EvaluateBool": dfljs.EvaluateBool,
3131
"EvaluateInt": dfljs.EvaluateInt,

cmd/dfl/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func main() {
8989
}
9090

9191
if version {
92-
fmt.Println(dfl.VERSION)
92+
fmt.Println(dfl.Version)
9393
os.Exit(0)
9494
}
9595

@@ -109,7 +109,7 @@ func main() {
109109
log.Fatal(errors.New("Context attribute \"" + a + "\" does not contain \"=\"."))
110110
}
111111
pair := strings.SplitN(a, "=", 2)
112-
value, err := dfl.Parse(strings.TrimSpace(pair[1]))
112+
value, _, err := dfl.Parse(strings.TrimSpace(pair[1]))
113113
if err != nil {
114114
log.Fatal(errors.Wrap(err, "Could not parse context variable"))
115115
}
@@ -136,7 +136,7 @@ func main() {
136136
}
137137
}
138138

139-
root, err := dfl.Parse(filter_text)
139+
root, _, err := dfl.Parse(filter_text)
140140
if err != nil {
141141
log.Fatal(errors.Wrap(err, "error parsing filter expression"))
142142
}

dfl/Add.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ func (a Add) Compile() Node {
5959
n := Literal{
6060
Value: left.(Literal).Value.(string) + fmt.Sprint(right.(Concat).Arguments[0].(Literal).Value),
6161
}
62-
return Concat{Arguments: append([]Node{n}, right.(Concat).Arguments[1:]...)}
62+
return Concat{&MultiOperator{Arguments: append([]Node{n}, right.(Concat).Arguments[1:]...)}}
6363
}
64-
return Concat{Arguments: append([]Node{left}, right.(Concat).Arguments...)}
64+
return Concat{&MultiOperator{Arguments: append([]Node{left}, right.(Concat).Arguments...)}}
6565
}
66-
return Concat{Arguments: []Node{left, right}}
66+
return Concat{&MultiOperator{Arguments: []Node{left, right}}}
6767
}
6868
case Attribute, *Attribute, Variable, *Variable:
6969
switch right.(type) {
7070
case Literal:
7171
switch right.(Literal).Value.(type) {
7272
case string:
73-
return Concat{Arguments: []Node{left, right}}
73+
return Concat{&MultiOperator{Arguments: []Node{left, right}}}
7474
}
7575
case Concat:
76-
return Concat{Arguments: append([]Node{left}, right.(Concat).Arguments...)}
76+
return Concat{&MultiOperator{Arguments: append([]Node{left}, right.(Concat).Arguments...)}}
7777
}
7878
}
7979
return &Add{&BinaryOperator{Left: left, Right: right}}

dfl/Add_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ func TestAdd(t *testing.T) {
2828
}
2929

3030
for _, testCase := range testCases {
31-
node, err := Parse(testCase.Expression)
31+
node, err := ParseCompile(testCase.Expression)
3232
if err != nil {
3333
t.Errorf(errors.Wrap(err, "Error parsing expression \""+testCase.Expression+"\"").Error())
3434
continue
3535
}
36-
node = node.Compile()
3736
_, got, err := node.Evaluate(map[string]interface{}{}, testCase.Context, NewFuntionMapWithDefaults(), DefaultQuotes)
3837
if err != nil {
3938
t.Errorf(errors.Wrap(err, "Error evaluating expression \""+testCase.Expression+"\"").Error())
@@ -61,12 +60,11 @@ func TestAddSql(t *testing.T) {
6160
}
6261

6362
for _, testCase := range testCases {
64-
node, err := Parse(testCase.Dfl)
63+
node, err := ParseCompile(testCase.Dfl)
6564
if err != nil {
6665
t.Errorf(errors.Wrap(err, "Error parsing expression \""+testCase.Dfl+"\"").Error())
6766
continue
6867
}
69-
node = node.Compile()
7068
got := node.Sql(false, 0)
7169
if err != nil {
7270
t.Errorf(errors.Wrap(err, "Error evaluating expression \""+testCase.Dfl+"\"").Error())

dfl/After_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ func TestAfter(t *testing.T) {
3232
}
3333

3434
for _, testCase := range testCases {
35-
node, err := Parse(testCase.Expression)
35+
node, err := ParseCompile(testCase.Expression)
3636
if err != nil {
3737
t.Errorf(errors.Wrap(err, "Error parsing expression \""+testCase.Expression+"\"").Error())
3838
continue
3939
}
40-
node = node.Compile()
4140
_, got, err := node.Evaluate(map[string]interface{}{}, testCase.Context, NewFuntionMapWithDefaults(), DefaultQuotes)
4241
if err != nil {
4342
t.Errorf(errors.Wrap(err, "Error evaluating expression \""+testCase.Expression+"\"").Error())

dfl/And_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ func TestAnd(t *testing.T) {
2828
}
2929

3030
for _, testCase := range testCases {
31-
node, err := Parse(testCase.Expression)
31+
node, err := ParseCompile(testCase.Expression)
3232
if err != nil {
3333
t.Errorf(errors.Wrap(err, "Error parsing expression \""+testCase.Expression+"\"").Error())
3434
continue
3535
}
36-
node = node.Compile()
3736
_, got, err := node.Evaluate(map[string]interface{}{}, testCase.Context, NewFuntionMapWithDefaults(), DefaultQuotes)
3837
if err != nil {
3938
t.Errorf(errors.Wrap(err, "Error evaluating expression \""+testCase.Expression+"\"").Error())

dfl/Array.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,17 @@ func (a Array) Attributes() []string {
9696
}
9797
return attrs
9898
}
99+
100+
func (a Array) Variables() []string {
101+
set := make(map[string]struct{})
102+
for _, n := range a.Nodes {
103+
for _, x := range n.Variables() {
104+
set[x] = struct{}{}
105+
}
106+
}
107+
attrs := make([]string, 0, len(set))
108+
for x := range set {
109+
attrs = append(attrs, x)
110+
}
111+
return attrs
112+
}

0 commit comments

Comments
 (0)