-
Notifications
You must be signed in to change notification settings - Fork 0
/
pick.go
55 lines (41 loc) · 812 Bytes
/
pick.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
package jq
import (
"fmt"
)
type (
Pick struct {
Expr FilterPath
merge
}
)
func NewPick(e FilterPath) *Pick { return &Pick{Expr: e} }
func (f *Pick) ApplyTo(b *Buffer, off Off, next bool) (res Off, more bool, err error) {
if next {
return None, false, nil
}
f.reset()
for {
res, f.path, next, err = f.Expr.ApplyToGetPath(b, off, f.path[:0], next)
if err != nil {
return off, false, err
}
if res == None && next {
continue
}
if res == None {
break
}
// log.Printf("pick %v#%v", f.path, res)
err = f.set(b, res, f.path)
if err != nil {
return None, false, err
}
// log.Printf("tree\n%v", f.root)
if !next {
break
}
}
res = f.render(b, f.root)
return res, false, nil
}
func (p Pick) String() string { return fmt.Sprintf("pick(%v)", p.Expr) }