@@ -21,7 +21,7 @@ public function testDisallowsUncommonControlCharacters(): void
2121 $ this ->expectSyntaxError (
2222 Utils::chr (0x0007 ),
2323 'Cannot contain the invalid character "\u0007" ' ,
24- $ this -> loc (1 , 1 )
24+ self :: loc (1 , 1 )
2525 );
2626 }
2727
@@ -53,7 +53,7 @@ private function lexOne(string $body): Token
5353 return $ lexer ->advance ();
5454 }
5555
56- private function loc (int $ line , int $ column ): SourceLocation
56+ private static function loc (int $ line , int $ column ): SourceLocation
5757 {
5858 return new SourceLocation ($ line , $ column );
5959 }
@@ -397,47 +397,32 @@ public function testLexesBlockString(): void
397397 }
398398
399399 /** @return iterable<array{string, string, SourceLocation}> */
400- public function reportsUsefulStringErrors (): iterable
400+ public static function reportsUsefulStringErrors (): iterable
401401 {
402- return [
403- ['" ' , 'Unterminated string. ' , $ this ->loc (1 , 2 )],
404- ['"no end quote ' , 'Unterminated string. ' , $ this ->loc (1 , 14 )],
405- [
406- "'single quotes' " ,
407- "Unexpected single quote character ('), did you mean to use a double quote ( \")? " ,
408- $ this ->loc (
409- 1 ,
410- 1
411- ),
412- ],
413- [
414- '"contains unescaped \u0007 control char" ' ,
415- 'Invalid character within String: " \\u0007" ' ,
416- $ this ->loc (
417- 1 ,
418- 21
419- ),
420- ],
421- ['"null-byte is not \u0000 end of file" ' , 'Invalid character within String: " \\u0000" ' , $ this ->loc (1 , 19 )],
422- ['"multi ' . "\n" . 'line" ' , 'Unterminated string. ' , $ this ->loc (1 , 7 )],
423- ['"multi line" ' , 'Unterminated string. ' , $ this ->loc (1 , 7 )],
424- ['"bad esc \\' , 'Unterminated string. ' , $ this ->loc (1 , 11 )],
425- ['"bad \\z esc" ' , 'Invalid character escape sequence: \\z ' , $ this ->loc (1 , 7 )],
426- ['"bad \\x esc" ' , 'Invalid character escape sequence: \\x ' , $ this ->loc (1 , 7 )],
427- ['"bad \\u1 esc" ' , 'Invalid character escape sequence: \\u1 es ' , $ this ->loc (1 , 7 )],
428- ['"bad \\u0XX1 esc" ' , 'Invalid character escape sequence: \\u0XX1 ' , $ this ->loc (1 , 7 )],
429- ['"bad \\uXXXX esc" ' , 'Invalid character escape sequence: \\uXXXX ' , $ this ->loc (1 , 7 )],
430- ['"bad \\uFXXX esc" ' , 'Invalid character escape sequence: \\uFXXX ' , $ this ->loc (1 , 7 )],
431- ['"bad \\uXXXF esc" ' , 'Invalid character escape sequence: \\uXXXF ' , $ this ->loc (1 , 7 )],
432- ['"bad \\uD835" ' , 'Invalid UTF-16 trailing surrogate: ' , $ this ->loc (1 , 13 )],
433- ['"bad \\uD835 \\u1" ' , 'Invalid UTF-16 trailing surrogate: \\u1 ' , $ this ->loc (1 , 13 )],
434- ['"bad \\uD835 \\u1 esc" ' , 'Invalid UTF-16 trailing surrogate: \\u1 es ' , $ this ->loc (1 , 13 )],
435- ['"bad \\uD835uuFFFF esc" ' , 'Invalid UTF-16 trailing surrogate: uuFFFF ' , $ this ->loc (1 , 13 )],
436- ['"bad \\uD835 \\u0XX1 esc" ' , 'Invalid UTF-16 trailing surrogate: \\u0XX1 ' , $ this ->loc (1 , 13 )],
437- ['"bad \\uD835 \\uXXXX esc" ' , 'Invalid UTF-16 trailing surrogate: \\uXXXX ' , $ this ->loc (1 , 13 )],
438- ['"bad \\uD835 \\uFXXX esc" ' , 'Invalid UTF-16 trailing surrogate: \\uFXXX ' , $ this ->loc (1 , 13 )],
439- ['"bad \\uD835 \\uXXXF esc" ' , 'Invalid UTF-16 trailing surrogate: \\uXXXF ' , $ this ->loc (1 , 13 )],
440- ];
402+ yield ['" ' , 'Unterminated string. ' , self ::loc (1 , 2 )];
403+ yield ['"no end quote ' , 'Unterminated string. ' , self ::loc (1 , 14 )];
404+ yield ["'single quotes' " , "Unexpected single quote character ('), did you mean to use a double quote ( \")? " , self ::loc (1 , 1 )];
405+ yield ['"contains unescaped \u0007 control char" ' , 'Invalid character within String: " \\u0007" ' , self ::loc (1 , 21 )];
406+ yield ['"null-byte is not \u0000 end of file" ' , 'Invalid character within String: " \\u0000" ' , self ::loc (1 , 19 )];
407+ yield ['"multi ' . "\n" . 'line" ' , 'Unterminated string. ' , self ::loc (1 , 7 )];
408+ yield ['"multi
409+ line" ' , 'Unterminated string. ' , self ::loc (1 , 7 )];
410+ yield ['"bad esc \\' , 'Unterminated string. ' , self ::loc (1 , 11 )];
411+ yield ['"bad \\z esc" ' , 'Invalid character escape sequence: \\z ' , self ::loc (1 , 7 )];
412+ yield ['"bad \\x esc" ' , 'Invalid character escape sequence: \\x ' , self ::loc (1 , 7 )];
413+ yield ['"bad \\u1 esc" ' , 'Invalid character escape sequence: \\u1 es ' , self ::loc (1 , 7 )];
414+ yield ['"bad \\u0XX1 esc" ' , 'Invalid character escape sequence: \\u0XX1 ' , self ::loc (1 , 7 )];
415+ yield ['"bad \\uXXXX esc" ' , 'Invalid character escape sequence: \\uXXXX ' , self ::loc (1 , 7 )];
416+ yield ['"bad \\uFXXX esc" ' , 'Invalid character escape sequence: \\uFXXX ' , self ::loc (1 , 7 )];
417+ yield ['"bad \\uXXXF esc" ' , 'Invalid character escape sequence: \\uXXXF ' , self ::loc (1 , 7 )];
418+ yield ['"bad \\uD835" ' , 'Invalid UTF-16 trailing surrogate: ' , self ::loc (1 , 13 )];
419+ yield ['"bad \\uD835 \\u1" ' , 'Invalid UTF-16 trailing surrogate: \\u1 ' , self ::loc (1 , 13 )];
420+ yield ['"bad \\uD835 \\u1 esc" ' , 'Invalid UTF-16 trailing surrogate: \\u1 es ' , self ::loc (1 , 13 )];
421+ yield ['"bad \\uD835uuFFFF esc" ' , 'Invalid UTF-16 trailing surrogate: uuFFFF ' , self ::loc (1 , 13 )];
422+ yield ['"bad \\uD835 \\u0XX1 esc" ' , 'Invalid UTF-16 trailing surrogate: \\u0XX1 ' , self ::loc (1 , 13 )];
423+ yield ['"bad \\uD835 \\uXXXX esc" ' , 'Invalid UTF-16 trailing surrogate: \\uXXXX ' , self ::loc (1 , 13 )];
424+ yield ['"bad \\uD835 \\uFXXX esc" ' , 'Invalid UTF-16 trailing surrogate: \\uFXXX ' , self ::loc (1 , 13 )];
425+ yield ['"bad \\uD835 \\uXXXF esc" ' , 'Invalid UTF-16 trailing surrogate: \\uXXXF ' , self ::loc (1 , 13 )];
441426 }
442427
443428 /**
@@ -451,27 +436,19 @@ public function testLexReportsUsefulStringErrors(string $str, string $expectedMe
451436 }
452437
453438 /** @return iterable<array{string, string, SourceLocation}> */
454- public function reportsUsefulBlockStringErrors (): iterable
439+ public static function reportsUsefulBlockStringErrors (): iterable
455440 {
456- return [
457- ['""" ' , 'Unterminated string. ' , $ this ->loc (1 , 4 )],
458- ['"""no end quote ' , 'Unterminated string. ' , $ this ->loc (1 , 16 )],
459- [
460- '"""contains unescaped ' . \json_decode ('"\u0007" ' ) . ' control char""" ' ,
461- 'Invalid character within String: " \\u0007" ' ,
462- $ this ->loc (
463- 1 ,
464- 23
465- ),
466- ],
467- [
468- '"""null-byte is not ' . \json_decode ('"\u0000" ' ) . ' end of file""" ' ,
469- 'Invalid character within String: " \\u0000" ' ,
470- $ this ->loc (
471- 1 ,
472- 21
473- ),
474- ],
441+ yield ['""" ' , 'Unterminated string. ' , self ::loc (1 , 4 )];
442+ yield ['"""no end quote ' , 'Unterminated string. ' , self ::loc (1 , 16 )];
443+ yield [
444+ '"""contains unescaped ' . \json_decode ('"\u0007" ' ) . ' control char""" ' ,
445+ 'Invalid character within String: " \\u0007" ' ,
446+ self ::loc (1 , 23 ),
447+ ];
448+ yield [
449+ '"""null-byte is not ' . \json_decode ('"\u0000" ' ) . ' end of file""" ' ,
450+ 'Invalid character within String: " \\u0000" ' ,
451+ self ::loc (1 , 21 ),
475452 ];
476453 }
477454
@@ -555,19 +532,17 @@ public function testLexesNumbers(): void
555532 }
556533
557534 /** @return iterable<array{string, string, SourceLocation}> */
558- public function reportsUsefulNumberErrors (): iterable
535+ public static function reportsUsefulNumberErrors (): iterable
559536 {
560- return [
561- ['00 ' , 'Invalid number, unexpected digit after 0: "0" ' , $ this ->loc (1 , 2 )],
562- ['+1 ' , 'Cannot parse the unexpected character "+". ' , $ this ->loc (1 , 1 )],
563- ['1. ' , 'Invalid number, expected digit but got: <EOF> ' , $ this ->loc (1 , 3 )],
564- ['1.e1 ' , 'Invalid number, expected digit but got: "e" ' , $ this ->loc (1 , 3 )],
565- ['.123 ' , 'Cannot parse the unexpected character ".". ' , $ this ->loc (1 , 1 )],
566- ['1.A ' , 'Invalid number, expected digit but got: "A" ' , $ this ->loc (1 , 3 )],
567- ['-A ' , 'Invalid number, expected digit but got: "A" ' , $ this ->loc (1 , 2 )],
568- ['1.0e ' , 'Invalid number, expected digit but got: <EOF> ' , $ this ->loc (1 , 5 )],
569- ['1.0eA ' , 'Invalid number, expected digit but got: "A" ' , $ this ->loc (1 , 5 )],
570- ];
537+ yield ['00 ' , 'Invalid number, unexpected digit after 0: "0" ' , self ::loc (1 , 2 )];
538+ yield ['+1 ' , 'Cannot parse the unexpected character "+". ' , self ::loc (1 , 1 )];
539+ yield ['1. ' , 'Invalid number, expected digit but got: <EOF> ' , self ::loc (1 , 3 )];
540+ yield ['1.e1 ' , 'Invalid number, expected digit but got: "e" ' , self ::loc (1 , 3 )];
541+ yield ['.123 ' , 'Cannot parse the unexpected character ".". ' , self ::loc (1 , 1 )];
542+ yield ['1.A ' , 'Invalid number, expected digit but got: "A" ' , self ::loc (1 , 3 )];
543+ yield ['-A ' , 'Invalid number, expected digit but got: "A" ' , self ::loc (1 , 2 )];
544+ yield ['1.0e ' , 'Invalid number, expected digit but got: <EOF> ' , self ::loc (1 , 5 )];
545+ yield ['1.0eA ' , 'Invalid number, expected digit but got: "A" ' , self ::loc (1 , 5 )];
571546 }
572547
573548 /**
@@ -638,14 +613,12 @@ public function testLexesPunctuation(): void
638613 }
639614
640615 /** @return iterable<array{string, string, SourceLocation}> */
641- public function reportsUsefulUnknownCharErrors (): iterable
616+ public static function reportsUsefulUnknownCharErrors (): iterable
642617 {
643- return [
644- ['.. ' , 'Cannot parse the unexpected character ".". ' , $ this ->loc (1 , 1 )],
645- ['? ' , 'Cannot parse the unexpected character "?". ' , $ this ->loc (1 , 1 )],
646- [\json_decode ('"\u203B" ' ), 'Cannot parse the unexpected character " \\u203b". ' , $ this ->loc (1 , 1 )],
647- [\json_decode ('"\u200b" ' ), 'Cannot parse the unexpected character " \\u200b". ' , $ this ->loc (1 , 1 )],
648- ];
618+ yield ['.. ' , 'Cannot parse the unexpected character ".". ' , self ::loc (1 , 1 )];
619+ yield ['? ' , 'Cannot parse the unexpected character "?". ' , self ::loc (1 , 1 )];
620+ yield [\json_decode ('"\u203B" ' ), 'Cannot parse the unexpected character " \\u203b". ' , self ::loc (1 , 1 )];
621+ yield [\json_decode ('"\u200b" ' ), 'Cannot parse the unexpected character " \\u200b". ' , self ::loc (1 , 1 )];
649622 }
650623
651624 /**
@@ -674,7 +647,7 @@ public function testReportsUsefulDashesInfo(): void
674647 $ lexer ->advance ();
675648 self ::fail ('Expected exception not thrown ' );
676649 } catch (SyntaxError $ error ) {
677- self ::assertEquals ([$ this -> loc (1 , 3 )], $ error ->getLocations ());
650+ self ::assertEquals ([self :: loc (1 , 3 )], $ error ->getLocations ());
678651
679652 throw $ error ;
680653 }
0 commit comments