Implement the NOT IN syntax for negated IN filter

This commit is contained in:
Loïc Lecrenier 2022-06-15 09:58:47 +02:00
parent ca97cb0eda
commit 2fd20fadfc

View File

@ -192,6 +192,19 @@ fn parse_in(input: Span) -> IResult<FilterCondition> {
let filter = FilterCondition::In { fid: value, els: content };
Ok((input, filter))
}
/// in = value "NOT" WS* "IN" "[" value_list "]"
fn parse_not_in(input: Span) -> IResult<FilterCondition> {
let (input, value) = parse_value(input)?;
let (input, _) = tag("NOT")(input)?;
let (input, _) = multispace1(input)?;
let (input, _) = ws(tag("IN"))(input)?;
let mut els_parser = delimited(tag("["), parse_value_list, tag("]"));
let (input, content) = els_parser(input)?;
let filter = FilterCondition::Not(Box::new(FilterCondition::In { fid: value, els: content }));
Ok((input, filter))
}
/// or = and ("OR" and)
fn parse_or(input: Span) -> IResult<FilterCondition> {
@ -290,6 +303,7 @@ fn parse_primary(input: Span) -> IResult<FilterCondition> {
),
parse_geo_radius,
parse_in,
parse_not_in,
parse_condition,
parse_exists,
parse_not_exists,
@ -361,6 +375,16 @@ pub mod tests {
]
}
),
(
"colour NOT IN[green,blue]",
Fc::Not(Box::new(Fc::In {
fid: rtok("", "colour"),
els: vec![
rtok("colour NOT IN[", "green"),
rtok("colour NOT IN[green, ", "blue"),
]
}))
),
(
" colour IN [ green , blue , ]",
Fc::In {