@@ -19,27 +19,43 @@ class ParserException extends \Exception
19
19
/** @var int */
20
20
private $ expectedTokenType ;
21
21
22
+ /** @var string */
23
+ private $ expectedTokenValue ;
24
+
22
25
public function __construct (
23
26
string $ currentTokenValue ,
24
27
int $ currentTokenType ,
25
28
int $ currentOffset ,
26
- int $ expectedTokenType
29
+ ?int $ expectedTokenType ,
30
+ ?string $ expectedTokenValue = null
27
31
)
28
32
{
29
33
$ this ->currentTokenValue = $ currentTokenValue ;
30
34
$ this ->currentTokenType = $ currentTokenType ;
31
35
$ this ->currentOffset = $ currentOffset ;
32
36
$ this ->expectedTokenType = $ expectedTokenType ;
37
+ $ this ->expectedTokenValue = $ expectedTokenValue ;
33
38
34
39
$ json = json_encode ($ currentTokenValue , JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES );
35
40
assert ($ json !== false );
36
41
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
+ }
43
59
}
44
60
45
61
@@ -66,4 +82,9 @@ public function getExpectedTokenType(): int
66
82
return $ this ->expectedTokenType ;
67
83
}
68
84
85
+ public function getExpectedTokenValue (): string
86
+ {
87
+ return $ this ->expectedTokenValue ;
88
+ }
89
+
69
90
}
0 commit comments