Index: trunk/core/kernel/parser/construct_tags.php =================================================================== diff -u -r932 -r1339 --- trunk/core/kernel/parser/construct_tags.php (.../construct_tags.php) (revision 932) +++ trunk/core/kernel/parser/construct_tags.php (.../construct_tags.php) (revision 1339) @@ -1,7 +1,7 @@ CheckEndRecursion($tag)) { + if (defined('EXPERIMENTAL_PRE_PARSE')) { + if ($tag->Tag == 'endif') { + $this->Parser->AppendCompiledCode('}'); + } + } $this->RestoreSkipMode(); //Restoring original SkipMode return true; } + else { + if (defined('EXPERIMENTAL_PRE_PARSE')) { + $this->Parser->AppendCode($tag->GetCode()); + $this->Parser->AppendCompiledCode(join("\n", $tag->GetCode())); + } + } return false; } @@ -131,6 +142,9 @@ $this->Parser->Recurve($this); //Saving current tag in parser recursion array $this->Parser->SetBuffer(''); $this->BlockName = $this->NP['name']; //Stroing BlockName + if (isset($this->NP['args']) ) { + $this->Parser->Args = explode(',', $this->NP['args']); + } $this->StoreSkipMode(); $this->SuggestSkipMode(skip_tags); //We need to skip tags from now break; @@ -141,128 +155,72 @@ { if (parent::CheckRecursion($tag)) { //if endtag matches (SkipMode would be restored then) //Creating template from buffer + + if (defined('EXPERIMENTAL_PRE_PARSE') && isset($this->Application->PreParsedBlocks[$this->BlockName])) return true; + $template = new Template(); $template->SetBody($this->Parser->GetBuffer()); $templates_cache =& $this->Application->recallObject('TemplatesCache'); //Adding template to application' cache - $templates_cache->SetTemplate($this->BlockName,$template); + $templates_cache->SetTemplate($this->BlockName, $template, $this->Parser->TemplateName); + + if (defined('EXPERIMENTAL_PRE_PARSE')) { + $code = $this->Parser->GetCode(); + array_unshift($code, '$o = \'\';'); + array_unshift($code, '$application =& kApplication::Instance();'); + array_unshift($code, 'extract($params);'); + + $code[] = 'return $o;'; + + global $debugger; + + $dbg_functions = $this->Application->isDebugMode() && dbg_ConstOn('DBG_PRINT_PREPARSED'); + + $f_body = ''; + //echo "
";
+				$l = 0;
+				if ($dbg_functions) echo "function ".$this->BlockName." {
"; + foreach ($code as $line) { + $l++; + if ($dbg_functions) { + echo $l.' '.$debugger->highlightString(trim($line)."\n", true); + } + $f_body .= rtrim($line, "\n")."\n"; + } + if ($dbg_functions) echo "} // function ".$this->BlockName." end

"; + //echo "
"; + + //caching func body + $this->Application->PreParsedCache[$this->BlockName] = $f_body; + + $func = create_function('$params', $f_body); + $this->Application->PreParsedBlocks[$this->BlockName] = $func; + $this->Parser->Args = null; + $this->Parser->ResetCode(); + + $this->Parser->AppendCompiledFunction($this->BlockName, $f_body); + } return true; } else { // append the tag itself to the block - while in block, we check every tag to be 'blockend' // if it is not - we need to append the tag to the buffer, which we'll parse later in 'parse_block' if ($tag->Tag != 'block') { - $this->Parser->AppendOutput($tag->GetFullTag()); + if (defined('EXPERIMENTAL_PRE_PARSE') && isset($this->Application->PreParsedBlocks[$this->BlockName])) { + return; + } + if (defined('EXPERIMENTAL_PRE_PARSE')) { + // $this->Parser->AppendCode($tag->GetCode()); + } + else { + $this->Parser->AppendOutput($tag->GetFullTag()); + } } return false; } } } -class XMLTag extends ConstructTag { - var $BlockName = ''; - - function Process() - { - switch ($this->Tag) { - case 'xml': - $this->SetStopTag('xmlend'); //This recursion level should end when 'blockend' is found - $this->Parser->Recurve($this); //Saving current tag in parser recursion array - $this->BlockName = $this->NP['name']; //Storing BlockName - $this->StoreSkipMode(); - $this->SuggestSkipMode(skip_tags); //We need to skip tags from now - $this->Parser->SetBuffer(''); - break; - } - } - - function CheckRecursion(&$tag) - { - if (parent::CheckRecursion($tag)) { //if endtag matches (SkipMode would be restored then) - //Creating template from buffer - $template = new Template(); - $template->SetBody($this->Parser->GetBuffer()); - - //Adding template to application' cache - $this->Parser->Application->Templates->SetTemplate( - $this->BlockName, - $template - ); - $this->Parser->ParseXML($this->BlockName, $this->NP); - return true; - } - else { - if ($tag->Tag != 'xml') { - $this->Parser->AppendOutput($tag->GetFullTag()); - } - return false; - } - } -} - -class IterateTag extends ConstructTag { - - function Process() - { - switch ($this->Tag) { - case 'iterate': - $this->SetStopTag('enditerate'); //This recursion level should end when 'blockend' is found - $this->Parser->Recurve($this); //Saving current tag in parser recursion array - $this->BlockName = $this->NP['block']; //Storing BlockName - $this->StoreSkipMode(); - $this->SuggestSkipMode(skip_tags); //We need to skip tags from now - $this->Parser->SetBuffer(''); - break; - } - } - - function CheckRecursion(&$tag) - { - if (parent::CheckRecursion($tag)) { //if endtag matches (SkipMode would be restored then) - //Creating template from buffer - $template = new Template(); - $template->SetBody($this->Parser->GetBuffer()); - - //Adding template to application' cache - $this->Parser->Application->Templates->SetTemplate( - $this->BlockName, - $template - ); - $this->Parser->ParseXML($this->BlockName, $this->NP); - return true; - } - else { - if ($tag->Tag != 'xml') { - $this->Parser->AppendOutput($tag->GetFullTag()); - } - return false; - } - } - -} - -global $suite; -if (isset($suite)) { - class TestConstructTag extends TestCase { - - function testIFLogic() - { - global $application; - - $tag =& new ConstructTag('m:if prefix="m" function="true"', $application->Parser); - $tag->GetLogic(); - $this->assertTrue($tag->Logic); - - - $tag =& new ConstructTag('m:if prefix="m" function="false"', $application->Parser); - $tag->GetLogic(); - $this->assertFalse($tag->Logic); - } - - } - $suite->addTest(new TestSuite("TestConstructTag")); -} - ?> \ No newline at end of file