An atom plus optional repetition operator. */
(&mut self)
| 73 | |
| 74 | /* An atom plus optional repetition operator. */ |
| 75 | fn quantified(&mut self) -> Result<Node, ParseError> { |
| 76 | let atom = self.atom()?; |
| 77 | let (min, max) = match self.peek() { |
| 78 | Some('*') => { self.bump(); (0, None) } |
| 79 | Some('+') => { self.bump(); (1, None) } |
| 80 | Some('?') => { self.bump(); (0, Some(1)) } |
| 81 | Some('{') => match self.try_bound()? { |
| 82 | Some(b) => b, |
| 83 | None => return Ok(atom), // a bare brace is a literal |
| 84 | }, |
| 85 | _ => return Ok(atom), |
| 86 | }; |
| 87 | let greedy = if self.peek() == Some('?') { self.bump(); false } else { true }; |
| 88 | if matches!(self.peek(), Some('*') | Some('+')) { |
| 89 | return Err(self.err("multiple repeat")); |
| 90 | } |
| 91 | Ok(Node::Repeat { node: Box::new(atom), min, max, greedy }) |
| 92 | } |
| 93 | |
| 94 | /* Parse a counted bound, restoring position when it is not one. */ |
| 95 | fn try_bound(&mut self) -> Result<Option<(usize, Option<usize>)>, ParseError> { |