This commit is contained in:
Stephen Chung 2023-02-18 14:28:38 +08:00
parent 6b301b4e70
commit 6d888cc0e4

View File

@ -1397,20 +1397,26 @@ impl Engine {
.into(), .into(),
)), )),
// Loops are allowed to act as expressions // Loops are allowed to act as expressions
Token::While | Token::Loop if settings.has_option(LangOptions::LOOP_EXPR) => { Token::While | Token::Loop
if self.allow_looping() && settings.has_option(LangOptions::LOOP_EXPR) =>
{
Expr::Stmt(Box::new( Expr::Stmt(Box::new(
self.parse_while_loop(input, state, lib, settings.level_up()?)? self.parse_while_loop(input, state, lib, settings.level_up()?)?
.into(), .into(),
)) ))
} }
Token::Do if settings.has_option(LangOptions::LOOP_EXPR) => Expr::Stmt(Box::new( Token::Do if self.allow_looping() && settings.has_option(LangOptions::LOOP_EXPR) => {
Expr::Stmt(Box::new(
self.parse_do(input, state, lib, settings.level_up()?)? self.parse_do(input, state, lib, settings.level_up()?)?
.into(), .into(),
)), ))
Token::For if settings.has_option(LangOptions::LOOP_EXPR) => Expr::Stmt(Box::new( }
Token::For if self.allow_looping() && settings.has_option(LangOptions::LOOP_EXPR) => {
Expr::Stmt(Box::new(
self.parse_for(input, state, lib, settings.level_up()?)? self.parse_for(input, state, lib, settings.level_up()?)?
.into(), .into(),
)), ))
}
// Switch statement is allowed to act as expressions // Switch statement is allowed to act as expressions
Token::Switch if settings.has_option(LangOptions::SWITCH_EXPR) => Expr::Stmt(Box::new( Token::Switch if settings.has_option(LangOptions::SWITCH_EXPR) => Expr::Stmt(Box::new(
self.parse_switch(input, state, lib, settings.level_up()?)? self.parse_switch(input, state, lib, settings.level_up()?)?