diff options
author | Kevin Chabowski <kevin@kch42.de> | 2014-05-18 00:25:49 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2014-05-18 00:25:49 +0200 |
commit | fad93506cd56b976d1413ed5adef87701df715bd (patch) | |
tree | dd4f0fca57633dcfeb66622b4c20497090bfff16 /VariableNode.php | |
parent | a77a2ec58947f5fc7cb4023db3b8f8298e2f01f2 (diff) | |
download | ste-fad93506cd56b976d1413ed5adef87701df715bd.tar.gz ste-fad93506cd56b976d1413ed5adef87701df715bd.tar.bz2 ste-fad93506cd56b976d1413ed5adef87701df715bd.zip |
One file per class and new namespace.
We should be able to use a PSR4 autoloader (like composer's) now. ste.php
is still there as a fallback for old applications.
Diffstat (limited to 'VariableNode.php')
-rw-r--r-- | VariableNode.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/VariableNode.php b/VariableNode.php new file mode 100644 index 0000000..b312e81 --- /dev/null +++ b/VariableNode.php @@ -0,0 +1,25 @@ +<?php + +namespace kch42\ste; + +class VariableNode extends ASTNode { + public $name; + public $arrayfields = array(); + public function transcompile() { + $varaccess = '@$ste->vars[' . (is_numeric($this->name) ? $this->name : '"' . Misc::escape_text($this->name) . '"'). ']'; + foreach($this->arrayfields as $af) { + if((count($af) == 1) and ($af[0] instanceof TextNode) and is_numeric($af[0]->text)) { + $varaccess .= '[' . $af->text . ']'; + } else { + $varaccess .= '[' . implode(".", array_map(function($node) { + if($node instanceof TextNode) { + return "\"" . Misc::escape_text($node->text) . "\""; + } else if($node instanceof VariableNode) { + return $node->transcompile(); + } + }, $af)). ']'; + } + } + return $varaccess; + } +} |