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

Method parse_boolean_expression

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

Parses a boolean operation expression. Note that the boolean `not` operator is parsed as a unary expression and not as a boolean expression. # Panics If the parser isn't positioned at a `or` or `and` token. See:

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

Source from the content-addressed store, hash-verified

1243 ///
1244 /// See: <https://docs.python.org/3/reference/expressions.html#boolean-operations>
1245 fn parse_boolean_expression(
1246 &mut self,
1247 lhs: Expr,
1248 start: TextSize,
1249 op: BoolOp,
1250 context: ExpressionContext,
1251 ) -> ast::ExprBoolOp {
1252 self.bump(TokenKind::from(op));
1253
1254 let values_snapshot = self.expr_scratch.snapshot();
1255 self.expr_scratch.push(lhs);
1256 let mut progress = ParserProgress::default();
1257
1258 // Keep adding the expression to `values` until we see a different
1259 // token than `operator_token`.
1260 loop {
1261 progress.assert_progressing(self);
1262
1263 let parsed_expr =
1264 self.parse_binary_expression_or_higher(OperatorPrecedence::from(op), context);
1265 self.expr_scratch.push(parsed_expr.expr);
1266
1267 if !self.eat(TokenKind::from(op)) {
1268 break;
1269 }
1270 }
1271
1272 ast::ExprBoolOp {
1273 values: self.expr_scratch.take(values_snapshot),
1274 op,
1275 range: self.node_range(start),
1276 node_index: AtomicNodeIndex::NONE,
1277 }
1278 }
1279
1280 /// Bump the appropriate token(s) for the given comparison operator.
1281 fn bump_cmp_op(&mut self, op: CmpOp) {

Calls 9

assert_progressingMethod · 0.80
node_rangeMethod · 0.80
defaultFunction · 0.50
bumpMethod · 0.45
snapshotMethod · 0.45
pushMethod · 0.45
eatMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected