Re: [SMARTY-DEV] Smarty compiler
| From: | Victor | Date: | Wed, 06 Nov 2002 20:51:52 +0000 |
| Subject: | Re: [SMARTY-DEV] Smarty compiler | ||
| References: | 1 2 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-326@lists.php.net to get a copy of this message | ||
> The overhead of regular expressions isn't such a big issue, it only does
> this at compile time. I see many drawbacks with a compiled solution,
> some already mentioned.
Maybe I've misunderstood it all, but who says you have to write a C-version
of smarty to do this?
Since the grammar in smarty is very simple, you can write a basic
token-based parser in PHP that does what we want, and doesn't _limit_ us
with what regexps can do. I don't care about the speed at all when
compiling, but I think we are limited by the way Smarty works now. Let's say
that you want to add the ability to use:
{$myvar + 5}
in a template. Right now you have to rewrite 5 complex regular expressions
to even allow simple math to not be completely cut off in this expression.
With a real compiler it wouldn't be that difficult at all to add this
feature (theoretically).
> One other would be the ability for everyone to
> contribute plugins/patches, etc. I'm sure there are a lot more php-savvy
> users than there are C-savvy, and we'd be cutting our own throats by
> limiting who can contribute.
Plugins would still be allowed in my way.
I have swept together a smarty-compatible (no, not at all ;) parser written
in PHP that generates a tree from a given source file. I guess I don't have
to tell you that it's far easier to use the tree to generate good PHP-code
compared to now.
Look at http://p22.ryd.student.liu.se/~yweb/pc/
I didn't write it, but one of my codevelopers.
// Victor
(PS, this is somewhat what the code looks like
$components["text"]["container"] = false;
$components["b"]["container"] = true;
$components["link"]["container"] = false;
$components["counter"]["container"] = false;
$data = "{{ Hi, this is \"a string\" and this is {b}something in bold. Not
that {this tag} doesn't get parsed.{/b}. This is a {link
url=\"http://www.google.com\"
title=\"link\"/} escaped in XML syntax (do we
want that? - it's possible anyway!) and this is a {counter cheat=100}
counter";
$parser = new Parser($components);
$tree = $parser->parse($data);
print_r($tree);
)