diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 1b6025e364..66b03043d7 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -1978,8 +1978,6 @@ def test_multi_line_str(self): self._check_end_pos(assign, 3, 40) self._check_end_pos(assign.value, 3, 40) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_continued_str(self): s = dedent(''' x = "first part" \\ diff --git a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_1.snap b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_1.snap index f57f903bc2..bfe109e114 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_1.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_1.snap @@ -24,7 +24,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 8, + column: 17, }, ), custom: (), @@ -38,7 +38,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 8, + column: 17, }, ), custom: (), diff --git a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_2.snap b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_2.snap index f57f903bc2..bfe109e114 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_2.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_2.snap @@ -24,7 +24,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 8, + column: 17, }, ), custom: (), @@ -38,7 +38,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 8, + column: 17, }, ), custom: (), diff --git a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap index 68582508b0..87b92127c2 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_f_string_concat_3.snap @@ -24,7 +24,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 8, + column: 22, }, ), custom: (), @@ -38,7 +38,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 8, + column: 22, }, ), custom: (), diff --git a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_string_concat.snap b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_string_concat.snap index 0052f8df6c..a8744263f5 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_string_concat.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_string_concat.snap @@ -24,7 +24,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 8, + column: 16, }, ), custom: (), diff --git a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap index d9d57865ed..76e6b1d220 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_1.snap @@ -24,7 +24,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 9, + column: 18, }, ), custom: (), @@ -38,7 +38,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 9, + column: 18, }, ), custom: (), diff --git a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap index a9f10f062c..8c073fd901 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_f_string_concat_2.snap @@ -24,7 +24,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 9, + column: 22, }, ), custom: (), @@ -38,7 +38,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 9, + column: 22, }, ), custom: (), diff --git a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_1.snap b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_1.snap index 503d5b5c13..868ba813e8 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_1.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_1.snap @@ -24,7 +24,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 8, + column: 17, }, ), custom: (), diff --git a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap index 432625993a..a24fc2b347 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap @@ -24,7 +24,7 @@ expression: parse_ast end_location: Some( Location { row: 1, - column: 9, + column: 17, }, ), custom: (), diff --git a/compiler/parser/src/string.rs b/compiler/parser/src/string.rs index 838da94c7e..cf18de9c2c 100644 --- a/compiler/parser/src/string.rs +++ b/compiler/parser/src/string.rs @@ -11,7 +11,7 @@ pub fn parse_strings( ) -> Result { // Preserve the initial location and kind. let initial_start = values[0].0; - let initial_end = values[0].2; + let last_end = values.last().unwrap().2; let initial_kind = (values[0].1 .1 == StringKind::U).then(|| "u".to_owned()); // Optimization: fast-track the common case of a single string. @@ -19,7 +19,7 @@ pub fn parse_strings( let value = values.into_iter().last().unwrap().1 .0; return Ok(Expr::new( initial_start, - initial_end, + last_end, ExprKind::Constant { value: Constant::Str(value), kind: initial_kind, @@ -38,7 +38,7 @@ pub fn parse_strings( let take_current = |current: &mut Vec| -> Expr { Expr::new( initial_start, - initial_end, + last_end, ExprKind::Constant { value: Constant::Str(current.drain(..).join("")), kind: initial_kind.clone(), @@ -81,18 +81,16 @@ pub fn parse_strings( deduped.push(take_current(&mut current)); } - Ok(if has_fstring { - Expr::new( - initial_start, - initial_end, - ExprKind::JoinedStr { values: deduped }, - ) + let node = if has_fstring { + ExprKind::JoinedStr { values: deduped } } else { deduped .into_iter() .exactly_one() .expect("String must be concatenated to a single element.") - }) + .node + }; + Ok(Expr::new(initial_start, last_end, node)) } #[cfg(test)]