Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/parser/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ MappingPattern: ast::PatternKind = {
rest: None,
};
},
<location:@L> "{" <e:OneOrMore<MatchMappingEntry>> "}" <end_location:@R> => {
<location:@L> "{" <e:OneOrMore<MatchMappingEntry>> ","? "}" <end_location:@R> => {
let (keys, patterns) = e
.into_iter()
.unzip();
Expand All @@ -811,14 +811,14 @@ MappingPattern: ast::PatternKind = {
rest: None,
};
},
<location:@L> "{" "**" <rest:Identifier> "}" <end_location:@R> => {
<location:@L> "{" "**" <rest:Identifier> ","? "}" <end_location:@R> => {
return ast::PatternKind::MatchMapping {
keys: vec![],
patterns: vec![],
rest: Some(rest),
};
},
<location:@L> "{" <e:OneOrMore<MatchMappingEntry>> "," "**" <rest:Identifier> "}" <end_location:@R> => {
<location:@L> "{" <e:OneOrMore<MatchMappingEntry>> "," "**" <rest:Identifier> ","? "}" <end_location:@R> => {
let (keys, patterns) = e
.into_iter()
.unzip();
Expand Down
32 changes: 31 additions & 1 deletion compiler/parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ match match:
}

#[test]
fn test_match_complex() {
fn test_patma() {
let source = r#"# Cases sampled from Lib/test/test_patma.py

# case test_patma_098
Expand Down Expand Up @@ -666,4 +666,34 @@ match w := x,:
let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast);
}

#[test]
fn test_match() {
let parse_ast = parse_program(
r#"
match {"test": 1}:
case {
**rest,
}:
print(rest)
match {"label": "test"}:
case {
"label": str() | None as label,
}:
print(label)
match x:
case [0, 1,]:
y = 0
match x:
case (0, 1,):
y = 0
match x:
case (0,):
y = 0
"#,
"<test>",
)
.unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
}
Loading