From 1df621868fda1aae193405057f69c3187debbae2 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 13 May 2022 16:39:41 +0200 Subject: Fix control flow bug --- src/eval/mod.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/eval') diff --git a/src/eval/mod.rs b/src/eval/mod.rs index d39c3c2c..b35cf1ef 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -111,6 +111,7 @@ fn eval_markup( scp: &mut Scopes, nodes: &mut impl Iterator, ) -> TypResult { + let flow = ctx.flow.take(); let mut seq = Vec::with_capacity(nodes.size_hint().1.unwrap_or_default()); while let Some(node) = nodes.next() { @@ -146,6 +147,10 @@ fn eval_markup( } } + if flow.is_some() { + ctx.flow = flow; + } + Ok(Content::sequence(seq)) } @@ -343,6 +348,7 @@ fn eval_code( scp: &mut Scopes, exprs: &mut impl Iterator, ) -> TypResult { + let flow = ctx.flow.take(); let mut output = Value::None; while let Some(expr) = exprs.next() { @@ -383,6 +389,10 @@ fn eval_code( } } + if flow.is_some() { + ctx.flow = flow; + } + Ok(output) } @@ -785,6 +795,7 @@ impl Eval for WhileExpr { type Output = Value; fn eval(&self, ctx: &mut Context, scp: &mut Scopes) -> TypResult { + let flow = ctx.flow.take(); let mut output = Value::None; let condition = self.condition(); @@ -804,6 +815,10 @@ impl Eval for WhileExpr { } } + if flow.is_some() { + ctx.flow = flow; + } + Ok(output) } } @@ -812,11 +827,12 @@ impl Eval for ForExpr { type Output = Value; fn eval(&self, ctx: &mut Context, scp: &mut Scopes) -> TypResult { + let flow = ctx.flow.take(); + let mut output = Value::None; + scp.enter(); + macro_rules! iter { (for ($($binding:ident => $value:ident),*) in $iter:expr) => {{ - let mut output = Value::None; - scp.enter(); - #[allow(unused_parens)] for ($($value),*) in $iter { $(scp.top.def_mut(&$binding, $value);)* @@ -836,8 +852,6 @@ impl Eval for ForExpr { } } - scp.exit(); - return Ok(output); }}; } @@ -878,6 +892,13 @@ impl Eval for ForExpr { bail!(self.iter().span(), "cannot loop over {}", iter.type_name()); } } + + if flow.is_some() { + ctx.flow = flow; + } + + scp.exit(); + Ok(output) } } -- cgit v1.2.3