MCPcopy Create free account
hub / github.com/Glyphack/enderpy / parse_binary_arithmetic_operation

Method parse_binary_arithmetic_operation

parser/src/parser/parser.rs:2170–2195  ·  view source on GitHub ↗

https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations

(
        &mut self,
        min_precedence: u8,
    )

Source from the content-addressed store, hash-verified

2168 // https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations
2169 //
2170 fn parse_binary_arithmetic_operation(
2171 &mut self,
2172 min_precedence: u8,
2173 ) -> Result<Expression, ParsingError> {
2174 let node = self.start_node();
2175 let mut lhs = self.parse_unary_arithmetic_operation()?;
2176 while let Some((op, precedence, associativity)) = self.cur_kind().bin_op_precedence() {
2177 if precedence < min_precedence {
2178 break;
2179 }
2180 self.bump_any();
2181 let next_precedence = match associativity {
2182 0 => precedence + 1,
2183 1 => precedence,
2184 _ => unreachable!(),
2185 };
2186 let rhs = self.parse_binary_arithmetic_operation(next_precedence)?;
2187 lhs = Expression::BinOp(Box::new(BinOp {
2188 node: self.finish_node(node),
2189 op,
2190 left: lhs,
2191 right: rhs,
2192 }));
2193 }
2194 Ok(lhs)
2195 }
2196
2197 // https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations
2198 fn parse_unary_arithmetic_operation(&mut self) -> Result<Expression, ParsingError> {

Callers 2

parse_literal_patternMethod · 0.80
parse_shift_exprMethod · 0.80

Calls 7

BinOpClass · 0.85
start_nodeMethod · 0.80
bin_op_precedenceMethod · 0.80
cur_kindMethod · 0.80
bump_anyMethod · 0.80
finish_nodeMethod · 0.80

Tested by

no test coverage detected