@@ -19,27 +19,43 @@ class ParserException extends \Exception
1919 /** @var int */
2020 private $ expectedTokenType ;
2121
22+ /** @var string */
23+ private $ expectedTokenValue ;
24+
2225 public function __construct (
2326 string $ currentTokenValue ,
2427 int $ currentTokenType ,
2528 int $ currentOffset ,
26- int $ expectedTokenType
29+ ?int $ expectedTokenType ,
30+ ?string $ expectedTokenValue = null
2731 )
2832 {
2933 $ this ->currentTokenValue = $ currentTokenValue ;
3034 $ this ->currentTokenType = $ currentTokenType ;
3135 $ this ->currentOffset = $ currentOffset ;
3236 $ this ->expectedTokenType = $ expectedTokenType ;
37+ $ this ->expectedTokenValue = $ expectedTokenValue ;
3338
3439 $ json = json_encode ($ currentTokenValue , JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES );
3540 assert ($ json !== false );
3641
37- parent ::__construct (sprintf (
38- 'Unexpected token %s, expected %s at offset %d ' ,
39- $ json ,
40- Lexer::TOKEN_LABELS [$ expectedTokenType ],
41- $ currentOffset
42- ));
42+ if ($ expectedTokenType !== null ) {
43+ parent ::__construct (sprintf (
44+ 'Unexpected token %s, expected %s at offset %d ' ,
45+ $ json ,
46+ Lexer::TOKEN_LABELS [$ expectedTokenType ],
47+ $ currentOffset
48+ ));
49+ } elseif ($ expectedTokenValue !== null ) {
50+ parent ::__construct (sprintf (
51+ 'Unexpected token value %s, expected value %s at offset %d ' ,
52+ $ json ,
53+ $ expectedTokenValue ,
54+ $ currentOffset
55+ ));
56+ } else {
57+ throw new \LogicException ();
58+ }
4359 }
4460
4561
@@ -66,4 +82,9 @@ public function getExpectedTokenType(): int
6682 return $ this ->expectedTokenType ;
6783 }
6884
85+ public function getExpectedTokenValue (): string
86+ {
87+ return $ this ->expectedTokenValue ;
88+ }
89+
6990}
0 commit comments