Skip to content

Commit 4be533a

Browse files
authored
Merge pull request RustPython#4220 from charliermarsh/charlie/str-loc
Start string location at kind or quote prefix
2 parents b437aa3 + ab159c9 commit 4be533a

8 files changed

+57
-18
lines changed

compiler/parser/src/lexer.rs

+3-1
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

compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_f_string.snap

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_string_triple_quotes_with_kind.snap

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/string.rs

+7
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)