Exemple #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);
     }
 }
Exemple #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);
            fatal_error("Unknown option: {$arg}");
    }
}
if ($name == "") {
    fatal_error("--name missing");
}
if ($input_file == "") {
    fatal_error("--input-file missing");
}
if ($output_dir == "") {
    fatal_error("--output-dir missing");
}
if (($data = file_get_contents($input_file)) === FALSE) {
    fatal_error("Failed to read input file");
}
if (!tokenize($data, $tokens)) {
    fatal_error("Failed to tokenize");
}
$parser = new parse_engine(new ProtoParser());
try {
    foreach ($tokens as $token) {
        $parser->eat($token[0], $token[1]);
    }
    $parser->eat_eof();
} catch (parse_error $e) {
    fatal_error("{$input_file}: Parse error: " . $e->getMessage());
}
$data = generate_header($name, $parser->semantic["directives"], $parser->semantic["messages"]);
if (file_put_contents("{$output_dir}/{$name}.h", $data) === NULL) {
    fatal_error("{$input_file}: Failed to write .h file");
}