diff --git a/pkg/ql/ast_parser.go b/pkg/ql/ast_parser.go index 514c6610b..b6e37b6bc 100644 --- a/pkg/ql/ast_parser.go +++ b/pkg/ql/ast_parser.go @@ -193,17 +193,18 @@ checkToken: list = append(list, String{Value: t.literal}) goto next case PARENTHESIS_OPEN: + depth := p.level p.level++ - dpth := p.level if sub, err := p.parseExpr(p.nextToken()); err != nil { return nil, err } else { list = append(list, sub) } + // Allow parent level to continue parsing. // Example: ((A) AND (B)) // +1 since PARENTHESIS_CLOSE decrease level - if p.level > 0 && (p.level+1) != dpth { + if (p.level + 1) != depth { p.nextToken() goto next } diff --git a/pkg/ql/ast_parser_test.go b/pkg/ql/ast_parser_test.go index 2b2e0188f..85a5ac283 100644 --- a/pkg/ql/ast_parser_test.go +++ b/pkg/ql/ast_parser_test.go @@ -183,6 +183,39 @@ func TestAstParser_Parser(t *testing.T) { Null{}, }, }, + { + parser: NewParser().ParseExpression, + in: `((foo1) AND (foo2))`, + tree: ASTNodes{ + ASTNodes{Ident{Value: "foo1"}}, + Operator{"AND"}, + ASTNodes{Ident{Value: "foo2"}}, + }, + }, + { + parser: NewParser().ParseExpression, + in: `((foo1) AND (foo2) AND foo3)`, + tree: ASTNodes{ + ASTNodes{Ident{Value: "foo1"}}, + Operator{"AND"}, + ASTNodes{Ident{Value: "foo2"}}, + Operator{"AND"}, + Ident{Value: "foo3"}, + }, + }, + { + parser: NewParser().ParseExpression, + in: `((foo1) AND (foo2)) AND foo3`, + tree: ASTNodes{ + ASTNodes{ + ASTNodes{Ident{Value: "foo1"}}, + Operator{"AND"}, + ASTNodes{Ident{Value: "foo2"}}, + }, + Operator{"AND"}, + Ident{Value: "foo3"}, + }, + }, } for i, test := range tests {