Skip to content

Commit aa6d3ec

Browse files
authored
Merge pull request #3 from NitroPack/fix/comment_parsing
Fix comment start interpreted as comment end
2 parents ac01e86 + a062a3b commit aa6d3ec

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/Parsing/ParserState.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -375,27 +375,26 @@ public function consumeExpression($mExpression, $iMaxLength = null): string
375375
*/
376376
public function consumeComment()
377377
{
378-
if ($this->peek() != '/' || $this->peek(1, 1) != '*') {
379-
return false;
380-
}
381-
382-
$sComment = '';
383-
$iLineNo = $this->iLineNo;
384-
$this->consume(1);
385-
while (($char = $this->consume(1)) !== '') {
386-
if ($char == '*' && $this->peek() == '/') {
387-
$this->consume(1);
388-
break;
378+
$mComment = false;
379+
if ($this->comes('/*')) {
380+
$iLineNo = $this->iLineNo;
381+
$this->consume(1);
382+
$mComment = '';
383+
while (($char = $this->consume(1)) !== '') {
384+
$mComment .= $char;
385+
if ($this->comes('*/')) {
386+
$this->consume(2);
387+
break;
388+
}
389389
}
390-
$sComment .= $char;
391390
}
392391

393-
if ($sComment !== '') {
392+
if ($mComment !== false) {
394393
// We skip the * which was included in the comment.
395-
return new Comment(\substr($sComment, 1), $iLineNo);
394+
return new Comment(\substr($mComment, 1), $iLineNo);
396395
}
397396

398-
return false;
397+
return $mComment;
399398
}
400399

401400
public function isEnd(): bool

0 commit comments

Comments
 (0)