diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-02-12 10:17:35 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-02-12 10:17:35 +0100 |
| commit | 03cbdea4b4dd81929743154ad79835bfbdf63db3 (patch) | |
| tree | e09596138454db8912b68a896b8354ac64ee37e4 | |
| parent | ebe919220d8b8f2966c15d73df82f20f38f4f9d5 (diff) | |
Fix "not in" precedence
| -rw-r--r-- | src/syntax/parser.rs | 19 | ||||
| -rw-r--r-- | tests/typ/compiler/ops-prec.typ | 4 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 9f951389..8082fd64 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -562,16 +562,17 @@ fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) { continue; } - let binop = if p.eat_if(SyntaxKind::Not) { - if p.at(SyntaxKind::In) { - Some(ast::BinOp::NotIn) + let binop = + if ast::BinOp::NotIn.precedence() >= min_prec && p.eat_if(SyntaxKind::Not) { + if p.at(SyntaxKind::In) { + Some(ast::BinOp::NotIn) + } else { + p.expected("keyword `in`"); + break; + } } else { - p.expected("keyword `in`"); - break; - } - } else { - ast::BinOp::from_kind(p.current()) - }; + ast::BinOp::from_kind(p.current()) + }; if let Some(op) = binop { let mut prec = op.precedence(); diff --git a/tests/typ/compiler/ops-prec.typ b/tests/typ/compiler/ops-prec.typ index 2fa90382..e243a640 100644 --- a/tests/typ/compiler/ops-prec.typ +++ b/tests/typ/compiler/ops-prec.typ @@ -24,6 +24,10 @@ #{-not true} --- +// Not in handles precedence. +#test(-1 not in (1, 2, 3), true) + +--- // Parentheses override precedence. #test((1), 1) #test((1+2)*-3, -9) |
