Skip to content

Commit 08c2e6b

Browse files
funkjedithunderer
authored andcommitted
Drop offsets when tokenizing with RegularParser
1 parent 9f81424 commit 08c2e6b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: src/Parser/RegularParser.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ private function match($type, $ws)
342342
*/
343343
private function tokenize($text)
344344
{
345-
$count = preg_match_all($this->lexerRegex, $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
345+
$count = preg_match_all($this->lexerRegex, $text, $matches, PREG_SET_ORDER);
346346
if(false === $count || preg_last_error() !== PREG_NO_ERROR) {
347347
throw new \RuntimeException(sprintf('PCRE failure `%s`.', preg_last_error()));
348348
}
@@ -352,13 +352,13 @@ private function tokenize($text)
352352

353353
foreach($matches as $match) {
354354
switch(true) {
355-
case -1 !== $match['string'][1]: { $token = $match['string'][0]; $type = self::TOKEN_STRING; break; }
356-
case -1 !== $match['ws'][1]: { $token = $match['ws'][0]; $type = self::TOKEN_WS; break; }
357-
case -1 !== $match['marker'][1]: { $token = $match['marker'][0]; $type = self::TOKEN_MARKER; break; }
358-
case -1 !== $match['delimiter'][1]: { $token = $match['delimiter'][0]; $type = self::TOKEN_DELIMITER; break; }
359-
case -1 !== $match['separator'][1]: { $token = $match['separator'][0]; $type = self::TOKEN_SEPARATOR; break; }
360-
case -1 !== $match['open'][1]: { $token = $match['open'][0]; $type = self::TOKEN_OPEN; break; }
361-
case -1 !== $match['close'][1]: { $token = $match['close'][0]; $type = self::TOKEN_CLOSE; break; }
355+
case array_key_exists('close', $match): { $token = $match['close']; $type = self::TOKEN_CLOSE; break; }
356+
case array_key_exists('open', $match): { $token = $match['open']; $type = self::TOKEN_OPEN; break; }
357+
case array_key_exists('separator', $match): { $token = $match['separator']; $type = self::TOKEN_SEPARATOR; break; }
358+
case array_key_exists('delimiter', $match): { $token = $match['delimiter']; $type = self::TOKEN_DELIMITER; break; }
359+
case array_key_exists('marker', $match): { $token = $match['marker']; $type = self::TOKEN_MARKER; break; }
360+
case array_key_exists('ws', $match): { $token = $match['ws']; $type = self::TOKEN_WS; break; }
361+
case array_key_exists('string', $match): { $token = $match['string']; $type = self::TOKEN_STRING; break; }
362362
default: { throw new \RuntimeException('Invalid token.'); }
363363
}
364364
$tokens[] = array($type, $token, $position);

0 commit comments

Comments
 (0)