Add tag syntax to KQL (#137)

This commit is contained in:
Lars Willighagen 2021-09-09 19:03:07 +02:00 committed by GitHub
parent f242250d22
commit 0e89878072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -24,12 +24,14 @@ lack of `*` (use `[]` instead), and the specific syntax for
## Matchers ## Matchers
Matchers are used to filter nodes by their various attributes (such as values, Matchers are used to filter nodes by their various attributes (such as values,
properties, node names, etc). With the exception of `top()`, they are all used properties, node names, etc). With the exception of `top()` and `()`, they are all
inside a `[ ]` selector. Some matchers are unary, but most of them involve used inside a `[ ]` selector. Some matchers are unary, but most of them involve
binary operators. binary operators.
* `top()`: Returns all toplevel children of the current document. * `top()`: Returns all toplevel children of the current document.
* `top() > []`: Equivalent to `top()` on its own. * `top() > []`: Equivalent to `top()` on its own.
* `(foo)`: Selects any element with a tag named `foo`.
* `()`: Selects any element with any tag.
* `[val()]`: Selects any element with a value. * `[val()]`: Selects any element with a value.
* `[val(1)]`: Selects any element with a second value. * `[val(1)]`: Selects any element with a second value.
* `[prop(foo)]`: Selects any element with a property named `foo`. * `[prop(foo)]`: Selects any element with a property named `foo`.
@ -41,9 +43,10 @@ Attribute matchers support certain binary operators:
* `[prop(name) = 1]`: Selects any element with a property `name` whose value is 1. * `[prop(name) = 1]`: Selects any element with a property `name` whose value is 1.
* `[name = 1]`: Equivalent to the above. * `[name = 1]`: Equivalent to the above.
* `[name() = "hi"]`: Selects any element whose _node name_ is "hi". Equivalent to just `hi`, but more useful when using string operators. * `[name() = "hi"]`: Selects any element whose _node name_ is "hi". Equivalent to just `hi`, but more useful when using string operators.
* `[tag() = "hi"]`: Selects any element whose tag is "hi". Equivalent to just `(hi)`, but more useful when using string operators.
* `[val() != 1]`: Selects any element whose first value exists, and is not 1. * `[val() != 1]`: Selects any element whose first value exists, and is not 1.
The following operators work with any `val()`, `prop()`, or `name()` values. The following operators work with any `val()` or `prop()` values.
If the value is not of the same type, the operator will always fail ("1" is If the value is not of the same type, the operator will always fail ("1" is
never coerced to 1, and there is no "universal" ordering across all types.): never coerced to 1, and there is no "universal" ordering across all types.):
@ -52,12 +55,18 @@ never coerced to 1, and there is no "universal" ordering across all types.):
* `[val() < 1]`: Selects any element whose first value is less than 1. * `[val() < 1]`: Selects any element whose first value is less than 1.
* `[val() <= 1]`: Selects any element whose first value is less than or equal to 1. * `[val() <= 1]`: Selects any element whose first value is less than or equal to 1.
The following operators work only with string `val()`, `prop()`, or `name()` values. If the value is not a string, the matcher will always fail: The following operators work only with string `val()`, `prop()`, `tag()`, or `name()` values.
If the value is not a string, the matcher will always fail:
* `[val() ^= "foo"]`: Selects any element whose first value starts with "foo". * `[val() ^= "foo"]`: Selects any element whose first value starts with "foo".
* `[val() $= "foo"]`: Selects any element whose first value ends with "foo". * `[val() $= "foo"]`: Selects any element whose first value ends with "foo".
* `[val() *= "foo"]`: Selects any element whose first value contains "foo". * `[val() *= "foo"]`: Selects any element whose first value contains "foo".
The following operators work only with `val()` or `prop()` values. If the value
is not one of those, the matcher will always fail:
* `[val() = (foo)]`: Selects any element whose tag is "foo".
## Map Operator ## Map Operator
KQL implementations MAY support a "map operator", `=>`, that allows selection KQL implementations MAY support a "map operator", `=>`, that allows selection