summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-01-08 21:53:41 +0100
committerKevin Chabowski <kevin@kch42.de>2012-01-08 21:53:41 +0100
commit5dae0519c2aef646938e5391cc28632ce0b2fc79 (patch)
treeacb19ec4bc9be734d322cf08ffe716fcb77b908d
parent1ef055e9879567e6f53c829ccdd88a4388811386 (diff)
downloadste-5dae0519c2aef646938e5391cc28632ce0b2fc79.tar.gz
ste-5dae0519c2aef646938e5391cc28632ce0b2fc79.tar.bz2
ste-5dae0519c2aef646938e5391cc28632ce0b2fc79.zip
ste:comment and ste:rawtext are now handled much cleaner.
-rw-r--r--stupid_template_engine.php34
1 files changed, 25 insertions, 9 deletions
diff --git a/stupid_template_engine.php b/stupid_template_engine.php
index 106b1be..fc22a81 100644
--- a/stupid_template_engine.php
+++ b/stupid_template_engine.php
@@ -244,6 +244,30 @@ function mk_ast($code, $tpl, $err_off)
if($matches[1][0] != "/")
{
+ /* Handling ste:comment pseudotag */
+ if($tag->name == "comment")
+ {
+ if(preg_match("/\\<\\s*\\/\\s*ste:comment\\s*\\>/s", $code, $matches, PREG_OFFSET_CAPTURE) == 0)
+ return array(); /* Treat the whole code as comment */
+ $comment_end = $matches[0][1] + strlen($matches[0][0]);
+ return mk_ast(substr($code, $comment_end), $tpl, $err_off + $comment_end);
+ }
+
+ /* Handling ste:rawtext pseudotag */
+ if($tag->name == "rawtext")
+ {
+ $tag = new TextNode($tpl, $tag->offset);
+ if(preg_match("/\\<\\s*\\/\\s*ste:rawtext\\s*\\>/s", $code, $matches, PREG_OFFSET_CAPTURE) == 0)
+ {
+ /* Treat the rest of the code as rawtext */
+ $tag->text = $code;
+ return array($tag);
+ }
+ $tag->text = strpos($code, 0, $matches[0][1]);
+ $rawtext_end = $matches[0][1] + strlen($matches[0][0]);
+ return array_merge(array($tag), mk_ast(substr($code, $rawtext_end), $tpl, $err_off + $rawtext_end));
+ }
+
$off = 0;
$last_tag_start = 0;
$tagstack = array(array($tag->name, $tag->offset));
@@ -270,15 +294,7 @@ function mk_ast($code, $tpl, $err_off)
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")
- {
- $tag = new TextNode($tpl, $err_off);
- $tag->text = substr($code, 0, $last_tag_start);
- }
- else if($tag->name == "comment")
- $tag = NULL; /* All this work to remove a comment ... */
- else
- $tag->sub = mk_ast(substr($code, 0, $last_tag_start), $tpl, $err_off);
+ $tag->sub = mk_ast(substr($code, 0, $last_tag_start), $tpl, $err_off);
$code = substr($code, $off);
$err_off += $off;
}