Skip to content

Commit

Permalink
Small lexer optimisation using the \G assertion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Nov 30, 2013
1 parent 067d223 commit f20b2fc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Llk/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ protected function matchLexeme ( $lexeme, $regex, $offset ) {

$_regex = str_replace('#', '\#', $regex);
$preg = preg_match(
'#(?|' . $_regex . ')#u',
'#\G(?|' . $_regex . ')#u',
$this->_text,
$matches,
PREG_OFFSET_CAPTURE,
0,
$offset
);

if(0 === $preg || $offset !== $matches[0][1])
if(0 === $preg)
return null;

if('' === $matches[0])
Expand All @@ -277,8 +277,8 @@ protected function matchLexeme ( $lexeme, $regex, $offset ) {

return array(
'token' => $lexeme,
'value' => $matches[0][0],
'length' => mb_strlen($matches[0][0])
'value' => $matches[0],
'length' => mb_strlen($matches[0])
);
}
}
Expand Down

0 comments on commit f20b2fc

Please sign in to comment.