Limit match range to end of last statement

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

View file

@ -359,7 +359,15 @@ CompoundStatement: ast::Stmt = {
}; };
MatchStatement: 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 { ast::Stmt {
location, location,
end_location: Some(end_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 { ast::Stmt {
location, location,
end_location: Some(end_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; let mut subjects = subjects;
subjects.insert(0, subject); subjects.insert(0, subject);
ast::Stmt { ast::Stmt {

View file

@ -10,8 +10,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 7, row: 6,
column: 0, column: 19,
}, },
), ),
custom: (), custom: (),
@ -178,8 +178,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 12, row: 11,
column: 0, column: 20,
}, },
), ),
custom: (), custom: (),
@ -453,8 +453,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 15, row: 14,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -631,8 +631,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 18, row: 17,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -809,8 +809,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 21, row: 20,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),

View file

@ -1538,8 +1538,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 21, row: 20,
column: 0, column: 12,
}, },
), ),
custom: (), custom: (),

View file

@ -10,8 +10,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 8, row: 6,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -154,8 +154,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 12, row: 10,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -302,8 +302,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 18, row: 16,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -562,8 +562,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 22, row: 20,
column: 0, column: 16,
}, },
), ),
custom: (), custom: (),
@ -810,8 +810,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 26, row: 24,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -1090,8 +1090,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 32, row: 30,
column: 0, column: 20,
}, },
), ),
custom: (), custom: (),
@ -1257,8 +1257,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 40, row: 38,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -2102,8 +2102,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 44, row: 42,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -2265,8 +2265,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 48, row: 46,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -2409,8 +2409,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 52, row: 50,
column: 0, column: 16,
}, },
), ),
custom: (), custom: (),
@ -2657,8 +2657,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 56, row: 54,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -2802,8 +2802,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 64, row: 62,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -3179,8 +3179,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 68, row: 66,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -3322,8 +3322,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 74, row: 72,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -3542,8 +3542,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 78, row: 76,
column: 0, column: 15,
}, },
), ),
custom: (), custom: (),
@ -3691,8 +3691,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 82, row: 80,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -3979,8 +3979,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 90, row: 88,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -4515,8 +4515,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 94, row: 92,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -4679,8 +4679,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 98, row: 96,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -4858,8 +4858,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 102, row: 100,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -5005,8 +5005,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 106, row: 104,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -5181,8 +5181,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 110, row: 108,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -5290,8 +5290,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 114, row: 112,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -5417,8 +5417,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 118, row: 116,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -5528,8 +5528,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 126, row: 124,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -5840,8 +5840,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 130, row: 128,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -5952,8 +5952,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 134, row: 132,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -6118,8 +6118,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 138, row: 136,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -6480,8 +6480,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 146, row: 144,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -7325,8 +7325,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 150, row: 148,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -7545,8 +7545,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 154, row: 152,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -7765,8 +7765,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 158, row: 156,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -7894,8 +7894,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 162, row: 160,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -7907,8 +7907,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 162, row: 160,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),
@ -8077,8 +8077,8 @@ expression: parse_ast
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 165, row: 164,
column: 0, column: 13,
}, },
), ),
custom: (), custom: (),