1use proc_macro::TokenStream;
4use quote::quote;
5extern crate proc_macro;
6
7pub mod nfa_static;
8pub mod parse_tree;
9pub mod simplified_tree;
10pub mod working_nfa;
11
12enum RegexEngines {
13 NFA(nfa_static::NFAStatic),
14}
15
16pub struct Regex(RegexEngines);
20impl Regex {
21 pub fn test(&self, text: &str) -> bool {
23 return match &self.0 {
24 RegexEngines::NFA(nfa) => nfa.test(text),
25 };
26 }
27}
28
29pub const fn __construct_nfa_regex(nfa: nfa_static::NFAStatic) -> Regex {
30 return Regex(RegexEngines::NFA(nfa));
31}
32
33pub fn __compile_regex(stream: TokenStream) -> TokenStream {
34 let ere: parse_tree::ERE = syn::parse_macro_input!(stream);
35 let tree = simplified_tree::SimplifiedTreeNode::from(ere);
36 let nfa = working_nfa::WorkingNFA::new(&tree);
37
38 let serialized_nfa = nfa_static::NFAStatic::serialize_as_token_stream(&nfa);
39
40 return quote! {
41 ::ere_core::__construct_nfa_regex(#serialized_nfa)
42 }
43 .into();
44}