src: mass rename project->package
[nit.git] / src / parser / prescc.pl
index 4159cf8..debd2f8 100755 (executable)
@@ -20,7 +20,7 @@
 #
 # Synopsis
 #
-#   Extends a sablecc grammar with parametrized productions.
+#   Extends a sablecc grammar with parametrized productions and other syntactic stuff.
 #
 # Description
 #
@@ -54,6 +54,34 @@ while (<>) {
 }
 $lines = join "", @lines;
 
+$current = "";
+for (@lines) {
+       if (/^.*{\s*->\s*(\w+)\s*}/) {
+               $current = $1;
+       }
+       $current = "" if /;/;
+       next if ($current eq "");
+       if (s/{\:(\w+)}/{$1}/) {
+               $alt = $1;
+               @newargs = ();
+               while (/((\[(\w*)\])?:)?([\w~]+)(})?/g) {
+                       $id=defined $3?$3:$4;
+                       next if ((defined $1) && !(defined $3));
+                       next if (defined $5);
+                       $4 =~ /([a-z]+)/;
+                       $argalt = $1;
+                       if ($id eq $argalt) {
+                               push @newargs, "$id";
+                       } else {
+                               push @newargs, "$id.$argalt";
+                       }
+               }
+               chomp;
+               $_ .= " {-> New $current.$alt(". join(", ", @newargs) .")}\n";
+               s/([^\]])\:(\w+)/$1$2/g;
+       }
+}
+
 # List all the available parameters in the extended grammar
 @params = ();
 while ($lines =~ /\~([a-zA-Z]+)/g) {