Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Drop offsets when tokenizing with RegularParser
  • Loading branch information
funkjedi authored and thunderer committed Dec 20, 2024
commit 08c2e6bbf982981fbfc392078deff453f178ed3c
16 changes: 8 additions & 8 deletions src/Parser/RegularParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,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()));
}
Expand All @@ -352,13 +352,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('Invalid token.'); }
}
$tokens[] = array($type, $token, $position);
Expand Down
Loading