Skip to content

Commit f527441

Browse files
committed
Fix && and || syntax error using invalid grammar rules
1 parent 3b0f068 commit f527441

3 files changed

Lines changed: 332 additions & 192 deletions

File tree

Grammar/python.gram

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, I
819819

820820
bitwise_or[expr_ty]:
821821
| a=bitwise_or '|' b=bitwise_xor { _PyAST_BinOp(a, BitOr, b, EXTRA) }
822+
| invalid_bitwise_or
822823
| bitwise_xor
823824

824825
bitwise_xor[expr_ty]:
@@ -827,6 +828,7 @@ bitwise_xor[expr_ty]:
827828

828829
bitwise_and[expr_ty]:
829830
| a=bitwise_and '&' b=shift_expr { _PyAST_BinOp(a, BitAnd, b, EXTRA) }
831+
| invalid_bitwise_and
830832
| shift_expr
831833

832834
shift_expr[expr_ty]:
@@ -1638,3 +1640,9 @@ invalid_type_params:
16381640
RAISE_SYNTAX_ERROR_STARTING_FROM(
16391641
token,
16401642
"Type parameter list cannot be empty")}
1643+
1644+
invalid_bitwise_and:
1645+
| a=bitwise_and b='&' c='&' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(b, c, "invalid syntax. Maybe you meant 'and' or '&' instead of '&&'") }
1646+
1647+
invalid_bitwise_or:
1648+
| a=bitwise_or b='|' c='|' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(b, c, "invalid syntax. Maybe you meant 'or' or '|' instead of '||'") }

0 commit comments

Comments
 (0)