Skip to content

Commit

Permalink
Allow boundaries outside of attribute expressions
Browse files Browse the repository at this point in the history
in match patterns

IMHO it just makes no sense to have boundaries inside attribute
expressions, because you could have a sequence of those and IMHO it
makes no sense to have more than one boundary defined.
  • Loading branch information
egli committed May 27, 2024
1 parent c202281 commit 235e983
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/parser/match_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum Attribute {
#[derive(Debug, PartialEq)]
pub enum Pattern {
Characters(String),
Boundary,
Any,
Set(HashSet<char>),
Attributes(HashSet<Attribute>),
Expand Down Expand Up @@ -165,10 +166,22 @@ impl<'a> PatternParser<'a> {
Ok(Pattern::Negate(Box::new(pattern)))
}

fn start_boundary(&mut self) -> Result<Pattern, ParseError> {
self.consume('^')?;
Ok(Pattern::Boundary)
}

fn end_boundary(&mut self) -> Result<Pattern, ParseError> {
self.consume('$')?;
Ok(Pattern::Boundary)
}

fn inner_pattern(&mut self) -> Result<Pattern, ParseError> {
match self.chars.peek() {
Some('.') => self.any(),
Some('%') => self.attributes(),
Some('^') => self.start_boundary(),
Some('$') => self.end_boundary(),
Some('!') => self.negate(),
Some('[') => self.characters(),
Some('(') => self.group(),
Expand Down

0 comments on commit 235e983

Please sign in to comment.