This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
basic processing script
- Loading branch information
Showing
3 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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> | ||
|
|