use core::num::NonZeroUsize;
use crate::{
alloc::sync::Arc,
spanners::span_lexers::{
SpanLexer,
accelerators,
},
support::regex::{
RegexPattern,
RegexWrapper,
},
};
pub fn build_regex_lexer(
pattern: RegexPattern,
enable_accelerators: bool,
enable_regex_automata: bool,
concurrent: bool,
max_pool: Option<NonZeroUsize>,
) -> Arc<dyn SpanLexer> {
if enable_accelerators
&& let Some(lexer) = accelerators::get_regex_accelerator(pattern.as_str())
{
return lexer;
}
if enable_regex_automata
&& (cfg!(not(feature = "concurrent")) || concurrent)
&& let Some(lexer) = super::regex_automata::try_build(pattern.as_str(), max_pool)
{
return lexer;
}
let re: RegexWrapper = pattern.into();
#[cfg(feature = "concurrent")]
if concurrent {
return Arc::new(crate::support::concurrency::PoolToy::new(re, max_pool));
}
Arc::new(re)
}