digraphs: update mkdigraphlist input description
[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.03';
10
11 # create a hash of desired input
12 my $di = do 'data/digraphs-rfc.inc.pl'
13         or die "error reading digraphs include: ", $@ // $!;
14
15 # personal addendums
16 my $extra = do 'data/digraphs-shiar.inc.pl'
17         or warn "could not include shiar proposals: ", $@ // $!;
18 my $vim = do 'data/digraphs-vim.inc.pl'
19         or warn "could not include vim extensions ", $@ // $!;
20 $di = { %{$vim // {}}, %{$di}, %{$extra // {}} };
21
22 # optionally get unicode character information
23 my $uninfo = do 'unicode-char.inc.pl'
24         or warn "could not include unicode details: ", $@ // $!;
25
26 # convert info hashes into arrays of strings to output in display order
27 for my $row (values %{$uninfo}) {
28         my ($class, $name, $di, $html, $string) = @{$row};
29         $row = [$name, $class];
30         push @{$row}, '', $string if defined $string;
31 }
32
33 # output perl code of hash
34 # (assume no backslashes or curlies, so we can just q{} w/o escaping)
35 print "# automatically generated by $0\n";
36 print "use utf8;\n";
37 print "+{\n";
38 printf '(map {$_=>0} qw{%s}),'."\n", join(' ',
39         grep { !defined $di->{$_} }
40         map { substr($_, 1, 1).substr($_, 0, 1) } sort keys %{$di}
41 );
42 printf "q{%s}=>[%s],\n", $_, join(',',
43         $di->{$_},   # original code point
44         (map {"'$_'"} @{ $uninfo->{ chr $di->{$_} } // [] }),  # optional additional arguments
45 ) for sort keys %{$di};
46 print "}\n";
47
48 __END__
49
50 =head1 NAME
51
52 mkdigraphlist - Output character list of combined digraph data
53
54 =head1 SYNOPSIS
55
56     mkdigraphlist >digraphs.inc.pl
57     perl -e'$di = do "digraphs.inc.pl"; print chr $di->{DO}->[0]'
58
59 =head1 DESCRIPTION
60
61 Combines precompiled digraph includes of rfc (1345), vim, and shiar
62 and outputs a complete map including character details and usage classes.
63
64 The value can either be a scalar string containing another
65 digraph which can be considered identical (usually inverted),
66 or an array ref containing at least the resulting character's
67 Unicode code point value.  If available, the following UCD data
68 is appended: character name, category, script, and output string.
69 For example:
70
71  +{
72    AE => [198, 'LATIN CAPITAL LETTER AE', 'Lu Xl', 'Latin'],
73    EA => 'AE',
74   }
75
76 =head1 AUTHOR
77
78 Mischa POSLAWSKY <perl@shiar.org>
79
80 =head1 LICENSE
81
82 Licensed under the GNU Affero General Public License version 3.
83