@@ -227,6 +227,30 @@ class Perl6::Actions is HLL::Actions does STDActions {
227
227
}
228
228
}
229
229
230
+ method deftermnow ($/ ) {
231
+ # 'my \foo' style declaration
232
+ if $ * SCOPE ne ' my' {
233
+ $ * W . throw ($/ , ' X::Comp::NYI' ,
234
+ feature => " $ * SCOPE scoped term definitions (only 'my' is supported at the moment)" );
235
+ }
236
+ my $ name := $ < defterm > . ast;
237
+ my $ cur_lexpad := $ * W . cur_lexpad;
238
+ if $ cur_lexpad . symbol($ name ) {
239
+ $ * W . throw ($/ , [' X' , ' Redeclaration' ], symbol => $ name );
240
+ }
241
+ if $ * OFTYPE {
242
+ my $ type := $ * OFTYPE . ast;
243
+ $ cur_lexpad [0 ]. push (QAST ::Var. new ( : $ name , : scope(' lexical' ),
244
+ : decl(' var' ), : returns($ type ) ));
245
+ $ cur_lexpad . symbol($ name , : $ type , : scope<lexical >);
246
+ }
247
+ else {
248
+ $ cur_lexpad [0 ]. push (QAST ::Var. new (: $ name , : scope(' lexical' ), : decl(' var' )));
249
+ $ cur_lexpad . symbol($ name , : scope(' lexical' ));
250
+ }
251
+ make $ < defterm > . ast;
252
+ }
253
+
230
254
method defterm ($/ ) {
231
255
my $ name := ~ $ < identifier > ;
232
256
if $ < colonpair > {
@@ -2432,22 +2456,11 @@ Compilation unit '$file' contained the following violations:
2432
2456
2433
2457
make $ list ;
2434
2458
}
2435
- elsif $ < defterm > {
2459
+ elsif $ < deftermnow > {
2436
2460
# 'my \foo' style declaration
2437
- if $ * SCOPE ne ' my' {
2438
- $ * W . throw ($/ , ' X::Comp::NYI' ,
2439
- feature => " $ * SCOPE scoped term definitions (only 'my' is supported at the moment)" );
2440
- }
2441
- my $ name := $ < defterm > . ast;
2442
- my $ cur_lexpad := $ * W . cur_lexpad;
2443
- if $ cur_lexpad . symbol($ name ) {
2444
- $ * W . throw ($/ , [' X' , ' Redeclaration' ], symbol => $ name );
2445
- }
2461
+ my $ name := $ < deftermnow > . ast;
2446
2462
if $ * OFTYPE {
2447
2463
my $ type := $ * OFTYPE . ast;
2448
- $ cur_lexpad [0 ]. push (QAST ::Var. new ( : $ name , : scope(' lexical' ),
2449
- : decl(' var' ), : returns($ type ) ));
2450
- $ cur_lexpad . symbol($ name , : $ type , : scope<lexical >);
2451
2464
make QAST ::Op. new (
2452
2465
: op<bind >,
2453
2466
QAST ::Var. new (: $ name , : scope<lexical >),
@@ -2461,14 +2474,12 @@ Compilation unit '$file' contained the following violations:
2461
2474
);
2462
2475
}
2463
2476
else {
2464
- $ cur_lexpad [0 ]. push (QAST ::Var. new (: $ name , : scope(' lexical' ), : decl(' var' )));
2465
- $ cur_lexpad . symbol($ name , : scope(' lexical' ));
2466
2477
make QAST ::Op. new (
2467
2478
: op<bind >,
2468
2479
QAST ::Var. new (: $ name , : scope<lexical >),
2469
2480
$ < term_init > . ast
2470
2481
);
2471
- }
2482
+ }
2472
2483
}
2473
2484
else {
2474
2485
$/ . CURSOR. panic(' Unknown declarator type' );
0 commit comments