8000 Make match guards accept a test, not just and expression · lezer-parser/python@0daf785 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0daf785

Browse files
committed
Make match guards accept a test, not just and expression
FIX: Fix parsing of match guards with conditional tests. Closes #28
1 parent f26a8dd commit 0daf785

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/python.grammar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ MatchStatement {
4242
}
4343

4444
MatchClause {
45-
skw<"case"> commaSep<pattern> Guard { kw<"if"> expression }? Body
45+
skw<"case"> commaSep<pattern> Guard { kw<"if"> test }? Body
4646
}
4747

4848
pattern[@isGroup=Pattern] {

test/statement.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ match foo:
368368
pass
369369
case [a, b, *rest] | (p, q):
370370
pass
371+
case (1, 2) if bar == 2:
372+
pass
371373

372374
==>
373375

@@ -392,6 +394,10 @@ Script(MatchStatement(match,VariableName,MatchBody(
392394
StarPattern(CapturePattern(VariableName))),
393395
LogicOp,
394396
SequencePattern(CapturePattern(VariableName),CapturePattern(VariableName))),
397+
Body(PassStatement(pass))),
398+
MatchClause(case,
399+
SequencePattern(LiteralPattern(Number),LiteralPattern(Number)),
400+
Guard(if,BinaryExpression(VariableName,CompareOp,Number)),
395401
Body(PassStatement(pass))))))
396402

397403
# Type Params

0 commit comments

Comments
 (0)
0