mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-12 23:55:21 +00:00
Fix slice location
This commit is contained in:
parent
6fc0d42d4a
commit
a5553aea43
3 changed files with 123 additions and 1 deletions
|
@ -1018,7 +1018,7 @@ SubscriptList: ast::Expr = {
|
||||||
|
|
||||||
Subscript: ast::Expr = {
|
Subscript: ast::Expr = {
|
||||||
Test<"all">,
|
Test<"all">,
|
||||||
<e1:Test<"all">?> <location:@L> ":" <e2:Test<"all">?> <e3:SliceOp?> <end_location:@R> => {
|
<location:@L> <e1:Test<"all">?> ":" <e2:Test<"all">?> <e3:SliceOp?> <end_location:@R> => {
|
||||||
let lower = e1.map(Box::new);
|
let lower = e1.map(Box::new);
|
||||||
let upper = e2.map(Box::new);
|
let upper = e2.map(Box::new);
|
||||||
let step = e3.flatten().map(Box::new);
|
let step = e3.flatten().map(Box::new);
|
||||||
|
|
|
@ -233,4 +233,11 @@ class Foo(A, B):
|
||||||
let parse_ast = parse_expression(&source, "<test>").unwrap();
|
let parse_ast = parse_expression(&source, "<test>").unwrap();
|
||||||
insta::assert_debug_snapshot!(parse_ast);
|
insta::assert_debug_snapshot!(parse_ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_slice() {
|
||||||
|
let source = String::from("x[1:2:3]");
|
||||||
|
let parse_ast = parse_expression(&source, "<test>").unwrap();
|
||||||
|
insta::assert_debug_snapshot!(parse_ast);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
---
|
||||||
|
source: compiler/parser/src/parser.rs
|
||||||
|
expression: parse_ast
|
||||||
|
---
|
||||||
|
Located {
|
||||||
|
location: Location {
|
||||||
|
row: 1,
|
||||||
|
column: 0,
|
||||||
|
},
|
||||||
|
end_location: Some(
|
||||||
|
Location {
|
||||||
|
row: 1,
|
||||||
|
column: 8,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
custom: (),
|
||||||
|
node: Subscript {
|
||||||
|
value: Located {
|
||||||
|
location: Location {
|
||||||
|
row: 1,
|
||||||
|
column: 0,
|
||||||
|
},
|
||||||
|
end_location: Some(
|
||||||
|
Location {
|
||||||
|
row: 1,
|
||||||
|
column: 1,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
custom: (),
|
||||||
|
node: Name {
|
||||||
|
id: "x",
|
||||||
|
ctx: Load,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
slice: Located {
|
||||||
|
location: Location {
|
||||||
|
row: 1,
|
||||||
|
column: 2,
|
||||||
|
},
|
||||||
|
end_location: Some(
|
||||||
|
Location {
|
||||||
|
row: 1,
|
||||||
|
column: 7,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
custom: (),
|
||||||
|
node: Slice {
|
||||||
|
lower: Some(
|
||||||
|
Located {
|
||||||
|
location: Location {
|
||||||
|
row: 1,
|
||||||
|
column: 2,
|
||||||
|
},
|
||||||
|
end_location: Some(
|
||||||
|
Location {
|
||||||
|
row: 1,
|
||||||
|
column: 3,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
custom: (),
|
||||||
|
node: Constant {
|
||||||
|
value: Int(
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
kind: None,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
upper: Some(
|
||||||
|
Located {
|
||||||
|
location: Location {
|
||||||
|
row: 1,
|
||||||
|
column: 4,
|
||||||
|
},
|
||||||
|
end_location: Some(
|
||||||
|
Location {
|
||||||
|
row: 1,
|
||||||
|
column: 5,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
custom: (),
|
||||||
|
node: Constant {
|
||||||
|
value: Int(
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
kind: None,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
step: Some(
|
||||||
|
Located {
|
||||||
|
location: Location {
|
||||||
|
row: 1,
|
||||||
|
column: 6,
|
||||||
|
},
|
||||||
|
end_location: Some(
|
||||||
|
Location {
|
||||||
|
row: 1,
|
||||||
|
column: 7,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
custom: (),
|
||||||
|
node: Constant {
|
||||||
|
value: Int(
|
||||||
|
3,
|
||||||
|
),
|
||||||
|
kind: None,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ctx: Load,
|
||||||
|
},
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue