Author: jonathan
Date: Tue Nov 11 07:30:06 2008
New Revision: 32542

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

Log:
[rakudo] A while back, some changes were done that set $?CLASS when a grammar 
was created. But since we checked $?PACKAGE =:= $?GRAMMAR second after checking 
$?PACKAGE =:= $?CLASS, we stopped creating grammars properly, meaning they 
started inheriting from Any instead of some grammar rules. This switches around 
the ordering. Also re-fixes the bug originally fixed before this change where 
$?NS wasn't cleared.

Modified: trunk/languages/perl6/src/parser/actions.pm
==============================================================================
--- trunk/languages/perl6/src/parser/actions.pm (original)
+++ trunk/languages/perl6/src/parser/actions.pm Tue Nov 11 07:30:06 2008
@@ -1592,7 +1592,29 @@
 
     if $key eq 'open' {
         # Start of package definition. Handle class and grammar specially.
-        if $?PACKAGE =:= $?CLASS {
+        if $?PACKAGE =:= $?GRAMMAR {
+            # Anonymous grammars not supported.
+            unless $name {
+                $/.panic('Anonymous grammars not supported');
+            }
+
+            # Start of grammar definition. Create grammar class object.
+            $?GRAMMAR.push(
+                PAST::Op.new(
+                    :pasttype('bind'),
+                    PAST::Var.new(
+                        :name('$def'),
+                        :scope('lexical')
+                    ),
+                    PAST::Op.new(
+                        :pasttype('call'),
+                        :name('!keyword_grammar'),
+                        PAST::Val.new( :value(~$name[0]) )
+                    )
+                )
+            );
+        }
+        elsif $?PACKAGE =:= $?CLASS {
             my $class_def;
 
             if !have_trait('also', 'is', $<trait>) {
@@ -1649,28 +1671,6 @@
 
             $?CLASS.push($class_def);
         }
-        elsif $?PACKAGE =:= $?GRAMMAR {
-            # Anonymous grammars not supported.
-            unless $name {
-                $/.panic('Anonymous grammars not supported');
-            }
-
-            # Start of grammar definition. Create grammar class object.
-            $?GRAMMAR.push(
-                PAST::Op.new(
-                    :pasttype('bind'),
-                    PAST::Var.new(
-                        :name('$def'),
-                        :scope('lexical')
-                    ),
-                    PAST::Op.new(
-                        :pasttype('call'),
-                        :name('!keyword_grammar'),
-                        PAST::Val.new( :value(~$name[0]) )
-                    )
-                )
-            );
-        }
         else {
             # Anonymous modules not supported.
             unless $name {
@@ -1701,7 +1701,41 @@
         $past.blocktype('declaration');
         $past.pirflags(':init :load');
 
-        if $?PACKAGE =:= $?CLASS {
+        if $?PACKAGE =:= $?GRAMMAR {
+            # Apply traits.
+            apply_package_traits($?GRAMMAR, $<trait>);
+
+            # Make proto-object for grammar.
+            $?GRAMMAR.push(
+                PAST::Op.new(
+                    :pasttype('callmethod'),
+                    :name('register'),
+                    PAST::Var.new(
+                        :scope('package'),
+                        :name('$!P6META'),
+                        :namespace('Perl6Object')
+                    ),
+                    PAST::Var.new(
+                        :scope('lexical'),
+                        :name('$def')
+                    ),
+                    PAST::Val.new(
+                        :value('Grammar'),
+                        :named( PAST::Val.new( :value('parent') ) )
+                    )
+                )
+            );
+
+            # Attatch grammar declaration to the init code.
+            unless defined( $?INIT ) {
+                $?INIT := PAST::Block.new();
+            }
+            $?INIT.push( $?GRAMMAR );
+
+            # Clear namespace.
+            $?NS := '';
+        }
+        elsif $?PACKAGE =:= $?CLASS {
             # Apply traits.
             apply_package_traits($?CLASS, $<trait>);
 
@@ -1760,40 +1794,6 @@
                 }
             }
         }
-        elsif $?PACKAGE =:= $?GRAMMAR {
-            # Apply traits.
-            apply_package_traits($?GRAMMAR, $<trait>);
-
-            # Make proto-object for grammar.
-            $?GRAMMAR.push(
-                PAST::Op.new(
-                    :pasttype('callmethod'),
-                    :name('register'),
-                    PAST::Var.new(
-                        :scope('package'),
-                        :name('$!P6META'),
-                        :namespace('Perl6Object')
-                    ),
-                    PAST::Var.new(
-                        :scope('lexical'),
-                        :name('$def')
-                    ),
-                    PAST::Val.new(
-                        :value('Grammar'),
-                        :named( PAST::Val.new( :value('parent') ) )
-                    )
-                )
-            );
-
-            # Attatch grammar declaration to the init code.
-            unless defined( $?INIT ) {
-                $?INIT := PAST::Block.new();
-            }
-            $?INIT.push( $?GRAMMAR );
-
-            # Clear namespace.
-            $?NS := '';
-        }
 
         make $past;
     }

Reply via email to