Skip to content

Commit 3aa0096

Browse files
authored
Merge pull request #4358 from harupy/fix-slice-location
Fix `Slice` location
2 parents 53dec88 + b2ac4f6 commit 3aa0096

3 files changed

Lines changed: 123 additions & 1 deletion

File tree

‎parser/python.lalrpop‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ SubscriptList: ast::Expr = {
10241024

10251025
Subscript: ast::Expr = {
10261026
Test<"all">,
1027-
<e1:Test<"all">?> <location:@L> ":" <e2:Test<"all">?> <e3:SliceOp?> <end_location:@R> => {
1027+
<location:@L> <e1:Test<"all">?> ":" <e2:Test<"all">?> <e3:SliceOp?> <end_location:@R> => {
10281028
let lower = e1.map(Box::new);
10291029
let upper = e2.map(Box::new);
10301030
let step = e3.flatten().map(Box::new);

‎parser/src/parser.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,11 @@ class Foo(A, B):
233233
let parse_ast = parse_expression(&source, "<test>").unwrap();
234234
insta::assert_debug_snapshot!(parse_ast);
235235
}
236+
237+
#[test]
238+
fn test_slice() {
239+
let source = String::from("x[1:2:3]");
240+
let parse_ast = parse_expression(&source, "<test>").unwrap();
241+
insta::assert_debug_snapshot!(parse_ast);
242+
}
236243
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
source: compiler/parser/src/parser.rs
3+
expression: parse_ast
4+
---
5+
Located {
6+
location: Location {
7+
row: 1,
8+
column: 0,
9+
},
10+
end_location: Some(
11+
Location {
12+
row: 1,
13+
column: 8,
14+
},
15+
),
16+
custom: (),
17+
node: Subscript {
18+
value: Located {
19+
location: Location {
20+
row: 1,
21+
column: 0,
22+
},
23+
end_location: Some(
24+
Location {
25+
row: 1,
26+
column: 1,
27+
},
28+
),
29+
custom: (),
30+
node: Name {
31+
id: "x",
32+
ctx: Load,
33+
},
34+
},
35+
slice: Located {
36+
location: Location {
37+
row: 1,
38+
column: 2,
39+
},
40+
end_location: Some(
41+
Location {
42+
row: 1,
43+
column: 7,
44+
},
45+
),
46+
custom: (),
47+
node: Slice {
48+
lower: Some(
49+
Located {
50+
location: Location {
51+
row: 1,
52+
column: 2,
53+
},
54+
end_location: Some(
55+
Location {
56+
row: 1,
57+
column: 3,
58+
},
59+
),
60+
custom: (),
61+
node: Constant {
62+
value: Int(
63+
1,
64+
),
65+
kind: None,
66+
},
67+
},
68+
),
69+
upper: Some(
70+
Located {
71+
location: Location {
72+
row: 1,
73+
column: 4,
74+
},
75+
end_location: Some(
76+
Location {
77+
row: 1,
78+
column: 5,
79+
},
80+
),
81+
custom: (),
82+
node: Constant {
83+
value: Int(
84+
2,
85+
),
86+
kind: None,
87+
},
88+
},
89+
),
90+
step: Some(
91+
Located {
92+
location: Location {
93+
row: 1,
94+
column: 6,
95+
},
96+
end_location: Some(
97+
Location {
98+
row: 1,
99+
column: 7,
100+
},
101+
),
102+
custom: (),
103+
node: Constant {
104+
value: Int(
105+
3,
106+
),
107+
kind: None,
108+
},
109+
},
110+
),
111+
},
112+
},
113+
ctx: Load,
114+
},
115+
}

0 commit comments

Comments
 (0)