diff --git a/filter-parser/src/condition.rs b/filter-parser/src/condition.rs index 834fac8b8..fe424539f 100644 --- a/filter-parser/src/condition.rs +++ b/filter-parser/src/condition.rs @@ -45,18 +45,19 @@ pub fn parse_condition(input: Span) -> IResult { Ok((input, condition)) } -/// null = value "NULL" -pub fn parse_null(input: Span) -> IResult { - let (input, key) = terminated(parse_value, tag("NULL"))(input)?; +/// null = value "IS" WS+ "NULL" +pub fn parse_is_null(input: Span) -> IResult { + let (input, key) = parse_value(input)?; + let (input, _) = tuple((tag("IS"), multispace1, tag("NULL")))(input)?; Ok((input, FilterCondition::Condition { fid: key, op: Null })) } -/// null = value "NOT" WS+ "NULL" -pub fn parse_not_null(input: Span) -> IResult { +/// null = value "IS" WS+ "NOT" WS+ "NULL" +pub fn parse_is_not_null(input: Span) -> IResult { let (input, key) = parse_value(input)?; - let (input, _) = tuple((tag("NOT"), multispace1, tag("NULL")))(input)?; + let (input, _) = tuple((tag("IS"), multispace1, tag("NOT"), multispace1, tag("NULL")))(input)?; Ok((input, FilterCondition::Not(Box::new(FilterCondition::Condition { fid: key, op: Null })))) } diff --git a/filter-parser/src/lib.rs b/filter-parser/src/lib.rs index 36657587f..513da07c5 100644 --- a/filter-parser/src/lib.rs +++ b/filter-parser/src/lib.rs @@ -47,7 +47,7 @@ mod value; use std::fmt::Debug; pub use condition::{parse_condition, parse_to, Condition}; -use condition::{parse_exists, parse_not_exists, parse_not_null, parse_null}; +use condition::{parse_exists, parse_is_not_null, parse_is_null, parse_not_exists}; use error::{cut_with_err, ExpectedValueKind, NomErrorExt}; pub use error::{Error, ErrorKind}; use nom::branch::alt; @@ -414,8 +414,8 @@ fn parse_primary(input: Span, depth: usize) -> IResult { parse_in, parse_not_in, parse_condition, - parse_null, - parse_not_null, + parse_is_null, + parse_is_not_null, parse_exists, parse_not_exists, parse_to, @@ -811,7 +811,7 @@ impl<'a> std::fmt::Display for Condition<'a> { Condition::GreaterThanOrEqual(token) => write!(f, ">= {token}"), Condition::Equal(token) => write!(f, "= {token}"), Condition::NotEqual(token) => write!(f, "!= {token}"), - Condition::Null => write!(f, "NULL"), + Condition::Null => write!(f, "IS NULL"), Condition::Exists => write!(f, "EXISTS"), Condition::LowerThan(token) => write!(f, "< {token}"), Condition::LowerThanOrEqual(token) => write!(f, "<= {token}"), diff --git a/filter-parser/src/value.rs b/filter-parser/src/value.rs index 9a0a5e710..f8f1c43bc 100644 --- a/filter-parser/src/value.rs +++ b/filter-parser/src/value.rs @@ -180,7 +180,16 @@ fn is_syntax_component(c: char) -> bool { fn is_keyword(s: &str) -> bool { matches!( s, - "AND" | "OR" | "IN" | "NOT" | "TO" | "EXISTS" | "NULL" | "_geoRadius" | "_geoBoundingBox" + "AND" + | "OR" + | "IN" + | "NOT" + | "TO" + | "EXISTS" + | "IS" + | "NULL" + | "_geoRadius" + | "_geoBoundingBox" ) }