Merge pull request #2632 from opencloud-eu/feat/kql-dotted-keys

feat(kql): support dotted keys in property restrictions
This commit is contained in:
Florian Schade
2026-04-22 09:45:59 +02:00
committed by GitHub
3 changed files with 1427 additions and 1072 deletions

View File

@@ -29,7 +29,7 @@ Node <-
////////////////////////////////////////////////////////
GroupNode <-
k:(Char+)? (OperatorColonNode / OperatorEqualNode)? "(" v:Nodes ")" {
k:Key? (OperatorColonNode / OperatorEqualNode)? "(" v:Nodes ")" {
return buildGroupNode(k, v, c.text, c.pos)
}
@@ -43,12 +43,12 @@ PropertyRestrictionNodes <-
TextPropertyRestrictionNode
YesNoPropertyRestrictionNode <-
k:Char+ (OperatorColonNode / OperatorEqualNode) v:("true" / "false"){
k:Key (OperatorColonNode / OperatorEqualNode) v:("true" / "false"){
return buildBooleanNode(k, v, c.text, c.pos)
}
DateTimeRestrictionNode <-
k:Char+ o:(
k:Key o:(
OperatorGreaterOrEqualNode /
OperatorLessOrEqualNode /
OperatorGreaterNode /
@@ -62,7 +62,7 @@ DateTimeRestrictionNode <-
) '"'? {
return buildDateTimeNode(k, o, v, c.text, c.pos)
} /
k:Char+ (
k:Key (
OperatorEqualNode /
OperatorColonNode
) '"'? v:NaturalLanguageDateTime '"'? {
@@ -70,7 +70,7 @@ DateTimeRestrictionNode <-
}
TextPropertyRestrictionNode <-
k:Char+ (OperatorColonNode / OperatorEqualNode) v:(String / [^ ()]+){
k:Key (OperatorColonNode / OperatorEqualNode) v:(String / [^ ()]+){
return buildStringNode(k, v, c.text, c.pos)
}
@@ -219,6 +219,11 @@ Char <-
return c.text, nil
}
Key <-
Char+ ("." Char+)* {
return c.text, nil
}
String <-
'"' v:[^"]* '"' {
return v, nil

View File

File diff suppressed because it is too large Load Diff

View File

@@ -916,6 +916,61 @@ func TestParse_Errors(t *testing.T) {
}
}
func TestParse_DottedKey(t *testing.T) {
tests := []testCase{
// TextPropertyRestrictionNode with a dotted key.
{
name: `audio.artist:Motörhead`,
ast: &ast.Ast{
Nodes: []ast.Node{
&ast.StringNode{Key: "audio.artist", Value: "Motörhead"},
},
},
},
// Multi-level key exercises the ("." Char+)* Kleene in the Key rule.
{
name: `foo.bar.baz:qux`,
ast: &ast.Ast{
Nodes: []ast.Node{
&ast.StringNode{Key: "foo.bar.baz", Value: "qux"},
},
},
},
// GroupNode also uses the Key rule via k:Key?.
{
name: `audio.artist:("Motörhead" OR Beatles)`,
ast: &ast.Ast{
Nodes: []ast.Node{
&ast.GroupNode{
Key: "audio.artist",
Nodes: []ast.Node{
&ast.StringNode{Value: "Motörhead"},
&ast.OperatorNode{Value: kql.BoolOR},
&ast.StringNode{Value: "Beatles"},
},
},
},
},
},
// A dot on the value side is still a literal character.
{
name: `name:foo.bar`,
ast: &ast.Ast{
Nodes: []ast.Node{
&ast.StringNode{Key: "name", Value: "foo.bar"},
},
},
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
testKQL(t, tc)
})
}
}
func TestParse_Stress(t *testing.T) {
tests := []testCase{
{