Merge pull request #4552 from charliermarsh/charlie/loc

Limit match range to end of last statement
This commit is contained in:
Jeong YunWon 2023-02-23 02:11:42 +09:00 committed by GitHub
commit f43e5b72e2
4 changed files with 109 additions and 85 deletions

View file

@ -358,7 +358,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),
@ -369,7 +377,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),
@ -380,7 +396,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 {