@@ -349,19 +349,9 @@ private function tokenize($text)
349349
350350 $ tokens = array ();
351351 $ position = 0 ;
352-
353352 foreach ($ matches as $ match ) {
354- switch (true ) {
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 ; }
362- default : { throw new \RuntimeException ('Invalid token. ' ); }
363- }
364- $ tokens [] = array ($ type , $ token , $ position );
353+ $ token = $ match [0 ];
354+ $ tokens [] = array ((int )$ match ['MARK ' ], $ token , $ position );
365355 $ position += mb_strlen ($ token , 'utf-8 ' );
366356 }
367357
@@ -373,31 +363,31 @@ private function prepareLexer(SyntaxInterface $syntax)
373363 {
374364 // FIXME: for some reason Psalm does not understand the `@psalm-var callable() $var` annotation
375365 /** @psalm-suppress MissingClosureParamType, MissingClosureReturnType */
376- $ group = function ($ text, $ group ) {
377- return ' (?< ' .( string ) $ group . ' > ' . preg_replace ('/(.)/us ' , '\\\\$0 ' , (string )$ text ). ' ) ' ;
366+ $ group = function ($ text ) {
367+ return preg_replace ('/(.)/us ' , '\\\\$0 ' , (string )$ text );
378368 };
379369 /** @psalm-suppress MissingClosureParamType, MissingClosureReturnType */
380370 $ quote = function ($ text ) {
381371 return preg_replace ('/(.)/us ' , '\\\\$0 ' , (string )$ text );
382372 };
383373
384374 $ rules = array (
385- '(?<string> \\\\.|(?:(?! ' .implode ('| ' , array (
375+ '\\\\.(*: ' . self :: TOKEN_STRING . ' ) |(?:(?! ' .implode ('| ' , array (
386376 $ quote ($ syntax ->getOpeningTag ()),
387377 $ quote ($ syntax ->getClosingTag ()),
388378 $ quote ($ syntax ->getClosingTagMarker ()),
389379 $ quote ($ syntax ->getParameterValueSeparator ()),
390380 $ quote ($ syntax ->getParameterValueDelimiter ()),
391381 '\s+ ' ,
392- )).').)+) ' ,
393- '(?<ws> \s+) ' ,
394- $ group ($ syntax ->getClosingTagMarker (), ' marker ' ) ,
395- $ group ($ syntax ->getParameterValueDelimiter (), ' delimiter ' ) ,
396- $ group ($ syntax ->getParameterValueSeparator (), ' separator ' ) ,
397- $ group ($ syntax ->getOpeningTag (), ' open ' ) ,
398- $ group ($ syntax ->getClosingTag (), ' close ' ) ,
382+ )).').)+(*: ' . self :: TOKEN_STRING . ' ) ' ,
383+ '\s+(*: ' . self :: TOKEN_WS . ' ) ' ,
384+ $ group ($ syntax ->getClosingTagMarker ()). ' (*: ' . self :: TOKEN_MARKER . ' ) ' ,
385+ $ group ($ syntax ->getParameterValueDelimiter ()). ' (*: ' . self :: TOKEN_DELIMITER . ' ) ' ,
386+ $ group ($ syntax ->getParameterValueSeparator ()). ' (*: ' . self :: TOKEN_SEPARATOR . ' ) ' ,
387+ $ group ($ syntax ->getOpeningTag ()). ' (*: ' . self :: TOKEN_OPEN . ' ) ' ,
388+ $ group ($ syntax ->getClosingTag ()). ' (*: ' . self :: TOKEN_CLOSE . ' ) ' ,
399389 );
400390
401- return '~( ' .implode ('| ' , $ rules ).')~us ' ;
391+ return '~(?| ' .implode ('| ' , $ rules ).')~us ' ;
402392 }
403393}
0 commit comments