diff --git a/src/tokens.rs b/src/tokens.rs index 46ce93e..23d1d1d 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -6,6 +6,25 @@ pub enum Case { None, } +#[derive(Debug, Clone, Default)] +pub struct ParserBuilder {} + +impl ParserBuilder { + pub fn new() -> Self { + Default::default() + } + + pub fn build(self) -> Parser { + let pattern = r#"\b(\p{Alphabetic}|\d|_|')+\b"#; + let words_str = regex::Regex::new(pattern).unwrap(); + let words_bytes = regex::bytes::Regex::new(pattern).unwrap(); + Parser { + words_str, + words_bytes, + } + } +} + #[derive(Debug, Clone)] pub struct Parser { words_str: regex::Regex, @@ -14,13 +33,7 @@ pub struct Parser { impl Parser { pub fn new() -> Self { - let pattern = r#"\b(\p{Alphabetic}|\d|_|')+\b"#; - let words_str = regex::Regex::new(pattern).unwrap(); - let words_bytes = regex::bytes::Regex::new(pattern).unwrap(); - Self { - words_str, - words_bytes, - } + ParserBuilder::default().build() } pub fn parse<'c>(&'c self, content: &'c str) -> impl Iterator> { @@ -37,6 +50,12 @@ impl Parser { } } +impl Default for Parser { + fn default() -> Self { + Self::new() + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Identifier<'t> { token: &'t str,