33 lines
876 B
PHP
33 lines
876 B
PHP
<?php
|
|
|
|
namespace Picea\ControlStructure;
|
|
|
|
class WhileToken extends AbstractLoop {
|
|
public array $token = [ "do", "while", "endwhile", ];
|
|
|
|
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) {
|
|
switch($token) {
|
|
case "do":
|
|
$context->iterationStack[] = [
|
|
'or' => false,
|
|
'token' => "do",
|
|
];
|
|
|
|
return "<?php do { ?>";
|
|
|
|
case "while":
|
|
if ( $context->iterationStack ?? false ) {
|
|
if ( end($context->iterationStack)['token'] === 'do' ) {
|
|
array_pop($context->iterationStack);
|
|
|
|
return "<?php } while($arguments); ?>";
|
|
}
|
|
}
|
|
}
|
|
|
|
return parent::parse($context, $arguments, $token);
|
|
}
|
|
}
|
|
|
|
|