- Added a Try/Catch token to the language (and DefaultRegistration also registers it automatically

This commit is contained in:
Dave M. 2024-10-29 13:40:17 +00:00
parent 35a7bd4cf7
commit fa815a506e
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace Picea\ControlStructure;
class TryCatchToken implements ControlStructure {
public array $token = [ "try", "catch", "finally", "endtry" ];
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
switch($token) {
case "try":
return "<?php try { ?>";
case "catch":
return "<?php } catch($arguments) { ?>";
case "finally":
return "<?php } finally { ?>";
case "endtry":
return "<?php } ?>";
}
}
}

View File

@ -32,6 +32,7 @@ class DefaultRegistrations implements LanguageRegistration
public function registerControlStructure(Compiler $compiler) : void public function registerControlStructure(Compiler $compiler) : void
{ {
$compiler->registerControlStructure(new \Picea\ControlStructure\TryCatchToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\NamespaceToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\NamespaceToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\UseToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\UseToken());
$compiler->registerControlStructure(new \Picea\ControlStructure\IfToken()); $compiler->registerControlStructure(new \Picea\ControlStructure\IfToken());