37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Picea\ControlStructure;
|
|
|
|
class SwitchToken implements ControlStructure {
|
|
|
|
public array $token = [ "switch", "case", "endcase", "endswitch", "/switch" ];
|
|
|
|
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
|
|
switch($token) {
|
|
case "switch":
|
|
$context->switchStack[] = true;
|
|
return "<?php switch($arguments):";
|
|
|
|
case "case":
|
|
$output = "";
|
|
|
|
if ( $context->switchStack ) {
|
|
array_pop($context->switchStack);
|
|
}
|
|
else {
|
|
$output = "<?php ";
|
|
}
|
|
|
|
return ( $output ?? "" ) . "case $arguments: ?>";
|
|
|
|
case "endcase":
|
|
case "/case":
|
|
return "<?php break; ?>";
|
|
|
|
case "endswitch":
|
|
case "/switch":
|
|
return "<?php endswitch; ?>";
|
|
}
|
|
}
|
|
}
|