[t/spec] Fix number of tests for defined.t.
[pugs.git] / util / grokprims.pl
blob0438adfe9d39a7098b88371959d112c591d0b9e6
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
5 while (<>) {
6 last if /^initSyms = /;
9 my %assoc = (
10 spre => 'special',
11 pre => 'prefix',
12 post => 'postfix',
13 left => 'left-associative infix',
14 right => 'right-associative infix',
15 non => 'non-associative infix',
16 list => 'list infix',
17 chain => 'chaining infix',
20 my @ops;
22 while (<>) {
23 last unless /^\\\\n[^"]/;
24 chomp;
26 my (undef, $ret, $assoc, $name, $args) = split ' ', $_, 5;
28 $name =~ s/\\(.)/$1/g;
30 $args =~ m/\((.*)\)/ or die "Bad args spec";
31 $args = $1;
33 my @args = split /, *| +/, $args;
35 if (exists $assoc{$assoc}) {
36 $assoc = $assoc{$assoc};
37 } else {
38 $assoc = "FIXME: $assoc";
41 push @ops, {name=>$name, ret=>$ret, assoc=>$assoc, args=>[@args], line=>$.}
44 print '<?xml version="1.1" encoding="UTF-8" ?><html><body><table border="1">';
48 foreach my $op (sort
50 $a->{name} cmp $b->{name} or
51 $a->{assoc} cmp $b->{assoc} or
52 @{$a->{args}} <=> @{$b->{args}}} @ops
53 ) {
55 my $example;
57 local $_=$op->{assoc};
58 my $name = $op->{name};
59 my $a0 = $op->{args}[0];
60 my $a1 = $op->{args}[1];
61 my $arity = 0+@{$op->{args}};
63 if (/prefix/) {
64 if (($arity>1 and $a0 =~ s/:$//) or
65 $arity==1) {
66 $example = "\$$a0.$name(".join(', ', map {"\$$_"} @{$op->{args}}[1..$arity-1]).")<br />";
68 $example .= "$name(". join(', ', map {$a=$_; $a=~s/:$//; '$'.$a} @{$op->{args}}) .")";
69 } elsif (/(list|chaining) infix/) {
70 $example = "\$$a0 $name \$$a0 $name \$$a0";
71 } elsif (/left-associative/ and $arity==2) {
72 $example = "(\$$a0 $name \$$a1) $name \$$a1";
73 } elsif (/left-associative/ and $arity==2) {
74 $example = "HUH: left-associative with arity $arity";
75 } elsif (/right-associative/) {
76 $example = "\$$a0 $name (\$$a0 $name \$$a1)";
77 } elsif (/non-associative/) {
78 $example = "\$$a0 $name \$$a1";
79 } elsif (/postfix/ and $arity == 1) {
80 $example = "\$$a0$name";
81 } elsif (/special/ and $arity == 1) {
82 $example = "$name\$$a0 # ???";
83 } else {
84 $example = "$_ ($arity)";
87 print " <tr>";
88 print "<td><tt>$example</tt></td>";
89 print "<td>$op->{assoc}</td>";
90 print "<td>$op->{ret}</td>";
91 print "<td><tt>$op->{name}</tt></td>";
92 print "<td>(</td>";
93 print "<td><table border='1' width='100%'><tr>";
94 foreach my $arg (@{$op->{args}}) {
95 print "<td>$arg</td>";
97 print "</td></tr></table>";
98 print "<td>)</td>";
99 # print "<td>Prim.hs line $op->{line}</td>";
100 print "</tr>\n";
103 print "</table></body></html>";