- First task of v2 done, tokens can now have unlimited options attached to it

This commit is contained in:
mcndave committed 2023-02-02 16:46:46 +00:00
1 parent afeb8789b5
commit acd9f8c72e
8 files changed
+82 -41

No files matched your search

+21 -9
View File
@@ -2,6 +2,7 @@
namespace Picea;
use Picea\Exception\RegisterExtensionToken;
use Picea\Extension\FunctionExtension;
use Picea\Language\LanguageRegistration;
@@ -47,18 +48,19 @@ class Compiler
$matches[2] = trim($matches[2]);
list($token, $arguments) = array_pad(array_filter(explode(' ', $matches[2], 2), 'strlen'), 2, null);
$token = strtolower(trim($token));
$tokenName = explode('.', $token, 2)[0];
# @TODO Refractor this parts to allows registration to the tag's name
if ( $this->tagList[$token] ?? false ) {
return $this->tagList[$token]->parse($context, $arguments, $token);
if ( $this->tagList[$tokenName] ?? false ) {
return $this->tagList[$tokenName]->parse($context, $arguments, $token);
}
elseif ( $this->extensionList[$token] ?? false ) {
return $this->extensionList[$token]->parse($context, $arguments, $token);
elseif ( $this->extensionList[$tokenName] ?? false ) {
return $this->extensionList[$tokenName]->parse($context, $arguments, $token);
}
else {
throw new \LogicException("Impossible to find token `$token` declared in `{$matches[2]}`. Perhapse you forgot to add a custom token to Picea's engine ?");
throw new \LogicException("Impossible to find token `$tokenName` declared in `{$matches[2]}`. Perhapse you forgot to add a custom token to Picea's engine ?");
}
}, $this->sourceCode);
@@ -87,6 +89,10 @@ class Compiler
public function registerControlStructure(ControlStructure\ControlStructure $controlStructureObject) : self
{
foreach($controlStructureObject->tokens ?? (array) ( $controlStructureObject->token ?? [] ) as $token) {
if ( strpos($token, '.') !== false ) {
throw new RegisterExtensionToken(sprintf("Could not register token '%s' from control structure '%s' in this version. Options are now delt by extensions themselve instead.", $token, $controlStructureObject::class));
}
$this->tagList[strtolower($token)] = $controlStructureObject;
}
@@ -98,6 +104,10 @@ class Compiler
$tokens = $extension->tokens ?? (array) ( $extension->token ?? [] );
foreach($tokens as $token) {
if ( strpos($token, '.') !== false ) {
throw new RegisterExtensionToken(sprintf("Could not register token '%s' from extension '%s' in this version. Options are now delt by extensions themselve instead.", $token, $extension::class));
}
$this->extensionList[strtolower($token)] = $extension;
}
@@ -129,13 +139,15 @@ class Compiler
public function getExtensionFromToken(string $name) : Extension\Extension
{
if ( ! isset($this->extensionList[$name]) ) {
$tokenName = explode('.', $name)[0];
if ( ! isset($this->extensionList[$tokenName]) ) {
throw new \InvalidArgumentException(<<<MSG
Requested extension from token `$name` could not be found from loaded Picea compiler's extension.
Requested extension from token `$tokenName` could not be found from loaded Picea compiler's extension.
MSG);
}
return $this->extensionList[$name];
return $this->extensionList[$tokenName];
}
public function exportFunctions() : void