diff --git a/pkg/yqlib/treeops/data_tree_navigator_test.go b/pkg/yqlib/treeops/data_tree_navigator_test.go index b19f9136..cdfde2f6 100644 --- a/pkg/yqlib/treeops/data_tree_navigator_test.go +++ b/pkg/yqlib/treeops/data_tree_navigator_test.go @@ -357,7 +357,7 @@ func TestDataTreeNavigatorCountMultipleMatchesInside(t *testing.T) { b: dally c: [3,4,5]`) - path, errPath := treeCreator.ParsePath("f(count(a or c))") + path, errPath := treeCreator.ParsePath("f | count(a or c)") if errPath != nil { t.Error(errPath) } @@ -384,7 +384,7 @@ func TestDataTreeNavigatorCollectMultipleMatchesInside(t *testing.T) { b: dally c: [3,4,5]`) - path, errPath := treeCreator.ParsePath("f(collect(a or c))") + path, errPath := treeCreator.ParsePath("f | collect(a or c)") if errPath != nil { t.Error(errPath) } diff --git a/pkg/yqlib/treeops/lib.go b/pkg/yqlib/treeops/lib.go index 43be04e6..d2b53791 100644 --- a/pkg/yqlib/treeops/lib.go +++ b/pkg/yqlib/treeops/lib.go @@ -30,15 +30,15 @@ type OperationType struct { } var None = &OperationType{Type: "NONE", NumArgs: 0, Precedence: 0} -var Traverse = &OperationType{Type: "TRAVERSE", NumArgs: 2, Precedence: 40, Handler: TraverseOperator} +var Traverse = &OperationType{Type: "TRAVERSE", NumArgs: 2, Precedence: 35, Handler: TraverseOperator} var Or = &OperationType{Type: "OR", NumArgs: 2, Precedence: 10, Handler: UnionOperator} var And = &OperationType{Type: "AND", NumArgs: 2, Precedence: 20, Handler: IntersectionOperator} var Equals = &OperationType{Type: "EQUALS", NumArgs: 2, Precedence: 30, Handler: EqualsOperator} -var Assign = &OperationType{Type: "ASSIGN", NumArgs: 2, Precedence: 35, Handler: AssignOperator} +var Assign = &OperationType{Type: "ASSIGN", NumArgs: 2, Precedence: 40, Handler: AssignOperator} var DeleteChild = &OperationType{Type: "DELETE", NumArgs: 2, Precedence: 30, Handler: DeleteChildOperator} -var Count = &OperationType{Type: "COUNT", NumArgs: 1, Precedence: 35, Handler: CountOperator} -var Collect = &OperationType{Type: "COLLECT", NumArgs: 1, Precedence: 35, Handler: CollectOperator} +var Count = &OperationType{Type: "COUNT", NumArgs: 1, Precedence: 40, Handler: CountOperator} +var Collect = &OperationType{Type: "COLLECT", NumArgs: 1, Precedence: 40, Handler: CollectOperator} // var Exists = &OperationType{Type: "Length", NumArgs: 2, Precedence: 35} // filters matches if they have the existing path diff --git a/pkg/yqlib/treeops/path_postfix_test.go b/pkg/yqlib/treeops/path_postfix_test.go index 7559e8e8..89f112cf 100644 --- a/pkg/yqlib/treeops/path_postfix_test.go +++ b/pkg/yqlib/treeops/path_postfix_test.go @@ -25,6 +25,26 @@ func testExpression(expression string) (string, error) { return formatted, nil } +func TestPostFixTraverseBar(t *testing.T) { + var infix = "animals | collect(.)" + var expectedOutput = `PathKey - 'animals' +-------- +SELF +-------- +Operation - COLLECT +-------- +Operation - TRAVERSE +-------- +` + + actual, err := testExpression(infix) + if err != nil { + t.Error(err) + } + + test.AssertResultComplex(t, expectedOutput, actual) +} + func TestPostFixArrayEquals(t *testing.T) { var infix = "animals(.== cat)" var expectedOutput = `PathKey - 'animals' diff --git a/pkg/yqlib/treeops/path_tokeniser.go b/pkg/yqlib/treeops/path_tokeniser.go index 3236ceda..ccb52012 100644 --- a/pkg/yqlib/treeops/path_tokeniser.go +++ b/pkg/yqlib/treeops/path_tokeniser.go @@ -94,8 +94,9 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte("( |\t|\n|\r)+"), skip) lexer.Add([]byte(`"[^ "]+"`), pathToken(true)) - lexer.Add([]byte(`[^ \.\[\(\)=]+`), pathToken(false)) + lexer.Add([]byte(`[^ \|\.\[\(\)=]+`), pathToken(false)) + lexer.Add([]byte(`\|`), opToken(Traverse, false)) lexer.Add([]byte(`\.`), opToken(Traverse, false)) err := lexer.Compile() if err != nil {