Use string start position as error position.

This commit is contained in:
Stephen Chung 2021-04-11 11:19:46 +08:00
parent 6b4553ffc8
commit c1c1e5f684

View File

@ -910,7 +910,7 @@ pub fn parse_string_literal(
None if !continuation && !verbatim => { None if !continuation && !verbatim => {
pos.advance(); pos.advance();
state.is_within_text_terminated_by = None; state.is_within_text_terminated_by = None;
return Err((LERR::UnterminatedString, *pos)); return Err((LERR::UnterminatedString, start));
} }
None => { None => {
if verbatim || escape != "\\" { if verbatim || escape != "\\" {
@ -1019,11 +1019,11 @@ pub fn parse_string_literal(
} }
// New-line cannot be escaped // New-line cannot be escaped
// Cannot have new-lines inside non-multi-line string literals // Cannot have new-lines inside non-verbatim strings
'\n' if !escape.is_empty() || !verbatim => { '\n' if !verbatim || !escape.is_empty() => {
pos.rewind(); pos.rewind();
state.is_within_text_terminated_by = None; state.is_within_text_terminated_by = None;
return Err((LERR::UnterminatedString, *pos)); return Err((LERR::UnterminatedString, start));
} }
'\n' => { '\n' => {
@ -1942,8 +1942,9 @@ impl<'a> Iterator for TokenIterator<'a> {
// {EOF} // {EOF}
None => return None, None => return None,
// Unterminated string at EOF // Unterminated string at EOF
Some((Token::StringConstant(_), _)) if self.state.is_within_text_terminated_by.is_some() => { Some((Token::StringConstant(_), pos)) if self.state.is_within_text_terminated_by.is_some() => {
return Some((Token::LexError(LERR::UnterminatedString), self.pos)); self.state.is_within_text_terminated_by = None;
return Some((Token::LexError(LERR::UnterminatedString), pos));
} }
// Reserved keyword/symbol // Reserved keyword/symbol
Some((Token::Reserved(s), pos)) => (match Some((Token::Reserved(s), pos)) => (match