pub fn parse<'a>(
input: impl AsRef<str> + 'a,
) -> Result<SearchEmailsQuery, Error>
Expand description
Parse the given string slice into a SearchEmailsQuery
.
Because of the recursive nature of SearchEmailsFilterQuery
, it
is not possible to directly parse a full query from a string using
chumsky
. Instead the string is splitted in two, and filters
and sorters are parsed separately.
A search emails query string can contain a filter query, a sorter
query or both. In this last case, the filter query needs to be
defined first, then the sorter query. They should be separated by
the keyword "order by"
.
See filter::parser::query
for more details on the filter query
string API, and sort::parser::query
for more details on the
sort query API.
§Examples
use email::search_query::SearchEmailsQuery;
use std::str::FromStr;
pub fn main() {
// filter only
"subject foo and body bar".parse::<SearchEmailsQuery>().unwrap();
// sort only
"order by date desc".parse::<SearchEmailsQuery>().unwrap();
// filter then sort
"subject foo and body bar order by subject".parse::<SearchEmailsQuery>().unwrap();
}
§ABNF
query = filter-query / "order by" SP sort-query / filter-query SP "order by" SP sort-query
filter-query = filter *(SP filter)
filter = "(" filter ")"
; nested filter
filter =/ and / or / not
; filter operators
filter =/ date / before-date / after-date / from / to / subject / body / flag
; filter conditions
and = filter SP "and" SP filter
or = filter SP "or" SP filter
not = "not" SP filter
date = "date" SP date-pattern
before-date = "before" SP date-pattern
after-date = "before" SP date-pattern
from = "from" SP text-pattern
to = "to" SP text-pattern
subject = "subject" SP text-pattern
body = "body" SP text-pattern
flag = "flag" SP text-pattern
date-pattern = 4DIGIT "-" 2DIGIT "-" 2DIGIT
; date matching "YYYY-MM-dd" format
date-pattern =/ 4DIGIT "/" 2DIGIT "/" 2DIGIT
; date matching "YYYY/MM/dd" format
date-pattern =/ 2DIGIT "-" 2DIGIT "-" 4DIGIT
; date matching "dd-MM-YYYY" format
date-pattern =/ 2DIGIT "/" 2DIGIT "/" 4DIGIT
; date matching "dd/MM/YYYY" format
text-pattern = DQUOTE *VCHAR DQUOTE
sort-query = sorter *(SP sorter)
sorter = sorter-kind [SP sorter-order]
sorter-kind = "date" / "from" / "to" / "subject"
sorter-order = "asc" / "desc"