infix reduce

This commit is contained in:
Mike Farah 2021-02-15 16:06:37 +11:00
parent 3e5f7b147f
commit b2317a14ef
3 changed files with 3 additions and 3 deletions

View File

@ -13,7 +13,7 @@ var pathTests = []struct {
expectedPostFix []interface{} expectedPostFix []interface{}
}{ }{
{ {
`.a as $item reduce (0; . + $item)`, // note - add code to shuffle reduce to this position for postfix `.a as $item ireduce (0; . + $item)`, // note - add code to shuffle reduce to this position for postfix
append(make([]interface{}, 0), "a", "ASSIGN_VARIABLE", "GET_VARIABLE", "REDUCE", "(", "0 (int64)", "BLOCK", "SELF", "ADD", "GET_VARIABLE", ")"), append(make([]interface{}, 0), "a", "ASSIGN_VARIABLE", "GET_VARIABLE", "REDUCE", "(", "0 (int64)", "BLOCK", "SELF", "ADD", "GET_VARIABLE", ")"),
append(make([]interface{}, 0), "a", "GET_VARIABLE", "ASSIGN_VARIABLE", "0 (int64)", "SELF", "GET_VARIABLE", "ADD", "BLOCK", "REDUCE"), append(make([]interface{}, 0), "a", "GET_VARIABLE", "ASSIGN_VARIABLE", "0 (int64)", "SELF", "GET_VARIABLE", "ADD", "BLOCK", "REDUCE"),
}, },

View File

@ -252,7 +252,7 @@ func initLexer() (*lex.Lexer, error) {
lexer.Add([]byte(`or`), opToken(orOpType)) lexer.Add([]byte(`or`), opToken(orOpType))
lexer.Add([]byte(`and`), opToken(andOpType)) lexer.Add([]byte(`and`), opToken(andOpType))
lexer.Add([]byte(`not`), opToken(notOpType)) lexer.Add([]byte(`not`), opToken(notOpType))
lexer.Add([]byte(`reduce`), opToken(reduceOpType)) lexer.Add([]byte(`ireduce`), opToken(reduceOpType))
lexer.Add([]byte(`;`), opToken(blockOpType)) lexer.Add([]byte(`;`), opToken(blockOpType))
lexer.Add([]byte(`\/\/`), opToken(alternativeOpType)) lexer.Add([]byte(`\/\/`), opToken(alternativeOpType))

View File

@ -7,7 +7,7 @@ import (
var reduceOperatorScenarios = []expressionScenario{ var reduceOperatorScenarios = []expressionScenario{
{ {
document: `[10,2, 5, 3]`, document: `[10,2, 5, 3]`,
expression: `.[] as $item reduce (0; . + $item)`, expression: `.[] as $item ireduce (0; . + $item)`,
expected: []string{ expected: []string{
"D0, P[], (!!int)::20\n", "D0, P[], (!!int)::20\n",
}, },