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:1191–1207  ·  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

1189 ///
1190 /// See: <https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations>
1191 pub(super) fn parse_unary_expression(
1192 &mut self,
1193 op: UnaryOp,
1194 context: ExpressionContext,
1195 ) -> ast::ExprUnaryOp {
1196 let start = self.node_start();
1197 self.bump(TokenKind::from(op));
1198
1199 let operand = self.parse_binary_expression_or_higher(OperatorPrecedence::from(op), context);
1200
1201 ast::ExprUnaryOp {
1202 op,
1203 operand: Box::new(operand.expr),
1204 range: self.node_range(start),
1205 node_index: AtomicNodeIndex::NONE,
1206 }
1207 }
1208
1209 /// Parses an attribute expression.
1210 ///

Callers 2

Calls 4

node_startMethod · 0.80
node_rangeMethod · 0.80
bumpMethod · 0.45

Tested by

no test coverage detected