summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2011-11-10 21:53:52 +0100
committerKevin Chabowski <kevin@kch42.de>2011-11-10 21:53:52 +0100
commit370099b50befed22208ec88a621f633d032c780b (patch)
tree8ba30d9dad125d51f0968720b797bc0f362fd8f3
parentf66cf42d751e9000c2d9593f933668989c24d0a2 (diff)
downloadste-370099b50befed22208ec88a621f633d032c780b.tar.gz
ste-370099b50befed22208ec88a621f633d032c780b.tar.bz2
ste-370099b50befed22208ec88a621f633d032c780b.zip
Better error messages and a bugfix.
* If there are unbalanced open/close Tags in the template, STE will now tell you exactly which Tag was not closed properly (before: the first opening tag during the current balaning check). * It was not possible to access array fields dynamically, e.g. this: $foo[$bar] was not possible before. Now fixed.
-rw-r--r--stupid_template_engine.php16
1 files changed, 10 insertions, 6 deletions
diff --git a/stupid_template_engine.php b/stupid_template_engine.php
index e55023d..ba840f0 100644
--- a/stupid_template_engine.php
+++ b/stupid_template_engine.php
@@ -57,7 +57,7 @@ class VariableNode extends ASTNode
if($node instanceof TextNode)
return "\"" . escape_text($node->text) . "\"";
else if($node instanceof VariableNode)
- return $node->transcompile;
+ return $node->transcompile();
}, $af
)
). ']';
@@ -244,26 +244,30 @@ function mk_ast($code, $tpl, $err_off)
if($matches[1][0] != "/")
{
- $tags_open = 1;
$off = 0;
$last_tag_start = 0;
+ $tagstack = array(array($tag->name, $tag->offset));
while(preg_match("/\\<((?:\\s*)|(?:\\s*\\/\\s*))ste:([a-zA-Z0-9_]*)(?:\\s+(?:[a-zA-Z0-9_]+)=(?:(?:\"(?:.*?)(?<!\\\\)\")|(?:'(?:.*?)(?<!\\\\)')))*((?:\\s*)|(?:\\s*\\/\\s*))\\>/s", $code, $matches, PREG_OFFSET_CAPTURE, $off) > 0) /* RegEx from hell! Matches all <ste:> Tags. Opening, closing and self-closing ones. */
{
if(trim($matches[3][0]) != "/")
{
$closingtag = trim($matches[1][0]);
if($closingtag[0] == "/")
- $tags_open--;
+ {
+ list($matching_opentag, $mo_off) = array_pop($tagstack);
+ if($matching_opentag != $matches[2][0])
+ throw new ParseCompileError("Parse Error: Missing closing \"ste:$matching_opentag\"-Tag.", $tpl, $mo_off + $err_off);
+ }
else
- $tags_open++;
+ $tagstack[] = array($matches[2][0], $matches[0][1]);
}
$last_tag_start = $matches[0][1];
$off = $last_tag_start + strlen($matches[0][0]);
- if($tags_open == 0)
+ if(empty($tagstack))
break;
}
- if(($tags_open != 0) or ($tag->name != $matches[2][0]))
+ if((!empty($tagstack)) or ($tag->name != $matches[2][0]))
throw new ParseCompileError("Parse Error: Missing closing \"ste:" . $tag->name . "\"-Tag.", $tpl, $tag->offset);
if($tag->name == "rawtext")