From 0f5ce2e8bb3debc613dd190dee7438b589ccf5a9 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 21 May 2021 18:12:27 +0300 Subject: [PATCH] [#3] policy: allow to use brackets in filters Signed-off-by: Evgenii Stratonikov --- pkg/policy/doc.go | 5 +---- pkg/policy/parser/Query.g4 | 1 + pkg/policy/parser/Query.interp | Bin 4174 -> 4346 bytes pkg/policy/parser/query_parser.go | Bin 59362 -> 60564 bytes pkg/policy/query.go | 4 ++++ pkg/policy/query_test.go | 24 ++++++++++++++++++++++++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/pkg/policy/doc.go b/pkg/policy/doc.go index 10394fa1..4e10a1be 100644 --- a/pkg/policy/doc.go +++ b/pkg/policy/doc.go @@ -2,10 +2,7 @@ // ANTLRv4 grammar is provided in `parser/Query.g4` and `parser/QueryLexer.g4`. // // Current limitations: -// 1. Grouping filter expressions in parenthesis is not supported right now. -// Requiring this will make query too verbose, making it optional makes -// our grammar not LL(1). This can be supported in future. -// 2. Filters must be defined before they are used. +// 1. Filters must be defined before they are used. // This requirement may be relaxed in future. // // Example query: diff --git a/pkg/policy/parser/Query.g4 b/pkg/policy/parser/Query.g4 index 0cad576e..fc74c6fc 100644 --- a/pkg/policy/parser/Query.g4 +++ b/pkg/policy/parser/Query.g4 @@ -24,6 +24,7 @@ clause: CLAUSE_SAME | CLAUSE_DISTINCT; // nodes from distinct buckets filterExpr: F1 = filterExpr Op = AND_OP F2 = filterExpr | F1 = filterExpr Op = OR_OP F2 = filterExpr + | '(' Inner = filterExpr ')' | expr ; diff --git a/pkg/policy/parser/Query.interp b/pkg/policy/parser/Query.interp index 63f74d9a5f7db8596c48f2d0c52c4bffcbc36599..9512ecb628462c54d2fb7c893a4d88015cbb1ffc 100644 GIT binary patch literal 4346 zcmaKv-A)@x5QXpiDSXH7ii>I60xC!Tgoq?Pbn>&5xy*<356g~c+=)&Wt$B?SozE+3q2f%a7;p=c^e0p06&#db3(A{|Hy>5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