@@ -30,6 +30,7 @@ var predicates = map[string]struct {
30
30
"findLastIndex" : {2 },
31
31
"groupBy" : {2 },
32
32
"countBy" : {2 },
33
+ "reduce" : {3 },
33
34
}
34
35
35
36
type parser struct {
@@ -357,6 +358,9 @@ func (p *parser) parseCall(token Token) Node {
357
358
358
359
if b , ok := predicates [token .Value ]; ok {
359
360
p .expect (Bracket , "(" )
361
+
362
+ // TODO: Refactor parser to use builtin.Builtins instead of predicates map.
363
+
360
364
if b .arity == 1 {
361
365
arguments = make ([]Node , 1 )
362
366
arguments [0 ] = p .parseExpression (0 )
@@ -366,6 +370,18 @@ func (p *parser) parseCall(token Token) Node {
366
370
p .expect (Operator , "," )
367
371
arguments [1 ] = p .parseClosure ()
368
372
}
373
+
374
+ if token .Value == "reduce" {
375
+ arguments = make ([]Node , 2 )
376
+ arguments [0 ] = p .parseExpression (0 )
377
+ p .expect (Operator , "," )
378
+ arguments [1 ] = p .parseClosure ()
379
+ if p .current .Is (Operator , "," ) {
380
+ p .next ()
381
+ arguments = append (arguments , p .parseExpression (0 ))
382
+ }
383
+ }
384
+
369
385
p .expect (Bracket , ")" )
370
386
371
387
node = & BuiltinNode {
@@ -596,9 +612,21 @@ func (p *parser) parsePipe(node Node) Node {
596
612
597
613
if b , ok := predicates [identifier .Value ]; ok {
598
614
p .expect (Bracket , "(" )
615
+
616
+ // TODO: Refactor parser to use builtin.Builtins instead of predicates map.
617
+
599
618
if b .arity == 2 {
600
619
arguments = append (arguments , p .parseClosure ())
601
620
}
621
+
622
+ if identifier .Value == "reduce" {
623
+ arguments = append (arguments , p .parseClosure ())
624
+ if p .current .Is (Operator , "," ) {
625
+ p .next ()
626
+ arguments = append (arguments , p .parseExpression (0 ))
627
+ }
628
+ }
629
+
602
630
p .expect (Bracket , ")" )
603
631
604
632
node = & BuiltinNode {
0 commit comments