diff --git a/milli/src/error.rs b/milli/src/error.rs index 3ae18165f..c0ce101c8 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -59,9 +59,7 @@ pub enum UserError { InvalidDocumentId { document_id: Value }, InvalidFacetsDistribution { invalid_facets_name: HashSet }, InvalidGeoField { document_id: Value, object: Value }, - InvalidFilterAttributeNom, - InvalidFilterValue, - InvalidFilterNom { input: String }, + InvalidFilter { input: String }, InvalidSortName { name: String }, InvalidSortableAttribute { field: String, valid_fields: HashSet }, SortRankingRuleMissing, @@ -209,10 +207,7 @@ impl StdError for InternalError {} impl fmt::Display for UserError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - //TODO - Self::InvalidFilterAttributeNom => write!(f, "parser error "), - Self::InvalidFilterValue => write!(f, "parser error "), - Self::InvalidFilterNom { input } => write!(f, "parser error {}", input), + Self::InvalidFilter { input } => write!(f, "parser error {}", input), Self::AttributeLimitReached => f.write_str("maximum number of attributes reached"), Self::CriterionError(error) => write!(f, "{}", error), Self::DocumentLimitReached => f.write_str("maximum number of documents reached"), diff --git a/milli/src/search/facet/filter_condition.rs b/milli/src/search/facet/filter_condition.rs index 2686e4a4b..0e98edd2c 100644 --- a/milli/src/search/facet/filter_condition.rs +++ b/milli/src/search/facet/filter_condition.rs @@ -90,7 +90,7 @@ impl FilterCondition { nom::Err::Failure(x) => x, _ => unreachable!(), }; - Err(Error::UserError(UserError::InvalidFilterNom { + Err(Error::UserError(UserError::InvalidFilter { input: convert_error(expression, ve).to_string(), })) } diff --git a/milli/src/search/facet/filter_parser.rs b/milli/src/search/facet/filter_parser.rs index 01e944a98..493c53920 100644 --- a/milli/src/search/facet/filter_parser.rs +++ b/milli/src/search/facet/filter_parser.rs @@ -56,13 +56,12 @@ pub struct ParseContext<'a> { } impl<'a> ParseContext<'a> { - fn parse_or_nom(&'a self, input: &'a str) -> IResult<&'a str, FilterCondition, E> + fn parse_or(&'a self, input: &'a str) -> IResult<&'a str, FilterCondition, E> where E: ParseError<&'a str> + ContextError<&'a str> + Debug, { - let (input, lhs) = self.parse_and_nom(input)?; - let (input, ors) = - many0(preceded(self.ws(tag("OR")), |c| Self::parse_or_nom(self, c)))(input)?; + let (input, lhs) = self.parse_and(input)?; + let (input, ors) = many0(preceded(self.ws(tag("OR")), |c| Self::parse_or(self, c)))(input)?; let expr = ors .into_iter() @@ -70,25 +69,20 @@ impl<'a> ParseContext<'a> { Ok((input, expr)) } - fn parse_and_nom(&'a self, input: &'a str) -> IResult<&'a str, FilterCondition, E> + fn parse_and(&'a self, input: &'a str) -> IResult<&'a str, FilterCondition, E> where E: ParseError<&'a str> + ContextError<&'a str> + Debug, { - let (input, lhs) = self.parse_not_nom(input)?; - // let (input, lhs) = alt(( - // delimited(self.ws(char('(')), |c| Self::parse_not_nom(self, c), self.ws(char(')'))), - // |c| self.parse_not_nom(c), - // ))(input)?; - + let (input, lhs) = self.parse_not(input)?; let (input, ors) = - many0(preceded(self.ws(tag("AND")), |c| Self::parse_and_nom(self, c)))(input)?; + many0(preceded(self.ws(tag("AND")), |c| Self::parse_and(self, c)))(input)?; let expr = ors .into_iter() .fold(lhs, |acc, branch| FilterCondition::And(Box::new(acc), Box::new(branch))); Ok((input, expr)) } - fn parse_not_nom(&'a self, input: &'a str) -> IResult<&'a str, FilterCondition, E> + fn parse_not(&'a self, input: &'a str) -> IResult<&'a str, FilterCondition, E> where E: ParseError<&'a str> + ContextError<&'a str> + Debug, { @@ -307,7 +301,7 @@ impl<'a> ParseContext<'a> { where E: ParseError<&'a str> + ContextError<&'a str> + Debug, { - let a = self.parse_or_nom(input); + let a = self.parse_or(input); a } } diff --git a/milli/src/search/facet/grammar.pest b/milli/src/search/facet/grammar.pest deleted file mode 100644 index 8bfdeb667..000000000 --- a/milli/src/search/facet/grammar.pest +++ /dev/null @@ -1,33 +0,0 @@ -key = _{reserved | quoted | word } -value = _{quoted | word } -quoted = _{ (PUSH("'") | PUSH("\"")) ~ string ~ POP } -string = {char*} -word = ${(LETTER | NUMBER | "_" | "-" | ".")+} - -char = _{ !(PEEK | "\\") ~ ANY - | "\\" ~ (PEEK | "\\" | "/" | "b" | "f" | "n" | "r" | "t") - | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})} - -reserved = { "_geoDistance" | ("_geoPoint" ~ parameters) | "_geo" } -// we deliberately choose to allow empty parameters to generate more specific error message later -parameters = {("(" ~ (value ~ ",")* ~ value? ~ ")") | ""} -condition = _{between | eq | greater | less | geq | leq | neq} -between = {key ~ value ~ "TO" ~ value} -geq = {key ~ ">=" ~ value} -leq = {key ~ "<=" ~ value} -neq = {key ~ "!=" ~ value} -eq = {key ~ "=" ~ value} -greater = {key ~ ">" ~ value} -less = {key ~ "<" ~ value} -geo_radius = {"_geoRadius" ~ parameters } - -prgm = {SOI ~ expr ~ EOI} -expr = _{ ( term ~ (operation ~ term)* ) } -term = { ("(" ~ expr ~ ")") | condition | not | geo_radius } -operation = _{ and | or } -and = {"AND"} -or = {"OR"} - -not = {"NOT" ~ term} - -WHITESPACE = _{ " " }