Re: [SMARTY-DEV] compiler-block functions (again, sorry)

From: Date: Fri, 10 Jan 2003 16:45:50 +0000
Subject: Re: [SMARTY-DEV] compiler-block functions (again, sorry)
References: 1 2 3 4  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-519@lists.php.net to get a copy of this message
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

« previous php.smarty.dev (#519) next »