@@ -349,19 +349,9 @@ private function tokenize($text)
349
349
350
350
$ tokens = array ();
351
351
$ position = 0 ;
352
-
353
352
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 );
365
355
$ position += mb_strlen ($ token , 'utf-8 ' );
366
356
}
367
357
@@ -373,31 +363,31 @@ private function prepareLexer(SyntaxInterface $syntax)
373
363
{
374
364
// FIXME: for some reason Psalm does not understand the `@psalm-var callable() $var` annotation
375
365
/** @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 );
378
368
};
379
369
/** @psalm-suppress MissingClosureParamType, MissingClosureReturnType */
380
370
$ quote = function ($ text ) {
381
371
return preg_replace ('/(.)/us ' , '\\\\$0 ' , (string )$ text );
382
372
};
383
373
384
374
$ rules = array (
385
- '(?<string> \\\\.|(?:(?! ' .implode ('| ' , array (
375
+ '\\\\.(*: ' . self :: TOKEN_STRING . ' ) |(?:(?! ' .implode ('| ' , array (
386
376
$ quote ($ syntax ->getOpeningTag ()),
387
377
$ quote ($ syntax ->getClosingTag ()),
388
378
$ quote ($ syntax ->getClosingTagMarker ()),
389
379
$ quote ($ syntax ->getParameterValueSeparator ()),
390
380
$ quote ($ syntax ->getParameterValueDelimiter ()),
391
381
'\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 . ' ) ' ,
399
389
);
400
390
401
- return '~( ' .implode ('| ' , $ rules ).')~us ' ;
391
+ return '~(?| ' .implode ('| ' , $ rules ).')~us ' ;
402
392
}
403
393
}
0 commit comments