3 * Smarty Internal Plugin Smarty Template Compiler Base
5 * This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
15 include ("smarty_internal_parsetree.php");
18 * Class SmartyTemplateCompiler
21 * @subpackage Compiler
23 class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase {
61 * array of vars which can be compiled in local scope
65 public $local_var = array();
70 * @param string $lexer_class class name
71 * @param string $parser_class class name
72 * @param Smarty $smarty global instance
74 public function __construct($lexer_class, $parser_class, $smarty)
76 $this->smarty = $smarty;
77 parent::__construct();
78 // get required plugins
79 $this->lexer_class = $lexer_class;
80 $this->parser_class = $parser_class;
84 * Methode to compile a Smarty template
86 * @param mixed $_content template source
87 * @return bool true if compiling succeeded, false if it failed
89 protected function doCompile($_content)
91 /* here is where the compiling takes place. Smarty
92 tags in the templates are replaces with PHP code,
93 then written to compiled files. */
94 // init the lexer/parser to compile the template
95 $this->lex = new $this->lexer_class($_content, $this);
96 $this->parser = new $this->parser_class($this->lex, $this);
97 if ($this->smarty->_parserdebug)
98 $this->parser->PrintTrace();
99 // get tokens from lexer and parse them
100 while ($this->lex->yylex() && !$this->abort_and_recompile) {
101 if ($this->smarty->_parserdebug) {
102 echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " .
103 htmlentities($this->lex->value) . "</pre>";
105 $this->parser->doParse($this->lex->token, $this->lex->value);
108 if ($this->abort_and_recompile) {
109 // exit here on abort
112 // finish parsing process
113 $this->parser->doParse(0, 0);
114 // check for unclosed tags
115 if (count($this->_tag_stack) > 0) {
117 list($openTag, $_data) = array_pop($this->_tag_stack);
118 $this->trigger_template_error("unclosed {" . $openTag . "} tag");
120 // return compiled code
121 // return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
122 return $this->parser->retvalue;