|
26 | 26 | use Codewithkyrian\Jinja\Exceptions\SyntaxError; |
27 | 27 | use Codewithkyrian\Jinja\Runtime\ArrayValue; |
28 | 28 | use Codewithkyrian\Jinja\Runtime\BooleanValue; |
| 29 | +use Codewithkyrian\Jinja\Runtime\BreakControl; |
| 30 | +use Codewithkyrian\Jinja\Runtime\ContinueControl; |
29 | 31 | use Codewithkyrian\Jinja\Runtime\FunctionValue; |
30 | 32 | use Codewithkyrian\Jinja\Runtime\KeywordArgumentsValue; |
31 | 33 | use Codewithkyrian\Jinja\Runtime\NullValue; |
@@ -73,6 +75,12 @@ function evaluate(?Statement $statement, Environment $environment): RuntimeValue |
73 | 75 | case "Macro": |
74 | 76 | return $this->evaluateMacro($statement, $environment); |
75 | 77 |
|
| 78 | + case "BreakStatement": |
| 79 | + throw new BreakControl(); |
| 80 | + |
| 81 | + case "ContinueStatement": |
| 82 | + throw new ContinueControl(); |
| 83 | + |
76 | 84 | case "NumericLiteral": |
77 | 85 | return new NumericValue($statement->value); |
78 | 86 |
|
@@ -786,8 +794,15 @@ private function evaluateFor(ForStatement $node, Environment $environment): Stri |
786 | 794 |
|
787 | 795 | $scopeUpdateFunction = $scopeUpdateFunctions[$i]; |
788 | 796 | $scopeUpdateFunction($scope); |
789 | | - $evaluated = $this->evaluateBlock($node->body, $scope); |
790 | | - $result .= $evaluated->value; |
| 797 | + |
| 798 | + try { |
| 799 | + $evaluated = $this->evaluateBlock($node->body, $scope); |
| 800 | + $result .= $evaluated->value; |
| 801 | + } catch (BreakControl $e) { |
| 802 | + break; |
| 803 | + } catch (ContinueControl $e) { |
| 804 | + continue; |
| 805 | + } |
791 | 806 |
|
792 | 807 | $noIteration = false; // At least one iteration took place |
793 | 808 | } |
|
0 commit comments