Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Parse scope declarators on packages; minor actions updates.
  • Loading branch information
jnthn committed Mar 11, 2011
1 parent 3100f3d commit e458b36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/NQP/Actions.pm
Expand Up @@ -414,7 +414,6 @@ method package_def($/) {

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

# Prefix the class initialization with initial setup. Also install it
# in the symbol table right away.
Expand All @@ -423,15 +422,23 @@ method package_def($/) {
PAST::Var.new( :name('type_obj'), :scope('register'), :isdecl(1) ),
$*SC.get_slot_past_for_object($*PKGMETA)
),
PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name($name), :namespace(@ns), :scope('package') ),
PAST::Var.new( :name('type_obj'), :scope('register') )
),
PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name('$?CLASS') ),
PAST::Var.new( :name('type_obj'), :scope('register') )
)
));

# Install it in the package or lexpad as needed.
if $*SCOPE eq 'our' || $*SCOPE eq '' {
$past.namespace( $<name><identifier> );
$*PACKAGE-SETUP[0].push(PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name($name), :namespace(@ns), :scope('package') ),
PAST::Var.new( :name('type_obj'), :scope('register') )
));
}
else {
$/.CURSOR.panic("$*SCOPE scoped packages are not supported");
}

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

method scoped($/) {
make $<declarator>
?? $<declarator>.ast
!! $<multi_declarator>.ast;
make $<declarator> ?? $<declarator>.ast !!
$<multi_declarator> ?? $<multi_declarator>.ast !!
$<package_declarator>.ast;
}

method declarator($/) {
Expand Down
1 change: 1 addition & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -358,6 +358,7 @@ token scope_declarator:sym<has> { <sym> <scoped('has')> }
rule scoped($*SCOPE) {
| <declarator>
| <multi_declarator>
| <package_declarator>
}

token typename { <name> }
Expand Down

0 comments on commit e458b36

Please sign in to comment.