picea/src/ControlStructure/OrToken.php

24 lines
733 B
PHP

<?php
namespace Picea\ControlStructure;
class OrToken implements ControlStructure {
public string $token = "or";
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
if ( empty($context->iterationStack) ) {
throw new \LogicException("Token `or` was used outside of iterator. Make sure your `for` or `foreach` declaration are properly made.");
}
$key = count( $context->iterationStack ) - 1;
$context->iterationStack[$key]['or'] = true;
$name = $context->iterationStack[$key]['uid'];
return "<?php {$context->iterationStack[$key]['token']}; if( false === ($name ?? false) ): ?>";
}
}