From 872752846bbfbed0e6f56435ef50713e2becfdfa Mon Sep 17 00:00:00 2001 From: Tim Robertson Date: Tue, 23 Apr 2024 00:22:45 -0400 Subject: [PATCH] Drop offsets when tokenizing with RegularParser --- src/Parser/RegularParser.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Parser/RegularParser.php b/src/Parser/RegularParser.php index bfddc2c..d5fe34f 100644 --- a/src/Parser/RegularParser.php +++ b/src/Parser/RegularParser.php @@ -335,7 +335,7 @@ private function match($type, $ws) */ private function tokenize($text) { - $count = preg_match_all($this->lexerRegex, $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); + $count = preg_match_all($this->lexerRegex, $text, $matches, PREG_SET_ORDER); if(false === $count || preg_last_error() !== PREG_NO_ERROR) { throw new \RuntimeException(sprintf('PCRE failure `%s`.', preg_last_error())); } @@ -345,13 +345,13 @@ private function tokenize($text) foreach($matches as $match) { switch(true) { - case -1 !== $match['string'][1]: { $token = $match['string'][0]; $type = self::TOKEN_STRING; break; } - case -1 !== $match['ws'][1]: { $token = $match['ws'][0]; $type = self::TOKEN_WS; break; } - case -1 !== $match['marker'][1]: { $token = $match['marker'][0]; $type = self::TOKEN_MARKER; break; } - case -1 !== $match['delimiter'][1]: { $token = $match['delimiter'][0]; $type = self::TOKEN_DELIMITER; break; } - case -1 !== $match['separator'][1]: { $token = $match['separator'][0]; $type = self::TOKEN_SEPARATOR; break; } - case -1 !== $match['open'][1]: { $token = $match['open'][0]; $type = self::TOKEN_OPEN; break; } - case -1 !== $match['close'][1]: { $token = $match['close'][0]; $type = self::TOKEN_CLOSE; break; } + case array_key_exists('close', $match): { $token = $match['close']; $type = self::TOKEN_CLOSE; break; } + case array_key_exists('open', $match): { $token = $match['open']; $type = self::TOKEN_OPEN; break; } + case array_key_exists('separator', $match): { $token = $match['separator']; $type = self::TOKEN_SEPARATOR; break; } + case array_key_exists('delimiter', $match): { $token = $match['delimiter']; $type = self::TOKEN_DELIMITER; break; } + case array_key_exists('marker', $match): { $token = $match['marker']; $type = self::TOKEN_MARKER; break; } + case array_key_exists('ws', $match): { $token = $match['ws']; $type = self::TOKEN_WS; break; } + case array_key_exists('string', $match): { $token = $match['string']; $type = self::TOKEN_STRING; break; } default: { throw new \RuntimeException(sprintf('Invalid token.')); } } $tokens[] = array($type, $token, $position);