frostfs-sdk-go/pkg/policy/parser/Query.g4
Evgenii Stratonikov 3aeeafe79e [#3] policy: use ANTLRv4 parser generator
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-06-15 11:42:14 +03:00

45 lines
1.2 KiB
ANTLR

parser grammar Query;
options {
tokenVocab = QueryLexer;
}
policy: repStmt+ cbfStmt? selectStmt* filterStmt*;
repStmt:
REP Count = NUMBER1 // number of object replicas
(IN Selector = ident)?; // optional selector name
cbfStmt: CBF BackupFactor = NUMBER1; // container backup factor
selectStmt:
SELECT Count = NUMBER1 // number of nodes to select without container backup factor *)
(IN clause? Bucket = ident)? // bucket name
FROM Filter = identWC // filter reference or whole netmap
(AS Name = ident)? // optional selector name
;
clause: CLAUSE_SAME | CLAUSE_DISTINCT; // nodes from distinct buckets
filterExpr:
F1 = filterExpr Op = AND_OP F2 = filterExpr
| F1 = filterExpr Op = OR_OP F2 = filterExpr
| expr
;
filterStmt:
FILTER Expr = filterExpr
AS Name = ident // obligatory filter name
;
expr:
AT Filter = ident // reference to named filter
| Key = filterKey SIMPLE_OP Value = filterValue // attribute comparison
;
filterKey : ident | STRING;
filterValue : ident | number | STRING;
number : ZERO | NUMBER1;
keyword : REP | IN | AS | SELECT | FROM | FILTER;
ident : keyword | IDENT;
identWC : ident | WILDCARD;