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

Method parse_unary_expression

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

Parses a unary expression. This includes the unary arithmetic `+` and `-`, bitwise `~`, and the boolean `not` operators. # Panics If the parser isn't positioned at any of the unary operators. See:

(
        &mut self,
        op: UnaryOp,
        context: ExpressionContext,
    )

Source from the content-addressed store, hash-verified

1102 ///
1103 /// See: <https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations>
1104 pub(super) fn parse_unary_expression(
1105 &mut self,
1106 op: UnaryOp,
1107 context: ExpressionContext,
1108 ) -> ast::ExprUnaryOp {
1109 let start = self.node_start();
1110 self.bump(TokenKind::from(op));
1111
1112 let operand = self.parse_binary_expression_or_higher(OperatorPrecedence::from(op), context);
1113
1114 ast::ExprUnaryOp {
1115 op,
1116 operand: Box::new(operand.expr),
1117 range: self.node_range(start),
1118 node_index: AtomicNodeIndex::NONE,
1119 }
1120 }
1121
1122 /// Parses an attribute expression.
1123 ///

Callers 2

parse_lhs_expressionMethod · 0.80

Calls 4

node_startMethod · 0.80
node_rangeMethod · 0.80
bumpMethod · 0.45

Tested by

no test coverage detected