filter-expr 0.1.9

A library for parsing the filter expression.
Documentation

filter-expr

A library for parsing the filter expression.

use filter_expr::{FilterExpr, SimpleContext};

let f = FilterExpr::parse("name = 'John' AND age > 18").unwrap();
let ctx = SimpleContext::new(HashMap::from([
    ("name".to_string(), "John".into()),
    ("age".to_string(), 19.into()),
]));
let result = f.eval(&ctx).await.unwrap();
assert_eq!(result, true);

Syntax

Filter

<filter> = <expr> | <empty>

<empty> =

Expression

<expr> = <factor> ('AND' <factor>)*

<factor> = <term> ('OR' <term>)*
<term> = ['NOT'] <comparison>
       | <value> [<operator> <value>]
<operator> = '=' | '>' | '<' | '>=' | '<=' | '!=' | 'IN'

Value

<value> = <str>
        | <i64>
        | <f64>
        | <bool>
        | <null>
        | <func-call>
        | <ident>
        | <array>

<func-call> = <ident> '(' [<value> (',' <value>)* ','?] ')'
<array> = '[' [<value> (',' <value>)* ','?] ']'