mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
implements parser
This commit is contained in:
parent
66568a913c
commit
dcf1096ac3
10 changed files with 111 additions and 330 deletions
28
meilisearch-core/src/filters/parser/grammar.pest
Normal file
28
meilisearch-core/src/filters/parser/grammar.pest
Normal file
|
@ -0,0 +1,28 @@
|
|||
key = _{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})}
|
||||
|
||||
condition = _{eq | greater | less | geq | leq | neq}
|
||||
geq = {key ~ ">=" ~ value}
|
||||
leq = {key ~ "<=" ~ value}
|
||||
neq = {key ~ "!=" ~ value}
|
||||
eq = {key ~ "=" ~ value}
|
||||
greater = {key ~ ">" ~ value}
|
||||
less = {key ~ "<" ~ value}
|
||||
|
||||
prgm = {SOI ~ expr ~ EOI}
|
||||
expr = _{ ( term ~ (operation ~ term)* ) }
|
||||
term = _{ ("(" ~ expr ~ ")") | condition | not }
|
||||
operation = _{ and | or }
|
||||
and = {"AND"}
|
||||
or = {"OR"}
|
||||
|
||||
not = {"NOT" ~ term}
|
||||
|
||||
WHITESPACE = _{ " " }
|
14
meilisearch-core/src/filters/parser/mod.rs
Normal file
14
meilisearch-core/src/filters/parser/mod.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use lazy_static::lazy_static;
|
||||
use pest::prec_climber::{Operator, Assoc, PrecClimber};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref PREC_CLIMBER: PrecClimber<Rule> = {
|
||||
use Assoc::*;
|
||||
use Rule::*;
|
||||
pest::prec_climber::PrecClimber::new(vec![Operator::new(or, Left), Operator::new(and, Left)])
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[grammar = "filters/parser/grammar.pest"]
|
||||
pub struct FilterParser;
|
Loading…
Add table
Add a link
Reference in a new issue