- Added a Try/Catch token to the language (and DefaultRegistration also registers it automatically
This commit is contained in:
parent
35a7bd4cf7
commit
fa815a506e
|
@ -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 } ?>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
|
Loading…
Reference in New Issue