mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-01 12:43:08 -04:00
Merge pull request #2632 from opencloud-eu/feat/kql-dotted-keys
feat(kql): support dotted keys in property restrictions
This commit is contained in:
@@ -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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user