2020-09-11 14:44:34 +00:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/alecthomas/participle"
|
|
|
|
)
|
|
|
|
|
|
|
|
var parser *participle.Parser
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
p, err := participle.Build(&query{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
parser = p
|
|
|
|
}
|
|
|
|
|
|
|
|
type query struct {
|
|
|
|
Replicas []*replicaStmt `@@+`
|
|
|
|
CBF uint32 `("CBF" @Int)?`
|
|
|
|
Selectors []*selectorStmt `@@*`
|
|
|
|
Filters []*filterStmt `@@*`
|
|
|
|
}
|
|
|
|
|
|
|
|
type replicaStmt struct {
|
|
|
|
Count int `"REP" @Int`
|
|
|
|
Selector string `("IN" @Ident)?`
|
|
|
|
}
|
|
|
|
|
|
|
|
type selectorStmt struct {
|
2020-10-14 15:25:21 +00:00
|
|
|
Count uint32 `"SELECT" @Int`
|
|
|
|
Bucket []string `("IN" @(("SAME" | "DISTINCT")? Ident))?`
|
|
|
|
Filter string `"FROM" @(Ident | "*")`
|
|
|
|
Name string `("AS" @Ident)?`
|
2020-09-11 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type filterStmt struct {
|
|
|
|
Value *orChain `"FILTER" @@`
|
|
|
|
Name string `"AS" @Ident`
|
|
|
|
}
|
|
|
|
|
|
|
|
type filterOrExpr struct {
|
|
|
|
Reference string `"@"@Ident`
|
|
|
|
Expr *simpleExpr `| @@`
|
|
|
|
}
|
|
|
|
|
|
|
|
type orChain struct {
|
|
|
|
Clauses []*andChain `@@ ("OR" @@)*`
|
|
|
|
}
|
|
|
|
|
|
|
|
type andChain struct {
|
|
|
|
Clauses []*filterOrExpr `@@ ("AND" @@)*`
|
|
|
|
}
|
|
|
|
|
|
|
|
type simpleExpr struct {
|
2021-02-24 14:02:50 +00:00
|
|
|
Key string `@(Ident | String)`
|
2020-09-11 14:44:34 +00:00
|
|
|
// We don't use literals here to improve error messages.
|
|
|
|
Op string `@Ident`
|
|
|
|
Value string `@(Ident | String | Int)`
|
|
|
|
}
|