443de5d025d71d04478c82920973fb7713f91646
[sheet.git] / tools / mkdigraphs-shiar
1 #!/usr/bin/env perl
2 use 5.010;
3 use strict;
4 use warnings;
5 use open IN => ':utf8', ':std';
6
7 our $VERSION = '1.02';
8
9 my $di = do "data/digraphs-rfc.inc.pl"
10         or warn "official digraphs not included for comparison: ", $@ // $!;
11
12 say "# automatically generated by $0";
13 say '+{';
14 for (readline) {
15         my ($mnem, $cp, $chr) = m{^([!"%'-Z_a-z]{2}) (?:(\\\d+)|(.))} or next;
16         warn("$mnem already defined"), next if defined $di->{$mnem};
17         my $chrstr = sprintf '"\x{%x}"', $cp // ord $chr;
18         say "q{$mnem} => $chrstr,";
19 }
20 say '}';
21
22 __END__
23
24 =head1 NAME
25
26 mkdigraphs-shiar - Output digraph data from proposal text
27
28 =head1 SYNOPSIS
29
30     mkdigraphs-shiar shiar.inc.txt >digraphs-shiar.inc.pl
31     perl -e'$di = do "digraphs-shiar.inc.pl"; print chr $di->{":)"}'
32
33 =head1 DESCRIPTION
34
35 Parses a text file containing digraphs followed by
36 the literal unicode character and optional comments.
37 If successful, Perl code is output resulting in a hash
38 with Unicode code points keyed by digraph.
39 Any errors and warnings are given at STDERR.
40
41 =head1 AUTHOR
42
43 Mischa POSLAWSKY <perl@shiar.org>
44
45 =head1 LICENSE
46
47 Licensed under the GNU Affero General Public License version 3.
48