From 22402877f27e7a04cbc97c4e8da424da8e3f35ef Mon Sep 17 00:00:00 2001 From: euzu Date: Wed, 13 Mar 2024 12:06:30 +0100 Subject: [PATCH] Case insenstive filter syntax --- src/filter.pest | 8 ++++---- src/filter.rs | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/filter.pest b/src/filter.pest index 704dc0854..9936f8587 100644 --- a/src/filter.pest +++ b/src/filter.pest @@ -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 } diff --git a/src/filter.rs b/src/filter.rs index aa00576c1..22f60453c 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -70,10 +70,27 @@ pub(crate) struct RegexWithCaptures { pub captures: Vec, } - #[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)]