[svn:parrot] r46957 - trunk/compilers/opsc/src/Ops/Compiler

bacek at svn.parrot.org bacek at svn.parrot.org
Mon May 24 10:50:41 UTC 2010


Author: bacek
Date: Mon May 24 10:50:41 2010
New Revision: 46957
URL: https://trac.parrot.org/parrot/changeset/46957

Log:
Improve opsc little bit more: rename op_params into singature, macro_param limited to 9, use rule instead of regex for op_macro

Modified:
   trunk/compilers/opsc/src/Ops/Compiler/Actions.pm
   trunk/compilers/opsc/src/Ops/Compiler/Grammar.pm

Modified: trunk/compilers/opsc/src/Ops/Compiler/Actions.pm
==============================================================================
--- trunk/compilers/opsc/src/Ops/Compiler/Actions.pm	Mon May 24 10:50:27 2010	(r46956)
+++ trunk/compilers/opsc/src/Ops/Compiler/Actions.pm	Mon May 24 10:50:41 2010	(r46957)
@@ -63,10 +63,7 @@
         %flags{~$_<identifier>} := 1;
     }
 
-    my @args := list();
-    if ($<op_params>) {
-        @args := @($<op_params>[0].ast);
-    }
+    my @args := @($<signature>.ast);
 
     my @norm_args := normalize_args(@args);
     # We have to clone @norm_args. Otherwise it will be destroyed...
@@ -224,7 +221,7 @@
 }
 
 
-method op_params($/) {
+method signature($/) {
     my $past := PAST::Stmts.new(
         :node($/)
     );

Modified: trunk/compilers/opsc/src/Ops/Compiler/Grammar.pm
==============================================================================
--- trunk/compilers/opsc/src/Ops/Compiler/Grammar.pm	Mon May 24 10:50:27 2010	(r46956)
+++ trunk/compilers/opsc/src/Ops/Compiler/Grammar.pm	Mon May 24 10:50:41 2010	(r46957)
@@ -34,9 +34,9 @@
 }
 
 rule op {
-    <op_type>? 'op' <op_name=identifier> '('
-        [ <op_params>? || <panic: "Fail to parse params"> ]
-    ')' <op_flag>*
+    <op_type>? 'op' <op_name=identifier>
+    [ '(' <signature> ')' || <panic: "Fail to parse signature"> ]
+    <op_flag>*
     [ <op_body> || <panic: "Fail to parse op body"> ]
     {*}
 }
@@ -45,9 +45,7 @@
     [ 'inline' | 'function' ]
 }
 
-rule op_params {
-    <op_param> [ ',' <op_param> ]*
-}
+rule signature { [ [<.ws><op_param><.ws>] ** ',' ]? }
 
 rule op_param {
     <op_param_direction> <op_param_type>
@@ -93,18 +91,18 @@
 #or goto NEXT() ) in the midst of the words.
 regex body_word {
     [
-    | <macro_param>
-    | <op_macro>
-    | $<word>=[<alnum>+|<punct>|<space>+]
+    || <macro_param>
+    || <op_macro>
+    || $<word>=[<alnum>+|<punct>|<space>+]
     ]
 }
 
 token macro_param {
-    '$' $<num>=[<digit>+]
+    '$' $<num>=<[1..9]> # Up to nine params.
 }
 
-regex op_macro {
-    <macro_type> <space>* <macro_destination> <space>* '(' <space>* <body_word>*? ')'
+rule op_macro {
+    <macro_type> <macro_destination> '(' <body_word>*? ')'
 }
 
 token macro_type {


More information about the parrot-commits mailing list