lib/grammar/ast/
comparators.rs

1use pest::iterators::Pair;
2use serde::Serialize;
3
4use crate::grammar::parser::Rule;
5
6#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
7#[serde(rename_all = "lowercase")]
8pub enum Comparators {
9    Is,
10    Matches,
11    Contains,
12    Count,
13    Regex,
14}
15
16impl<'r> From<Pair<'r, Rule>> for Comparators {
17    fn from(pair: Pair<'r, Rule>) -> Self {
18        match pair.as_span().as_str() {
19            ":is" => Comparators::Is,
20            ":matches" => Comparators::Matches,
21            ":contains" => Comparators::Contains,
22            ":count" => Comparators::Count,
23            ":regex" => Comparators::Regex,
24            _ => {
25                unreachable!("Unexpected {:?} comparator", pair.as_rule())
26            }
27        }
28    }
29}