MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / quantified

Method quantified

std/re/src/main/parser.rs:75–92  ·  view source on GitHub ↗

An atom plus optional repetition operator. */

(&mut self)

Source from the content-addressed store, hash-verified

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> {

Callers 1

concatMethod · 0.80

Calls 5

atomMethod · 0.80
bumpMethod · 0.80
try_boundMethod · 0.80
peekMethod · 0.45
errMethod · 0.45

Tested by

no test coverage detected