From 6b4553ffc8da2ddd20c125bce5b8a65962008065 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 10 Apr 2021 17:47:44 +0800 Subject: [PATCH] Fix panic with unterminated interpolated string. --- src/parser.rs | 3 +++ src/token.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 63c22822..18de1c75 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 diff --git a/src/token.rs b/src/token.rs index 4d7bbdb1..197ed303 100644 --- a/src/token.rs +++ b/src/token.rs @@ -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 ")`
next token is `{`|`None` | +/// |`` } hello` `` |`StringConstant(" hello")` |``Some('`')`` | pub fn parse_string_literal( stream: &mut impl InputStream, state: &mut TokenizeState,