Change the IS NULL filter syntax to use the IS keyword

This commit is contained in:
Clément Renault 2023-03-14 10:31:04 +01:00
parent c25779afba
commit 030263caa3
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
3 changed files with 21 additions and 11 deletions

View File

@ -45,18 +45,19 @@ pub fn parse_condition(input: Span) -> IResult<FilterCondition> {
Ok((input, condition))
}
/// null = value "NULL"
pub fn parse_null(input: Span) -> IResult<FilterCondition> {
let (input, key) = terminated(parse_value, tag("NULL"))(input)?;
/// null = value "IS" WS+ "NULL"
pub fn parse_is_null(input: Span) -> IResult<FilterCondition> {
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<FilterCondition> {
/// null = value "IS" WS+ "NOT" WS+ "NULL"
pub fn parse_is_not_null(input: Span) -> IResult<FilterCondition> {
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 }))))
}

View File

@ -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<FilterCondition> {
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}"),

View File

@ -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"
)
}