Fix panic with unterminated interpolated string.

This commit is contained in:
Stephen Chung 2021-04-10 17:47:44 +08:00
parent 40fda5139d
commit 6b4553ffc8
2 changed files with 15 additions and 0 deletions

View File

@ -1039,6 +1039,9 @@ fn parse_primary(
segments.push(Expr::StringConstant(s.into(), pos));
}
}
(Token::LexError(err @ LexError::UnterminatedString), pos) => {
return Err(err.into_err(pos))
}
(token, _) => unreachable!(
"expected a string within an interpolated string literal, but gets {:?}",
token

View File

@ -871,6 +871,18 @@ pub trait InputStream {
/// # Volatile API
///
/// This function is volatile and may change.
///
/// # Returns
///
/// |Type |Return Value |`state.is_within_text_terminated_by`|
/// |---------------------------------|----------------------------|------------------------------------|
/// |`"hello"` |`StringConstant("hello")` |`None` |
/// |`"hello`_{LF}_ or _{EOF}_ |`LexError` |`None` |
/// |`"hello\`_{EOF}_ or _{LF}{EOF}_ |`StringConstant("hello")` |`Some('"')` |
/// |`` `hello``_{EOF}_ |`StringConstant("hello")` |``Some('`')`` |
/// |`` `hello``_{LF}{EOF}_ |`StringConstant("hello\n")` |``Some('`')`` |
/// |`` `hello ${`` |`InterpolatedString("hello ")`<br/>next token is `{`|`None` |
/// |`` } hello` `` |`StringConstant(" hello")` |``Some('`')`` |
pub fn parse_string_literal(
stream: &mut impl InputStream,
state: &mut TokenizeState,