mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-27 04:24:43 +01:00
Merge branch '1.x'
This commit is contained in:
commit
9c9a8cddce
@ -222,23 +222,13 @@ class Lexer
|
|||||||
* @return string Remaining text
|
* @return string Remaining text
|
||||||
*/
|
*/
|
||||||
public function handleHaltCompiler() {
|
public function handleHaltCompiler() {
|
||||||
// get the length of the text before the T_HALT_COMPILER token
|
|
||||||
$textBefore = '';
|
|
||||||
for ($i = 0; $i <= $this->pos; ++$i) {
|
|
||||||
if (is_string($this->tokens[$i])) {
|
|
||||||
$textBefore .= $this->tokens[$i];
|
|
||||||
} else {
|
|
||||||
$textBefore .= $this->tokens[$i][1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// text after T_HALT_COMPILER, still including ();
|
// text after T_HALT_COMPILER, still including ();
|
||||||
$textAfter = substr($this->code, strlen($textBefore));
|
$textAfter = substr($this->code, $this->filePos);
|
||||||
|
|
||||||
// ensure that it is followed by ();
|
// ensure that it is followed by ();
|
||||||
// this simplifies the situation, by not allowing any comments
|
// this simplifies the situation, by not allowing any comments
|
||||||
// in between of the tokens.
|
// in between of the tokens.
|
||||||
if (!preg_match('~\s*\(\s*\)\s*(?:;|\?>\r?\n?)~', $textAfter, $matches)) {
|
if (!preg_match('~^\s*\(\s*\)\s*(?:;|\?>\r?\n?)~', $textAfter, $matches)) {
|
||||||
throw new Error('__HALT_COMPILER must be followed by "();"');
|
throw new Error('__HALT_COMPILER must be followed by "();"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +217,18 @@ class LexerTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \PhpParser\Error
|
||||||
|
* @expectedExceptionMessage __HALT_COMPILER must be followed by "();"
|
||||||
|
*/
|
||||||
|
public function testHandleHaltCompilerError() {
|
||||||
|
$lexer = $this->getLexer();
|
||||||
|
$lexer->startLexing('<?php ... __halt_compiler invalid ();');
|
||||||
|
|
||||||
|
while (Tokens::T_HALT_COMPILER !== $lexer->getNextToken());
|
||||||
|
$lexer->handleHaltCompiler();
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetTokens() {
|
public function testGetTokens() {
|
||||||
$code = '<?php "a";' . "\n" . '// foo' . "\n" . '"b";';
|
$code = '<?php "a";' . "\n" . '// foo' . "\n" . '"b";';
|
||||||
$expectedTokens = array(
|
$expectedTokens = array(
|
||||||
|
Loading…
Reference in New Issue
Block a user