diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-10-20 14:15:53 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-10-20 14:15:53 +0200 |
commit | a68a8f7ccf60fa17fc5aa379ac191f555668fe25 (patch) | |
tree | 2fe685ff250f1ee890386a8f2da39e20b7f5a809 /stupid_template_engine.php | |
parent | 3ecf03caace8e6b05946f2f7983439bd9cb40530 (diff) | |
download | ste-a68a8f7ccf60fa17fc5aa379ac191f555668fe25.tar.gz ste-a68a8f7ccf60fa17fc5aa379ac191f555668fe25.tar.bz2 ste-a68a8f7ccf60fa17fc5aa379ac191f555668fe25.zip |
Some smaller fixes. Parser seems to work now.
* Parser::next fixed
* Parser::search_multi fixes (wrong variable, wrong offset added)
* fixed shortifopen and shortcompopen overwriting parser result.
Diffstat (limited to 'stupid_template_engine.php')
-rw-r--r-- | stupid_template_engine.php | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/stupid_template_engine.php b/stupid_template_engine.php index bef1fac..2c8a5ac 100644 --- a/stupid_template_engine.php +++ b/stupid_template_engine.php @@ -129,7 +129,7 @@ class Parser { throw new \InvalidArgumentException("\$n must be > 0"); } $c = mb_substr($this->text, $this->off, $n); - $this->off = max($this->off + $n, $this->len); + $this->off = min($this->off + $n, $this->len); return $c; } @@ -151,7 +151,7 @@ class Parser { $minoff = $this->len; $which = NULL; - foreach($needle as $key => $needle) { + foreach($needles as $key => $needle) { if(($off = $this->search_off($needle)) === false) { continue; } @@ -162,7 +162,7 @@ class Parser { } } - $this->off = $minoff + (($which === NULL) ? 0 : mb_strlen($which)); + $this->off = $minoff + (($which === NULL) ? 0 : mb_strlen((string) $needles[$which])); return array($which, $minoff, mb_substr($this->text, $oldoff, $minoff - $oldoff), $oldoff); } @@ -301,12 +301,12 @@ class Parser { } break; case "shortifopen": - $elems = $this->parse_short("?{", $off); - if(count($elems) != 3) { + $shortelems = $this->parse_short("?{", $off); + if(count($shortelems) != 3) { throw new ParseCompileError("A short if tag must have the form ?{..|..|..}", $this->name, $off); } - list($cond, $then, $else) = $elems; + list($cond, $then, $else) = $shortelems; $thentag = new TagNode($this->name, $off); $thentag->name = "then"; $thentag->sub = $then; @@ -324,13 +324,13 @@ class Parser { $astlist[] = $iftag; break; case "shortcompopen": - $elems = $this->parse_short("~{", $off); - if(count($elems) != 3) { + $shortelems = $this->parse_short("~{", $off); + if(count($shortelems) != 3) { throw new ParseCompileError("A short comparasion tag must have the form ~{..|..|..}", $this->name, $off); } // TODO: What will happen, if a tag was in one of the elements? - list($a, $op, $b) = $elems; + list($a, $op, $b) = $shortelems; $cmptag = new TagNode($this->name, $off); $cmptag->name = "cmp"; $cmptag->params["text_a"] = $a; |