Skip to content

Commit 3397737

Browse files
committed
Start string location at kind or quote prefix
1 parent 6211a3a commit 3397737

8 files changed

Lines changed: 57 additions & 18 deletions

‎parser/src/lexer.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ where
205205

206206
// Check if we have a string:
207207
if self.chr0 == Some('"') || self.chr0 == Some('\'') {
208-
return self.lex_string(saw_b, saw_r, saw_u, saw_f);
208+
return self
209+
.lex_string(saw_b, saw_r, saw_u, saw_f)
210+
.map(|(_, tok, end_pos)| (start_pos, tok, end_pos));
209211
}
210212
}
211213

‎parser/src/snapshots/rustpython_parser__parser__tests__parse_f_string.snap‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---
2-
source: parser/src/parser.rs
2+
source: compiler/parser/src/parser.rs
33
expression: parse_ast
44
---
55
[
66
Located {
77
location: Location {
88
row: 1,
9-
column: 3,
9+
column: 1,
1010
},
1111
custom: (),
1212
node: Expr {
1313
value: Located {
1414
location: Location {
1515
row: 1,
16-
column: 3,
16+
column: 1,
1717
},
1818
custom: (),
1919
node: JoinedStr {
2020
values: [
2121
Located {
2222
location: Location {
2323
row: 1,
24-
column: 3,
24+
column: 1,
2525
},
2626
custom: (),
2727
node: Constant {

‎parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/string.rs
2+
source: compiler/parser/src/string.rs
33
expression: parse_ast
44
---
55
[
@@ -34,7 +34,7 @@ expression: parse_ast
3434
Located {
3535
location: Location {
3636
row: 1,
37-
column: 12,
37+
column: 10,
3838
},
3939
custom: (),
4040
node: FormattedValue {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
source: compiler/parser/src/string.rs
3+
expression: parse_ast
4+
---
5+
[
6+
Located {
7+
location: Location {
8+
row: 1,
9+
column: 1,
10+
},
11+
custom: (),
12+
node: Expr {
13+
value: Located {
14+
location: Location {
15+
row: 1,
16+
column: 1,
17+
},
18+
custom: (),
19+
node: Constant {
20+
value: Str(
21+
"Hello, world!",
22+
),
23+
kind: Some(
24+
"u",
25+
),
26+
},
27+
},
28+
},
29+
},
30+
]

‎parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---
2-
source: parser/src/string.rs
2+
source: compiler/parser/src/string.rs
33
expression: parse_ast
44
---
55
[
66
Located {
77
location: Location {
88
row: 1,
9-
column: 3,
9+
column: 1,
1010
},
1111
custom: (),
1212
node: Expr {
1313
value: Located {
1414
location: Location {
1515
row: 1,
16-
column: 3,
16+
column: 1,
1717
},
1818
custom: (),
1919
node: JoinedStr {
2020
values: [
2121
Located {
2222
location: Location {
2323
row: 1,
24-
column: 3,
24+
column: 1,
2525
},
2626
custom: (),
2727
node: Constant {

‎parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---
2-
source: parser/src/string.rs
2+
source: compiler/parser/src/string.rs
33
expression: parse_ast
44
---
55
[
66
Located {
77
location: Location {
88
row: 1,
9-
column: 3,
9+
column: 1,
1010
},
1111
custom: (),
1212
node: Expr {
1313
value: Located {
1414
location: Location {
1515
row: 1,
16-
column: 3,
16+
column: 1,
1717
},
1818
custom: (),
1919
node: JoinedStr {
2020
values: [
2121
Located {
2222
location: Location {
2323
row: 1,
24-
column: 3,
24+
column: 1,
2525
},
2626
custom: (),
2727
node: Constant {

‎parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
2-
source: parser/src/string.rs
2+
source: compiler/parser/src/string.rs
33
expression: parse_ast
44
---
55
[
66
Located {
77
location: Location {
88
row: 1,
9-
column: 3,
9+
column: 1,
1010
},
1111
custom: (),
1212
node: Expr {
1313
value: Located {
1414
location: Location {
1515
row: 1,
16-
column: 3,
16+
column: 1,
1717
},
1818
custom: (),
1919
node: Constant {

‎parser/src/string.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,11 @@ mod tests {
131131
let parse_ast = parse_program(&source, "<test>").unwrap();
132132
insta::assert_debug_snapshot!(parse_ast);
133133
}
134+
135+
#[test]
136+
fn test_parse_string_triple_quotes_with_kind() {
137+
let source = String::from("u'''Hello, world!'''");
138+
let parse_ast = parse_program(&source, "<test>").unwrap();
139+
insta::assert_debug_snapshot!(parse_ast);
140+
}
134141
}

0 commit comments

Comments
 (0)