Parses a capture group name. Assumes that the parser is positioned at the first character in the name following the opening `<` (and may possibly be EOF). This advances the parser to the first character following the closing `>`. The caller must provide the capture index of the group for this name.
(
&self,
capture_index: u32,
)
| 1253 | /// |
| 1254 | /// The caller must provide the capture index of the group for this name. |
| 1255 | fn parse_capture_name( |
| 1256 | &self, |
| 1257 | capture_index: u32, |
| 1258 | ) -> Result<ast::CaptureName> { |
| 1259 | if self.is_eof() { |
| 1260 | return Err(self.error( |
| 1261 | self.span(), |
| 1262 | ast::ErrorKind::GroupNameUnexpectedEof, |
| 1263 | )); |
| 1264 | } |
| 1265 | let start = self.pos(); |
| 1266 | loop { |
| 1267 | if self.char() == '>' { |
| 1268 | break; |
| 1269 | } |
| 1270 | if !is_capture_char(self.char(), self.pos() == start) { |
| 1271 | return Err(self.error( |
| 1272 | self.span_char(), |
| 1273 | ast::ErrorKind::GroupNameInvalid, |
| 1274 | )); |
| 1275 | } |
| 1276 | if !self.bump() { |
| 1277 | break; |
| 1278 | } |
| 1279 | } |
| 1280 | let end = self.pos(); |
| 1281 | if self.is_eof() { |
| 1282 | return Err(self.error( |
| 1283 | self.span(), |
| 1284 | ast::ErrorKind::GroupNameUnexpectedEof, |
| 1285 | )); |
| 1286 | } |
| 1287 | assert_eq!(self.char(), '>'); |
| 1288 | self.bump(); |
| 1289 | let name = &self.pattern()[start.offset..end.offset]; |
| 1290 | if name.is_empty() { |
| 1291 | return Err(self.error( |
| 1292 | Span::new(start, start), |
| 1293 | ast::ErrorKind::GroupNameEmpty, |
| 1294 | )); |
| 1295 | } |
| 1296 | let capname = ast::CaptureName { |
| 1297 | span: Span::new(start, end), |
| 1298 | name: name.to_string(), |
| 1299 | index: capture_index, |
| 1300 | }; |
| 1301 | self.add_capture_name(&capname)?; |
| 1302 | Ok(capname) |
| 1303 | } |
| 1304 | |
| 1305 | /// Parse a sequence of flags starting at the current character. |
| 1306 | /// |
no test coverage detected