diff --git a/crates/compiler/can/src/desugar.rs b/crates/compiler/can/src/desugar.rs index 66a77eca88..4d06abf270 100644 --- a/crates/compiler/can/src/desugar.rs +++ b/crates/compiler/can/src/desugar.rs @@ -1045,20 +1045,6 @@ fn desugar_str_segments<'a>( StrSegment::Plaintext(_) | StrSegment::Unicode(_) | StrSegment::EscapedChar(_) => { *segment } - StrSegment::DeprecatedInterpolated(loc_expr) => { - let loc_desugared = desugar_expr( - env, - scope, - env.arena.alloc(Loc { - region: loc_expr.region, - value: *loc_expr.value, - }), - ); - StrSegment::DeprecatedInterpolated(Loc { - region: loc_desugared.region, - value: env.arena.alloc(loc_desugared.value), - }) - } StrSegment::Interpolated(loc_expr) => { let loc_desugared = desugar_expr( env, diff --git a/crates/compiler/can/src/expr.rs b/crates/compiler/can/src/expr.rs index 18f295bb0f..890370382a 100644 --- a/crates/compiler/can/src/expr.rs +++ b/crates/compiler/can/src/expr.rs @@ -2515,9 +2515,7 @@ pub fn is_valid_interpolation(expr: &ast::Expr<'_>) -> bool { | ast::StrSegment::Plaintext(_) => true, // Disallow nested interpolation. Alternatively, we could allow it but require // a comment above it apologizing to the next person who has to read the code. - ast::StrSegment::Interpolated(_) | ast::StrSegment::DeprecatedInterpolated(_) => { - false - } + ast::StrSegment::Interpolated(_) => false, }) } ast::Expr::Record(fields) => fields.iter().all(|loc_field| match loc_field.value { @@ -2648,7 +2646,7 @@ fn flatten_str_lines<'a>( ); } }, - Interpolated(loc_expr) | DeprecatedInterpolated(loc_expr) => { + Interpolated(loc_expr) => { if is_valid_interpolation(loc_expr.value) { // Interpolations desugar to Str.concat calls output.references.insert_call(Symbol::STR_CONCAT); diff --git a/crates/compiler/can/src/pattern.rs b/crates/compiler/can/src/pattern.rs index ffd097e3ae..153cb83a0f 100644 --- a/crates/compiler/can/src/pattern.rs +++ b/crates/compiler/can/src/pattern.rs @@ -1109,7 +1109,7 @@ fn flatten_str_lines(lines: &[&[StrSegment<'_>]]) -> Pattern { Unicode(loc_digits) => { todo!("parse unicode digits {:?}", loc_digits); } - Interpolated(loc_expr) | DeprecatedInterpolated(loc_expr) => { + Interpolated(loc_expr) => { return Pattern::UnsupportedPattern(loc_expr.region); } EscapedChar(escaped) => buf.push(escaped.unescape()), diff --git a/crates/compiler/fmt/src/expr.rs b/crates/compiler/fmt/src/expr.rs index 46e004d7f1..c3deed750e 100644 --- a/crates/compiler/fmt/src/expr.rs +++ b/crates/compiler/fmt/src/expr.rs @@ -662,7 +662,7 @@ fn format_str_segment(seg: &StrSegment, buf: &mut Buf, indent: u16) { buf.push('\\'); buf.push(escaped.to_parsed_char()); } - DeprecatedInterpolated(loc_expr) | Interpolated(loc_expr) => { + Interpolated(loc_expr) => { buf.push_str("$("); // e.g. (name) in "Hi, $(name)!" loc_expr.value.format_with_options( diff --git a/crates/compiler/load/tests/test_reporting.rs b/crates/compiler/load/tests/test_reporting.rs index 585d8fd430..c1b93d91f8 100644 --- a/crates/compiler/load/tests/test_reporting.rs +++ b/crates/compiler/load/tests/test_reporting.rs @@ -5657,7 +5657,7 @@ mod test_reporting { test_report!( weird_escape, r#""abc\qdef""#, - @r###" + @r#" ── WEIRD ESCAPE in tmp/weird_escape/Test.roc ─────────────────────────────────── I was partway through parsing a string literal, but I got stuck here: @@ -5674,8 +5674,7 @@ mod test_reporting { - An escaped quote: \" - An escaped backslash: \\ - A unicode code point: \u(00FF) - - An interpolated string: $(myVariable) - "### + "# ); test_report!( diff --git a/crates/compiler/parse/src/ast.rs b/crates/compiler/parse/src/ast.rs index b59fdb591e..f186010047 100644 --- a/crates/compiler/parse/src/ast.rs +++ b/crates/compiler/parse/src/ast.rs @@ -281,11 +281,10 @@ pub struct WhenPattern<'a> { #[derive(Clone, Copy, Debug, PartialEq)] pub enum StrSegment<'a> { - Plaintext(&'a str), // e.g. "foo" - Unicode(Loc<&'a str>), // e.g. "00A0" in "\u(00A0)" - EscapedChar(EscapedChar), // e.g. '\n' in "Hello!\n" - Interpolated(Loc<&'a Expr<'a>>), - DeprecatedInterpolated(Loc<&'a Expr<'a>>), // The old "$(...)" syntax - will be removed someday + Plaintext(&'a str), // e.g. "foo" + Unicode(Loc<&'a str>), // e.g. "00A0" in "\u(00A0)" + EscapedChar(EscapedChar), // e.g. '\n' in "Hello!\n" + Interpolated(Loc<&'a Expr<'a>>), // e.g. "$(expr)" } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -379,7 +378,6 @@ impl<'a> TryFrom> for SingleQuoteSegment<'a> { StrSegment::Unicode(s) => Ok(SingleQuoteSegment::Unicode(s)), StrSegment::EscapedChar(s) => Ok(SingleQuoteSegment::EscapedChar(s)), StrSegment::Interpolated(_) => Err(ESingleQuote::InterpolationNotAllowed), - StrSegment::DeprecatedInterpolated(_) => Err(ESingleQuote::InterpolationNotAllowed), } } } @@ -2516,9 +2514,7 @@ impl<'a> Malformed for StrSegment<'a> { fn is_malformed(&self) -> bool { match self { StrSegment::Plaintext(_) | StrSegment::Unicode(_) | StrSegment::EscapedChar(_) => false, - StrSegment::Interpolated(expr) | StrSegment::DeprecatedInterpolated(expr) => { - expr.is_malformed() - } + StrSegment::Interpolated(expr) => expr.is_malformed(), } } } diff --git a/crates/compiler/parse/src/normalize.rs b/crates/compiler/parse/src/normalize.rs index a1def6c677..4781cba5e5 100644 --- a/crates/compiler/parse/src/normalize.rs +++ b/crates/compiler/parse/src/normalize.rs @@ -649,13 +649,6 @@ fn normalize_str_segments<'a>( } new_segments.push(StrSegment::Interpolated(e.normalize(arena))); } - StrSegment::DeprecatedInterpolated(e) => { - if !last_text.is_empty() { - let text = std::mem::replace(last_text, String::new_in(arena)); - new_segments.push(StrSegment::Plaintext(text.into_bump_str())); - } - new_segments.push(StrSegment::Interpolated(e.normalize(arena))); - } } } } @@ -680,7 +673,6 @@ impl<'a> Normalize<'a> for StrSegment<'a> { StrSegment::Unicode(t) => StrSegment::Unicode(t.normalize(arena)), StrSegment::EscapedChar(c) => StrSegment::EscapedChar(c), StrSegment::Interpolated(t) => StrSegment::Interpolated(t.normalize(arena)), - StrSegment::DeprecatedInterpolated(t) => StrSegment::Interpolated(t.normalize(arena)), } } } diff --git a/crates/compiler/parse/src/string_literal.rs b/crates/compiler/parse/src/string_literal.rs index 97d4c2cd4e..f7fe50a645 100644 --- a/crates/compiler/parse/src/string_literal.rs +++ b/crates/compiler/parse/src/string_literal.rs @@ -364,36 +364,6 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri // This is the start of a new escape. Look at the next byte // to figure out what type of escape it is. match bytes.next() { - Some(b'(') => { - // Advance past the `\(` before using the expr parser - state.advance_mut(2); - - let original_byte_count = state.bytes().len(); - - // This is an interpolated variable. - // Parse an arbitrary expression, then give a - // canonicalization error if that expression variant - // is not allowed inside a string interpolation. - let (_progress, loc_expr, new_state) = skip_second( - specialize_err_ref( - EString::Format, - loc(allocated(reset_min_indent(expr::expr_help()))), - ), - byte(b')', EString::FormatEnd), - ) - .parse(arena, state, min_indent)?; - - // Advance the iterator past the expr we just parsed. - for _ in 0..(original_byte_count - new_state.bytes().len()) { - bytes.next(); - } - - segments.push(StrSegment::DeprecatedInterpolated(loc_expr)); - - // Reset the segment - segment_parsed_bytes = 0; - state = new_state; - } Some(b'u') => { // Advance past the `\u` before using the expr parser state.advance_mut(2); @@ -444,8 +414,8 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri } _ => { // Invalid escape! A backslash must be followed - // by either an open paren or else one of the - // escapable characters (\n, \t, \", \\, etc) + // by one of these escapable characters: + // (\n, \t, \", \\, etc) return Err((MadeProgress, EString::UnknownEscape(state.pos()))); } } diff --git a/crates/compiler/test_syntax/tests/snapshots/fail/deprecated_interpolated_string.expr.result-ast b/crates/compiler/test_syntax/tests/snapshots/fail/deprecated_interpolated_string.expr.result-ast new file mode 100644 index 0000000000..a7810c1813 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/fail/deprecated_interpolated_string.expr.result-ast @@ -0,0 +1 @@ +Expr(Str(UnknownEscape(@1), @0), @0) \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/snapshots/fail/deprecated_interpolated_string.expr.roc b/crates/compiler/test_syntax/tests/snapshots/fail/deprecated_interpolated_string.expr.roc new file mode 100644 index 0000000000..72df415ec7 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/fail/deprecated_interpolated_string.expr.roc @@ -0,0 +1 @@ +"\(e)" \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.formatted.roc deleted file mode 100644 index 0ff8b60204..0000000000 --- a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.formatted.roc +++ /dev/null @@ -1 +0,0 @@ -"$(e)" \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.result-ast b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.result-ast deleted file mode 100644 index 31432b47f4..0000000000 --- a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.result-ast +++ /dev/null @@ -1,17 +0,0 @@ -SpaceAfter( - Str( - Line( - [ - DeprecatedInterpolated( - @3-4 Var { - module_name: "", - ident: "e", - }, - ), - ], - ), - ), - [ - Newline, - ], -) diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.roc b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.roc deleted file mode 100644 index b48439b918..0000000000 --- a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.roc +++ /dev/null @@ -1 +0,0 @@ -"\(e)" diff --git a/crates/compiler/test_syntax/tests/test_snapshots.rs b/crates/compiler/test_syntax/tests/test_snapshots.rs index 802411df08..05bf4d7e6a 100644 --- a/crates/compiler/test_syntax/tests/test_snapshots.rs +++ b/crates/compiler/test_syntax/tests/test_snapshots.rs @@ -192,6 +192,7 @@ mod test_snapshots { fail/comment_with_tab.expr, fail/def_missing_final_expression.expr, fail/def_without_newline.expr, + fail/deprecated_interpolated_string.expr, fail/double_plus.expr, fail/elm_function_syntax.expr, fail/empty_or_pattern.expr, @@ -303,11 +304,10 @@ mod test_snapshots { pass/comment_with_non_ascii.expr, pass/control_characters_in_scalar.expr, pass/crash.expr, + pass/dbg.expr, pass/dbg_stmt.expr, pass/dbg_stmt_multiline.expr, - pass/dbg.expr, pass/defs_suffixed_middle_extra_indents.moduledefs, - pass/deprecated_interpolated_string.expr, pass/destructure_tag_assignment.expr, pass/docs.expr, pass/empty_app_header.header, diff --git a/crates/reporting/src/error/parse.rs b/crates/reporting/src/error/parse.rs index efad8a114c..06966cd5f2 100644 --- a/crates/reporting/src/error/parse.rs +++ b/crates/reporting/src/error/parse.rs @@ -995,7 +995,6 @@ fn to_str_report<'a>( suggestion("An escaped quote: ", "\\\""), suggestion("An escaped backslash: ", "\\\\"), suggestion("A unicode code point: ", "\\u(00FF)"), - suggestion("An interpolated string: ", "$(myVariable)"), ]) .indent(4), ]);