Moved passing of errors to the parser itself

master
Richard van Velzen 2012-01-02 13:40:10 +01:00
parent acf176718d
commit d88047272e
4 changed files with 9 additions and 7 deletions

View File

@ -359,6 +359,7 @@ class calc extends lime_parser {
"'%'" => 'modulo operator (%)',
"'^'" => 'exponentiation operator (^)'
);
public $errors = array();
function reduce_0_stmt_1($tokens, &$result) {
// (0) stmt := exp
$result = reset($tokens);
@ -660,5 +661,5 @@ class calc extends lime_parser {
);
}
// Time: 0.12659001350403 seconds
// Memory: 2765212 bytes
// Time: 0.093108177185059 seconds
// Memory: 2768108 bytes

View File

@ -61,6 +61,7 @@ class parser extends lime_parser {
public $d = array(
);
public $errors = array();
function reduce_0_slist_1($tokens, &$result) {
// (0) slist := slist stmt ';'
$result = reset($tokens);
@ -148,5 +149,5 @@ class parser extends lime_parser {
);
}
// Time: 0.039383888244629 seconds
// Memory: 1514364 bytes
// Time: 0.032855033874512 seconds
// Memory: 1516852 bytes

View File

@ -1063,6 +1063,7 @@ class lime_language_php extends lime_language {
$code .= 'public $qi = ' . lime_export($ptab['qi'], true) . ';' . PHP_EOL;
$code .= 'public $i = ' . lime_export($ptab['i'], true) . ';' . PHP_EOL;
$code .= 'public $d = ' . lime_export($ptab['d'], true) . ';' . PHP_EOL;
$code .= 'public $errors = array();' . PHP_EOL;
$rc = array();
$method = array();

View File

@ -109,7 +109,6 @@ class parse_engine {
public $rule;
public $step;
public $descr;
public $errors = array();
/**
* @var boolean
*/
@ -132,7 +131,7 @@ class parse_engine {
public function reset() {
$this->accept = false;
$this->stack = new parse_stack($this->qi);
$this->errors = array();
$this->parser->errors = array();
}
private function enter_error_tolerant_state() {
@ -333,7 +332,7 @@ class parse_engine {
// get these before doing anything
$expected = $this->get_steps();
$this->errors[] = $this->descr($type, $semantic) . ' not expected, expected {' . implode(', ', $expected) . '}';
$this->parser->errors[] = $this->descr($type, $semantic) . ' not expected, expected {' . implode(', ', $expected) . '}';
if ($this->debug) echo "Possibilities before error fixing: {" . implode(', ', $expected) . "}\n";