Limit match range to end of last statement

This commit is contained in:
Charlie Marsh 2023-02-22 11:25:50 -05:00
parent b61f4d7b69
commit 7ebef61c47
4 changed files with 109 additions and 85 deletions

View file

@ -359,7 +359,15 @@ CompoundStatement: ast::Stmt = {
};
MatchStatement: ast::Stmt = {
<location:@L> "match" <subject:TestOrStarNamedExpr> ":" "\n" Indent <cases:MatchCase+> Dedent <end_location:@R> => {
<location:@L> "match" <subject:TestOrStarNamedExpr> ":" "\n" Indent <cases:MatchCase+> Dedent => {
let end_location = cases
.last()
.unwrap()
.body
.last()
.unwrap()
.end_location
.unwrap();
ast::Stmt {
location,
end_location: Some(end_location),
@ -370,7 +378,15 @@ MatchStatement: ast::Stmt = {
}
}
},
<location:@L> "match" <subject:TestOrStarNamedExpr> "," ":" "\n" Indent <cases:MatchCase+> Dedent <end_location:@R> => {
<location:@L> "match" <subject:TestOrStarNamedExpr> "," ":" "\n" Indent <cases:MatchCase+> Dedent => {
let end_location = cases
.last()
.unwrap()
.body
.last()
.unwrap()
.end_location
.unwrap();
ast::Stmt {
location,
end_location: Some(end_location),
@ -381,7 +397,15 @@ MatchStatement: ast::Stmt = {
}
}
},
<location:@L> "match" <subject:TestOrStarNamedExpr> "," <subjects:OneOrMore<TestOrStarNamedExpr>> ","? ":" "\n" Indent <cases:MatchCase+> Dedent <end_location:@R> => {
<location:@L> "match" <subject:TestOrStarNamedExpr> "," <subjects:OneOrMore<TestOrStarNamedExpr>> ","? ":" "\n" Indent <cases:MatchCase+> Dedent => {
let end_location = cases
.last()
.unwrap()
.body
.last()
.unwrap()
.end_location
.unwrap();
let mut subjects = subjects;
subjects.insert(0, subject);
ast::Stmt {