ab0c2f95ad201344672794a94449b6268cfa3c80
[sheet.git] / tools / mkdigraphlist
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use utf8;
6
7 use open OUT => ':utf8', ':std';
8
9 our $VERSION = '1.06';
10
11 # import and combine various digraph data
12 my $rfc = do 'data/digraphs-rfc.inc.pl'
13         or die "error reading digraphs include: ", $@ // $!;
14 my $extra = do 'data/digraphs-shiar.inc.pl'
15         or warn "could not include shiar proposals: ", $@ // $!;
16 my $vim = do 'data/digraphs-vim.inc.pl'
17         or warn "could not include vim extensions ", $@ // $!;
18 my $di = { %{$vim // {}}, %{$rfc}, %{$extra // {}} };
19
20 # optionally get unicode character information
21 my $uninfo = do 'unicode-char.inc.pl'
22         or warn "could not include unicode details: ", $@ // $!;
23
24 # output perl code of hash
25 # (assume no backslashes or curlies, so we can just q{} w/o escaping)
26 print "# automatically generated by $0\n";
27 print "use utf8;\n";
28 print "+{\n";
29 printf '(map {$_=>0} qw{%s}),'."\n", join(' ',
30         grep { !defined $di->{$_} }
31         map { substr($_, 1, 1).substr($_, 0, 1) } sort keys %{$di}
32 );
33 printf "q{%s}=>[%s],\n", s/(?=[\\}])/\\/gr, join(',',
34         ord $di->{$_},   # original code point
35         map {"'$_'"}
36         $uninfo->{ $di->{$_} }->[1] // '',  # name
37         $rfc->{$_}
38                 ? $vim->{$_} ? 'l4' : 'l1'  # vim+rfc or rfc only
39                 : $vim->{$_} ? 'l3' : 'l2',  # vim only or neither
40         ($uninfo->{ $di->{$_} }->[0] // '') =~ s/ u-di| u-prop| ex//gr,  # class
41         $uninfo->{ $di->{$_} }->[4] // (),  # string
42 ) for sort keys %{$di};
43 print "}\n";
44
45 __END__
46
47 =head1 NAME
48
49 mkdigraphlist - Output character list of combined digraph data
50
51 =head1 SYNOPSIS
52
53     mkdigraphlist >digraphs.inc.pl
54     perl -e'$di = do "digraphs.inc.pl"; print chr $di->{DO}->[0]'
55
56 =head1 DESCRIPTION
57
58 Combines precompiled digraph includes of rfc (1345), vim, and shiar
59 and outputs a complete map including character details and usage classes.
60
61 The value can either be a scalar string containing another
62 digraph which can be considered identical (usually inverted),
63 or an array ref containing at least the resulting character's
64 Unicode code point value.  If available, the following UCD data
65 is appended: character name, usage classes, unicode classes,
66 and replacement output string.
67 For example:
68
69  +{
70    AE => [198, 'LATIN CAPITAL LETTER AE', 'u-di', 'Latin Lu Xl u-v11'],
71    EA => 'AE',
72   }
73
74 =head1 AUTHOR
75
76 Mischa POSLAWSKY <perl@shiar.org>
77
78 =head1 LICENSE
79
80 Licensed under the GNU Affero General Public License version 3.
81