mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-13 08:05:17 +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:
|
// Check if we have a string:
|
||||||
if self.chr0 == Some('"') || self.chr0 == Some('\'') {
|
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
|
expression: parse_ast
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
Located {
|
Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: Expr {
|
node: Expr {
|
||||||
value: Located {
|
value: Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: JoinedStr {
|
node: JoinedStr {
|
||||||
|
@ -21,7 +21,7 @@ expression: parse_ast
|
||||||
Located {
|
Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: Constant {
|
node: Constant {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
source: parser/src/string.rs
|
source: compiler/parser/src/string.rs
|
||||||
expression: parse_ast
|
expression: parse_ast
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
|
@ -34,7 +34,7 @@ expression: parse_ast
|
||||||
Located {
|
Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 12,
|
column: 10,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: FormattedValue {
|
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
|
expression: parse_ast
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
Located {
|
Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: Expr {
|
node: Expr {
|
||||||
value: Located {
|
value: Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: JoinedStr {
|
node: JoinedStr {
|
||||||
|
@ -21,7 +21,7 @@ expression: parse_ast
|
||||||
Located {
|
Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: Constant {
|
node: Constant {
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
---
|
---
|
||||||
source: parser/src/string.rs
|
source: compiler/parser/src/string.rs
|
||||||
expression: parse_ast
|
expression: parse_ast
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
Located {
|
Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: Expr {
|
node: Expr {
|
||||||
value: Located {
|
value: Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: JoinedStr {
|
node: JoinedStr {
|
||||||
|
@ -21,7 +21,7 @@ expression: parse_ast
|
||||||
Located {
|
Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: Constant {
|
node: Constant {
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
---
|
---
|
||||||
source: parser/src/string.rs
|
source: compiler/parser/src/string.rs
|
||||||
expression: parse_ast
|
expression: parse_ast
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
Located {
|
Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: Expr {
|
node: Expr {
|
||||||
value: Located {
|
value: Located {
|
||||||
location: Location {
|
location: Location {
|
||||||
row: 1,
|
row: 1,
|
||||||
column: 3,
|
column: 1,
|
||||||
},
|
},
|
||||||
custom: (),
|
custom: (),
|
||||||
node: Constant {
|
node: Constant {
|
||||||
|
|
|
@ -131,4 +131,11 @@ mod tests {
|
||||||
let parse_ast = parse_program(&source, "<test>").unwrap();
|
let parse_ast = parse_program(&source, "<test>").unwrap();
|
||||||
insta::assert_debug_snapshot!(parse_ast);
|
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