Author: jonathan
Date: Thu Jan 31 15:24:06 2008
New Revision: 25391

Modified:
   trunk/languages/perl6/perl6.pir
   trunk/languages/perl6/src/parser/actions.pm

Log:
[rakudo] Start to handle nested classes. We don't get the nested namespaces 
right yet, but at least attributes and methods get associated with the correct 
class now.

Modified: trunk/languages/perl6/perl6.pir
==============================================================================
--- trunk/languages/perl6/perl6.pir     (original)
+++ trunk/languages/perl6/perl6.pir     Thu Jan 31 15:24:06 2008
@@ -92,6 +92,10 @@
     $P0 = new 'List'
     set_hll_global ['Perl6';'Grammar';'Actions'], '@?BLOCK', $P0
 
+    ## create a list for holding the stack of nested classes
+    $P0 = new 'List'
+    set_hll_global ['Perl6';'Grammar';'Actions'], '@?CLASS', $P0
+
     ##  create a list of END blocks to be run
     $P0 = new 'List'
     set_hll_global ['Perl6'], '@?END_BLOCKS', $P0

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 31 15:24:06 2008
@@ -471,18 +471,22 @@
 
 method package_declarator($/, $key) {
     our $?CLASS;
+    our @?CLASS;
 
     if $key eq 'open' {
         # Start of the block; if it's a class, need to make $?CLASS available
         # for storing current class definition in.
-        # XXX need array to support nested classes
-        my $decl_past := PAST::Stmts.new();
-
-        # Code to create the class.
-        my $pir := "    $P0 = subclass 'Perl6Object', '" ~ $<name> ~ "'\n";
-        $decl_past.push(PAST::Op.new( :inline($pir) ));
-
-        $?CLASS := $decl_past;
+        if $<sym> eq 'class' {
+            # Code to create the class.
+            my $decl_past := PAST::Stmts.new();
+            my $pir := "    $P0 = subclass 'Perl6Object', '" ~ $<name> ~ "'\n";
+            $decl_past.push(PAST::Op.new( :inline($pir) ));
+            
+            # Put current class, if any, on @?CLASS list so we can handle
+            # nested classes.
+            @?CLASS.unshift( $?CLASS );
+            $?CLASS := $decl_past;
+        }
     }
     else {
         my $past := $( $/{$key} );
@@ -500,6 +504,9 @@
             
             # Attatch class declaration to this block.
             $past.unshift( $?CLASS );
+
+            # Restore outer class.
+            $?CLASS := @?CLASS.shift();
         }
         else {
             $past.namespace($<name><ident>);

Reply via email to