Skip to content

Commit

Permalink
feat(parse): Make digits in identifier optional
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Aug 7, 2019
1 parent 50c89ef commit e093135
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum Case {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ParserBuilder {
ignore_hex: bool,
include_digits: bool,
}

impl ParserBuilder {
Expand All @@ -21,10 +22,19 @@ impl ParserBuilder {
self
}

pub fn include_digits(&mut self, yes: bool) -> &mut Self {
self.include_digits = yes;
self
}

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();
let mut pattern = r#"\b(\p{Alphabetic}|_|'"#.to_owned();
if self.include_digits {
pattern.push_str(r#"|\d"#);
}
pattern.push_str(r#")+\b"#);
let words_str = regex::Regex::new(&pattern).unwrap();
let words_bytes = regex::bytes::Regex::new(&pattern).unwrap();
Parser {
words_str,
words_bytes,
Expand All @@ -35,7 +45,10 @@ impl ParserBuilder {

impl Default for ParserBuilder {
fn default() -> Self {
Self { ignore_hex: true }
Self {
ignore_hex: true,
include_digits: true,
}
}
}

Expand Down

0 comments on commit e093135

Please sign in to comment.