From 39578681982e0bbca9590889a14e525a11a7f2e3 Mon Sep 17 00:00:00 2001 From: Christian Egli Date: Tue, 24 Dec 2024 12:55:13 +0100 Subject: [PATCH] Handle the empty pre and post pattern --- src/parser/match_rule.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/parser/match_rule.rs b/src/parser/match_rule.rs index e89162a..c3018b7 100644 --- a/src/parser/match_rule.rs +++ b/src/parser/match_rule.rs @@ -32,6 +32,7 @@ pub enum Attribute { #[derive(Debug, PartialEq)] pub enum Pattern { + Empty, Characters(String), Boundary, Any, @@ -218,9 +219,13 @@ impl<'a> PatternParser<'a> { pub fn pattern(&mut self) -> Result { 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) } } @@ -333,5 +338,9 @@ mod tests { PatternParser::new("a**").pattern(), Err(ParseError::MissingPatternBeforeQuantifier) ); + assert_eq!( + PatternParser::new("-").pattern(), + Ok(vec![Pattern::Empty]) + ); } }