Beispiel #1
0
 /**
  *  Compile the $code and return the "opcodes"
  *  (the Abstract syntax tree).
  *
  *  @param string $code Template content
  *  @param string $file File path (used for erro reporting)
  *
  *  @return Haanga_AST
  *
  */
 public function getOpCodes($code, $file)
 {
     $oldfile = $this->file;
     $this->file = $file;
     $parsed = Haanga_Compiler_Tokenizer::init($code, $this, $file);
     $body = new Haanga_AST();
     if (isset($parsed[0]) && $parsed[0]['operation'] == 'base') {
         throw new Exception("{% base is not supported on inlines %}");
     }
     $body = new Haanga_AST();
     $this->generate_op_code($parsed, $body);
     $this->file = $oldfile;
     return $body;
 }
Beispiel #2
0
 static function init($template, $compiler, $file = '')
 {
     $lexer = new Haanga_Compiler_Tokenizer($template, $compiler, $file);
     $parser = new Haanga_Compiler_Parser($lexer, $file);
     $parser->compiler = $compiler;
     try {
         for ($i = 0;; $i++) {
             if (!$lexer->yylex()) {
                 break;
             }
             $parser->doParse($lexer->token, $lexer->value);
         }
     } catch (Exception $e) {
         /* destroy the parser */
         try {
             $parser->doParse(0, 0);
         } catch (Exception $y) {
         }
         throw $e;
         /* re-throw exception */
     }
     $parser->doParse(0, 0);
     return (array) $parser->body;
 }