/// Parse an expression suffix. Given an already parsed expression and its
/// precedence, try to parse additional tokens that extend the already parsed
/// expression. This is currently limited to binary operations.
Parse an expression suffix. Given an already parsed expression and its
precedence, try to parse additional tokens that extend the already parsed
expression. This is currently limited to binary operations.
Parse an expression suffix . Given an already parsed expression and its precedence try to parse additional tokens that extend the already parsed expression . This is currently limited to binary operations .
pub fn parse_expr_suffix<P: Parser>(
    p: &mut P,
    prefix: ast::Expr,
    prec: ExprPrec,
) -> ReportedResult<ast::Expr> {
    let tkn = p.peek(0);
    // Try to parse a binary operation.
    if let Some(op) = as_binary_op(tkn.value) {
        let op_prec = binary_prec(op);
        if prec <= op_prec {
            p.bump();
            let rhs = parse_expr_prec(p, op_prec)?;
            let span = Span::union(prefix.span, p.last_span());
            return parse_expr_suffix(
                p,
                ast::Expr {
                    span: span,
                    data: ast::BinaryExpr(
                        Spanned::new(op, tkn.span),
                        Box::new(prefix),
                        Box::new(rhs),
                    ),
                },
                prec,
            );
        }
    }
    // If we arrive here, none of the suffices matched, so we simply return the
    // expression that we have received.
    Ok(prefix)
}
pub fn parse_expr_suffix < P : Parser > ( p : & mut P , prefix : ast :: Expr , prec : ExprPrec , ) -> ReportedResult < ast :: Expr > { let tkn = p . peek ( 0 ) ; // Try to parse a binary operation. if let Some ( op ) = as_binary_op ( tkn . value ) { let op_prec = binary_prec ( op ) ; if prec <= op_prec { p . bump ( ) ; let rhs = parse_expr_prec ( p , op_prec ) ? ; let span = Span :: union ( prefix . span , p . last_span ( ) ) ; return parse_expr_suffix ( p , ast :: Expr { span : span , data : ast :: BinaryExpr ( Spanned :: new ( op , tkn . span ) , Box :: new ( prefix ) , Box :: new ( rhs ) , ) , } , prec , ) ; } } // If we arrive here, none of the suffices matched, so we simply return the // expression that we have received. Ok ( prefix ) }
Parse an expression suffix.
Parse an expression suffix .
p
&mut P
prefix
ast::Expr
prec
ExprPrec