- Addedd a new Money extension and a new Function token

This commit is contained in:
mcndave committed 2022-06-03 15:31:50 +00:00
1 parent 48ecd9f7d9
commit b08325049b
3 files changed
+89

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
<?php
namespace Picea\ControlStructure;
class FunctionToken implements ControlStructure {
public array $token = [ "function", "endfunction", "return" ];
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
switch($token) {
case "function":
return $this->printFunction($context, $arguments);
case "return":
if ( empty($context->functions) ) {
throw new \RuntimeException("A function return tag {% return %} was found without an opening {% function ... %} tag");
}
return $this->printReturn($context, $arguments);
case "endfunction":
if ( empty($context->functions) ) {
throw new \RuntimeException("A function closing tag {% endfunction %} was found without an opening {% function ... %} tag");
}
$context->functions--;
return $this->printEndFunction($context);
}
}
protected function printFunction($context, ?string $arguments) : string
{
$context->functions++;
return "<?php function $arguments { ?>";
}
protected function printReturn($context, ?string $arguments) : string
{
return "<?php return $arguments; ?>";
}
protected function printEndFunction($context) : string
{
return "<?php } ?>";
}
}