Skip to content
Newer
Older
100644 99 lines (90 sloc) 2.53 KB
7701afe @moritz basic processing script
moritz authored
1 use 5.010;
2 use strict;
3 use warnings;
4 use utf8;
5 use autodie;
6
7
8 use Data::Dumper;
9 my $comment = qr{^\s*(?:\#.*)?$};
10
11 open my $f, '<:encoding(UTF-8)', 'features.txt';
12 my %abbr_name;
13 my %abbr_index;
14 my $index = 0;
15 my $in_abbr_section;
16 my @sections;
17
18 while (<$f>) {
19 chomp;
20 next if $_ ~~ $comment;
21 if (/^=\s+(.*)/) {
22 my $title = $1;
23 if ($title eq 'ABBREVIATIONS') {
24 $in_abbr_section = 1;
25 } else {
26 $in_abbr_section = 0;
27 push @sections, [$title];
28 }
29 }
30 else {
31 if ($in_abbr_section) {
32 my ($abbr, $name) = split /\s+/, $_, 2;
33 $abbr_name{$abbr} = $name;
34 $abbr_index{$abbr} = ++$index;
35 }
36 else {
37 my ($name, $rest) = split /:\s*/, $_, 2;
38 push @{$sections[-1]}, [$name];
39 while ($rest =~ m/(\w+)([+-]+)\s*(?:\(([^()]+)\)\s*)?/g) {
40 my ($abbr, $rating, $comment) = ($1, $2, $3);
41 die "Unknown abbreviation '$abbr'"
42 unless exists $abbr_name{$abbr};
43 my $i = $abbr_index{$abbr};
44 die "Multiple data points for abbr '$abbr' at line $. -- possible typo?"
45 if $sections[-1][-1][$i];
46 # TODO: don't throw away the comments;
47 $sections[-1][-1][$i] = $rating;
48 }
49 }
50 }
51 }
52
53 close $f;
54 write_html();
55
56 sub write_html {
57 require HTML::Template::Compiled;
58 my $t = HTML::Template::Compiled->new(
59 filename => 'template.html',
60 open_mode => ':encoding(UTF-8)',
61 default_escape => 'HTML',
62 global_vars => 1,
63 );
64 my @compilers;
65 for (keys %abbr_index) {
66 $compilers[$abbr_index{$_}] = {name => $abbr_name{$_}};
67 }
68 shift @compilers;
69 $t->param(compilers => \@compilers);
70 $t->param(columns => 1 + @compilers);
71
72 my %status_map = (
73 '+' => 'implemented',
74 '+-' => 'partial',
75 '-' => 'missing',
76 '' => 'unknown',
77 );
78
79 my @rows;
80 for my $s (@sections) {
81 my @sec = @$s;
82 push @rows, {section => shift @sec};
83 for (@sec) {
84 my %ht_row;
85 my @row = @$_;
86 $ht_row{feature} = shift @row;
87 $ht_row{compilers} = [ map {
9e8d0db @moritz some small tweaks; center-align +/-, pmichaud++
moritz authored
88 {
89 status => $row[$_] // '',
90 class => $status_map{$row[$_] // ''},
91 }
7701afe @moritz basic processing script
moritz authored
92 } 0..($index - 1) ];
93 push @rows, \%ht_row;
94 }
95 }
96 $t->param(rows => \@rows);
97 say $t->output;
98 }
Something went wrong with that request. Please try again.