kbnf_syntax/
regex.rs

1use kbnf_regex_automata::dfa::{self, Automaton};
2#[derive(Debug, Clone)]
3pub enum FiniteStateAutomaton {
4    Dfa(dfa::dense::DFA<Vec<u32>>),
5}
6impl FiniteStateAutomaton {
7    pub fn has_empty(&self) -> bool {
8        match self {
9            Self::Dfa(dfa) => dfa::Automaton::has_empty(&dfa),
10        }
11    }
12
13    pub fn only_empty(&self, config: &kbnf_regex_automata::util::start::Config) -> bool {
14        if !self.has_empty() {
15            return false;
16        }
17        match self {
18            Self::Dfa(dfa) => {
19                let start_state = match dfa.start_state(config) {
20                    Ok(x) => x,
21                    Err(_) => {
22                        return true;
23                    }
24                };
25                (0..=u8::MAX).all(|byte| {
26                    let next_state = dfa.next_state(start_state, byte);
27                    dfa.is_dead_state(next_state) || dfa.is_quit_state(next_state)
28                })
29            }
30        }
31    }
32}
33
34#[derive(Debug, Clone)]
35pub enum FiniteStateAutomatonConfig {
36    Dfa(dfa::dense::Config),
37}