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

Method parse_escape

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

Parse an escape sequence as a primitive AST. This assumes the parser is positioned at the start of the escape sequence, i.e., `\`. It advances the parser to the first position immediately following the escape sequence.

(&self)

Source from the content-addressed store, hash-verified

1438 /// sequence, i.e., `\`. It advances the parser to the first position
1439 /// immediately following the escape sequence.
1440 fn parse_escape(&self) -> Result<Primitive> {
1441 assert_eq!(self.char(), '\\');
1442 let start = self.pos();
1443 if !self.bump() {
1444 return Err(self.error(
1445 Span::new(start, self.pos()),
1446 ast::ErrorKind::EscapeUnexpectedEof,
1447 ));
1448 }
1449 let c = self.char();
1450 // Put some of the more complicated routines into helpers.
1451 match c {
1452 '0'...'7' => {
1453 if !self.parser().octal {
1454 return Err(self.error(
1455 Span::new(start, self.span_char().end),
1456 ast::ErrorKind::UnsupportedBackreference,
1457 ));
1458 }
1459 let mut lit = self.parse_octal();
1460 lit.span.start = start;
1461 return Ok(Primitive::Literal(lit));
1462 }
1463 '8'...'9' if !self.parser().octal => {
1464 return Err(self.error(
1465 Span::new(start, self.span_char().end),
1466 ast::ErrorKind::UnsupportedBackreference,
1467 ));
1468 }
1469 'x' | 'u' | 'U' => {
1470 let mut lit = self.parse_hex()?;
1471 lit.span.start = start;
1472 return Ok(Primitive::Literal(lit));
1473 }
1474 'p' | 'P' => {
1475 let mut cls = self.parse_unicode_class()?;
1476 cls.span.start = start;
1477 return Ok(Primitive::Unicode(cls));
1478 }
1479 'd' | 's' | 'w' | 'D' | 'S' | 'W' => {
1480 let mut cls = self.parse_perl_class();
1481 cls.span.start = start;
1482 return Ok(Primitive::Perl(cls));
1483 }
1484 _ => {}
1485 }
1486
1487 // Handle all of the one letter sequences inline.
1488 self.bump();
1489 let span = Span::new(start, self.pos());
1490 if is_meta_character(c) {
1491 return Ok(Primitive::Literal(ast::Literal {
1492 span: span,
1493 kind: ast::LiteralKind::Punctuation,
1494 c: c,
1495 }));
1496 }
1497 let special = |kind, c| Ok(Primitive::Literal(ast::Literal {

Callers 2

parse_primitiveMethod · 0.80
parse_set_class_itemMethod · 0.80

Calls 15

UnicodeClass · 0.85
is_meta_characterFunction · 0.85
AssertionClass · 0.85
bumpMethod · 0.80
parserMethod · 0.80
span_charMethod · 0.80
parse_octalMethod · 0.80
parse_hexMethod · 0.80
parse_unicode_classMethod · 0.80
parse_perl_classMethod · 0.80
LiteralClass · 0.70
posMethod · 0.45

Tested by

no test coverage detected