Author: jonathan Date: Thu Jan 22 05:01:36 2009 New Revision: 35884 Modified: trunk/languages/perl6/perl6.pir trunk/languages/perl6/src/parser/actions.pm trunk/languages/perl6/src/parser/grammar.pg trunk/languages/perl6/src/parser/methods.pir
Log: [rakudo] Improve support for nested packages; gets the issues in various RT tickets resolved. Modified: trunk/languages/perl6/perl6.pir ============================================================================== --- trunk/languages/perl6/perl6.pir (original) +++ trunk/languages/perl6/perl6.pir Thu Jan 22 05:01:36 2009 @@ -96,6 +96,12 @@ $P0 = new 'List' set_hll_global ['Perl6';'Grammar';'Actions'], '@?PKGDECL', $P0 + ## create a list for holding the stack of nested package + ## namespaces (we store the namespace as a flat, :: + ## separated string for now, for handing to .parse_name) + $P0 = new 'List' + set_hll_global ['Perl6';'Grammar';'Actions'], '@?NS', $P0 + ## create a (shared) metaclass node $P0 = get_hll_global ['PAST'], 'Var' $P0 = $P0.'new'( 'name'=>'metaclass', 'scope'=>'register' ) Modified: trunk/languages/perl6/src/parser/actions.pm ============================================================================== --- trunk/languages/perl6/src/parser/actions.pm (original) +++ trunk/languages/perl6/src/parser/actions.pm Thu Jan 22 05:01:36 2009 @@ -1505,6 +1505,7 @@ method package_declarator($/, $key) { our @?PKGDECL; + our @?NS; my $sym := ~$<sym>; my $past; if $key eq 'open' { @@ -1523,17 +1524,32 @@ method package_def($/, $key) { our @?PKGDECL; my $?PKGDECL := @?PKGDECL[0]; + our @?NS; if $key eq 'panic' { $/.panic("Unable to parse " ~ $?PKGDECL ~ " definition"); } + # At block opening, unshift module name (fully qualified) onto @?NS; otherwise, + # shift it off. + if $key eq 'open' { + my $fqname := +...@?ns ?? @?NS[0] ~ '::' ~ ~$<module_name>[0] !! ~$<module_name>[0]; + @?NS.unshift($fqname); + return 0; + } + else { + @?NS.shift(); + } + my $block := $( $/{$key} ); $block.lexical(0); my $modulename := $<module_name> ?? ~$<module_name>[0] !! $block.unique('!ANON'); + if +...@?ns > 0 { + $modulename := @?NS[0] ~ '::' ~ $modulename; + } # See note at top of file for %?CLASSMAP. if %?CLASSMAP{$modulename} { $modulename := %?CLASSMAP{$modulename}; } @@ -1555,7 +1571,7 @@ # And if there's no signature, make sure we set one up and add [] to # the namespace name. - if $modulename eq ~$<module_name>[0]<name> { + if substr($modulename, -1, 1) ne ']' { $modulename := $modulename ~ '[]'; block_signature($block); } Modified: trunk/languages/perl6/src/parser/grammar.pg ============================================================================== --- trunk/languages/perl6/src/parser/grammar.pg (original) +++ trunk/languages/perl6/src/parser/grammar.pg Thu Jan 22 05:01:36 2009 @@ -636,7 +636,8 @@ $S0 = $P0.'text'() match.'add_type'($S0) }} - ]? + ]? + {*} #= open <trait>* [ | <?{{ $P0 = get_global '$begin_compunit' Modified: trunk/languages/perl6/src/parser/methods.pir ============================================================================== --- trunk/languages/perl6/src/parser/methods.pir (original) +++ trunk/languages/perl6/src/parser/methods.pir Thu Jan 22 05:01:36 2009 @@ -47,6 +47,19 @@ it_loop_end: cur_block.'symbol'(name, 'does_abstraction'=>1) + # We also need to register it under it's fully qualified name at the outermost + # block. + $P0 = get_hll_global ['Perl6';'Grammar';'Actions'], '@?NS' + unless $P0 goto no_ns + $S0 = $P0[0] + concat $S0, '::' + name = concat $S0, name + no_ns: + $I0 = elements blocks + dec $I0 + $P0 = blocks[$I0] + $P0.'symbol'(name, 'does_abstraction'=>1) + done: .end