parser: add negated key glob filter (!key:pattern)

Fixes split agent query: all | type:semantic | !key:_* | sort:content-len | limit:1

Also adds glob_pattern rule that allows * and ? wildcards in key filters.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-12 03:15:02 -04:00
parent c8280ae871
commit c8922c9408

View file

@ -97,7 +97,8 @@ peg::parser! {
/ "select:" f:field_list_colon() { Stage::Transform(Transform::Select(f)) } / "select:" f:field_list_colon() { Stage::Transform(Transform::Select(f)) }
/ "type:" t:ident() { make_type_filter(&t) } / "type:" t:ident() { make_type_filter(&t) }
/ "age:" c:cmp_duration() { Stage::Filter(Filter::Age(c)) } / "age:" c:cmp_duration() { Stage::Filter(Filter::Age(c)) }
/ "key:" g:ident() { Stage::Filter(Filter::KeyGlob(g)) } / "key:" g:glob_pattern() { Stage::Filter(Filter::KeyGlob(g)) }
/ "!key:" g:glob_pattern() { Stage::Filter(Filter::Negated(Box::new(Filter::KeyGlob(g)))) }
/ "provenance:" p:ident() { Stage::Filter(Filter::Provenance(p)) } / "provenance:" p:ident() { Stage::Filter(Filter::Provenance(p)) }
/ "not-visited:" a:ident() "," d:integer() { Stage::Filter(Filter::NotVisited { agent: a, duration: d as i64 }) } / "not-visited:" a:ident() "," d:integer() { Stage::Filter(Filter::NotVisited { agent: a, duration: d as i64 }) }
/ "visited:" a:ident() { Stage::Filter(Filter::Visited { agent: a }) } / "visited:" a:ident() { Stage::Filter(Filter::Visited { agent: a }) }
@ -220,6 +221,12 @@ peg::parser! {
= s:$(['a'..='z' | 'A'..='Z' | '_']['a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '-' | '.']*) { = s:$(['a'..='z' | 'A'..='Z' | '_']['a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '-' | '.']*) {
s.to_string() s.to_string()
} }
// Glob pattern for key matching (allows * and ?)
rule glob_pattern() -> String
= s:$(['a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '-' | '.' | '*' | '?']+) {
s.to_string()
}
} }
} }