digraphs: intermediate parse of shiar.inc.txt proposals
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 21 Feb 2015 02:03:54 +0000 (03:03 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 9 Jun 2015 03:43:41 +0000 (05:43 +0200)
Makefile
tools/mkdigraphlist
tools/mkdigraphs-shiar [new file with mode: 0755]

index 46d68171802bf3c9ee3484582f61bacec199befe..6314e18f154cd29d25ddcc43d0a0e2005d7a74e7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,10 @@ data/rfc1345.txt:
 data/digraphs-rfc.inc.pl: tools/mkdigraphs-rfc data/rfc1345.txt
        $< $(word 2,$^) >$@
 
-digraphs.inc.pl: tools/mkdigraphlist data/digraphs-rfc.inc.pl shiar.inc.txt
+data/digraphs-shiar.inc.pl: tools/mkdigraphs-shiar shiar.inc.txt
+       $< $(word 2,$^) >$@
+
+digraphs.inc.pl: tools/mkdigraphlist data/digraphs-rfc.inc.pl data/digraphs-shiar.inc.pl
        $< >$@
 
 unicode-char.inc.pl: tools/mkcharinfo digraphs.inc.pl unicode-age.inc.pl
index 66ffd2ab4af40d0ddada8418ab12b31d9d2c0607..4cacc6c4b9aec1c15ef26cde73813acc99b36d2d 100755 (executable)
@@ -14,17 +14,9 @@ my $di = do 'data/digraphs-rfc.inc.pl'
        or die "error reading digraphs include: ", $@ // $!;
 
 # personal addendums
-my @extra;
-if (-r 'shiar.inc.txt') {
-       open my $include, '<:utf8', 'shiar.inc.txt';
-       for (readline $include) {
-               m{^(\$?[!"%'-Z_a-z]{2}) (.)} or next;
-               warn("$1 already defined"), next if defined $di->{$1};
-               $di->{$1} = ord $2;
-               push @extra, $1;
-       }
-}
-warn $@ if $@;
+my $extra = do 'data/digraphs-shiar.inc.pl'
+       or warn "could not include shiar proposals: ", $@ // $!;
+$di = { %{$di}, %{$extra // {}} };
 
 $di->{chr $_} = $_ for 32 .. 126;
 $di->{'\\'.$_} = delete $di->{$_} for '{', '}', '\\';
@@ -45,7 +37,7 @@ for (values %info) {
 }
 
 # mark unofficial extras as such
-$info{$_}->{category} .= ' Xz' for @extra;
+$info{$_}->{category} .= ' Xz' for keys %{$extra};
 
 for (keys %{$di}) {
        $info{$_}->{string} = chr(9676) . chr($di->{$_}) if $info{$_}->{combining};
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.
+