4 * Smarty Internal Plugin Smarty Template Compiler Base
6 * This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
13 require_once("smarty_internal_parsetree.php");
16 * Class SmartyTemplateCompiler
18 class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase {
19 // array of vars which can be compiled in local scope
20 public $local_var = array();
24 public function __construct($lexer_class, $parser_class, $smarty)
26 $this->smarty = $smarty;
27 parent::__construct();
28 // get required plugins
29 $this->lexer_class = $lexer_class;
30 $this->parser_class = $parser_class;
34 * Methode to compile a Smarty template
36 * @param $_content template source
37 * @return bool true if compiling succeeded, false if it failed
39 protected function doCompile($_content)
41 /* here is where the compiling takes place. Smarty
42 tags in the templates are replaces with PHP code,
43 then written to compiled files. */
44 // init the lexer/parser to compile the template
45 $this->lex = new $this->lexer_class($_content, $this);
46 $this->parser = new $this->parser_class($this->lex, $this);
47 if (isset($this->smarty->_parserdebug)) $this->parser->PrintTrace();
48 // get tokens from lexer and parse them
49 while ($this->lex->yylex() && !$this->abort_and_recompile) {
50 if (isset($this->smarty->_parserdebug)) echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " . htmlentities($this->lex->value) . "</pre>";
51 $this->parser->doParse($this->lex->token, $this->lex->value);
54 if ($this->abort_and_recompile) {
58 // finish parsing process
59 $this->parser->doParse(0, 0);
60 // check for unclosed tags
61 if (count($this->_tag_stack) > 0) {
63 list($_open_tag, $_data) = array_pop($this->_tag_stack);
64 $this->trigger_template_error("unclosed {" . $_open_tag . "} tag");
66 // return compiled code
67 // return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
68 return $this->parser->retvalue;