From 30af3212152d05d18554ebfbabb2ce1e8ddd5c26 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 1 Mar 2021 16:07:39 +0000 Subject: [PATCH] - Corrected a bug where the 'or' variable was not reset properly on a iterations of for/foreach. --- src/ControlStructure/ForToken.php | 11 +++-------- src/ControlStructure/ForeachToken.php | 13 ++++++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/ControlStructure/ForToken.php b/src/ControlStructure/ForToken.php index 9f44026..34ffead 100644 --- a/src/ControlStructure/ForToken.php +++ b/src/ControlStructure/ForToken.php @@ -20,23 +20,18 @@ class ForToken implements ControlStructure { return ""; case "endfor": - if ( $context->iterationStack === null ){ + $last = end($context->iterationStack); - } - - if ( end($context->iterationStack)['or'] === false ) { + if ( $last['or'] === false ) { $output = ""; } else { - $output = ""; + $output = ""; } array_pop($context->iterationStack); return $output; - - case "continue": - return ""; } } } diff --git a/src/ControlStructure/ForeachToken.php b/src/ControlStructure/ForeachToken.php index e5c8d91..8184e35 100644 --- a/src/ControlStructure/ForeachToken.php +++ b/src/ControlStructure/ForeachToken.php @@ -4,13 +4,10 @@ namespace Picea\ControlStructure; class ForeachToken implements ControlStructure { - public array $token = [ "foreach", "endforeach", "continue" ]; + public array $token = [ "foreach", "endforeach" ]; public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { switch($token) { - case "continue": - return ""; - case "foreach": $name = "$".uniqid("foreach_"); @@ -30,14 +27,16 @@ class ForeachToken implements ControlStructure { 'token' => 'endforeach', ]; - return ""; + return ""; case "endforeach": - if ( end($context->iterationStack)['or'] === false ) { + $last = end($context->iterationStack); + + if ( $last['or'] === false ) { $output = ""; } else { - $output = ""; + $output = ""; } array_pop($context->iterationStack);