@@ -76,9 +76,7 @@ private function getPattern() : AST\Pattern
76
76
break ;
77
77
78
78
default :
79
- $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , '@type@ pattern ' );
80
-
81
- break ;
79
+ throw PatternException::syntaxError ($ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , '@type@ pattern ' ));
82
80
}
83
81
84
82
$ this ->lexer ->moveNext ();
@@ -119,7 +117,7 @@ private function getNextExpanderNode() : ?AST\Expander
119
117
}
120
118
121
119
if (!$ this ->isNextCloseParenthesis ()) {
122
- $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , ') ' );
120
+ throw PatternException:: syntaxError ( $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , ') ' ) );
123
121
}
124
122
125
123
return $ expander ;
@@ -128,9 +126,15 @@ private function getNextExpanderNode() : ?AST\Expander
128
126
private function getExpanderName () : string
129
127
{
130
128
if ($ this ->lexer ->lookahead ['type ' ] !== Lexer::T_EXPANDER_NAME ) {
131
- $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , '.expanderName(args) definition ' );
129
+ throw PatternException:: syntaxError ( $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , '.expanderName(args) definition ' ) );
132
130
}
131
+
133
132
$ expander = $ this ->lexer ->lookahead ['value ' ];
133
+
134
+ if ($ expander === null ) {
135
+ throw PatternException::syntaxError ($ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , '.expanderName(args) definition ' ));
136
+ }
137
+
134
138
$ this ->lexer ->moveNext ();
135
139
136
140
return $ expander ;
@@ -152,7 +156,7 @@ private function addArgumentValues(AST\Expander $expander) : void
152
156
$ this ->lexer ->moveNext ();
153
157
154
158
if ($ this ->lexer ->isNextToken (Lexer::T_CLOSE_PARENTHESIS )) {
155
- $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , 'string, number, boolean or null argument ' );
159
+ throw PatternException:: syntaxError ( $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , 'string, number, boolean or null argument ' ) );
156
160
}
157
161
}
158
162
}
@@ -182,7 +186,7 @@ private function getNextArgumentValue()
182
186
}
183
187
184
188
if (!$ this ->lexer ->isNextTokenAny ($ validArgumentTypes )) {
185
- $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , 'string, number, boolean or null argument ' );
189
+ throw PatternException:: syntaxError ( $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , 'string, number, boolean or null argument ' ) );
186
190
}
187
191
188
192
$ tokenType = $ this ->lexer ->lookahead ['type ' ];
@@ -206,7 +210,7 @@ private function getArrayArgument() : array
206
210
}
207
211
208
212
if (!$ this ->lexer ->isNextToken (Lexer::T_CLOSE_CURLY_BRACE )) {
209
- $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , '} ' );
213
+ throw PatternException:: syntaxError ( $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , '} ' ) );
210
214
}
211
215
212
216
$ this ->lexer ->moveNext ();
@@ -227,7 +231,7 @@ private function getNextArrayElement(array &$array)
227
231
}
228
232
229
233
if (!$ this ->lexer ->isNextToken (Lexer::T_COLON )) {
230
- $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , ': ' );
234
+ throw PatternException:: syntaxError ( $ this ->unexpectedSyntaxError ($ this ->lexer ->lookahead , ': ' ) );
231
235
}
232
236
233
237
$ this ->lexer ->moveNext ();
@@ -258,17 +262,15 @@ private function isNextCloseParenthesis() : bool
258
262
/**
259
263
* @param array $unexpectedToken
260
264
* @param string $expected
261
- *
262
- * @throws PatternException
263
265
*/
264
- private function unexpectedSyntaxError (array $ unexpectedToken , string $ expected = null ) : void
266
+ private function unexpectedSyntaxError (array $ unexpectedToken , string $ expected = null ) : string
265
267
{
266
268
$ tokenPos = (isset ($ unexpectedToken ['position ' ])) ? $ unexpectedToken ['position ' ] : '-1 ' ;
267
269
$ message = \sprintf ('line 0, col %d: Error: ' , $ tokenPos );
268
270
$ message .= (isset ($ expected )) ? \sprintf ('Expected "%s", got ' , $ expected ) : 'Unexpected ' ;
269
271
$ message .= \sprintf ('"%s" ' , $ unexpectedToken ['value ' ]);
270
272
271
- throw PatternException:: syntaxError ( $ message) ;
273
+ return $ message ;
272
274
}
273
275
274
276
/**
0 commit comments