digraphs: intermediate parse of shiar.inc.txt proposals
[sheet.git] / tools / mkdigraphs-shiar
diff --git a/tools/mkdigraphs-shiar b/tools/mkdigraphs-shiar
new file mode 100755 (executable)
index 0000000..4f2b75a
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+use 5.010;
+use strict;
+use warnings;
+use open IN => ':utf8', ':std';
+
+our $VERSION = '1.00';
+
+my $di = do "data/digraphs-rfc.inc.pl"
+       or warn "official digraphs not included for comparison: ", $@ // $!;
+
+say "# automatically generated by $0";
+say '+{';
+for (readline) {
+       my ($mnem, $chr) = m{^([!"%'-Z_a-z]{2}) (.)} or next;
+       warn("$mnem already defined"), next if defined $di->{$mnem};
+       my $chrnum = ord $chr;
+       say "q{$1} => $chrnum,";
+}
+say '}';
+
+__END__
+
+=head1 NAME
+
+mkdigraphs-shiar - Output digraph data from proposal text
+
+=head1 SYNOPSIS
+
+    mkdigraphs-shiar shiar.inc.txt >digraphs-shiar.inc.pl
+    perl -e'$di = do "digraphs-shiar.inc.pl"; print chr $di->{":)"}'
+
+=head1 DESCRIPTION
+
+Parses a text file containing digraphs followed by
+the literal unicode character and optional comments.
+If successful, Perl code is output resulting in a hash
+with Unicode code points keyed by digraph.
+Any errors and warnings are given at STDERR.
+
+=head1 AUTHOR
+
+Mischa POSLAWSKY <perl@shiar.org>
+
+=head1 LICENSE
+
+Licensed under the GNU Affero General Public License version 3.
+