1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-30 04:19:30 +01:00

Add column info to EOF errors

EOF errors are now located one past the end of the file.
This commit is contained in:
Nikita Popov 2015-04-27 15:33:51 +02:00
parent 55b2ead967
commit a35c2a2067
3 changed files with 18 additions and 7 deletions

View File

@ -121,7 +121,7 @@ class Error extends \RuntimeException
}
private function toColumn($code, $pos) {
if ($pos >= strlen($code)) {
if ($pos > strlen($code)) {
throw new \RuntimeException('Invalid position information');
}

View File

@ -123,8 +123,13 @@ class Lexer
$startAttributes = array();
$endAttributes = array();
while (isset($this->tokens[++$this->pos])) {
$token = $this->tokens[$this->pos];
while (1) {
if (isset($this->tokens[++$this->pos])) {
$token = $this->tokens[$this->pos];
} else {
// EOF token with ID 0
$token = "\0";
}
if (isset($this->usedAttributes['startTokenPos'])) {
$startAttributes['startTokenPos'] = $this->pos;
@ -192,10 +197,7 @@ class Lexer
}
}
$startAttributes['startLine'] = $this->line;
// 0 is the EOF token
return 0;
throw new \RuntimeException('Reached end of lexer loop');
}
/**

View File

@ -0,0 +1,9 @@
Error positions
-----
<?php foo
-----
Syntax error, unexpected EOF from 1:10 to 1:10
-----
<?php foo /* bar */
-----
Syntax error, unexpected EOF from 1:20 to 1:20