Parses an uncounted repetition operation. An uncounted repetition operator includes ?, * and +, but does not include the {m,n} syntax. The given `kind` should correspond to the operator observed by the caller. This assumes that the paser is currently positioned at the repetition operator and advances the parser to the first character after the operator. (Note that the operator may include a singl
(
&self,
mut concat: ast::Concat,
kind: ast::RepetitionKind,
)
| 1037 | /// concatenation returned includes the repetition operator applied to the |
| 1038 | /// last expression in the given concatenation. |
| 1039 | fn parse_uncounted_repetition( |
| 1040 | &self, |
| 1041 | mut concat: ast::Concat, |
| 1042 | kind: ast::RepetitionKind, |
| 1043 | ) -> Result<ast::Concat> { |
| 1044 | assert!( |
| 1045 | self.char() == '?' || self.char() == '*' || self.char() == '+'); |
| 1046 | let op_start = self.pos(); |
| 1047 | let ast = match concat.asts.pop() { |
| 1048 | Some(ast) => ast, |
| 1049 | None => return Err(self.error( |
| 1050 | self.span(), |
| 1051 | ast::ErrorKind::RepetitionMissing, |
| 1052 | )), |
| 1053 | }; |
| 1054 | match ast { |
| 1055 | Ast::Empty(_) | Ast::Flags(_) => return Err(self.error( |
| 1056 | self.span(), |
| 1057 | ast::ErrorKind::RepetitionMissing, |
| 1058 | )), |
| 1059 | _ => {} |
| 1060 | } |
| 1061 | let mut greedy = true; |
| 1062 | if self.bump() && self.char() == '?' { |
| 1063 | greedy = false; |
| 1064 | self.bump(); |
| 1065 | } |
| 1066 | concat.asts.push(Ast::Repetition(ast::Repetition { |
| 1067 | span: ast.span().with_end(self.pos()), |
| 1068 | op: ast::RepetitionOp { |
| 1069 | span: Span::new(op_start, self.pos()), |
| 1070 | kind: kind, |
| 1071 | }, |
| 1072 | greedy: greedy, |
| 1073 | ast: Box::new(ast), |
| 1074 | })); |
| 1075 | Ok(concat) |
| 1076 | } |
| 1077 | |
| 1078 | /// Parses a counted repetition operation. A counted repetition operator |
| 1079 | /// corresponds to the {m,n} syntax, and does not include the ?, * or + |
no test coverage detected