Skip to content

Commit e458b36

Browse files
committed
Parse scope declarators on packages; minor actions updates.
1 parent 3100f3d commit e458b36

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/NQP/Actions.pm

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ method package_def($/) {
414414

415415
# Get the body code.
416416
my $past := $<block> ?? $<block>.ast !! $<comp_unit>.ast;
417-
$past.namespace( $<name><identifier> );
418417

419418
# Prefix the class initialization with initial setup. Also install it
420419
# in the symbol table right away.
@@ -423,15 +422,23 @@ method package_def($/) {
423422
PAST::Var.new( :name('type_obj'), :scope('register'), :isdecl(1) ),
424423
$*SC.get_slot_past_for_object($*PKGMETA)
425424
),
426-
PAST::Op.new( :pasttype('bind'),
427-
PAST::Var.new( :name($name), :namespace(@ns), :scope('package') ),
428-
PAST::Var.new( :name('type_obj'), :scope('register') )
429-
),
430425
PAST::Op.new( :pasttype('bind'),
431426
PAST::Var.new( :name('$?CLASS') ),
432427
PAST::Var.new( :name('type_obj'), :scope('register') )
433428
)
434429
));
430+
431+
# Install it in the package or lexpad as needed.
432+
if $*SCOPE eq 'our' || $*SCOPE eq '' {
433+
$past.namespace( $<name><identifier> );
434+
$*PACKAGE-SETUP[0].push(PAST::Op.new( :pasttype('bind'),
435+
PAST::Var.new( :name($name), :namespace(@ns), :scope('package') ),
436+
PAST::Var.new( :name('type_obj'), :scope('register') )
437+
));
438+
}
439+
else {
440+
$/.CURSOR.panic("$*SCOPE scoped packages are not supported");
441+
}
435442

436443
# Evaluate everything in the package in-line unless this is a generic
437444
# type in which case it needs delayed evaluation. Normally, $?CLASS is
@@ -531,9 +538,9 @@ method scope_declarator:sym<our>($/) { make $<scoped>.ast; }
531538
method scope_declarator:sym<has>($/) { make $<scoped>.ast; }
532539

533540
method scoped($/) {
534-
make $<declarator>
535-
?? $<declarator>.ast
536-
!! $<multi_declarator>.ast;
541+
make $<declarator> ?? $<declarator>.ast !!
542+
$<multi_declarator> ?? $<multi_declarator>.ast !!
543+
$<package_declarator>.ast;
537544
}
538545

539546
method declarator($/) {

src/NQP/Grammar.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ token scope_declarator:sym<has> { <sym> <scoped('has')> }
358358
rule scoped($*SCOPE) {
359359
| <declarator>
360360
| <multi_declarator>
361+
| <package_declarator>
361362
}
362363

363364
token typename { <name> }

0 commit comments

Comments
 (0)