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

Method parse_primitive

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

Parse a primitive AST. e.g., A literal, non-set character class or assertion. This assumes that the parser expects a primitive at the current location. i.e., All other non-primitive cases have been handled. For example, if the parser's position is at `|`, then `|` will be treated as a literal (e.g., inside a character class). This advances the parser to the first character immediately following

(&self)

Source from the content-addressed store, hash-verified

1397 /// This advances the parser to the first character immediately following
1398 /// the primitive.
1399 fn parse_primitive(&self) -> Result<Primitive> {
1400 match self.char() {
1401 '\\' => self.parse_escape(),
1402 '.' => {
1403 let ast = Primitive::Dot(self.span_char());
1404 self.bump();
1405 Ok(ast)
1406 }
1407 '^' => {
1408 let ast = Primitive::Assertion(ast::Assertion {
1409 span: self.span_char(),
1410 kind: ast::AssertionKind::StartLine,
1411 });
1412 self.bump();
1413 Ok(ast)
1414 }
1415 '$' => {
1416 let ast = Primitive::Assertion(ast::Assertion {
1417 span: self.span_char(),
1418 kind: ast::AssertionKind::EndLine,
1419 });
1420 self.bump();
1421 Ok(ast)
1422 }
1423 c => {
1424 let ast = Primitive::Literal(ast::Literal {
1425 span: self.span_char(),
1426 kind: ast::LiteralKind::Verbatim,
1427 c: c,
1428 });
1429 self.bump();
1430 Ok(ast)
1431 }
1432 }
1433 }
1434
1435 /// Parse an escape sequence as a primitive AST.
1436 ///

Callers 1

parse_with_commentsMethod · 0.80

Calls 6

AssertionClass · 0.85
parse_escapeMethod · 0.80
span_charMethod · 0.80
bumpMethod · 0.80
LiteralClass · 0.70
charMethod · 0.45

Tested by

no test coverage detected