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

Method parse_postfix_expression

crates/ruff_python_parser/src/parser/expression.rs:749–777  ·  view source on GitHub ↗

Parses a postfix expression in a loop until there are no postfix expressions left to parse. For a given left-hand side, a postfix expression can begin with either `(` for a call expression, `[` for a subscript expression, or `.` for an attribute expression. This method does nothing if the current token is not a candidate for a postfix expression.

(
        &mut self,
        mut lhs: Expr,
        start: TextSize,
        context: ExpressionContext,
    )

Source from the content-addressed store, hash-verified

747 ///
748 /// This method does nothing if the current token is not a candidate for a postfix expression.
749 pub(super) fn parse_postfix_expression(
750 &mut self,
751 mut lhs: Expr,
752 start: TextSize,
753 context: ExpressionContext,
754 ) -> Expr {
755 loop {
756 lhs = match self.current_token_kind() {
757 TokenKind::Lpar => {
758 if self.tokens.nesting() > self.max_nesting_depth {
759 self.report_recursion_limit_exceeded(self.current_token_range());
760 break lhs;
761 }
762 Expr::Call(self.parse_call_expression(lhs, start))
763 }
764 TokenKind::Lsqb => {
765 if self.tokens.nesting() > self.max_nesting_depth {
766 self.report_recursion_limit_exceeded(self.current_token_range());
767 break lhs;
768 }
769 Expr::Subscript(self.parse_subscript_expression(lhs, start))
770 }
771 TokenKind::Dot => {
772 Expr::Attribute(self.parse_attribute_expression(lhs, start, context))
773 }
774 _ => break lhs,
775 };
776 }
777 }
778
779 /// Parse a call expression.
780 ///

Callers 1

Calls 7

current_token_kindMethod · 0.80
current_token_rangeMethod · 0.80
parse_call_expressionMethod · 0.80
nestingMethod · 0.45

Tested by

no test coverage detected