Case insenstive filter syntax

This commit is contained in:
euzu
2024-03-13 12:06:30 +01:00
parent e35efb4949
commit 22402877f2
2 changed files with 23 additions and 6 deletions
+4 -4
View File
@@ -1,8 +1,8 @@
WHITESPACE = _{ " " | "\t" }
field = { "Group" | "Title" | "Name" | "Url" }
and = {"AND" | "and"}
or = {"OR" | "or"}
not = { "NOT" | "not" }
field = { ^"group" | ^"title" | ^"name" | ^"url" }
and = { ^"and" }
or = { ^"or" }
not = { ^"not" }
regexp = @{ "\"" ~ ( "\\\"" | (!"\"" ~ ANY) )* ~ "\"" }
comparison_value = _{ regexp }
comparison = { field ~ "~" ~ comparison_value }
+19 -2
View File
@@ -70,10 +70,27 @@ pub(crate) struct RegexWithCaptures {
pub captures: Vec<String>,
}
#[derive(Parser)]
//#[grammar = "filter.pest"]
#[grammar_inline = "WHITESPACE = _{ \" \" | \"\\t\" }\nfield = { \"Group\" | \"Title\" | \"Name\" | \"Url\" }\nand = {\"AND\" | \"and\"}\nor = {\"OR\" | \"or\"}\nnot = { \"NOT\" | \"not\" }\nregexp = @{ \"\\\"\" ~ ( \"\\\\\\\"\" | (!\"\\\"\" ~ ANY) )* ~ \"\\\"\" }\ncomparison_value = _{ regexp }\ncomparison = { field ~ \"~\" ~ comparison_value }\nbool_op = { and | or}\nexpr_group = { \"(\" ~ expr ~ \")\" }\nexpr = {comparison ~ (bool_op ~ expr)* | expr_group ~ (bool_op ~ expr)* | not ~ expr ~ (bool_op ~ expr)* }\nstmt = { expr ~ (bool_op ~ expr)* }\nmain = _{ SOI ~ stmt ~ EOI }"]
#[grammar_inline = r#"
WHITESPACE = _{ " " | "\t" }
field = { ^"group" | ^"title" | ^"name" | ^"url" }
and = { ^"and" }
or = { ^"or" }
not = { ^"not" }
regexp = @{ "\"" ~ ( "\\\"" | (!"\"" ~ ANY) )* ~ "\"" }
comparison_value = _{ regexp }
comparison = { field ~ "~" ~ comparison_value }
bool_op = { and | or}
expr_group = { "(" ~ expr ~ ")" }
expr = {
comparison ~ (bool_op ~ expr)*
| expr_group ~ (bool_op ~ expr)*
| not ~ expr ~ (bool_op ~ expr)*
}
stmt = { expr ~ (bool_op ~ expr)* }
main = _{ SOI ~ stmt ~ EOI }
"#]
struct FilterParser;
#[derive(Debug, Clone)]