/**
  * display compiler error messages without dying
  * If parameter $args is empty it is a parser detected syntax error.
  * In this case the parser is called to obtain information about expected tokens.
  * If parameter $args contains a string this is used as error message
  *
  * @param  string   $args    individual error message or null
  * @param  string   $line    line-number
  * @param null|bool $tagline if true the line number of last tag
  *
  * @throws \SmartyCompilerException when an unexpected token is found
  */
 public function trigger_template_error($args = null, $line = null, $tagline = null)
 {
     $lex = $this->parser->lex;
     if ($tagline === true) {
         // get line number of Tag
         $line = $lex->taglineno;
     } elseif (!isset($line)) {
         // get template source line which has error
         $line = $lex->line;
     } else {
         $line = (int) $line;
     }
     if (in_array($this->template->source->type, array('eval', 'string'))) {
         $templateName = $this->template->source->type . ':' . trim(preg_replace('![\\t\\r\\n]+!', ' ', strlen($lex->data) > 40 ? substr($lex->data, 0, 40) . '...' : $lex->data));
     } else {
         $templateName = $this->template->source->type . ':' . $this->template->source->filepath;
     }
     //        $line += $this->trace_line_offset;
     $match = preg_split("/\n/", $lex->data);
     $error_text = 'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . '"  on line ' . ($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\\t\\r\\n]+!', ' ', $match[$line - 1])) . '" ';
     if (isset($args)) {
         // individual error message
         $error_text .= $args;
     } else {
         $expect = array();
         // expected token from parser
         $error_text .= ' - Unexpected "' . $lex->value . '"';
         if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) {
             foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
                 $exp_token = $this->parser->yyTokenName[$token];
                 if (isset($lex->smarty_token_names[$exp_token])) {
                     // token type from lexer
                     $expect[] = '"' . $lex->smarty_token_names[$exp_token] . '"';
                 } else {
                     // otherwise internal token name
                     $expect[] = $this->parser->yyTokenName[$token];
                 }
             }
             $error_text .= ', expected one of: ' . implode(' , ', $expect);
         }
     }
     $e = new SmartyCompilerException($error_text);
     $e->line = $line;
     $e->source = trim(preg_replace('![\\t\\r\\n]+!', ' ', $match[$line - 1]));
     $e->desc = $args;
     $e->template = $this->template->source->filepath;
     throw $e;
 }
 static function PrintTrace()
 {
     self::$yyTraceFILE = fopen('php://output', 'w');
     self::$yyTracePrompt = '<br>';
 }
 /**
  * display compiler error messages without dying
  * 
  * If parameter $args is empty it is a parser detected syntax error.
  * In this case the parser is called to obtain information about expected tokens.
  * 
  * If parameter $args contains a string this is used as error message
  * 
  * @todo output exact position of parse error in source line
  * @param  $args string individual error message or null
  */
 public function trigger_template_error($args = null)
 {
     $this->lex = Smarty_Internal_Templatelexer::instance();
     $this->parser = Smarty_Internal_Templateparser::instance();
     // get template source line which has error
     $line = $this->lex->line;
     if (isset($args)) {
         // $line--;
     }
     $match = preg_split("/\n/", $this->lex->data);
     $error_text = 'Syntax Error in template "' . $this->template->getTemplateFilepath() . '"  on line ' . $line . ' "' . $match[$line - 1] . '" ';
     if (isset($args)) {
         // individual error message
         $error_text .= $args;
     } else {
         // expected token from parser
         foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
             $exp_token = $this->parser->yyTokenName[$token];
             if (isset($this->lex->smarty_token_names[$exp_token])) {
                 // token type from lexer
                 $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
             } else {
                 // otherwise internal token name
                 $expect[] = $this->parser->yyTokenName[$token];
             }
         }
         // output parser error message
         $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
     }
     throw new Exception($error_text);
     // set error flag
     $this->compile_error = true;
 }