MCPcopy Create free account
hub / github.com/astral-sh/ruff / parse_match_pattern

Method parse_match_pattern

crates/ruff_python_parser/src/parser/pattern.rs:90–110  ·  view source on GitHub ↗

Parses an `or_pattern` or an `as_pattern`. See:

(&mut self, allow_star_pattern: AllowStarPattern)

Source from the content-addressed store, hash-verified

88 ///
89 /// See: <https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-pattern>
90 fn parse_match_pattern(&mut self, allow_star_pattern: AllowStarPattern) -> Pattern {
91 if let Some(result) =
92 self.with_recursion(|parser| parser.parse_match_pattern_inner(allow_star_pattern))
93 {
94 result
95 } else {
96 let range = self.missing_node_range();
97 self.report_recursion_limit_exceeded(self.current_token_range());
98 let invalid_node = Expr::Name(ast::ExprName {
99 range,
100 id: Name::empty(),
101 ctx: ExprContext::Invalid,
102 node_index: AtomicNodeIndex::NONE,
103 });
104 Pattern::MatchValue(ast::PatternMatchValue {
105 range: invalid_node.range(),
106 value: Box::new(invalid_node),
107 node_index: AtomicNodeIndex::NONE,
108 })
109 }
110 }
111
112 fn parse_match_pattern_inner(&mut self, allow_star_pattern: AllowStarPattern) -> Pattern {
113 let start = self.node_start();

Calls 8

NameClass · 0.85
with_recursionMethod · 0.80
missing_node_rangeMethod · 0.80
current_token_rangeMethod · 0.80
emptyFunction · 0.50
rangeMethod · 0.45

Tested by

no test coverage detected