Re: [SMARTY-DEV] compiler-block functions (again, sorry)
| From: | Andrei Zmievski | Date: | Fri, 10 Jan 2003 17:07:08 +0000 |
| Subject: | Re: [SMARTY-DEV] compiler-block functions (again, sorry) | ||
| References: | 1 2 3 4 5 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-520@lists.php.net to get a copy of this message | ||
Sorry, I won't be able to intelligently comment on this until after I
get back from my trip, on the 19th..
On Fri, 10 Jan 2003, M Mohr wrote:
> On Fri, Jan 10, 2003 at 11:15:30AM -0500, Andrei Zmievski wrote:
> > On Fri, 10 Jan 2003, M Mohr wrote:
> > > On Fri, Jan 10, 2003 at 10:00:38AM -0500, Andrei Zmievski wrote:
> > > > I would do it this way, but rather provide a stack, similar to block
> > > > functions, so that you can inspect it to see what functions enclose
> > > > youru current one.
> > >
> > > yes. the stack is also useful to be able to acces the $tag_args, that
> > > where passed to the block when opening it, on the closing side.
> > >
> > > i just wanted to make it as simple as possible in the first place. i
> > > thougt if i minimize the implications that come with it, i raise the
> > > chance you accept my patch :)
> > >
> > > for now the compiler-plugins have to maintain their own stack(s).
> > > i will have a look, if i could bring this inside
> > > _compile_compiler_tag().
> >
> > Just copy it from block functions, omitting irrelevant details, of
> > course.
>
> hmm, i don't know. block-functions do the stack-handling at runtime
> not at compile. furthermore, the compiler does not know, if
> $tag_command is an opening tag or a short tag. it just knows it if it
> encounters the corresponding closing tag, but then it is too late.
>
> i didn't find a way to do this better without becoming incompatible
> with existing compiler-functions. so i solved this with some kind of
> optimistic approach: popping all tags, until a matching tag is found.
> normally all popped tags were short-tags, or there is an error in the
> template.
>
> i think the diff is still concise:
>
> RCS file: /repository/smarty/Smarty_Compiler.class.php,v
> retrieving revision 1.145
> diff -r1.145 Smarty_Compiler.class.php
> 50a51,52
> > var $_compiler_tag_stack = array(); // keeps track of compiler-functions'
> > tag_args
> >
> 480a483,494
> > /* check if we were called closing ore opening */
> > if ($tag_command{0} != '/') {
> > /* handle opening tag */
> >
> > /* put this in an object-property so that plugin-functions can ask for it */
> > $this->_compiler_tag_start = true;
> > } else {
> > /* handle closing tag */
> > $this->_compiler_tag_start = false;
> > $tag_command = substr($tag_command, 1);
> > }
> >
> 517a532,552
> > if ($this->_compiler_tag_start) {
> > /* handle opening tag */
> > array_push($this->_compiler_tag_stack, array($tag_command, $tag_args));
> > } else {
> > /* handle closing tag */
> >
> > /* we pop all tags, till we find $tag_command. this pops all opening tags,
> > that did not
> > have a corresponding closing tag: short tags or errorneous nested tags
> > */
> > $tag_found = false;
> > while (list($found_tag_command, $tag_args) =
> > array_pop($this->_compiler_tag_stack)) {
> > if ($tag_command==$found_tag_command) {
> > $tag_found = true;
> > break;
> > }
> > }
> > if (!$tag_found) {
> > $this->_syntax_error("missing opening tag
> > \"$tag_command\"", E_USER_ERROR, __FILE__, __LINE__);
> > }
> > }
> >
>
>
> any thoughts/comments?
>
> > -Andrei
> > http://www.gravitonic.com/
>
> regards
> messju
-Andrei http://www.gravitonic.com/
"The human brain is a wonderful thing. It starts working the moment you
are born, and never stops until you stand up to speak in public. "
-- Sir George Jessel