Remove deprecated string interpolation syntax

This commit is contained in:
hrishisd 2024-10-08 16:31:22 -04:00
parent 72011fba73
commit cb98c45e88
No known key found for this signature in database
GPG key ID: E447B3759263B767
15 changed files with 17 additions and 94 deletions

View file

@ -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<StrSegment<'a>> 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(),
}
}
}

View file

@ -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)),
}
}
}

View file

@ -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())));
}
}