## mktables -- create the runtime Perl Unicode files (lib/unicore/**/*.pl)
## from the Unicode database files (lib/unicore/*.txt).
} elsif ($arg eq '-maketest') {
die "usage: $0 [-v|-q] [-maketest]";
my $LastUnicodeCodepoint = 0x10FFFF; # As of Unicode 3.1.1.
# !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
# This file is built by $0 from e.g. UnicodeData.txt.
# Any changes made here will be lost!
## Given a filename and a reference to an array of lines,
## write the lines to the file only if the contents have not changed.
my $TextToWrite = join '', @
$lines;
if ($PreviousText eq $TextToWrite) {
print "$file unchanged.\n" if $Verbose;
if (not open OUT
, ">$file") {
die "$0: can't open $file for output: $!\n";
print "$file written.\n" if $Verbose;
## The main datastructure (a "Table") represents a set of code points that
## are part of a particular quality (that are part of \pL, \p{InGreek},
## etc.). They are kept as ranges of code points (starting and ending of
## For example, a range ASCII LETTERS would be represented as:
## [ [ 0x41 => 0x5A, 'UPPER' ],
## [ 0x61 => 0x7A, 'LOWER, ] ]
sub RANGE_START
() { 0 } ## index into range element
sub RANGE_END
() { 1 } ## index into range element
sub RANGE_NAME
() { 2 } ## index into range element
## Conceptually, these should really be folded into the 'Table' objects
$name =~ s/(?<![a-z])(\w)/\u$1/g;
$CanonicalToOrig{$name} = $orig if not $CanonicalToOrig{$name};
## Associates a property ("Greek", "Lu", "Assigned",...) with a Table.
## New_Prop(In => 'Greek', $Table, Desc => 'Greek Block', Fuzzy => 1);
## Normally, these parameters are set when the Table is created (when the
## Table->New constructor is called), but there are times when it needs to
## be done after-the-fact...)
my $Type = shift; ## "Is" or "In";
## remaining args are optional key/val
my $Fuzzy = delete $Args{Fuzzy
};
my $Desc = delete $Args{Desc
}; # description
$Name = CanonicalName
($Name) if $Fuzzy;
## sanity check a few args
if (%Args or ($Type ne 'Is' and $Type ne 'In') or not ref $Table) {
confess
"$0: bad args to New_Prop"
if (not $TableInfo{$Type}->{$Name})
$TableInfo{$Type}->{$Name} = $Table;
$TableDesc{$Type}->{$Name} = $Desc;
$FuzzyNames{$Type}->{$Name} = $Name;
## Creates a new Table object.
## Args are key/value pairs:
## In => Name -- Name of "In" property to be associated with
## Is => Name -- Name of "Is" property to be associated with
## Fuzzy => Boolean -- True if name can be accessed "fuzzily"
## Desc => String -- Description of the property
my $Table = bless [], $class;
my $Fuzzy = delete $Args{Fuzzy
};
my $Desc = delete $Args{Desc
};
for my $Type ('Is', 'In')
if (my $Name = delete $Args{$Type}) {
New_Prop
($Type => $Name, $Table, Desc
=> $Desc, Fuzzy
=> $Fuzzy);
## shouldn't have any left over
confess
"$0: bad args to Table->New"
## Returns true if the Table has no code points
## Returns true if the Table has code points
## Returns the maximum code point currently in the table.
confess
"oops" if $Table->IsEmpty; ## must have code points to have a max
return $Table->[-1]->[RANGE_END
];
## Replaces the codepoints in the Table with those in the Table given
## as an arg. (NOTE: this is not a "deep copy").
## Given a new code point, make the last range of the Table extend to
## include the new (and all intervening) code points.
my $PrevMax = $Table->Max;
confess
"oops ($codepoint <= $PrevMax)" if $codepoint <= $PrevMax;
$Table->[-1]->[RANGE_END
] = $codepoint;
## Given a code point range start and end (and optional name), blindly
## append them to the list of ranges for the Table.
## NOTE: Code points must be added in strictly ascending numeric order.
sub Table
::RawAppendRange
$name = "" if not defined $name; ## warning: $name can be "0"
push @
$Table, [ $start, # RANGE_START
## Given a code point (and optional name), add it to the Table.
## NOTE: Code points must be added in strictly ascending numeric order.
$name = "" if not defined $name; ## warning: $name can be "0"
## If we've already got a range working, and this code point is the next
## one in line, and if the name is the same, just extend the current range.
$Table->Max == $codepoint - 1
$Table->[-1]->[RANGE_NAME
] eq $name)
$Table->Extend($codepoint);
$Table->RawAppendRange($codepoint, $codepoint, $name);
## Given a code point range starting value and ending value (and name),
## Add the range to teh Table.
## NOTE: Code points must be added in strictly ascending numeric order.
$name = "" if not defined $name; ## warning: $name can be "0"
$Table->Append($start, $name);
$Table->Extend($end) if $end > $start;
## Return a new Table that represents all code points not in the Table.
my $start = $range->[RANGE_START
];
my $end = $range->[RANGE_END
];
if ($start-1 >= $max+1) {
$New->AppendRange($max+1, $start-1, "");
if ($max+1 < $LastUnicodeCodepoint) {
$New->AppendRange($max+1, $LastUnicodeCodepoint);
## Merges any number of other tables with $self, returning the new table.
## (existing tables are not modified)
## Args may be Tables, or individual code points (as integers).
## Can be called as either a constructor or a method.
shift(@_) if not ref $_[0]; ## if called as a constructor, lose the class
## Accumulate all records from all tables
## arg is a table -- get its ranges
## arg is a codepoint, make a range
push @Records, [ $Arg, $Arg ]
## sort by range start, with longer ranges coming first.
my ($first, @Rest) = sort {
($a->[RANGE_START
] <=> $b->[RANGE_START
])
($b->[RANGE_END
] <=> $b->[RANGE_END
])
## Ensuring the first range is there makes the subsequent loop easier
$New->AppendRange($first->[RANGE_START
],
## Fold in records so long as they add new information.
my $start = $set->[RANGE_START
];
my $end = $set->[RANGE_END
];
if ($start > $New->Max) {
$New->AppendRange($start, $end);
} elsif ($end > $New->Max) {
## Given a filename, write a representation of the Table to a file.
## May have an optional comment as a 2nd arg.
push @OUT, "#\n$comment\n#\n";
push @OUT, "return <<'END';\n";
my $start = $set->[RANGE_START
];
my $end = $set->[RANGE_END
];
my $name = $set->[RANGE_NAME
];
push @OUT, sprintf "%04X\t\t%s\n", $start, $name;
push @OUT, sprintf "%04X\t%04X\t%s\n", $start, $end, $name;
WriteIfChanged($filename, @OUT);
## This used only for making the test script.
return 0 if $code <= 0x0000; ## don't use null
return 0 if $code >= $LastUnicodeCodepoint; ## keep in range
return 0 if ($code >= 0xD800 and $code <= 0xDFFF); ## no surrogates
return 0 if ($code >= 0xFDD0 and $code <= 0xFDEF); ## utf8.c says no good
return 0 if (($code & 0xFFFF) == 0xFFFE); ## utf8.c says no good
return 0 if (($code & 0xFFFF) == 0xFFFF); ## utf8.c says no good
## Return a code point that's part of the table.
## Returns nothing if the table is empty (or covers only surrogates).
## This used only for making the test script.
return $set->[RANGE_END] if IsUsable($set->[RANGE_END]);
## Return a code point that's not part of the table
## Returns nothing if the table covers all code points.
## This used only for making the test script.
return 0x1234 if $Table->IsEmpty();
if (IsUsable($set->[RANGE_END] + 1))
return $set->[RANGE_END] + 1;
if (IsUsable($set->[RANGE_START] - 1))
return $set->[RANGE_START] - 1;
###########################################################################
###########################################################################
###########################################################################
## New_Alias(Is => 'All', SameAs => 'Any', Fuzzy => 1);
## The args must be in that order, although the Fuzzy pair may be omitted.
## This creates 'IsAll' as an alias for 'IsAny'
my $Type = shift; ## "Is
" or "In
"
my $SameAs = shift; # expecting "SameAs
" -- just ignored
## remaining args are optional key/val
my $Fuzzy = delete $Args{Fuzzy};
## sanity check a few args
if (%Args or ($Type ne 'Is' and $Type ne 'In') or $SameAs ne 'SameAs') {
confess "$0: bad args to New_Alias
"
$Alias = CanonicalName($Alias) if $Fuzzy;
if (not $TableInfo{$Type}->{$Name})
my $CName = CanonicalName($Name);
if ($TableInfo{$Type}->{$CName}) {
confess "$0: Use canonical form
'$CName' instead of
'$Name' for alias
.";
confess "$0: don
't have orignial $Type => $Name to make alias";
if ($TableInfo{$Alias}) {
confess "$0: already have original $Type => $Alias; can't make alias
";
$AliasInfo{$Type}->{$Name} = $Alias;
$FuzzyNames{$Type}->{$Alias} = $Name;
## All assigned code points
my $Assigned = Table->New(Is => 'Assigned',
Desc => "All assigned code points
",
my $Name = Table->New(); ## all characters, individually by name
my $General = Table->New(); ## all characters, grouped by category
## Process UnicodeData.txt (Categories, etc.)
my $Number = Table->New();
my $Mirrored = Table->New(Is => 'Mirrored',
Desc => "Mirrored
in bidirectional text
",
$Deco{Canon} = Table->New(Is => 'Canon',
Desc => 'Decomposes to multiple characters',
$Deco{Compat} = Table->New(Is => 'Compat',
Desc => 'Compatible with a more-basic character',
## Initialize Perl-generated categories
## (Categories from UnicodeData.txt are auto-initialized in gencat)
Table->New(Is => 'Alnum', Desc => "[[:Alnum
:]]", Fuzzy => 0);
Table->New(Is => 'Alpha', Desc => "[[:Alpha
:]]", Fuzzy => 0);
Table->New(Is => 'ASCII', Desc => "[[:ASCII
:]]", Fuzzy => 0);
Table->New(Is => 'Blank', Desc => "[[:Blank
:]]", Fuzzy => 0);
Table->New(Is => 'Cntrl', Desc => "[[:Cntrl
:]]", Fuzzy => 0);
Table->New(Is => 'Digit', Desc => "[[:Digit
:]]", Fuzzy => 0);
Table->New(Is => 'Graph', Desc => "[[:Graph
:]]", Fuzzy => 0);
Table->New(Is => 'Lower', Desc => "[[:Lower
:]]", Fuzzy => 0);
Table->New(Is => 'Print', Desc => "[[:Print
:]]", Fuzzy => 0);
Table->New(Is => 'Punct', Desc => "[[:Punct
:]]", Fuzzy => 0);
Table->New(Is => 'Space', Desc => "[[:Space
:]]", Fuzzy => 0);
Table->New(Is => 'Title', Desc => "[[:Title
:]]", Fuzzy => 0);
Table->New(Is => 'Upper', Desc => "[[:Upper
:]]", Fuzzy => 0);
Table->New(Is => 'XDigit', Desc => "[[:XDigit
:]]", Fuzzy => 0);
Table->New(Is => 'Word', Desc => "[[:Word
:]]", Fuzzy => 0);
Table->New(Is => 'SpacePerl', Desc => '\s', Fuzzy => 0);
$To{Upper} = Table->New();
$To{Lower} = Table->New();
$To{Title} = Table->New();
$To{Digit} = Table->New();
my ($name, ## Name ("LATIN CAPITAL LETTER A
")
$cat, ## Category ("Lu
", "Zp
", "Nd
", etc.)
$code, ## Code point (as an integer)
my $MajorCat = substr($cat, 0, 1); ## L, M, Z, S, etc
$Name->$op($code, $name);
$General->$op($code, $cat);
## add to the sub category (e.g. "Lu
", "Nd
", "Cf
", ..)
$Cat{$cat} ||= Table->New(Is => $cat,
Desc => "General Category
'$cat'",
## add to the major category (e.g. "L
", "N
", "C
", ...)
$Cat{$MajorCat} ||= Table->New(Is => $MajorCat,
Desc => "Major Category
'$MajorCat'",
$Cat{$MajorCat}->$op($code);
($General{$name} ||= Table->New)->$op($code, $name);
# 005F: SPACING UNDERSCORE
$Cat{Word}->$op($code) if $cat =~ /^[LMN]/ || $code == 0x005F;
$Cat{Alnum}->$op($code) if $cat =~ /^[LMN]/;
$Cat{Alpha}->$op($code) if $cat =~ /^[LM]/;
$Cat{Space}->$op($code) if $cat =~ /^Z/
|| $code == 0x0009 # 0009: HORIZONTAL TAB
|| $code == 0x000A # 000A: LINE FEED
|| $code == 0x000B # 000B: VERTICAL TAB
|| $code == 0x000C # 000C: FORM FEED
|| $code == 0x000D; # 000D: CARRIAGE RETURN
$Cat{SpacePerl}->$op($code) if $cat =~ /^Z/
|| $code == 0x0009 # 0009: HORIZONTAL TAB
|| $code == 0x000A # 000A: LINE FEED
|| $code == 0x000C # 000C: FORM FEED
|| $code == 0x000D # 000D: CARRIAGE RETURN
|| $code == 0x0085 # 0085: <NEXT LINE>
|| $code == 0x2028 # 2028: LINE SEPARATOR
|| $code == 0x2029;# 2029: PARAGRAPH SEP.
$Cat{Blank}->$op($code) if $cat =~ /^Z[^lp]$/
|| $code == 0x0009 # 0009: HORIZONTAL TAB
|| $code == 0x0020; # 0020: SPACE
$Cat{Digit}->$op($code) if $cat eq "Nd
";
$Cat{Upper}->$op($code) if $cat eq "Lu
";
$Cat{Lower}->$op($code) if $cat eq "Ll
";
$Cat{Title}->$op($code) if $cat eq "Lt
";
$Cat{ASCII}->$op($code) if $code <= 0x007F;
$Cat{Cntrl}->$op($code) if $cat =~ /^C/;
$Cat{Graph}->$op($code) if $cat =~ /^([LMNPS]|Co)/;
$Cat{Print}->$op($code) if $cat =~ /^([LMNPS]|Co|Zs)/;
$Cat{Punct}->$op($code) if $cat =~ /^P/;
$Cat{XDigit}->$op($code) if ($code >= 0x30 && $code <= 0x39) ## 0..9
|| ($code >= 0x41 && $code <= 0x46) ## A..F
|| ($code >= 0x61 && $code <= 0x66); ## a..f
## open ane read file.....
if (not open IN, "UnicodeData
.txt
") {
die "$0: UnicodeData
.txt
: $!\n";
## For building \p{_CombAbove} and \p{_CanonDCIJ}
my %_Above_HexCodes; ## Hexcodes for chars with $comb == 230 ("ABOVE
")
my %CodeToDeco; ## Maps code to decomp. list for chars with first
## decomp. char an "i
" or "j
" (for \p{_CanonDCIJ})
## This is filled in as we go....
my $CombAbove = Table->New(Is => '_CombAbove',
Desc => '(for internal casefolding use)',
next unless /^[0-9A-Fa-f]+;/;
my ($hexcode, ## code point in hex (e.g. "0041")
$name, ## character name (e.g. "LATIN CAPITAL LETTER A
")
$cat, ## category (e.g. "Lu
")
$comb, ## Canonical combining class (e.t. "230")
$bidi, ## directional category (e.g. "L
")
$deco, ## decomposition mapping
$decimal, ## decimal digit value
$number, ## numeric value
$unicode10, ## name in Unicode 1.0
$comment, ## comment field
$upper, ## uppercase mapping
$lower, ## lowercase mapping
$title, ## titlecase mapping
# Note that in Unicode 3.2 there will be names like
# LINE FEED (LF), which probably means that \N{} needs
# to cope also with LINE FEED and LF.
$name = $unicode10 if $name eq '<control>' && $unicode10 ne '';
my $code = hex($hexcode);
if ($comb and $comb == 230) {
$CombAbove->Append($code);
$_Above_HexCodes{$hexcode} = 1;
## Used in building \p{_CanonDCIJ}
if ($deco and $deco =~ m/^006[9A]\b/) {
$CodeToDeco{$code} = $deco;
## There are a few pairs of lines like:
## AC00;<Hangul Syllable, First>;Lo;0;L;;;;;N;;;;;
## D7A3;<Hangul Syllable, Last>;Lo;0;L;;;;;N;;;;;
if ($name =~ /^<(.+), (First|Last)>$/)
gencat($name, $cat, $code, $2 eq 'First' ? 'Append' : 'Extend');
#New_Prop(In => $name, $General{$name}, Fuzzy => 1);
## normal (single-character) lines
gencat($name, $cat, $code, 'Append');
# No Append() here since since several codes may map into one.
$To{Upper}->RawAppendRange($code, $code, $upper) if $upper;
$To{Lower}->RawAppendRange($code, $code, $lower) if $lower;
$To{Title}->RawAppendRange($code, $code, $title) if $title;
$To{Digit}->Append($code, $decimal) if length $decimal;
$Bidi->Append($code, $bidi);
$Comb->Append($code, $comb) if $comb;
$Number->Append($code, $number) if length $number;
$Mirrored->Append($code) if $mirrored eq "Y
";
$Bidi{$bidi} ||= Table->New(Is => "Bidi
$bidi",
Desc => "Bi
-directional category
'$bidi'",
$Bidi{$bidi}->Append($code);
$Deco->Append($code, $deco);
$Deco{Compat}->Append($code);
$DC{$1} ||= Table->New(Is => "DC
$1",
Desc => "Compatible with
'$1'",
$Deco{Canon}->Append($code);
## Tidy up a few special cases....
$Cat{Cn} = $Assigned->Invert; ## Cn is everything that doesn't exist
Desc => "General Category
'Cn' [not functional
in Perl
]",
## Unassigned is the same as 'Cn'
New_Alias(Is => 'Unassigned', SameAs => 'Cn', Fuzzy => 0);
$Cat{C}->Replace($Cat{C}->Merge($Cat{Cn})); ## Now merge in Cn into C
Table->Merge(@Cat{qw[Ll Lu Lt]}),
Desc => '[\p{Ll}\p{Lu}\p{Lt}]',
## Any and All are all code points.
my $Any = Table->New(Is => 'Any',
Desc => sprintf("[\\x
{0000}-\\x
{%X}]",
$Any->RawAppendRange(0, $LastUnicodeCodepoint);
New_Alias(Is => 'All', SameAs => 'Any', Fuzzy => 0);
## Build special properties for Perl's internal case-folding needs:
## _CombAbove was built above. Others are built here....
## \p{_CaseIgnorable} is [\p{Mn}\0x00AD\x2010]
New_Prop(Is => '_CaseIgnorable',
Desc => '(for internal casefolding use)',
## \p{_CanonDCIJ} is fairly complex...
my $CanonCDIJ = Table->New(Is => '_CanonDCIJ',
Desc => '(for internal casefolding use)',
## It contains the ASCII 'i' and 'j'....
$CanonCDIJ->Append(0x0069); # ASCII ord("i
")
$CanonCDIJ->Append(0x006A); # ASCII ord("j
")
## ...and any character with a decomposition that starts with either of
## those code points, but only if the decomposition does not have any
## combining character with the "ABOVE
" canonical combining class.
for my $code (sort { $a <=> $b} keys %CodeToDeco)
## Need to ensure that all decomposition characters do not have
## a %HexCodeToComb in %AboveCombClasses.
for my $deco_hexcode (split / /, $CodeToDeco{$code})
if (exists $_Above_HexCodes{$deco_hexcode}) {
## one of the decmposition chars has an ABOVE combination
## class, so we're not interested in this one
$CanonCDIJ->Append($code);
$Bidi->Write("Bidirectional
.pl
");
$Comb->Write("CombiningClass
.pl
");
$Deco->Write("Decomposition
.pl
");
$Number->Write("Number
.pl
");
$General->Write("Category
.pl
");
for my $to (sort keys %To) {
$To{$to}->Write("To
/$to.pl
");
if (not open IN, "LineBreak
.txt
") {
die "$0: LineBreak
.txt
: $!\n";
next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(\w+)/;
my ($first, $last, $lbrk) = (hex($1), hex($2||""), $3);
$Lbrk->Append($first, $lbrk);
$Lbrk{$lbrk} ||= Table->New(Is => "Lbrk
$lbrk",
Desc => "Linebreak category
'$lbrk'",
$Lbrk{$lbrk}->Append($first);
$Lbrk{$lbrk}->Extend($last);
## Process ArabicShaping.txt.
if (not open IN, "ArabicShaping
.txt
") {
die "$0: ArabicShaping
.txt
: $!\n";
my $ArabLink = Table->New();
my $ArabLinkGroup = Table->New();
next unless /^[0-9A-Fa-f]+;/;
my ($hexcode, $name, $link, $linkgroup) = split(/\s*;\s*/);
my $code = hex($hexcode);
$ArabLink->Append($code, $link);
$ArabLinkGroup->Append($code, $linkgroup);
$ArabLink->Write("ArabLink
.pl
");
$ArabLinkGroup->Write("ArabLnkGrp
.pl
");
if (not open IN, "Jamo
.txt
") {
die "$0: Jamo
.txt
: $!\n";
my $Short = Table->New();
next unless /^([0-9A-Fa-f]+)\s*;\s*(\w*)/;
my ($code, $short) = (hex($1), $2);
$Short->Append($code, $short);
$Short->Write("JamoShort
.pl
");
if (not open(IN, "Scripts
.txt
")) {
die "$0: Scripts
.txt
: $!\n";
next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
# Wait until all the scripts have been read since
# they are not listed in numeric order.
push @ScriptInfo, [ hex($1), hex($2||""), $3 ];
# Now append the scripts properties in their code point order.
my $Scripts = Table->New();
for my $script (sort { $a->[0] <=> $b->[0] } @ScriptInfo)
my ($first, $last, $name) = @$script;
$Scripts->Append($first, $name);
$Script{$name} ||= Table->New(Is => $name,
Desc => "Script
'$name'",
$Script{$name}->Append($first, $name);
$Script{$name}->Extend($last);
$Scripts->Write("Scripts
.pl
");
## Common is everything not explicitly assigned to a Script
## ***shouldn't this be intersected with \p{Assigned}? ******
Desc => 'Pseudo-Script of codepoints not in other Unicode scripts',
## Given a name like "Close Punctuation
", return a regex (that when applied
## with /i) matches any valid form of that name (e.g. "ClosePunctuation
",
## "Close
-Punctuation
", etc.)
## Accept any space, dash, or underbar where in the official name there is
## space or a dash (or underbar, but there never is).
$Name =~ s/[- _]/(?:[-_]|\\s+)?/g;
my $Blocks = Table->New();
if (not open IN, "Blocks
.txt
") {
die "$0: Blocks
.txt
: $!\n";
#next if not /Private Use$/;
next if not /^([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+)\s*;\s*(.+?)\s*$/;
my ($first, $last, $name) = (hex($1), hex($2), $3);
$Blocks->Append($first, $name);
$Blocks{$name} ||= Table->New(In => $name,
$Blocks{$name}->Append($first, $name);
if ($last and $last != $first) {
$Blocks{$name}->Extend($last);
$Blocks->Write("Blocks
.pl
");
## Read in the PropList.txt. It contains extended properties not
## listed in the UnicodeData.txt, such as 'Other_Alphabetic':
## alphabetic but not of the general category L; many modifiers
## belong to this extended property category: while they are not
## alphabets, they are alphabetic in nature.
if (not open IN, "PropList
.txt
") {
die "$0: PropList
.txt
: $!\n";
next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
# Wait until all the extended properties have been read since
# they are not listed in numeric order.
push @PropInfo, [ hex($1), hex($2||""), $3 ];
# Now append the extended properties in their code point order.
my $Props = Table->New();
for my $prop (sort { $a->[0] <=> $b->[0] } @PropInfo)
my ($first, $last, $name) = @$prop;
$Props->Append($first, $name);
$Prop{$name} ||= Table->New(Is => $name,
Desc => "Extended property
'$name'",
$Prop{$name}->Append($first, $name);
$Prop{$name}->Extend($last);
# Alphabetic is L and Other_Alphabetic.
New_Prop(Is => 'Alphabetic',
Table->Merge($Cat{L}, $Prop{Other_Alphabetic}),
Desc => '[\p{L}\p{OtherAlphabetic}]', # use canonical names here
# Lowercase is Ll and Other_Lowercase.
New_Prop(Is => 'Lowercase',
Table->Merge($Cat{Ll}, $Prop{Other_Lowercase}),
Desc => '[\p{Ll}\p{OtherLowercase}]', # use canonical names here
# Uppercase is Lu and Other_Uppercase.
New_Prop(Is => 'Uppercase',
Table->Merge($Cat{Lu}, $Prop{Other_Uppercase}),
Desc => '[\p{Lu}\p{Other_Uppercase}]', # use canonical names here
# Math is Sm and Other_Math.
Table->Merge($Cat{Sm}, $Prop{Other_Math}),
Desc => '[\p{Sm}\p{OtherMath}]', # use canonical names here
# ID_Start is Ll, Lu, Lt, Lm, Lo, and Nl.
New_Prop(Is => 'ID_Start',
Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl]}),
Desc => '[\p{Ll}\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]',
# ID_Continue is ID_Start, Mn, Mc, Nd, and Pc.
New_Prop(Is => 'ID_Continue',
Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl Mn Mc Nd Pc ]}),
Desc => '[\p{ID_Start}\p{Mn}\p{Mc}\p{Nd}\p{Pc}]',
## The mapping from General Category long forms to short forms is
## currently hardwired here since no simple data file in the UCD
## seems to do that. Unicode 3.2 will assumedly correct this.
'Uppercase_Letter' => 'Lu',
'Lowercase_Letter' => 'Ll',
'Titlecase_Letter' => 'Lt',
'Modifier_Letter' => 'Lm',
'Non_Spacing_Mark' => 'Mn',
'Enclosing_Mark' => 'Me',
'Space_Separator' => 'Zs',
'Line_Separator' => 'Zl',
'Paragraph_Separator' => 'Zp',
'Decimal_Number' => 'Nd',
'Connector_Punctuation' => 'Pc',
'Dash_Punctuation' => 'Pd',
'Open_Punctuation' => 'Ps',
'Close_Punctuation' => 'Pe',
'Initial_Punctuation' => 'Pi',
'Final_Punctuation' => 'Pf',
'Other_Punctuation' => 'Po',
'Currency_Symbol' => 'Sc',
'Modifier_Symbol' => 'Sk',
while (my ($Alias, $Name) = each %Is) {
New_Alias(Is => $Alias, SameAs => $Name, Fuzzy => 1);
## for making the test script.
## This used only for making the test script
if (defined $MatchCode) {
printf $FH qq/Expect(1, "\\x
{%04X}", '\\p{$Prop}' );\n/, $MatchCode;
printf $FH qq/Expect(0, "\\x
{%04X}", '\\p{^$Prop}');\n/, $MatchCode;
printf $FH qq/Expect(0, "\\x
{%04X}", '\\P{$Prop}' );\n/, $MatchCode;
printf $FH qq/Expect(1, "\\x
{%04X}", '\\P{^$Prop}');\n/, $MatchCode;
printf $FH qq/Expect(0, "\\x
{%04X}", '\\p{$Prop}' );\n/, $FailCode;
printf $FH qq/Expect(1, "\\x
{%04X}", '\\p{^$Prop}');\n/, $FailCode;
printf $FH qq/Expect(1, "\\x
{%04X}", '\\P{$Prop}' );\n/, $FailCode;
printf $FH qq/Expect(0, "\\x
{%04X}", '\\P{^$Prop}');\n/, $FailCode;
## This used only for making the test script
print $FH qq/Error('\\p{$prop}');\n/;
print $FH qq/Error('\\P{$prop}');\n/;
## This used only for making the test script
## This used only for making the test script
sub RandomlyFuzzifyName($;$)
my $WantError = shift; ## if true, make an error
for my $part (split /[-\s_]+/, $Name)
if ($WantError and rand() < 0.3) {
push @parts, $BadSeps[rand(@BadSeps)];
push @parts, $GoodSeps[rand(@GoodSeps)];
my $switch = int rand(4);
push @parts, ucfirst $part;
my $new = join('', @parts);
$new .= $BadSeps[rand(@BadSeps)];
$new = $BadSeps[rand(@BadSeps)] . $new;
## This used only for making the test script
## this written directly -- it's huge.
if (not open OUT, ">TestProp
.pl
") {
die "$0: TestProp
.pl
: $!\n";
while (my ($Name, $Table) = each %ExactNameToTest)
GenTests(*OUT, $Name, $Table->ValidCode, $Table->InvalidCode);
ExpectError(*OUT, uc $Name) if uc $Name ne $Name;
ExpectError(*OUT, lc $Name) if lc $Name ne $Name;
while (my ($Name, $Table) = each %FuzzyNameToTest)
my $Orig = $CanonicalToOrig{$Name};
RandomlyFuzzifyName($Orig) => 1
for my $N (keys %Names) {
GenTests(*OUT, $N, $Table->ValidCode, $Table->InvalidCode);
ExpectError(*OUT, RandomlyFuzzifyName($Orig, 'ERROR'));
print OUT "Finished
();\n";
## These are used only in:
my %Exact; ## will become %utf8::Exact;
my %Canonical; ## will become %utf8::Canonical;
my %CaComment; ## Comment for %Canonical entry of same key
## Given info about a name and a datafile that it should be associated with,
## register that assocation in %Exact and %Canonical.
sub RegisterFileForName($$$$)
## Now in details for the mapping. $Type eq 'Is' has the
## Is removed, as it will be removed in utf8_heavy when this
## data is being checked. In keeps its "In
", but a second
## sans-In record is written if it doesn't conflict with
## anything already there.
die "oops
[$Name]" if $Exact{$Name};
$Exact{$Name} = $filename;
die "oops
[$Type$Name]" if $Exact{"$Type$Name"};
$Exact{"$Type$Name"} = $filename;
$Exact{$Name} = $filename if not $Exact{$Name};
die "oops
[$CName]" if $Canonical{$CName};
$Canonical{$CName} = $filename;
$CaComment{$CName} = $Name if $Name =~ tr/A-Z// >= 2;
die "oops
[$Type$CName]" if $Canonical{lc "$Type$CName"};
$Canonical{lc "$Type$CName"} = $filename;
$CaComment{lc "$Type$CName"} = "$Type$Name";
if (not $Canonical{$CName}) {
$Canonical{$CName} = $filename;
$CaComment{$CName} = "$Type$Name";
## Writes the info accumulated in
my %BaseNames; ## Base names already used (for avoiding 8.3 conflicts)
## 'Is' *MUST* come first, so its names have precidence over 'In's
for my $Type ('Is', 'In')
my %RawNameToFile; ## a per-$Type cache
for my $Name (sort {length $a <=> length $b} keys %{$TableInfo{$Type}})
## Note: $Name is already canonical
my $Table = $TableInfo{$Type}->{$Name};
my $IsFuzzy = $FuzzyNames{$Type}->{$Name};
## Need an 8.3 safe filename (which means "an
8 safe
" $filename)
## 'Is' items lose 'Is' from the basename.
$filename = $Type eq 'Is' ? $Name : "$Type$Name";
$filename =~ s/[^\w_]+/_/g; # "L
&" -> "L_
"
substr($filename, 8) = '' if length($filename) > 8;
## Make sure the basename doesn't conflict with something we
## might have already written. If we have, say,
while (my $num = $BaseNames{lc $filename}++)
$num++; ## so basenames with numbers start with '2', which
## just looks more natural.
## Want to append $num, but if it'll make the basename longer
## than 8 characters, pre-truncate $filename so that the result
my $delta = length($filename) + length($num) - 8;
substr($filename, -$delta) = $num;
## Construct a nice comment to add to the file, and build data
## for the "./Properties
" file along the way.
my $Desc = $TableDesc{$Type}->{$Name} || "";
## get list of names this table is reference by
while (my ($Orig, $Alias) = each %{ $AliasInfo{$Type} })
my $TypeToShow = $Type eq 'Is' ? "" : $Type;
$Comment = "This file supports
:\n";
my $IsFuzzy = $FuzzyNames{$Type}->{$N};
my $Prop = "\\p
{$TypeToShow$Name}";
$OrigProp = $Prop if not $OrigProp; #cache for aliases
$Comment .= "\t$Prop (and fuzzy permutations
)\n";
my $MyDesc = ($N eq $Name) ? $Desc : "Alias
for $OrigProp ($Desc)";
push @MAP, sprintf("%s %-42s
%s\n",
$IsFuzzy ? '*' : ' ', $Prop, $MyDesc);
$Comment .= "\nMeaning
: $Desc\n";
## Okay, write the file...
$Table->Write("lib
/$filename.pl
", $Comment);
$RawNameToFile{$Name} = $filename;
RegisterFileForName($Type => $Name, $IsFuzzy, $filename);
my $CName = CanonicalName($Type . '_'. $Name);
$FuzzyNameToTest{$Name} = $Table if !$FuzzyNameToTest{$Name};
$FuzzyNameToTest{$CName} = $Table if !$FuzzyNameToTest{$CName};
$ExactNameToTest{$Name} = $Table;
for my $Name (sort {length $a <=> length $b} keys %{$AliasInfo{$Type}})
my $Alias = $AliasInfo{$Type}->{$Name};
my $IsFuzzy = $FuzzyNames{$Type}->{$Alias};
my $filename = $RawNameToFile{$Name};
die "oops
[$Alias]->[$Name]" if not $filename;
RegisterFileForName($Type => $Alias, $IsFuzzy, $filename);
my $Table = $TableInfo{$Type}->{$Name};
die "oops
" if not $Table;
my $CName = CanonicalName($Type .'_'. $Alias);
$FuzzyNameToTest{$Alias} = $Table if !$FuzzyNameToTest{$Alias};
$FuzzyNameToTest{$CName} = $Table if !$FuzzyNameToTest{$CName};
$ExactNameToTest{$Alias} = $Table;
## Write out the property list
"## This file created by $0\n",
"## List of built-in \\p{...}/\\P{...} properties.\n",
"## '*' means name may be 'fuzzy'\n",
sort { substr($a,2) cmp substr($b, 2) } @MAP,
WriteIfChanged
('Properties', @OUT);
use Text
::Tabs
(); ## using this makes the files about half the size
"## Data in this file used by ../utf8_heavy.pl\n",
"## Mapping from name to filename in ./lib\n",
for my $Name (sort keys %Exact)
my $File = $Exact{$Name};
$Name = $Name =~ m/\W/ ?
qq/'$Name'/ : " $Name ";
my $Text = sprintf("%-15s => %s,\n", $Name, qq/'$File'/);
push @OUT, Text
::Tabs
::unexpand
($Text);
WriteIfChanged
('Exact.pl', @OUT);
"## Data in this file used by ../utf8_heavy.pl\n",
"## Mapping from lc(canonical name) to filename in ./lib\n",
"%utf8::Canonical = (\n",
my $Trail = ""; ## used just to keep the spacing pretty
for my $Name (sort keys %Canonical)
my $File = $Canonical{$Name};
push @OUT, "\n" if not $Trail;
push @OUT, " # $CaComment{$Name}\n";
$Name = $Name =~ m/\W/ ?
qq/'$Name'/ : " $Name ";
my $Text = sprintf(" %-41s => %s,\n$Trail", $Name, qq/'$File'/);
push @OUT, Text
::Tabs
::unexpand
($Text);
WriteIfChanged
('Canonical.pl', @OUT);
MakePropTestScript
() if $MakeTestScript;
# Read in the special cases.
if (not open IN
, "SpecialCasing.txt") {
die "$0: SpecialCasing.txt: $!\n";
next unless /^[0-9A-Fa-f]+;/;
my ($code, $lower, $title, $upper, $condition) = split(/\s*;\s*/);
if ($condition) { # not implemented yet
print "# SKIPPING $_\n" if $Verbose;
# Wait until all the special cases have been read since
# they are not listed in numeric order.
push @
{$CaseInfo{Lower
}}, [ $ix, $code, $lower ]
push @
{$CaseInfo{Title
}}, [ $ix, $code, $title ]
push @
{$CaseInfo{Upper
}}, [ $ix, $code, $upper ]
# Now write out the special cases properties in their code point order.
# Prepend them to the To/{Upper,Lower,Title}.pl.
for my $case (qw(Lower Title Upper))
my $NormalCase = do "To/$case.pl" || die "$0: $@\n";
"%utf8::ToSpec$case =\n(\n",
for my $prop (sort { $a->[0] <=> $b->[0] } @
{$CaseInfo{$case}}) {
my ($ix, $code, $to) = @
$prop;
join "", map { sprintf "\\x{%s}", $_ } split ' ', $to;
push @OUT, sprintf qq['%04X' => "$tostr",\n], $ix;
# Remove any single-character mappings for
# the same character since we are going for
# the special casing rules.
$NormalCase =~ s/^$code\t\t\w+\n//m;
WriteIfChanged("To
/$case.pl
", @OUT);
# Read in the case foldings.
# We will do full case folding, C + F + I (see CaseFolding.txt).
if (not open IN, "CaseFolding
.txt
") {
die "$0: CaseFolding
.txt
: $!\n";
# Skip status 'S', simple case folding
next unless /^([0-9A-Fa-f]+)\s*;\s*([CFI])\s*;\s*([0-9A-Fa-f]+(?: [0-9A-Fa-f]+)*)\s*;/;
my ($code, $status, $fold) = (hex($1), $2, $3);
if ($status eq 'C') { # Common: one-to-one folding
# No append() since several codes may fold into one.
$Fold->RawAppendRange($code, $code, $fold);
} else { # F: full, or I: dotted uppercase I -> dotless lowercase I
$Fold->Write("To
/Fold
.pl
");
# Prepend the special foldings to the common foldings.
my $CommonFold = do "To
/Fold.pl" || die "$0: To/Fold
.pl
: $!\n";
"%utf8::ToSpecFold
=\n(\n",
for my $code (sort { $a <=> $b } keys %Fold) {
join "", map { sprintf "\\x
{%s}", $_ } split ' ', $Fold{$code};
push @OUT, sprintf qq['%04X' => "$foldstr",\n], $code;
WriteIfChanged("To
/Fold
.pl
", @OUT);
## TRAILING CODE IS USED BY MakePropTestScript()
$String =~ $RegObj ? 1 : 0
if (not defined $result) {
print "couldn
't compile /$Regex/ on $0 line $Line: $@\n";
} elsif ($result ^ $Expect) {
print "bad result (expected $Expect) on $0 line $Line: $@\n";
if (eval { 'x
' =~ qr/$Regex/; 1 }) {
print "expected error for /$Regex/ on $0 line $Line: $@\n";
print "All $Tests tests passed.\n";
print "$Tests tests, $Fails failed!\n";