2 # Copyright 2008 The Go Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style
4 # license that can be found in the LICENSE file.
6 # Modified version of RE2's make_perl_groups.pl.
8 # Generate table entries giving character ranges
9 # for POSIX/Perl character classes. Rather than
10 # figure out what the definition is, it is easier to ask
11 # Perl about each letter from 0-128 and write down
40 my $regexp = "[$class]";
42 for (my $i=0; $i<=129; $i++) {
43 if ($i == 129) { $i = 256; }
44 if ($i <= 128 && chr($i) =~ $regexp) {
50 push @ranges, [$start, $i-1];
59 my ($cname, $name, @ranges) = @_;
60 print "var code$cname = []rune{ /* $name */\n";
61 for (my $i=0; $i<@ranges; $i++) {
62 my @a = @{$ranges[$i]};
63 printf "\t0x%x, 0x%x,\n", $a[0], $a[1];
68 if ($negname =~ /:/) {
71 $negname =~ y/a-z/A-Z/;
73 return "\t`$name`: {+1, code$cname},\n" .
74 "\t`$negname`: {-1, code$cname},\n";
79 sub PrintClasses($@) {
80 my ($cname, @classes) = @_;
82 foreach my $cl (@classes) {
83 my @ranges = ComputeClass($cl);
84 push @entries, PrintClass(++$gen, $cl, @ranges);
86 print "var ${cname}Group = map[string]charGroup{\n";
87 foreach my $e (@entries) {
95 // Copyright 2013 The Go Authors. All rights reserved.
96 // Use of this source code is governed by a BSD-style
97 // license that can be found in the LICENSE file.
99 // GENERATED BY make_perl_groups.pl; DO NOT EDIT.
100 // make_perl_groups.pl >perl_groups.go
106 PrintClasses("perl", @perlclasses);
107 PrintClasses("posix", @posixclasses);