From b08fc4382ac84f568954fb2d7bf36bbc210fc2d1 Mon Sep 17 00:00:00 2001 From: Romain Delamare Date: Sun, 14 Apr 2024 16:17:28 +0200 Subject: [PATCH 1/3] kql: only allow top() at start of selector --- QUERY-SPEC.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/QUERY-SPEC.md b/QUERY-SPEC.md index 114a75c..bd6a802 100644 --- a/QUERY-SPEC.md +++ b/QUERY-SPEC.md @@ -110,8 +110,9 @@ what they expand to. ``` query-str := $bom? query -query := selector q-ws* "||" q-ws* query | selector -selector := filter q-ws* selector-operator q-ws* selector | filter +query := selector-start q-ws* "||" q-ws* query | selector-start +selector-start := filter q-ws* selector-operator q-ws* selector | filter +selector := matchers q-ws* selector-operator q-ws* selector | matchers selector-operator := ">>" | ">" | "++" | "+" filter := "top(" q-ws* ")" | matchers matchers := type-matcher $string? accessor-matcher* | $string accessor-matcher* | accessor-matcher+ From 6c4c27e8c0d098b80f25632d2eb0d9a3cb609fa7 Mon Sep 17 00:00:00 2001 From: Romain Delamare Date: Tue, 16 Apr 2024 18:47:09 +0200 Subject: [PATCH 2/3] kql: add some explanation for top() matcher --- QUERY-SPEC.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/QUERY-SPEC.md b/QUERY-SPEC.md index bd6a802..371b711 100644 --- a/QUERY-SPEC.md +++ b/QUERY-SPEC.md @@ -30,6 +30,11 @@ properties, node names, etc). With the exception of `top()` and `()`, they are a used inside a `[]` selector. Some matchers are unary, but most of them involve binary operators. +The `top()` matcher can only be used as the first matcher of a selector. This means +that it cannot be the right operand of the `>`, `>>`, `+`, or `++` operators. As `||` +combines selectors, the `top()` can appear just after it. For instance, + `a > b || top() > b` is valid, but `a > top()` is not. + * `top()`: Returns all toplevel children of the current document. * `top() > []`: Equivalent to `top()` on its own. * `(foo)`: Selects any element whose type annotation is `foo`. From b6a4627fdb316563abe86e6df5cd6b12571ef63b Mon Sep 17 00:00:00 2001 From: Romain Delamare Date: Wed, 17 Apr 2024 18:05:13 +0200 Subject: [PATCH 3/3] kql: rename selector rules in grammar --- QUERY-SPEC.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/QUERY-SPEC.md b/QUERY-SPEC.md index 371b711..70e4906 100644 --- a/QUERY-SPEC.md +++ b/QUERY-SPEC.md @@ -115,9 +115,9 @@ what they expand to. ``` query-str := $bom? query -query := selector-start q-ws* "||" q-ws* query | selector-start -selector-start := filter q-ws* selector-operator q-ws* selector | filter -selector := matchers q-ws* selector-operator q-ws* selector | matchers +query := selector q-ws* "||" q-ws* query | selector +selector := filter q-ws* selector-operator q-ws* selector-subsequent | filter +selector-subsequent := matchers q-ws* selector-operator q-ws* selector-subsequent | matchers selector-operator := ">>" | ">" | "++" | "+" filter := "top(" q-ws* ")" | matchers matchers := type-matcher $string? accessor-matcher* | $string accessor-matcher* | accessor-matcher+