Fix hanging when parsing unterminated statements block.

This commit is contained in:
Stephen Chung 2021-04-20 11:22:38 +08:00
parent e9de975450
commit a186eb8d97

View File

@ -2417,7 +2417,23 @@ fn parse_block(
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
let prev_mods_len = state.modules.len(); let prev_mods_len = state.modules.len();
while !match_token(input, Token::RightBrace).0 { loop {
// Terminated?
match input.peek().unwrap() {
(Token::RightBrace, _) => {
eat_token(input, Token::RightBrace);
break;
}
(Token::EOF, pos) => {
return Err(PERR::MissingToken(
Token::RightBrace.into(),
"to terminate this block".into(),
)
.into_err(*pos));
}
_ => (),
}
// Parse statements inside the block // Parse statements inside the block
settings.is_global = false; settings.is_global = false;
@ -2443,11 +2459,13 @@ fn parse_block(
eat_token(input, Token::SemiColon); eat_token(input, Token::SemiColon);
} }
// { ... { stmt } ; // { ... { stmt } ;
(Token::SemiColon, _) if !need_semicolon => (), (Token::SemiColon, _) if !need_semicolon => {
eat_token(input, Token::SemiColon);
}
// { ... { stmt } ??? // { ... { stmt } ???
(_, _) if !need_semicolon => (), (_, _) if !need_semicolon => (),
// { ... stmt <error> // { ... stmt <error>
(Token::LexError(err), pos) => return Err(err.clone().into_err(*pos)), (Token::LexError(err), err_pos) => return Err(err.clone().into_err(*err_pos)),
// { ... stmt ??? // { ... stmt ???
(_, pos) => { (_, pos) => {
// Semicolons are not optional between statements // Semicolons are not optional between statements