diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2020-09-15 22:21:04 +0200 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2020-09-15 22:21:04 +0200 |
commit | 71176122872e7d200167cd77d48ed30fda95b3ae (patch) | |
tree | 99a5f37ab70d66a5fa222fd0e114899751aa662b /src/ste | |
parent | 76a1e915e0eea54b9b9a01d921efa6f9edffb3a8 (diff) | |
download | ste-71176122872e7d200167cd77d48ed30fda95b3ae.tar.gz ste-71176122872e7d200167cd77d48ed30fda95b3ae.tar.bz2 ste-71176122872e7d200167cd77d48ed30fda95b3ae.zip |
Add some unit tests for the parser
So far only testing success, we should also test failing parse inputs.
Diffstat (limited to 'src/ste')
-rw-r--r-- | src/ste/Parser.php | 9 | ||||
-rw-r--r-- | src/ste/TagNode.php | 6 | ||||
-rw-r--r-- | src/ste/VariableNode.php | 16 |
3 files changed, 26 insertions, 5 deletions
diff --git a/src/ste/Parser.php b/src/ste/Parser.php index a588203..a2f966c 100644 --- a/src/ste/Parser.php +++ b/src/ste/Parser.php @@ -443,12 +443,15 @@ class Parser */ private function parse_var(int $openedat, bool $curly): VariableNode { - $varnode = new VariableNode($this->name, $openedat); - $varnode->name = $this->get_name(); + $varname = $this->get_name(); + + $arrayfields = []; if (!$this->eof()) { - $varnode->arrayfields = $this->parse_array(); + $arrayfields = $this->parse_array(); } + $varnode = new VariableNode($this->name, $openedat, $varname, $arrayfields); + if ($curly && ($this->next() != "}")) { throw new ParseCompileError("Unclosed '\${'", $this->name, $openedat); } diff --git a/src/ste/TagNode.php b/src/ste/TagNode.php index 4adcad8..ce713c0 100644 --- a/src/ste/TagNode.php +++ b/src/ste/TagNode.php @@ -17,10 +17,14 @@ class TagNode extends ASTNode * @param string $tpl * @param int $off * @param string $name + * @param ASTNode[][] $params + * @param ASTNode[] $sub */ - public function __construct(string $tpl, int $off, string $name = "") + public function __construct(string $tpl, int $off, string $name = "", array $params = [], array $sub = []) { parent::__construct($tpl, $off); $this->name = $name; + $this->params = $params; + $this->sub = $sub; } } diff --git a/src/ste/VariableNode.php b/src/ste/VariableNode.php index f5a0b26..cdffc3f 100644 --- a/src/ste/VariableNode.php +++ b/src/ste/VariableNode.php @@ -8,7 +8,21 @@ class VariableNode extends ASTNode public $name; /** @var ASTNode[][] */ - public $arrayfields = []; + public $arrayfields; + + /** + * @param string $tpl + * @param int $off + * @param string $name + * @param ASTNode[][] $arrayfields + */ + public function __construct(string $tpl, int $off, string $name, array $arrayfields) + { + parent::__construct($tpl, $off); + + $this->name = $name; + $this->arrayfields = $arrayfields; + } /** * @return string |