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:
parent
55b2ead967
commit
a35c2a2067
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
9
test/code/parser/error_pos.test-fail
Normal file
9
test/code/parser/error_pos.test-fail
Normal 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
|
Loading…
Reference in New Issue
Block a user