aboutsummaryrefslogtreecommitdiff
path: root/src/fexpr/mod.rs
blob: aafdea7f51bdf6c9312a27c6c2cc54863e9888a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! Filter expression language.
//!
//! This module contains methods to parse a given string into an abstract filter tree, check its
//! type and convert it to a [`Filter`][super::filters::Filter].
// Make it available in the grammar mod.
use super::{filters, FightOutcome, SearchField, Weekday};
use lalrpop_util::{lalrpop_mod, lexer::Token, ParseError};

use thiserror::Error;

lalrpop_mod!(pub grammar, "/fexpr/grammar.rs");

#[derive(Debug, Error)]
pub enum FError {
    #[error("invalid regular expression: {0}")]
    InvalidRegex(String),
    #[error("invalid fight outcome: {0}")]
    InvalidFightOutcome(String),
    #[error("invalid weekday: {0}")]
    InvalidWeekday(String),
    #[error("invalid timestamp: {0}")]
    InvalidTimestamp(String),
    #[error("invalid boss name: {0}")]
    InvalidBoss(String),
}

pub fn parse_logfilter(
    input: &str,
) -> Result<Box<dyn filters::log::LogFilter>, ParseError<usize, Token, FError>> {
    grammar::LogFilterParser::new().parse(input)
}