コード例 #1
0
 static function init($template, $compiler, $file = '')
 {
     $lexer = new Haanga_Compiler_Lexer($template, $compiler);
     $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) {
         throw new Haanga_Compiler_Exception($e->getMessage() . ' on line ' . $lexer->getLine());
     }
     $parser->doParse(0, 0);
     return (array) $parser->body;
 }
コード例 #2
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_Lexer::init($code, $this, $file);
     $body = new Haanga_AST();
     if (isset($parsed[0]) && $parsed[0]['operation'] == 'base') {
         $this->Error("{% base is not supported on inlines %}");
     }
     $body = new Haanga_AST();
     $this->generate_op_code($parsed, $body);
     $this->file = $oldfile;
     return $body;
 }