Fix parsing of stement-ish binary expressions

closes #3512
This commit is contained in:
Aleksey Kladov 2020-03-11 12:40:38 +01:00
parent bddf6b5266
commit 4a745cc8cf
3 changed files with 49 additions and 2 deletions

View file

@ -278,7 +278,7 @@ fn current_op(p: &Parser) -> (u8, SyntaxKind) {
}
// Parses expression with binding power of at least bp.
fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>, BlockLike) {
fn expr_bp(p: &mut Parser, mut r: Restrictions, bp: u8) -> (Option<CompletedMarker>, BlockLike) {
let mut lhs = match lhs(p, r) {
Some((lhs, blocklike)) => {
// test stmt_bin_expr_ambiguity
@ -311,6 +311,12 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>,
let m = lhs.precede(p);
p.bump(op);
// test binop_resets_statementness
// fn foo() {
// v = {1}&2;
// }
r = Restrictions { prefer_stmt: false, ..r };
if is_range {
// test postfix_range
// fn foo() {
@ -327,7 +333,7 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>,
}
}
expr_bp(p, r, op_bp + 1);
expr_bp(p, Restrictions { prefer_stmt: false, ..r }, op_bp + 1);
lhs = m.complete(p, if is_range { RANGE_EXPR } else { BIN_EXPR });
}
(Some(lhs), BlockLike::NotBlock)