2019-10-04 08:38:11 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Picea\Language;
|
|
|
|
|
|
|
|
use Picea\Compiler;
|
|
|
|
|
|
|
|
class DefaultRegistrations implements LanguageRegistration
|
|
|
|
{
|
2019-12-19 11:23:21 -05:00
|
|
|
protected array $extensions;
|
|
|
|
|
|
|
|
protected array $syntaxes;
|
|
|
|
|
|
|
|
protected array $controlStructures;
|
2021-02-16 03:17:32 +00:00
|
|
|
|
|
|
|
public function __construct(array $extensions = [], array $syntaxes = [], array $controlStructure = [])
|
2019-12-19 11:23:21 -05:00
|
|
|
{
|
|
|
|
$this->extensions = $extensions;
|
|
|
|
$this->syntaxes = $syntaxes;
|
|
|
|
$this->controlStructures = $controlStructure;
|
|
|
|
}
|
|
|
|
|
2019-10-04 08:38:11 -04:00
|
|
|
public function registerAll(Compiler $compiler) : void
|
|
|
|
{
|
|
|
|
$this->registerSyntax($compiler);
|
|
|
|
$this->registerControlStructure($compiler);
|
|
|
|
$this->registerExtension($compiler);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function registerSyntax(Compiler $compiler) : void
|
|
|
|
{
|
|
|
|
$compiler->registerSyntax(new \Picea\Syntax\PhpTagToken());
|
|
|
|
$compiler->registerSyntax(new \Picea\Syntax\CommentToken());
|
|
|
|
$compiler->registerSyntax(new \Picea\Syntax\EchoRawToken());
|
|
|
|
$compiler->registerSyntax(new \Picea\Syntax\EchoSafeToken());
|
2019-12-19 11:23:21 -05:00
|
|
|
|
|
|
|
foreach($this->syntaxes ?? [] as $syntax) {
|
|
|
|
$compiler->registerSyntax($syntax);
|
|
|
|
}
|
2019-10-04 08:38:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function registerControlStructure(Compiler $compiler) : void
|
|
|
|
{
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\NamespaceToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\UseToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\IfToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\ForeachToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\ForToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\OrToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\SwitchToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\DefaultToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\BreakToken());
|
2021-03-24 13:49:38 +00:00
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\ContinueToken());
|
2019-10-04 08:38:11 -04:00
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken());
|
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken());
|
2022-06-03 15:31:50 +00:00
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\FunctionToken());
|
2020-03-30 12:13:02 -04:00
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\BlockToken());
|
2020-10-20 19:38:37 +00:00
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\IncludeToken());
|
2019-11-01 14:46:01 -04:00
|
|
|
$compiler->registerControlStructure(new \Picea\ControlStructure\ViewToken());
|
2019-12-19 11:23:21 -05:00
|
|
|
|
|
|
|
foreach($this->controlStructures ?? [] as $controlStructure) {
|
|
|
|
$compiler->registerControlStructure($controlStructure);
|
|
|
|
}
|
2019-10-04 08:38:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function registerExtension(Compiler $compiler) : void
|
|
|
|
{
|
2020-03-31 10:57:26 -04:00
|
|
|
$compiler->registerExtension(new \Picea\Extension\PhpExtension());
|
2021-01-06 19:31:58 +00:00
|
|
|
$compiler->registerExtension(new \Picea\Extension\PrintExtension());
|
2021-02-16 03:17:32 +00:00
|
|
|
$compiler->registerExtension(new \Picea\Extension\JsonExtension());
|
|
|
|
|
2019-12-19 11:23:21 -05:00
|
|
|
foreach($this->extensions ?? [] as $extension) {
|
|
|
|
$compiler->registerExtension($extension);
|
|
|
|
}
|
2019-10-04 08:38:11 -04:00
|
|
|
}
|
|
|
|
}
|