-
Notifications
You must be signed in to change notification settings - Fork 30
/
generator.go
77 lines (66 loc) · 2.18 KB
/
generator.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
package scolumn
import (
"bytes"
"github.com/tobgu/qframe/filter"
"github.com/tobgu/qframe/internal/maps"
"github.com/tobgu/qframe/internal/template"
)
//go:generate qfgenerate -source=sfilter -dst-file=filters_gen.go
//go:generate qfgenerate -source=sdoc -dst-file=doc_gen.go
const basicColConstComparison = `
func {{.name}}(index index.Int, c Column, comparatee string, bIndex index.Bool) error {
for i, x := range bIndex {
if !x {
s, isNull := c.stringAt(index[i])
bIndex[i] = !isNull && s {{.operator}} comparatee
}
}
return nil
}
`
const basicColColComparison = `
func {{.name}}(index index.Int, col, col2 Column, bIndex index.Bool) error {
for i, x := range bIndex {
if !x {
s, isNull := col.stringAt(index[i])
s2, isNull2 := col2.stringAt(index[i])
bIndex[i] = !isNull && !isNull2 && s {{.operator}} s2
}
}
return nil
}
`
func spec(name, operator, templateStr string) template.Spec {
return template.Spec{
Name: name,
Template: templateStr,
Values: map[string]interface{}{"name": name, "operator": operator}}
}
func colConstComparison(name, operator string) template.Spec {
return spec(name, operator, basicColConstComparison)
}
func colColComparison(name, operator string) template.Spec {
return spec(name, operator, basicColColComparison)
}
func GenerateFilters() (*bytes.Buffer, error) {
// If adding more filters here make sure to also add a reference to them
// in the corresponding filter map so that they can be looked up.
return template.GenerateFilters("scolumn", []template.Spec{
colConstComparison("lt", filter.Lt),
colConstComparison("lte", filter.Lte),
colConstComparison("gt", filter.Gt),
colConstComparison("gte", filter.Gte),
colConstComparison("eq", "=="), // Go eq ("==") differs from qframe eq ("=")
colColComparison("lt2", filter.Lt),
colColComparison("lte2", filter.Lte),
colColComparison("gt2", filter.Gt),
colColComparison("gte2", filter.Gte),
colColComparison("eq2", "=="), // Go eq ("==") differs from qframe eq ("=")
})
}
func GenerateDoc() (*bytes.Buffer, error) {
return template.GenerateDocs(
"scolumn",
maps.StringKeys(filterFuncs0, filterFuncs1, filterFuncs2, multiInputFilterFuncs),
maps.StringKeys())
}