diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cb3012e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019 Dave Mc Nicoll + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/composer.json b/composer.json index d387c1b..ca9152d 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "mcnd/picea", - "description": "A templating engine based on Twig's syntax and Plates's native uses of PHP.", + "description": "A templating engine based on Twig's syntax and Plates's native uses of PHP transpiling code into vanilla PHP template.", "type": "library", "license": "MIT", "authors": [ @@ -9,10 +9,12 @@ "email": "mcndave@gmail.com" } ], - "require": {}, "autoload": { "psr-4": { "Picea\\": "src/" } + }, + "require": { + "psr/http-message": "^1.0" } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..38b0808 --- /dev/null +++ b/composer.lock @@ -0,0 +1,68 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "9771fcd7256da80520a2d0d0f95bf311", + "packages": [ + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/src/Builder/ClassTemplate.php b/src/Builder/ClassTemplate.php index 1a866ec..18a4686 100644 --- a/src/Builder/ClassTemplate.php +++ b/src/Builder/ClassTemplate.php @@ -10,12 +10,12 @@ class %CLASSNAME% %EXTENDS% { protected array $__variables_list = []; - public function output() : void + public final function __output() : void { extract($this->__variables_list); ?>%CONTENT%__section_list[$name][$item], fn($a, $b) => $a['order'] <=> $b['order']); @@ -30,9 +30,9 @@ class %CLASSNAME% %EXTENDS% { } } - public function __renderTemplate() { + public final function __invoke() { ob_start(); - $this->output(); + $this->__output(); return ob_get_clean(); } } diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php new file mode 100644 index 0000000..39f34b3 --- /dev/null +++ b/src/Caching/Cache.php @@ -0,0 +1,11 @@ +cachePath = $cachePath; - } - - public function loadFile(string $fileName) : bool - { - if ( file_exists($path = $this->filePath($fileName)) ) { - require_once($path); - } + #if ( file_exists($path = $this->filePath($fileName)) ) { + # require_once($path); + #} return false; } + public function load() {} + public function saveFile(string $fileName) : bool { } - - public function filePath(string $fileName) : string - { - return $this->cachePath . $fileName; - } } diff --git a/src/Caching/Opcache.php b/src/Caching/Opcache.php index 71eb5d6..c15b88b 100644 --- a/src/Caching/Opcache.php +++ b/src/Caching/Opcache.php @@ -2,16 +2,16 @@ namespace Picea\Caching; -class Opcache { +class Opcache implements Cache { protected string $cachePath = ""; - public function __construct(string $cachePath) + public function __construct(?string $cachePath = null) { - $this->cachePath = $cachePath; + $this->cachePath = $cachePath ?? sys_get_temp_dir(); } - public function loadFile(string $fileName) : bool + public function handle(string $fileName) : bool { if ( file_exists($path = $this->filePath($fileName)) ) { require_once($path); @@ -23,6 +23,8 @@ class Opcache { public function saveFile(string $fileName, string $content) : bool { + $this->validateCachePath(); + file_put_contents($this->filePath($fileName), $content); return false; @@ -32,4 +34,21 @@ class Opcache { { return $this->cachePath . $fileName; } + + protected function validateCachePath() : bool + { + if ( ! file_exists($this->cachePath) ) { + mkdir($this->cachePath, 0750, true); + } + + if ( ! is_writeable($this->cachePath) ) { + throw new \RuntimeException( + sprintf("Given cache path `%s` is not writeable by `%s`", $this->cachePath, static::class) + ); + + return false; + } + + return true; + } } diff --git a/src/Compiler.php b/src/Compiler.php index 1c9280d..ca93999 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -2,6 +2,8 @@ namespace Picea; +use Picea\Language\LanguageRegistration; + class Compiler { protected string $sourceCode = ""; @@ -16,8 +18,16 @@ class Compiler protected array $extensionList = []; + protected ? LanguageRegistration $languageRegistration; + + public function __construct(?LanguageRegistration $languageRegistration = null) + { + $this->languageRegistration = $languageRegistration; + } + public function compile(Compiler\Context $context) : string { + $this->languageRegistration->registerAll($this); $context->compiler = $this; /** @@ -39,7 +49,7 @@ class Compiler # @TODO Refractor this parts to allows registration to the tag's name if ( $this->tagList[$token] ?? false ) { - return $this->tagList[$token]->parse($context, $arguments); + return $this->tagList[$token]->parse($context, $arguments, $token); } elseif ( $this->extensionList[$token] ?? false ) { return $this->extensionList[$token]->parse($context, $arguments, $token); @@ -59,12 +69,6 @@ class Compiler return $this; } - public function registerExtension(Extension\Extension $extension) : self - { - $this->extensionList[$extension->token] = $extension; - return $this; - } - public function registerCaching(CachingStrategy $cachingStrategy) : self { return $this; @@ -72,13 +76,25 @@ class Compiler public function registerSyntax(Syntax\Syntax $syntaxObject) : self { - $this->syntaxObjectList[] = $syntaxObject; + $this->syntaxObjectList[get_class($syntaxObject)] = $syntaxObject; return $this; } public function registerControlStructure(ControlStructure\ControlStructure $controlStructureObject) : self { - $this->tagList[$controlStructureObject->token] = $controlStructureObject; + foreach($controlStructureObject->tokens ?? (array) $controlStructureObject->token as $token) { + $this->tagList[$token] = $controlStructureObject; + } + + return $this; + } + + public function registerExtension(Extension\Extension $extension) : self + { + foreach($extension->tokens ?? (array) $extension->token as $token) { + $this->extensionList[$token] = $extension; + } + return $this; } } diff --git a/src/Compiler/Context.php b/src/Compiler/Context.php index 5c61674..98bdc85 100644 --- a/src/Compiler/Context.php +++ b/src/Compiler/Context.php @@ -41,4 +41,9 @@ abstract class Context { { return implode(",", $context->useStack ?? []); } + + public function variables(array $variables) : void + { + $this->variables = $variables; + } } diff --git a/src/ControlStructure/BreakToken.php b/src/ControlStructure/BreakToken.php index adcd8d7..8f815ac 100644 --- a/src/ControlStructure/BreakToken.php +++ b/src/ControlStructure/BreakToken.php @@ -6,7 +6,7 @@ class BreakToken implements ControlStructure { public string $token = "break"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { return ""; } diff --git a/src/ControlStructure/CaseToken.php b/src/ControlStructure/CaseToken.php index 0dffdbc..127e3fa 100644 --- a/src/ControlStructure/CaseToken.php +++ b/src/ControlStructure/CaseToken.php @@ -6,7 +6,7 @@ class CaseToken implements ControlStructure { public string $token = "case"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { $output = ""; if ( $context->switchStack ) { diff --git a/src/ControlStructure/ControlStructure.php b/src/ControlStructure/ControlStructure.php index cd5a25d..51c0add 100644 --- a/src/ControlStructure/ControlStructure.php +++ b/src/ControlStructure/ControlStructure.php @@ -3,5 +3,5 @@ namespace Picea\ControlStructure; interface ControlStructure { - public function parse(\Picae\Compiler\Context &$context, string $sourceCode); + public function parse(\Picae\Compiler\Context &$context, string $sourceCode, string $token); } diff --git a/src/ControlStructure/DefaultToken.php b/src/ControlStructure/DefaultToken.php index 33bb590..cb6b6c9 100644 --- a/src/ControlStructure/DefaultToken.php +++ b/src/ControlStructure/DefaultToken.php @@ -6,7 +6,7 @@ class DefaultToken implements ControlStructure { public string $token = "default"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { $output = ""; if ( $context->switchStack ) { diff --git a/src/ControlStructure/ElseIfToken.php b/src/ControlStructure/ElseIfToken.php index 8c2f3d2..3405492 100644 --- a/src/ControlStructure/ElseIfToken.php +++ b/src/ControlStructure/ElseIfToken.php @@ -6,7 +6,7 @@ class ElseIfToken implements ControlStructure { public string $token = "elseif"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { return ""; } diff --git a/src/ControlStructure/ElseToken.php b/src/ControlStructure/ElseToken.php index 1789dab..cc9ea3d 100644 --- a/src/ControlStructure/ElseToken.php +++ b/src/ControlStructure/ElseToken.php @@ -6,7 +6,7 @@ class ElseToken implements ControlStructure { public string $token = "else"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { return ""; } diff --git a/src/ControlStructure/EndIfToken.php b/src/ControlStructure/EndIfToken.php index 55b296e..1cf3491 100644 --- a/src/ControlStructure/EndIfToken.php +++ b/src/ControlStructure/EndIfToken.php @@ -6,7 +6,7 @@ class EndIfToken implements ControlStructure { public string $token = "endif"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { return ""; } diff --git a/src/ControlStructure/EndRawToken.php b/src/ControlStructure/EndRawToken.php new file mode 100644 index 0000000..a705f02 --- /dev/null +++ b/src/ControlStructure/EndRawToken.php @@ -0,0 +1,12 @@ +sections) ) { throw new \RuntimeException("A section closing tag {% endsection %} was found without an opening {% section %} tag"); } diff --git a/src/ControlStructure/EndSwitchToken.php b/src/ControlStructure/EndSwitchToken.php index d346293..f74a929 100644 --- a/src/ControlStructure/EndSwitchToken.php +++ b/src/ControlStructure/EndSwitchToken.php @@ -6,7 +6,7 @@ class EndSwitchToken implements ControlStructure { public string $token = "endswitch"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { return ""; } } diff --git a/src/ControlStructure/EndforToken.php b/src/ControlStructure/EndforToken.php index 07156a2..3f62099 100644 --- a/src/ControlStructure/EndforToken.php +++ b/src/ControlStructure/EndforToken.php @@ -6,7 +6,7 @@ class EndforToken implements ControlStructure { public string $token = "endfor"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { if ( end($context->iterationStack)['or'] === false ) { $output = ""; } diff --git a/src/ControlStructure/EndforeachToken.php b/src/ControlStructure/EndforeachToken.php index a407c08..a8088b4 100644 --- a/src/ControlStructure/EndforeachToken.php +++ b/src/ControlStructure/EndforeachToken.php @@ -6,7 +6,7 @@ class EndforeachToken implements ControlStructure { public string $token = "endforeach"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { if ( end($context->iterationStack)['or'] === false ) { $output = ""; } diff --git a/src/ControlStructure/ExtendsToken.php b/src/ControlStructure/ExtendsToken.php index 648a91a..0d7c52b 100644 --- a/src/ControlStructure/ExtendsToken.php +++ b/src/ControlStructure/ExtendsToken.php @@ -6,7 +6,7 @@ class ExtendsToken implements ControlStructure { public string $token = "extends"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $path) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $path, string $token) { # Triming string's quotes $path = trim($path, "\"\' \t"); diff --git a/src/ControlStructure/ForToken.php b/src/ControlStructure/ForToken.php index 972d5be..e662336 100644 --- a/src/ControlStructure/ForToken.php +++ b/src/ControlStructure/ForToken.php @@ -6,7 +6,7 @@ class ForToken implements ControlStructure { public string $token = "for"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { $uid = "$".uniqid("for_"); $context->iterationStack[] = [ diff --git a/src/ControlStructure/ForeachToken.php b/src/ControlStructure/ForeachToken.php index 1420086..09c833c 100644 --- a/src/ControlStructure/ForeachToken.php +++ b/src/ControlStructure/ForeachToken.php @@ -6,7 +6,7 @@ class ForeachToken implements ControlStructure { public string $token = "foreach"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { $uid = "$".uniqid("foreach_"); $context->iterationStack[] = [ diff --git a/src/ControlStructure/IfToken.php b/src/ControlStructure/IfToken.php index db22919..4ef0d6d 100644 --- a/src/ControlStructure/IfToken.php +++ b/src/ControlStructure/IfToken.php @@ -6,7 +6,7 @@ class IfToken implements ControlStructure { public string $token = "if"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { return ""; } diff --git a/src/ControlStructure/NamespaceToken.php b/src/ControlStructure/NamespaceToken.php index 157c757..d0b9cd7 100644 --- a/src/ControlStructure/NamespaceToken.php +++ b/src/ControlStructure/NamespaceToken.php @@ -6,7 +6,7 @@ class NamespaceToken implements ControlStructure { public string $token = "namespace"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { $context->namespace = $arguments; return ""; } diff --git a/src/ControlStructure/OrToken.php b/src/ControlStructure/OrToken.php index 955e8f3..862cbab 100644 --- a/src/ControlStructure/OrToken.php +++ b/src/ControlStructure/OrToken.php @@ -6,7 +6,7 @@ class OrToken implements ControlStructure { public string $token = "or"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { if ( empty($context->iterationStack) ) { throw new \LogicException("Token `or` was used outside of iterator. Make sure your `for` or `foreach` declaration are properly made."); } diff --git a/src/ControlStructure/RawToken.php b/src/ControlStructure/RawToken.php new file mode 100644 index 0000000..8834bca --- /dev/null +++ b/src/ControlStructure/RawToken.php @@ -0,0 +1,12 @@ +switchStack[] = true; return "useStack[] = $arguments; return ""; } diff --git a/src/ControlStructure/ViewToken.php b/src/ControlStructure/ViewToken.php index d4f70bf..ed079a8 100644 --- a/src/ControlStructure/ViewToken.php +++ b/src/ControlStructure/ViewToken.php @@ -6,7 +6,7 @@ class ViewToken implements ControlStructure { public string $token = "view"; - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments) { + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { #$context->switchStack[] = true; #return "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()); + } + + public function registerControlStructure(Compiler $compiler) : void + { +# @TODO -- a rewrite on the compiler has to be done to accept this kind of functionnality +# $compiler->registerControlStructure(new \Picea\ControlStructure\RawToken()); +# $compiler->registerControlStructure(new \Picea\ControlStructure\EndRawToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\NamespaceToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\UseToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\IfToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\ElseToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\ElseIfToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\EndIfToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\ForeachToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\ForToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\OrToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\EndforeachToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\EndforToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\SwitchToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\CaseToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\DefaultToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\BreakToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\EndCaseToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\EndSwitchToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken()); + $compiler->registerControlStructure(new \Picea\ControlStructure\EndSectionToken()); + } + + public function registerExtension(Compiler $compiler) : void + { + $compiler->registerExtension(new \Picea\Extension\JsonExtension()); + } +} diff --git a/src/Language/LanguageRegistration.php b/src/Language/LanguageRegistration.php new file mode 100644 index 0000000..e2fba89 --- /dev/null +++ b/src/Language/LanguageRegistration.php @@ -0,0 +1,14 @@ +response = $responseHtml; + $this->cache = $cache ?? new Caching\Memory(""); $this->context = $context ?? new Compiler\BaseContext(); - $this->compiler = $compiler ?: $this->instanciateCompiler(); + $this->compiler = $compiler ?? $this->instanciateCompiler(); + $this->languageRegistration = $languageRegistration ?? new Language\DefaultRegistrations(); + $this->builderTemplatePath = $builderTemplatePath ?? dirname(__FILE__) . static::DEFAULT_BUILDER_TEMPLATE; + } + + public function outputHtml(string $viewPath, array $variables) : ResponseInterface + { + if ( $this->response ?? false ) { + if ( false === $content = $this->cache->handle($viewPath) ) { + # if ( ) + } + + $source = $this->compileSource($source ?? "test"); + + $response = $this->response; + return $response("abc"); + } + + throw new \InvalidArgumentException("No \Psr\Http\Message\ResponseInterface closure provided. Please provide one using the constructor or assinging it to the class variable `responseHtml`."); } public function compileSource(string $source) : array @@ -27,11 +67,11 @@ class Picea public function compileFile(string $filePath) : array { if (! file_exists($filePath) ) { - throw new \InvalidArgumentException("File `$filePath` cannot be found or it is a permission problem"); + throw new \InvalidArgumentException("File `$filePath` cannot be found or there is a permission problem."); } if ( false === $fileContent = file_get_contents($filePath) ) { - throw new \ErrorException("Given file could not be opened `$filePath`. This could indicate a permission misconfiguration on your file or folder"); + throw new \ErrorException("Given file could not be opened `$filePath`. This could indicate a permission misconfiguration on your file or folder."); } $this->compiler->loadSourceCode($fileContent); @@ -64,64 +104,35 @@ class Picea } - public function instanciateCompiler(string $sourceCode = "") : Compiler + public function instanciateCompiler() : Compiler { - $compiler = new Compiler(); - $compiler->loadSourceCode($sourceCode); - - $this->registerSyntax($compiler) - ->registerControlStructure($compiler) - ->registerExtension($compiler); - - return $compiler; + return new Compiler($this->languageRegistration); } public function instanciateBuilder() : Builder { - $builder = new Builder(dirname(__FILE__) . "/Builder/ClassTemplate.php"); - return $builder; + return new Builder($this->builderTemplatePath); } - protected function registerSyntax(Compiler $compiler) : self + public function registerAll(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() ); - - return $this; + $this->registerSyntax($compiler); + $this->registerControlStructure($compiler); + $this->registerExtension($compiler); } - protected function registerControlStructure(Compiler $compiler) : self + public function registerSyntax(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\ElseToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\ElseIfToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\EndIfToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\ForeachToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\ForToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\OrToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\EndforeachToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\EndforToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\SwitchToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\CaseToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\DefaultToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\BreakToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\EndCaseToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\EndSwitchToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken()); - $compiler->registerControlStructure(new \Picea\ControlStructure\EndSectionToken()); - - return $this; + $this->languageRegistration->registerSyntax($compiler); } - protected function registerExtension(Compiler $compiler) : self + public function registerControlStructure(Compiler $compiler) : void { - $compiler->registerExtension(new \Picea\Extension\JsonExtension()); + $this->languageRegistration->registerControlStructure($compiler); + } - return $this; + public function registerExtension(Compiler $compiler) : void + { + $this->languageRegistration->registerExtension($compiler); } } diff --git a/src/Syntax/CommentToken.php b/src/Syntax/CommentToken.php index 07bb3eb..e895023 100644 --- a/src/Syntax/CommentToken.php +++ b/src/Syntax/CommentToken.php @@ -4,6 +4,8 @@ namespace Picea\Syntax; class CommentToken implements Syntax { + public string $token = "#"; + protected string $tokenOpen = "\{\#"; protected string $tokenClose = "\#\}";