diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index 59c76a5..5e5264f 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -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)); } } diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_f_string.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_f_string.snap index 445e51d..97b49bd 100644 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_f_string.snap +++ b/parser/src/snapshots/rustpython_parser__parser__tests__parse_f_string.snap @@ -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 { diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap index 197f1c5..a41e765 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap @@ -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 { diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_string_triple_quotes_with_kind.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_string_triple_quotes_with_kind.snap new file mode 100644 index 0000000..66db231 --- /dev/null +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_string_triple_quotes_with_kind.snap @@ -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", + ), + }, + }, + }, + }, +] diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap index bcba052..dd6d338 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap @@ -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 { diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap index 4e4ba23..b5d6f94 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap @@ -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 { diff --git a/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap b/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap index 190854c..74bf59c 100644 --- a/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap +++ b/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap @@ -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 { diff --git a/parser/src/string.rs b/parser/src/string.rs index 7529d3d..4c8ff85 100644 --- a/parser/src/string.rs +++ b/parser/src/string.rs @@ -131,4 +131,11 @@ mod tests { let parse_ast = parse_program(&source, "").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, "").unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } }