mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Catch lexer errors in throwOnError=0 mode
This commit is contained in:
parent
ea47b6e0d6
commit
c5e0c3d7e2
@ -132,9 +132,21 @@ abstract class ParserAbstract implements Parser
|
||||
* unable to recover from an error).
|
||||
*/
|
||||
public function parse($code) {
|
||||
$this->lexer->startLexing($code);
|
||||
$this->errors = array();
|
||||
|
||||
// Initialize the lexer
|
||||
try {
|
||||
$this->lexer->startLexing($code);
|
||||
} catch (Error $e) {
|
||||
$this->errors[] = $e;
|
||||
if ($this->throwOnError) {
|
||||
throw $e;
|
||||
} else {
|
||||
// Currently can't recover from lexer errors
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// We start off with no lookahead-token
|
||||
$symbol = self::SYMBOL_NONE;
|
||||
|
||||
|
25
test/code/parser/errorHandling/lexerErrors.test
Normal file
25
test/code/parser/errorHandling/lexerErrors.test
Normal file
@ -0,0 +1,25 @@
|
||||
Lexer errors
|
||||
-----
|
||||
<?php
|
||||
|
||||
$a = 42;
|
||||
/*
|
||||
$b = 24;
|
||||
-----
|
||||
Unterminated comment on line 4
|
||||
-----
|
||||
<?php
|
||||
|
||||
$a = 42;
|
||||
@@{ "\1" }@@
|
||||
$b = 24;
|
||||
-----
|
||||
Unexpected character "@@{ "\1" }@@" (ASCII 1) on unknown line
|
||||
-----
|
||||
<?php
|
||||
|
||||
$a = 42;
|
||||
@@{ "\0" }@@
|
||||
$b = 24;
|
||||
-----
|
||||
Unexpected null byte on unknown line
|
Loading…
Reference in New Issue
Block a user