File tree 3 files changed +18
-4
lines changed
3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -209,7 +209,7 @@ tuple
209
209
;
210
210
211
211
lambdacaptures
212
- : (' (' | LPAREN_NEW) lambdacapture (' ,' lambdacapture)* ' )'
212
+ : (' (' | LPAREN_NEW) ( lambdacapture | ' this ' ) (' ,' ( lambdacapture | ' this ' ) )* ' )'
213
213
;
214
214
215
215
lambdacapture
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ DECL(parampattern);
26
26
DECL (pattern );
27
27
DECL (idseq_in_seq );
28
28
DECL (members );
29
+ DECL (thisliteral );
29
30
30
31
31
32
/* Precedence
@@ -309,12 +310,13 @@ DEF(lambdacapture);
309
310
IF (TK_ASSIGN , RULE ("capture value" , infix ));
310
311
DONE ();
311
312
312
- // (LPAREN | LPAREN_NEW) lambdacapture {COMMA lambdacapture} RPAREN
313
+ // (LPAREN | LPAREN_NEW) (lambdacapture | thisliteral)
314
+ // {COMMA (lambdacapture | thisliteral)} RPAREN
313
315
DEF (lambdacaptures );
314
316
AST_NODE (TK_LAMBDACAPTURES );
315
317
SKIP (NULL , TK_LPAREN , TK_LPAREN_NEW );
316
- RULE ("capture" , lambdacapture );
317
- WHILE (TK_COMMA , RULE ("capture" , lambdacapture ));
318
+ RULE ("capture" , lambdacapture , thisliteral );
319
+ WHILE (TK_COMMA , RULE ("capture" , lambdacapture , thisliteral ));
318
320
SKIP (NULL , TK_RPAREN );
319
321
DONE ();
320
322
Original file line number Diff line number Diff line change @@ -955,6 +955,18 @@ static ast_result_t syntax_lambda(pass_opt_t* opt, ast_t* ast)
955
955
default : {}
956
956
}
957
957
958
+ ast_t * capture = ast_child (captures );
959
+ while (capture != NULL )
960
+ {
961
+ if (ast_id (capture ) == TK_THIS )
962
+ {
963
+ ast_error (opt -> check .errors , capture ,
964
+ "use a named capture to capture 'this'" );
965
+ return AST_ERROR ;
966
+ }
967
+ capture = ast_sibling (capture );
968
+ }
969
+
958
970
return AST_OK ;
959
971
}
960
972
You can’t perform that action at this time.
0 commit comments