- Added while/endwhile and do/while syntaxes
- Fix the abstractclass requirement of parse() function
This commit is contained in:
1 parent
33298ff2e4
commit
bb29a56077
36 files changed
+115
-73
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user