Skip to content

Commit 3957868

Browse files
committed
Handle the empty pre and post pattern
1 parent 166a4c1 commit 3957868

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/parser/match_rule.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum Attribute {
3232

3333
#[derive(Debug, PartialEq)]
3434
pub enum Pattern {
35+
Empty,
3536
Characters(String),
3637
Boundary,
3738
Any,
@@ -218,9 +219,13 @@ impl<'a> PatternParser<'a> {
218219

219220
pub fn pattern(&mut self) -> Result<Patterns, ParseError> {
220221
let mut patterns: Patterns = Vec::new();
221-
while self.chars.peek().is_some() {
222-
patterns.push(self.pattern_with_quantifier()?);
223-
}
222+
if self.chars.next_if(|&c| c == '-').is_some() {
223+
patterns.push(Pattern::Empty);
224+
} else {
225+
while self.chars.peek().is_some() {
226+
patterns.push(self.pattern_with_quantifier()?);
227+
}
228+
}
224229
Ok(patterns)
225230
}
226231
}
@@ -333,5 +338,9 @@ mod tests {
333338
PatternParser::new("a**").pattern(),
334339
Err(ParseError::MissingPatternBeforeQuantifier)
335340
);
341+
assert_eq!(
342+
PatternParser::new("-").pattern(),
343+
Ok(vec![Pattern::Empty])
344+
);
336345
}
337346
}

0 commit comments

Comments
 (0)