Parse a pattern into a Program or fail with a positioned error. */
(pattern: &str)
| 5 | |
| 6 | /* Parse a pattern into a Program or fail with a positioned error. */ |
| 7 | pub fn parse(pattern: &str) -> Result<Program, ParseError> { |
| 8 | let chars: Vec<char> = pattern.chars().collect(); |
| 9 | let mut p = Parser { |
| 10 | p: &chars, |
| 11 | pos: 0, |
| 12 | group_count: 0, |
| 13 | names: Vec::new(), |
| 14 | flags: Flags::default(), |
| 15 | }; |
| 16 | let root = p.alternation()?; |
| 17 | if p.pos != p.p.len() { |
| 18 | return Err(p.err("unbalanced parenthesis")); |
| 19 | } |
| 20 | Ok(Program { root, group_count: p.group_count, names: p.names, flags: p.flags }) |
| 21 | } |
| 22 | |
| 23 | struct Parser<'a> { |
| 24 | p: &'a [char], |
no test coverage detected