From 648a246be0aecef568fe36edd060f1ab5050dfb3 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 30 Sep 2016 20:57:21 +0200 Subject: [PATCH] Next try to fix HHVM build --- lib/PhpParser/Lexer.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/PhpParser/Lexer.php b/lib/PhpParser/Lexer.php index af0df66..c4cfe47 100644 --- a/lib/PhpParser/Lexer.php +++ b/lib/PhpParser/Lexer.php @@ -159,9 +159,24 @@ class Lexer $line += substr_count($tokenValue, "\n"); } - // Invalid characters at the end of the input if ($filePos !== \strlen($this->code)) { - $this->handleInvalidCharacterRange($filePos, \strlen($this->code), $line); + if (substr($this->code, $filePos, 2) === '/*') { + // Unlike PHP, HHVM will drop unterminated comments entirely + $comment = substr($this->code, $filePos); + $this->errors[] = new Error('Unterminated comment', [ + 'startLine' => $line, + 'endLine' => $line + substr_count($comment, "\n"), + 'startFilePos' => $filePos, + 'endFilePos' => $filePos + \strlen($comment), + ]); + + // Emulate the PHP behavior + $isDocComment = isset($comment[3]) && $comment[3] === '*'; + $this->tokens[] = [$isDocComment ? T_DOC_COMMENT : T_COMMENT, $comment, $line]; + } else { + // Invalid characters at the end of the input + $this->handleInvalidCharacterRange($filePos, \strlen($this->code), $line); + } } // Check for unterminated comment