Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
basic processing script
  • Loading branch information
moritz committed Jul 25, 2011
1 parent 569fb82 commit 7701afe
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 2 deletions.
4 changes: 2 additions & 2 deletions features.txt
Expand Up @@ -50,8 +50,8 @@ Argument coercion: rm+ rn- n-
Type captures: rm+ rn+ n-

= Built-in types and functions
Strings, split, join, case folding, substr:
Basic numbers, arithmethic operations:
Strings, split, join, case folding, substr: rm+ rn+ n+
Basic numbers, arithmethic operations: rm+ rn+ n+
Big integers: rm- rn- n+
Complex numbers: rm+ rn+ n+
Rat type: rm+ rn+ n+
Expand Down
95 changes: 95 additions & 0 deletions process.pl
@@ -0,0 +1,95 @@
use 5.010;
use strict;
use warnings;
use utf8;
use autodie;


use Data::Dumper;
my $comment = qr{^\s*(?:\#.*)?$};

open my $f, '<:encoding(UTF-8)', 'features.txt';
my %abbr_name;
my %abbr_index;
my $index = 0;
my $in_abbr_section;
my @sections;

while (<$f>) {
chomp;
next if $_ ~~ $comment;
if (/^=\s+(.*)/) {
my $title = $1;
if ($title eq 'ABBREVIATIONS') {
$in_abbr_section = 1;
} else {
$in_abbr_section = 0;
push @sections, [$title];
}
}
else {
if ($in_abbr_section) {
my ($abbr, $name) = split /\s+/, $_, 2;
$abbr_name{$abbr} = $name;
$abbr_index{$abbr} = ++$index;
}
else {
my ($name, $rest) = split /:\s*/, $_, 2;
push @{$sections[-1]}, [$name];
while ($rest =~ m/(\w+)([+-]+)\s*(?:\(([^()]+)\)\s*)?/g) {
my ($abbr, $rating, $comment) = ($1, $2, $3);
die "Unknown abbreviation '$abbr'"
unless exists $abbr_name{$abbr};
my $i = $abbr_index{$abbr};
die "Multiple data points for abbr '$abbr' at line $. -- possible typo?"
if $sections[-1][-1][$i];
# TODO: don't throw away the comments;
$sections[-1][-1][$i] = $rating;
}
}
}
}

close $f;
write_html();

sub write_html {
require HTML::Template::Compiled;
my $t = HTML::Template::Compiled->new(
filename => 'template.html',
open_mode => ':encoding(UTF-8)',
default_escape => 'HTML',
global_vars => 1,
);
my @compilers;
for (keys %abbr_index) {
$compilers[$abbr_index{$_}] = {name => $abbr_name{$_}};
}
shift @compilers;
$t->param(compilers => \@compilers);
$t->param(columns => 1 + @compilers);

my %status_map = (
'+' => 'implemented',
'+-' => 'partial',
'-' => 'missing',
'' => 'unknown',
);

my @rows;
for my $s (@sections) {
my @sec = @$s;
push @rows, {section => shift @sec};
for (@sec) {
my %ht_row;
my @row = @$_;
$ht_row{feature} = shift @row;
$ht_row{compilers} = [ map {
{ status => $status_map{$row[$_] // ''} }
} 0..($index - 1) ];
push @rows, \%ht_row;
}
}
$t->param(rows => \@rows);
say $t->output;
}
44 changes: 44 additions & 0 deletions template.html
@@ -0,0 +1,44 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Feature comparison blah</title>
<style type="text/css">
.implemented { background-color: green }
.partial { background-color: yellow }
.missing { background-color: red }
</style>

</head>
<body>
<h1>Feature comparison of Perl 6 compilers</h1>
<table>
<thead>
<tr>
<th>Feature</th>
<%loop compilers%>
<th><%var name%></th>
<%/loop%>
</tr>
</thead>
<tbody>
<%loop rows%>
<tr>
<%if section%>
<th colspan="<%var columns%>"><%var section%></th>
<%else%>
<td><%var feature%></td>
<%loop compilers%>
<td class="<%var status%>">
<%var status%>
</td>
<%/loop%>
<%/if%>
</tr>
<%/loop%>
</tbody>
</table>
</body>
</html>

0 comments on commit 7701afe

Please sign in to comment.