- Added while/endwhile and do/while syntaxes

- Fix the abstractclass requirement of parse() function
This commit is contained in:
mcndave committed 2022-12-19 19:36:39 +00:00
1 parent 33298ff2e4
commit bb29a56077
36 files changed
+115 -73

No files matched your search

+2 -40
View File
@@ -2,46 +2,8 @@
namespace Picea\ControlStructure;
class ForeachToken implements ControlStructure {
use DI\Definition\Source\AnnotationBasedAutowiring;
class ForeachToken extends AbstractLoop {
public array $token = [ "foreach", "endforeach" ];
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
switch($token) {
case "foreach":
$name = "$".uniqid("foreach_");
$stack = array_filter($context->iterationStack ?? [], function($item) {
return ! $item['or'];
});
$count = count($stack);
if ( $count > 0 ) {
$name .= "[" . end($stack)['uid'] . "]";
}
$context->iterationStack[] = [
'or' => false,
'uid' => $name,
'token' => 'endforeach',
];
return "<?php foreach ($arguments): $name = ( $name ?? 0 ) + 1; ; ?>";
case "endforeach":
$last = end($context->iterationStack);
if ( $last['or'] === false ) {
$output = "<?php endforeach; ?>";
}
else {
$output = "<?php endif; unset({$last['uid']}) ?>";
}
array_pop($context->iterationStack);
return $output;
}
}
}