Skip to content

Commit

Permalink
Handle the empty pre and post pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
egli committed Dec 24, 2024
1 parent 166a4c1 commit 3957868
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/parser/match_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum Attribute {

#[derive(Debug, PartialEq)]
pub enum Pattern {
Empty,
Characters(String),
Boundary,
Any,
Expand Down Expand Up @@ -218,9 +219,13 @@ impl<'a> PatternParser<'a> {

pub fn pattern(&mut self) -> Result<Patterns, ParseError> {
let mut patterns: Patterns = Vec::new();
while self.chars.peek().is_some() {
patterns.push(self.pattern_with_quantifier()?);
}
if self.chars.next_if(|&c| c == '-').is_some() {
patterns.push(Pattern::Empty);
} else {
while self.chars.peek().is_some() {
patterns.push(self.pattern_with_quantifier()?);
}
}
Ok(patterns)
}
}
Expand Down Expand Up @@ -333,5 +338,9 @@ mod tests {
PatternParser::new("a**").pattern(),
Err(ParseError::MissingPatternBeforeQuantifier)
);
assert_eq!(
PatternParser::new("-").pattern(),
Ok(vec![Pattern::Empty])
);
}
}

0 comments on commit 3957868

Please sign in to comment.