mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
refactor(parser): Split out parser creation
This commit is contained in:
parent
8e4708dfdf
commit
d0b9979c36
1 changed files with 26 additions and 7 deletions
|
@ -6,6 +6,25 @@ pub enum Case {
|
||||||
None,
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Parser {
|
pub struct Parser {
|
||||||
words_str: regex::Regex,
|
words_str: regex::Regex,
|
||||||
|
@ -14,13 +33,7 @@ pub struct Parser {
|
||||||
|
|
||||||
impl Parser {
|
impl Parser {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let pattern = r#"\b(\p{Alphabetic}|\d|_|')+\b"#;
|
ParserBuilder::default().build()
|
||||||
let words_str = regex::Regex::new(pattern).unwrap();
|
|
||||||
let words_bytes = regex::bytes::Regex::new(pattern).unwrap();
|
|
||||||
Self {
|
|
||||||
words_str,
|
|
||||||
words_bytes,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse<'c>(&'c self, content: &'c str) -> impl Iterator<Item = Identifier<'c>> {
|
pub fn parse<'c>(&'c self, content: &'c str) -> impl Iterator<Item = Identifier<'c>> {
|
||||||
|
@ -37,6 +50,12 @@ impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Parser {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct Identifier<'t> {
|
pub struct Identifier<'t> {
|
||||||
token: &'t str,
|
token: &'t str,
|
||||||
|
|
Loading…
Reference in a new issue