mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 21:55:26 +00:00
Start string location at kind or quote prefix
This commit is contained in:
parent
eede189959
commit
15e2ac3fd7
8 changed files with 57 additions and 18 deletions
|
@ -205,7 +205,9 @@ where
|
|||
|
||||
// Check if we have a string:
|
||||
if self.chr0 == Some('"') || self.chr0 == Some('\'') {
|
||||
return self.lex_string(saw_b, saw_r, saw_u, saw_f);
|
||||
return self
|
||||
.lex_string(saw_b, saw_r, saw_u, saw_f)
|
||||
.map(|(_, tok, end_pos)| (start_pos, tok, end_pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
---
|
||||
source: parser/src/parser.rs
|
||||
source: compiler/parser/src/parser.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Expr {
|
||||
value: Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: JoinedStr {
|
||||
|
@ -21,7 +21,7 @@ expression: parse_ast
|
|||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Constant {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: parser/src/string.rs
|
||||
source: compiler/parser/src/string.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
|
@ -34,7 +34,7 @@ expression: parse_ast
|
|||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 12,
|
||||
column: 10,
|
||||
},
|
||||
custom: (),
|
||||
node: FormattedValue {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
source: compiler/parser/src/string.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Expr {
|
||||
value: Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Constant {
|
||||
value: Str(
|
||||
"Hello, world!",
|
||||
),
|
||||
kind: Some(
|
||||
"u",
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
|
@ -1,19 +1,19 @@
|
|||
---
|
||||
source: parser/src/string.rs
|
||||
source: compiler/parser/src/string.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Expr {
|
||||
value: Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: JoinedStr {
|
||||
|
@ -21,7 +21,7 @@ expression: parse_ast
|
|||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Constant {
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
---
|
||||
source: parser/src/string.rs
|
||||
source: compiler/parser/src/string.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Expr {
|
||||
value: Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: JoinedStr {
|
||||
|
@ -21,7 +21,7 @@ expression: parse_ast
|
|||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Constant {
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
---
|
||||
source: parser/src/string.rs
|
||||
source: compiler/parser/src/string.rs
|
||||
expression: parse_ast
|
||||
---
|
||||
[
|
||||
Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Expr {
|
||||
value: Located {
|
||||
location: Location {
|
||||
row: 1,
|
||||
column: 3,
|
||||
column: 1,
|
||||
},
|
||||
custom: (),
|
||||
node: Constant {
|
||||
|
|
|
@ -131,4 +131,11 @@ mod tests {
|
|||
let parse_ast = parse_program(&source, "<test>").unwrap();
|
||||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_string_triple_quotes_with_kind() {
|
||||
let source = String::from("u'''Hello, world!'''");
|
||||
let parse_ast = parse_program(&source, "<test>").unwrap();
|
||||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue