Exemplo n.º 1
0
 function parse($input)
 {
     try {
         global $LINE;
         $tok = new Tokeniser($input);
         $parser = new parse_engine($this->_haml);
         $parser->reset();
         $tokens = $tok->get_all_tokens();
         $tokens = array_merge(array(new Token('INDENT', 0)), $tokens);
         foreach ($tokens as $t) {
             $LINE = $this->_line = $t->line();
             $parser->eat($t->type(), $t->value());
         }
         $parser->eat_eof();
         return true;
     } catch (parse_error $e) {
         $token = $value = '';
         preg_match('/\\((.*?)\\)\\((.*?)\\)/', $e->getMessage(), $matches);
         if ($matches) {
             $token = $matches[1];
             $value = $matches[2];
             $message = "Parse error: unexpected {$token} ('{$value}')";
         } else {
             $message = $e->getMessage();
         }
         $message .= " at line {$this->_line}";
         if ($this->_file) {
             $message .= " in {$this->_file}";
         }
         $message .= "\n";
         throw new FammelParseException($message, $this->_line, $token, $value);
     }
 }
Exemplo n.º 2
0
<?php

include_once "../../parse_engine.php";
include_once "error.class";
$parser = new parse_engine(new parser());
//$parser->debug = true;
$tokens = array(array('ZZ', 'zz'), array('ZZ', 'zz'), array('YY', 'yy'), ';', array('ZZ', 'zz'), array('ZZ', 'zz'), ';');
foreach ($tokens as $token) {
    if (is_array($token)) {
        $parser->eat($token[0], $token[1]);
    } else {
        $parser->eat("'{$token}'", $token);
    }
}
$parser->eat_eof();
var_dump($parser->semantic);
var_dump($parser->errors);