digraphs: parse vim :digraphs to indicate extensions
[sheet.git] / tools / mkcharinfo
index c6c890011abb33a33a873de67c9edaa4a40c9a59..2c006c5d34fd202cc8aec19648953516796116be 100755 (executable)
@@ -11,9 +11,13 @@ use Data::Dump 'pp';
 our $VERSION = '1.00';
 
 my %info = (
+       # prepare presentational string for some control(lish) entries
        "\xAD"     => {string => '-'},
        "\x{200E}" => {string => '→'},
        "\x{200F}" => {string => '←'},
+       "\x{200B}" => {string => '␣'},
+       "\x{200C}" => {string => '|'}, # ISO-9995-7-081 lookalike (alt: ∣ ⊺ ⟙)
+       "\x{200D}" => {string => '⁀'}, # join (alt: ∤ |ͯ ⨝)
 );
 $info{chr $_} //= {} for 32 .. 126;
 
@@ -43,21 +47,18 @@ eval {
 } or warn "Failed importing html entities: $@";
 
 my %diinc = (
-       'digraphs.inc.pl' => 'u-di',
+       'data/digraphs-rfc.inc.pl' => 'u-di',
+       'data/digraphs-shiar.inc.pl' => 'u-prop ex',
+       'data/digraphs-vim.inc.pl' => 'u-prop',
 );
-for (keys %diinc) {
+for (sort keys %diinc) {
        -e $_ or next;
        my $di = do $_ or die "Error reading digraphs file $_: ", $@ || $!;
        while (my ($mnem, $cp) = each %$di) {
                length $mnem == 2 or next;  # limit to digraphs
                my $class = $diinc{$_};
-               if (ref $cp) {
-                       # old style array
-                       $class = 'u-prop' if $cp->[2] and $cp->[2] =~ m/\bXz\b/;
-                       $cp = chr $cp->[0];
-               }
-               $info{$cp}->{di} //= $mnem;
-               $info{$cp}->{class}->{$class}++;
+               $info{chr $cp}->{di} //= $mnem;
+               $info{chr $cp}->{class}->{$class}++;
        }
 }
 
@@ -82,6 +83,10 @@ for my $chr (keys %info) {
 
        $info->{$_} = $info{$chr}->{$_} for keys %{ $info{$chr} };
 
+       # official digraphs either lose vim flag or gain experimental
+       delete $info->{class}->{'u-prop'} or $info->{class}->{ex}++
+               if $info->{class}->{'u-di'};
+
        # categorise by unicode types and writing script
        $info->{class}->{$_}++ for $info->{category};
        $info->{class}->{$_}++ for $info->{script} || ();
@@ -90,22 +95,24 @@ for my $chr (keys %info) {
        $info->{class}->{Xa}++ if $info->{block} eq 'Basic Latin';
        $info->{class}->{Xl}++ if $info->{block} eq 'Latin-1 Supplement';
 
-       given ($cp) {
-               when ($info->{string}) {
+       {
+               if ($info->{string}) {
                        # keep predefined presentational string
                }
-               when ($info->{combining}) {
+               elsif ($info->{combining}) {
                        # overlay combining accents
                        $info->{string} = chr(9676) . $chr;
                }
-               when (($cp & ~0b1001_1111) == 0 or $cp == 127) {
+               elsif (($cp & ~0b1001_1111) == 0 or $cp == 127) {
                        # control characters (first 32 chars from 0 and 128)
                        # rename to something more descriptive
                        $info->{name} = $info->{unicode10}
                                ? '<'.$info->{unicode10}.'>'  # the old name was much more useful
                                : sprintf('<control U+%04X>', $cp);  # at least identify by value
                        # show descriptive symbols instead of control chars themselves
-                       $info->{string} = $cp < 32 ? chr($cp + 0x2400) : chr(0xFFFD);
+                       $info->{string} = $cp < 32   ? chr($cp + 0x2400) :
+                                         $cp == 127 ? chr(0x2421) :
+                                                      chr(0xFFFD);
                }
        }
 
@@ -113,6 +120,7 @@ for my $chr (keys %info) {
 }
 
 # output perl code of hash
+say "# automatically generated by $0";
 say 'use utf8;';
 say '+{';
 for my $cp (sort keys %info) {