/[suikacvs]/perl/charclass/lib/Char/Class/mkpm.pl
Suika

Contents of /perl/charclass/lib/Char/Class/mkpm.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Thu Apr 24 22:34:02 2003 UTC (21 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.7: +25 -14 lines
File MIME type: text/plain
Renewal

1 wakaba 1.1 use strict;
2     use vars qw(%PROP %SET %SET_ALIAS $VERSION);
3 wakaba 1.8 $VERSION=do{my @r=(q$Revision: 1.7 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 wakaba 1.1
5 wakaba 1.8 $PROP{perl_namespace_name} = 'Char::Class::';
6 wakaba 1.1 $PROP{module_name} = 'FooScript';
7    
8     sub header () {
9     <<"EOH";
10 wakaba 1.7 ## This file is auto-generated (at @{[ sprintf '%04d-%02d-%02dT%02d:%02d:%02dZ', (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3,2,1,0] ]}).
11     ## Do not edit by hand!
12 wakaba 1.1 use strict;
13    
14 wakaba 1.8 package $PROP{perl_namespace_name}$PROP{module_name};
15     our \$VERSION = '$PROP{version}';
16     @{[
17     #use Exporter;
18     #use vars qw(\@EXPORT_OK \@ISA \$VERSION);
19     #\@ISA = qw(Exporter);
20     ]}
21     package main;
22 wakaba 1.4
23     =head1 NAME
24    
25 wakaba 1.8 $PROP{module_name}.pm --- @{[ $PROP{script_name} || $PROP{module_name} ]} character set classes for C<\\p{In@{[ exists $PROP{prefix_name} ? $PROP{prefix_name} : $PROP{module_name} ]}HogeHoge}> regexps
26 wakaba 1.6 @{[$PROP{pod_description}? "
27     =head1 DESCRIPTION
28    
29     $PROP{pod_description}":'']}
30 wakaba 1.4
31     =cut
32    
33 wakaba 1.1 EOH
34     }
35    
36     sub table () {
37 wakaba 1.3 my $prefix = exists $PROP{prefix_name} ? $PROP{prefix_name} : $PROP{module_name};
38 wakaba 1.1 my $r = '';
39     my @set;
40 wakaba 1.6 my %set_description;
41 wakaba 1.1 for (sort keys %SET) {
42 wakaba 1.2 my (@aline,@aitem);
43 wakaba 1.1 $SET{$_} =~ s{^#\+(\w+)$}{
44 wakaba 1.3 push @aline, qq(\&In${prefix}$1.); ''
45 wakaba 1.1 }mge;
46 wakaba 1.8 $SET{$_} =~ s{^!(.+)$}{ ## Pre-formatted
47 wakaba 1.2 push @aitem, $1; ''
48     }mge;
49 wakaba 1.6 $SET{$_} =~ s{^#DESCRIPTION\x20(.+)$}{
50 wakaba 1.8 $set_description{qq(In${prefix}$_)} = $1; ''
51 wakaba 1.6 }me;
52 wakaba 1.1 $SET{$_} =~ s{^#.+$}{}mg;
53     $SET{$_} =~ tr/\x09\x0A\x0D\x20//d;
54 wakaba 1.3 push @set, [qq(In${prefix}$_) =>
55     join "\n", qq(sub In${prefix}$_ {),
56 wakaba 1.2 @aline,
57     (length $SET{$_}?
58     (q(<<EOH;),
59     @aitem,
60     (map {sprintf '%04X', $_} sort {$a <=> $b}
61     map {ord $_} split //, $SET{$_}),
62     q(EOH)):
63     @aitem > 0? (q(<<EOH;), @aitem, q(EOH)): "''"),
64     q(})
65 wakaba 1.1 ];
66     }
67     for (sort keys %SET_ALIAS) {
68 wakaba 1.3 push @set, [qq(In${prefix}$_) => qq(\*In${prefix}$_ = \\&In${prefix}$SET_ALIAS{$_};)];
69 wakaba 1.1 }
70    
71 wakaba 1.8 #$r = qq(\@EXPORT_OK = qw(@{[map {$_->[0]} @set]});\n\n);
72 wakaba 1.1 $r .= join '', map {$_->[1]."\n\n"} @set;
73 wakaba 1.4
74     $r .= "=head1 COLLECTION NAMES\n\n=over 4\n\n";
75 wakaba 1.6 for (sort {$a->[0] cmp $b->[0]} @set) {
76 wakaba 1.4 $r .= sprintf "=item %s\n\n", $_->[0];
77 wakaba 1.6 $r .= sprintf "%s\n\n", $set_description{ $_->[0] }
78     if $set_description{ $_->[0] };
79 wakaba 1.4 }
80     $r .= "=cut\n\n";
81    
82 wakaba 1.1 $r;
83     }
84    
85     sub footer () {
86     my $r = <<EOH;
87 wakaba 1.6 @{[$PROP{pod_example}? "
88 wakaba 1.4 =head1 EXAMPLE
89 wakaba 1.1
90 wakaba 1.8 $PROP{pod_example}":"
91     =head1 EXAMPLE
92    
93     use $PROP{perl_namespace_name}$PROP{module_name};
94     if (\$s =~ /\\p{In$PROP{module_name}HogeHoge}/) {
95     print \"Match!\\n\";
96     }
97     "]}@{[$PROP{pod_see_also}? "
98 wakaba 1.4 =head1 SEE ALSO
99 wakaba 1.2
100 wakaba 1.4 $PROP{pod_see_also}":'']}@{[$PROP{pod_license}? "
101     =head1 LICENSE
102 wakaba 1.1
103 wakaba 1.6 $PROP{pod_license}":"
104     =head1 LICENSE
105 wakaba 1.1
106 wakaba 1.2 Copyright @{[(gmtime)[5]+1900]} $PROP{author_name} <$PROP{author_mail}>
107 wakaba 1.1
108     This library and the library generated by it is free software;
109     you can redistribute them and/or modify them under the same
110     terms as Perl itself.
111 wakaba 1.4 "]}
112 wakaba 1.1 =cut
113    
114     1;
115     ### $PROP{module_name}.pm ends here
116     EOH
117     $r;
118     }
119    
120 wakaba 1.3 sub col2list ($) {
121     my $s = shift;
122     my @s;
123 wakaba 1.6 my @c;
124     $s =~ s{^(#.+)}{
125     push @c, $1; '';
126     }gem;
127 wakaba 1.3 $s =~ s{^[\x20\x09]*([0-9A-F][0-9A-F])((?:[\x20\x09]+[0-9A-F][0-9A-F](?:-[0-9A-F][0-9A-F])?)+)}{
128     my ($r, @c) = ($1, grep {length} split /\s+/, $2);
129     for (@c) {
130     if (/([0-9A-F][0-9A-F])-([0-9A-F][0-9A-F])/) {
131     push @s, sprintf '%s%s %s%s ', $r,$1, $r,$2;
132     } else {
133     push @s, sprintf '%s%s', $r,$_;
134     }
135     }
136     }gem;
137 wakaba 1.6 join ("\n", @c, map {'!'.$_} @s)."\n";
138 wakaba 1.3 }
139    
140 wakaba 1.1 sub print_module () {
141     no warnings;
142     print &header.&table.&footer;
143     }
144    
145     =head1 NAME
146    
147 wakaba 1.8 mkpm.pl --- Char::Class::* modules generating library
148 wakaba 1.1
149     =head1 LICENSE
150    
151 wakaba 1.8 Copyright 2002-2003 Wakaba <w@suika.fam.cx>
152 wakaba 1.1
153     This library and the library generated by it is free software;
154     you can redistribute them and/or modify them under the same
155     terms as Perl itself.
156    
157     =cut
158    
159 wakaba 1.8 1; ## $Date: 2002/10/22 11:03:09 $
160 wakaba 1.1 ### mkpm.pl ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24