1313import java .util .LinkedList ;
1414import java .util .List ;
1515import java .util .Queue ;
16+ import java .util .function .Supplier ;
1617
1718import static java .util .Arrays .asList ;
1819
@@ -160,13 +161,13 @@ private void addError(ParserContext context, ParserException error) {
160161 throw new ParserException .CompositeParserException (context .errors );
161162 }
162163
163- private < V > V handleAstError (ParserContext context , final Func < V > action ) {
164- return handleExternalError (context , action , null );
164+ private void handleAstError (ParserContext context , final Supplier < Void > action ) {
165+ handleExternalError (context , null , action );
165166 }
166167
167- private <V > V handleExternalError (ParserContext context , Func < V > action , V defaultValue ) {
168+ private <V > V handleExternalError (ParserContext context , V defaultValue , Supplier < V > action ) {
168169 try {
169- return action .call ();
170+ return action .get ();
170171 } catch (ParserException .CompositeParserException compositeParserException ) {
171172 for (ParserException error : compositeParserException .errors ) {
172173 addError (context , error );
@@ -178,148 +179,99 @@ private <V> V handleExternalError(ParserContext context, Func<V> action, V defau
178179 }
179180
180181 private void build (final ParserContext context , final Token token ) {
181- handleAstError (context , new Func <Void >() {
182- public Void call () {
183- builder .build (token );
184- return null ;
185- }
182+ handleAstError (context , () -> {
183+ builder .build (token );
184+ return null ;
186185 });
187186 }
188187
189188 private void startRule (final ParserContext context , final RuleType ruleType ) {
190- handleAstError (context , new Func <Void >() {
191- public Void call () {
192- builder .startRule (ruleType );
193- return null ;
194- }
189+ handleAstError (context , () -> {
190+ builder .startRule (ruleType );
191+ return null ;
195192 });
196193 }
197194
198195 private void endRule (final ParserContext context , final RuleType ruleType ) {
199- handleAstError (context , new Func <Void >() {
200- public Void call () {
201- builder .endRule (ruleType );
202- return null ;
203- }
196+ handleAstError (context , () -> {
197+ builder .endRule (ruleType );
198+ return null ;
204199 });
205200 }
206201
207202 private Token readToken (ParserContext context ) {
208203 return context .tokenQueue .isEmpty () ? context .tokenScanner .read () : context .tokenQueue .remove ();
209204 }
210205
211-
212206 private boolean match_EOF (final ParserContext context , final Token token ) {
213- return handleExternalError (context , new Func <Boolean >() {
214- public Boolean call () {
215- return context .tokenMatcher .match_EOF (token );
216- }
217- }, false );
207+ return handleExternalError (context , false , () -> context .tokenMatcher .match_EOF (token ));
218208 }
209+
219210 private boolean match_Empty (final ParserContext context , final Token token ) {
220211 if (token .isEOF ()) return false ;
221- return handleExternalError (context , new Func <Boolean >() {
222- public Boolean call () {
223- return context .tokenMatcher .match_Empty (token );
224- }
225- }, false );
212+ return handleExternalError (context , false , () -> context .tokenMatcher .match_Empty (token ));
226213 }
214+
227215 private boolean match_Comment (final ParserContext context , final Token token ) {
228216 if (token .isEOF ()) return false ;
229- return handleExternalError (context , new Func <Boolean >() {
230- public Boolean call () {
231- return context .tokenMatcher .match_Comment (token );
232- }
233- }, false );
217+ return handleExternalError (context , false , () -> context .tokenMatcher .match_Comment (token ));
234218 }
219+
235220 private boolean match_TagLine (final ParserContext context , final Token token ) {
236221 if (token .isEOF ()) return false ;
237- return handleExternalError (context , new Func <Boolean >() {
238- public Boolean call () {
239- return context .tokenMatcher .match_TagLine (token );
240- }
241- }, false );
222+ return handleExternalError (context , false , () -> context .tokenMatcher .match_TagLine (token ));
242223 }
224+
243225 private boolean match_FeatureLine (final ParserContext context , final Token token ) {
244226 if (token .isEOF ()) return false ;
245- return handleExternalError (context , new Func <Boolean >() {
246- public Boolean call () {
247- return context .tokenMatcher .match_FeatureLine (token );
248- }
249- }, false );
227+ return handleExternalError (context , false , () -> context .tokenMatcher .match_FeatureLine (token ));
250228 }
229+
251230 private boolean match_RuleLine (final ParserContext context , final Token token ) {
252231 if (token .isEOF ()) return false ;
253- return handleExternalError (context , new Func <Boolean >() {
254- public Boolean call () {
255- return context .tokenMatcher .match_RuleLine (token );
256- }
257- }, false );
232+ return handleExternalError (context , false , () -> context .tokenMatcher .match_RuleLine (token ));
258233 }
234+
259235 private boolean match_BackgroundLine (final ParserContext context , final Token token ) {
260236 if (token .isEOF ()) return false ;
261- return handleExternalError (context , new Func <Boolean >() {
262- public Boolean call () {
263- return context .tokenMatcher .match_BackgroundLine (token );
264- }
265- }, false );
237+ return handleExternalError (context , false , () -> context .tokenMatcher .match_BackgroundLine (token ));
266238 }
239+
267240 private boolean match_ScenarioLine (final ParserContext context , final Token token ) {
268241 if (token .isEOF ()) return false ;
269- return handleExternalError (context , new Func <Boolean >() {
270- public Boolean call () {
271- return context .tokenMatcher .match_ScenarioLine (token );
272- }
273- }, false );
242+ return handleExternalError (context , false , () -> context .tokenMatcher .match_ScenarioLine (token ));
274243 }
244+
275245 private boolean match_ExamplesLine (final ParserContext context , final Token token ) {
276246 if (token .isEOF ()) return false ;
277- return handleExternalError (context , new Func <Boolean >() {
278- public Boolean call () {
279- return context .tokenMatcher .match_ExamplesLine (token );
280- }
281- }, false );
247+ return handleExternalError (context , false , () -> context .tokenMatcher .match_ExamplesLine (token ));
282248 }
249+
283250 private boolean match_StepLine (final ParserContext context , final Token token ) {
284251 if (token .isEOF ()) return false ;
285- return handleExternalError (context , new Func <Boolean >() {
286- public Boolean call () {
287- return context .tokenMatcher .match_StepLine (token );
288- }
289- }, false );
252+ return handleExternalError (context , false , () -> context .tokenMatcher .match_StepLine (token ));
290253 }
254+
291255 private boolean match_DocStringSeparator (final ParserContext context , final Token token ) {
292256 if (token .isEOF ()) return false ;
293- return handleExternalError (context , new Func <Boolean >() {
294- public Boolean call () {
295- return context .tokenMatcher .match_DocStringSeparator (token );
296- }
297- }, false );
257+ return handleExternalError (context , false , () -> context .tokenMatcher .match_DocStringSeparator (token ));
298258 }
259+
299260 private boolean match_TableRow (final ParserContext context , final Token token ) {
300261 if (token .isEOF ()) return false ;
301- return handleExternalError (context , new Func <Boolean >() {
302- public Boolean call () {
303- return context .tokenMatcher .match_TableRow (token );
304- }
305- }, false );
262+ return handleExternalError (context , false , () -> context .tokenMatcher .match_TableRow (token ));
306263 }
264+
307265 private boolean match_Language (final ParserContext context , final Token token ) {
308266 if (token .isEOF ()) return false ;
309- return handleExternalError (context , new Func <Boolean >() {
310- public Boolean call () {
311- return context .tokenMatcher .match_Language (token );
312- }
313- }, false );
267+ return handleExternalError (context , false , () -> context .tokenMatcher .match_Language (token ));
314268 }
269+
315270 private boolean match_Other (final ParserContext context , final Token token ) {
316271 if (token .isEOF ()) return false ;
317- return handleExternalError (context , new Func <Boolean >() {
318- public Boolean call () {
319- return context .tokenMatcher .match_Other (token );
320- }
321- }, false );
272+ return handleExternalError (context , false , () -> context .tokenMatcher .match_Other (token ));
322273 }
274+
323275 private int matchToken (int state , Token token , ParserContext context ) {
324276 int newState ;
325277 switch (state ) {
@@ -455,7 +407,6 @@ private int matchToken(int state, Token token, ParserContext context) {
455407 return newState ;
456408 }
457409
458-
459410 // Start
460411 private int matchTokenAt_0 (Token token , ParserContext context ) {
461412 if (match_EOF (context , token ))
0 commit comments