perl.cvs.parrot
[Top] [All Lists]

[svn:parrot] r23869 - trunk/languages/perl6/src/parser

Subject: [svn:parrot] r23869 - trunk/languages/perl6/src/parser
From:
Date: Thu, 13 Dec 2007 15:52:28 -0800 PST
Newsgroups: perl.cvs.parrot

Author: pmichaud
Date: Thu Dec 13 15:52:27 2007
New Revision: 23869

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

Log:
[perl6]:  Add arity-based multisubs
* t/01-sanity/07-simple_multisub.t passes (two left to go!)
* Signatures now set the 'arity' attribute on any blocks they create.
* Subs marked 'multi' use the arity attribute to generate a PIR
  :multi(...) flag on the PAST block.


Modified: trunk/languages/perl6/src/parser/actions.pm
==============================================================================
--- trunk/languages/perl6/src/parser/actions.pm (original)
+++ trunk/languages/perl6/src/parser/actions.pm Thu Dec 13 15:52:27 2007
@@ -210,6 +210,28 @@
 }
 
 
+method plurality_declarator($/) {
+    my $past := $( $<routine_declarator> );
+    if $<sym> eq 'multi' {
+        my $pirflags := ~ $past.pirflags();
+        my $arity := $past.arity();
+        if    $arity == 0 { $pirflags := $pirflags ~ ' :multi()'; }
+        elsif $arity == 1 { $pirflags := $pirflags ~ ' :multi(_)'; }
+        else {
+            $pirflags := $pirflags ~ ' :multi(_';
+            my $count := 1;
+            while $count != $arity {
+                $pirflags := $pirflags ~ ',_';
+                $count := $count + 1;
+            }
+            $pirflags := $pirflags ~ ')';
+        }
+        $past.pirflags($pirflags);
+    }
+    make $past;
+}
+
+
 method routine_declarator($/, $key) {
     if ($key eq 'sub') {
         my $past := $($<routine_def>);
@@ -237,6 +259,7 @@
         $past.symbol($param_var.name(), :scope('lexical'));
         $params.push($param_var);
     }
+    $past.arity( +$/[0] );
     our $?BLOCK_SIGNATURED := $past;
     make $past;
 }

Modified: trunk/languages/perl6/src/parser/grammar.pg
==============================================================================
--- trunk/languages/perl6/src/parser/grammar.pg (original)
+++ trunk/languages/perl6/src/parser/grammar.pg Thu Dec 13 15:52:27 2007
@@ -246,7 +246,11 @@
 
 #### Subroutine and method definitions ####
 
-rule routine_declarator {
+rule plurality_declarator {
+    $<sym>=[multi|proto|only] <routine_declarator> {*}
+}
+
+token routine_declarator {
     | $<sym>='sub' <routine_def> {*}             #= sub
     # | $<sym>='method' <method_def> {*}           #= method
 }
@@ -314,6 +318,7 @@
 
 token noun {
     | <scope_declarator> {*}                     #= scope_declarator
+    | <plurality_declarator> {*}                 #= plurality_declarator
     | <routine_declarator> {*}                   #= routine_declarator
     | <circumfix> {*}                            #= circumfix
     | <variable> {*}                             #= variable

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:parrot] r23869 - trunk/languages/perl6/src/parser, pmichaud <=