MCPcopy Create free account
hub / github.com/davidblewett/rure-python / parse_flags

Method parse_flags

regex/regex-syntax/src/ast/parse.rs:1319–1367  ·  view source on GitHub ↗

Parse a sequence of flags starting at the current character. This advances the parser to the character immediately following the flags, which is guaranteed to be either `:` or `)`. # Errors If any flags are duplicated, then an error is returned. If the negation operator is used more than once, then an error is returned. If no flags could be found or if the negation operation is not followed b

(&self)

Source from the content-addressed store, hash-verified

1317 /// If no flags could be found or if the negation operation is not followed
1318 /// by any flags, then an error is returned.
1319 fn parse_flags(&self) -> Result<ast::Flags> {
1320 let mut flags = ast::Flags {
1321 span: self.span(),
1322 items: vec![],
1323 };
1324 let mut last_was_negation = None;
1325 while self.char() != ':' && self.char() != ')' {
1326 if self.char() == '-' {
1327 last_was_negation = Some(self.span_char());
1328 let item = ast::FlagsItem {
1329 span: self.span_char(),
1330 kind: ast::FlagsItemKind::Negation,
1331 };
1332 if let Some(i) = flags.add_item(item) {
1333 return Err(self.error(
1334 self.span_char(),
1335 ast::ErrorKind::FlagRepeatedNegation {
1336 original: flags.items[i].span,
1337 },
1338 ));
1339 }
1340 } else {
1341 last_was_negation = None;
1342 let item = ast::FlagsItem {
1343 span: self.span_char(),
1344 kind: ast::FlagsItemKind::Flag(self.parse_flag()?),
1345 };
1346 if let Some(i) = flags.add_item(item) {
1347 return Err(self.error(
1348 self.span_char(),
1349 ast::ErrorKind::FlagDuplicate {
1350 original: flags.items[i].span,
1351 },
1352 ));
1353 }
1354 }
1355 if !self.bump() {
1356 return Err(self.error(
1357 self.span(),
1358 ast::ErrorKind::FlagUnexpectedEof,
1359 ));
1360 }
1361 }
1362 if let Some(span) = last_was_negation {
1363 return Err(self.error(span, ast::ErrorKind::FlagDanglingNegation));
1364 }
1365 flags.span.end = self.pos();
1366 Ok(flags)
1367 }
1368
1369 /// Parse the current character as a flag. Do not advance the parser.
1370 ///

Callers 1

parse_groupMethod · 0.80

Calls 9

FlagEnum · 0.85
span_charMethod · 0.80
add_itemMethod · 0.80
parse_flagMethod · 0.80
bumpMethod · 0.80
spanMethod · 0.45
charMethod · 0.45
errorMethod · 0.45
posMethod · 0.45

Tested by

no test coverage detected