mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Fix incorrect line number extraction
This commit is contained in:
parent
a6f97681f6
commit
cc80385aae
@ -27,7 +27,7 @@ class PHPParser_Lexer
|
||||
$this->code = $code;
|
||||
$this->tokens = @token_get_all($code);
|
||||
$this->pos = -1;
|
||||
$this->line = -1;
|
||||
$this->line = 1;
|
||||
|
||||
$error = error_get_last();
|
||||
|
||||
@ -77,12 +77,16 @@ class PHPParser_Lexer
|
||||
$value = $token;
|
||||
$line = $this->line;
|
||||
return ord($token);
|
||||
} elseif (T_DOC_COMMENT === $token[0]) {
|
||||
$docComment = $token[1];
|
||||
} elseif (!isset(self::$dropTokens[$token[0]])) {
|
||||
$value = $token[1];
|
||||
$line = $this->line = $token[2];
|
||||
return self::$tokenMap[$token[0]];
|
||||
} else {
|
||||
$this->line += substr_count($token[1], "\n");
|
||||
|
||||
if (T_DOC_COMMENT === $token[0]) {
|
||||
$docComment = $token[1];
|
||||
} elseif (!isset(self::$dropTokens[$token[0]])) {
|
||||
$value = $token[1];
|
||||
$line = $token[2];
|
||||
return self::$tokenMap[$token[0]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,14 +43,25 @@ class Unit_LexerTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function provideTestLex() {
|
||||
return array(
|
||||
// tests conversion of closing PHP tag and drop of whitespace, comments and opening tags
|
||||
array(
|
||||
'<?php tokens ?>plaintext',
|
||||
'<?php tokens // ?>plaintext',
|
||||
array(
|
||||
array(PHPParser_Parser::T_STRING, 'tokens', 1, null),
|
||||
array(ord(';'), '?>', 1, null),
|
||||
array(PHPParser_Parser::T_INLINE_HTML, 'plaintext', 1, null),
|
||||
)
|
||||
),
|
||||
// tests line numbers
|
||||
array(
|
||||
'<?php' . "\n" . '$ token /** doc' . "\n" . 'comment */ $',
|
||||
array(
|
||||
array(ord('$'), '$', 2, null),
|
||||
array(PHPParser_Parser::T_STRING, 'token', 2, null),
|
||||
array(ord('$'), '$', 3, '/** doc' . "\n" . 'comment */')
|
||||
)
|
||||
),
|
||||
// tests doccomment extraction
|
||||
array(
|
||||
'<?php /** docComment 1 *//** docComment 2 */ token',
|
||||
array(
|
||||
|
Loading…
Reference in New Issue
Block a user