-    my $args = $action->[2] == 1 ? '' : join(', ', map { "action[$_]" } (2..$action->[2]));
-
-    printf('      %s if (action[0] == \'%s\')%s $(action[1]).%s(%s);' . "\n",
-           $first ? '    ' : 'else',
-           $action->[1],
-           ' ' x ($longest - length($action->[1])),
-           $action->[1],
-           $args);
-    $first = 0;
+    my $args = $action->[2] == 1 ? ''
+             : $action->[2] <  0 ? 'action.slice(2, action.length)'
+             :                     join(', ', map { "action[$_]" } (2..$action->[2]));
+
+    $output .= sprintf('      %s if (action[0] == \'%s\')%s ',
+                       $first ? '    ' : 'else',
+                       $action->[1],
+                       ' ' x ($longest - length($action->[1])));
+
+    my $function =  $action->[1];
+    $function    =~ s/.*://;
+
+    my $call     =  $action->[3] || $pattern;
+    $call        =~ s/<TARGET>/'action[1]'/eg;
+    $call        =~ s/<FUNCTION>/$function/eg;
+    $call        =~ s/<ARGS>/$args/eg;
+    $call        =~ s/<ARG(\d+)>/'action[' . ($1 + 1) . ']'/eg;
+
+    $output .= $call . ";\n";
+    $first   = 0;