Parse deprecated interpolation syntax differently

This commit is contained in:
Richard Feldman 2024-01-06 17:41:03 -05:00
parent 08ab7996a0
commit af8e9c7292
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
7 changed files with 47 additions and 11 deletions

View file

@ -119,10 +119,11 @@ 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>>), // e.g. (name) in "Hi, \(name)!"
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
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -216,6 +217,7 @@ 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),
}
}
}
@ -1590,7 +1592,9 @@ impl<'a> Malformed for StrSegment<'a> {
fn is_malformed(&self) -> bool {
match self {
StrSegment::Plaintext(_) | StrSegment::Unicode(_) | StrSegment::EscapedChar(_) => false,
StrSegment::Interpolated(expr) => expr.is_malformed(),
StrSegment::Interpolated(expr) | StrSegment::DeprecatedInterpolated(expr) => {
expr.is_malformed()
}
}
}
}