[prev in list] [next in list] [prev in thread] [next in thread] 

List:       smarty-dev
Subject:    Re: [SMARTY-DEV] nested ...templates?
From:       boots <jayboots () yahoo ! com>
Date:       2003-12-15 5:14:03
[Download RAW message or body]

--- Andrei Zmievski <andrei@gravitonic.com> wrote:
> On Fri, 12 Dec 2003, Monte Ohrt wrote:
> > We can't do recursion with the tokenizer (unrolling bracket pairs),
> > so these kind of things are out of the question. Maybe at some
point
> > we can move away from using preg_* for the parser, but that isn't
> > too practical
> > at the moment.
> 
> Unless you write a custom C extension to parse the template, preg_*
> is your best bet. I can't imagine how much slower a parser written in
> pure PHP (without preg_*) would be.

Very true.

Here is a very simple modification to the regex which gives a different
precedence for {** **} as per Monte's suggestion. Actually, this change
should allow for any number of levels (eg. {*** ***} not that it really
means much. The caveat is that this won't work properly unless the
"higher-order" comments wrap the "lower-order" comments, so a better
implementation would be welcome.

Basically, instead of checking for {* .. *} this checks for {(*+) .. 
\1}, if you see my meaning.

xo boots

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
["comment.patch" (text/plain)]

Index: libs/Smarty_Compiler.class.php
===================================================================
RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
retrieving revision 1.303
diff -u -r1.303 Smarty_Compiler.class.php
--- libs/Smarty_Compiler.class.php	11 Dec 2003 19:52:38 -0000	1.303
+++ libs/Smarty_Compiler.class.php	15 Dec 2003 05:10:15 -0000
@@ -255,8 +255,8 @@
         }
 
         /* Annihilate the comments. */
-        $source_content = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se",
-                                        "'\\1*'.str_repeat(\"\n\", \
substr_count('\\2', \"\n\")) .'*\\3'", +        $source_content = \
preg_replace("!({$ldq})(\*+)(.*?)\\2({$rdq})!se", +                                   \
"'\\1*'.str_repeat(\"\n\", substr_count('\\3', \"\n\")) .'*\\4'",  $source_content);
 
         /* Pull out the literal blocks. */



-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic