line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::Babelfish::Phrase::PluralFormsParser; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Babelfish plurals syntax parser. |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
154979
|
use utf8; |
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
15
|
|
6
|
3
|
|
|
3
|
|
96
|
use strict; |
|
3
|
|
|
|
|
23
|
|
|
3
|
|
|
|
|
60
|
|
7
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
91
|
|
8
|
3
|
|
|
3
|
|
17
|
use feature 'state'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
263
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
458
|
use Locale::Babelfish::Phrase::Parser (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
143
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '2.10'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
20
|
use parent qw( Class::Accessor::Fast ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
16
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw( phrase strict_forms regular_forms ) ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
96
|
|
|
96
|
1
|
3397
|
my ( $class, $phrase ) = @_; |
22
|
96
|
|
|
|
|
217
|
my $parser = bless {}, $class; |
23
|
96
|
50
|
|
|
|
244
|
$parser->init( $phrase ) if defined $phrase; |
24
|
96
|
|
|
|
|
221
|
return $parser; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub init { |
29
|
23
|
|
|
23
|
1
|
1304
|
my ( $self, $phrase ) = @_; |
30
|
23
|
|
|
|
|
471
|
$self->phrase( $phrase ); |
31
|
23
|
|
|
|
|
578
|
$self->regular_forms( [] ); |
32
|
23
|
|
|
|
|
561
|
$self->strict_forms( {} ); |
33
|
23
|
|
|
|
|
167
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub parse { |
38
|
22
|
|
|
22
|
1
|
46829
|
my ( $self, $phrase ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
22
|
50
|
|
|
|
105
|
$self->init( $phrase ) if defined $phrase; |
41
|
22
|
|
|
|
|
59
|
state $phrase_parser = Locale::Babelfish::Phrase::Parser->new(); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# тут проще регуляркой |
44
|
22
|
|
|
|
|
145
|
my @forms = split( m/(?<!\\)\|/s, $phrase ); |
45
|
|
|
|
|
|
|
|
46
|
22
|
|
|
|
|
61
|
for my $form ( @forms ) { |
47
|
58
|
|
|
|
|
282
|
my $value = undef; |
48
|
2
|
100
|
|
2
|
|
753
|
if ( $form =~ m/\A=([0-9]+)\p{PerlSpace}*(.+)\z/s ) { |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
37
|
|
|
58
|
|
|
|
|
172
|
|
49
|
7
|
|
|
|
|
34
|
( $value, $form ) = ( $1, $2 ); |
50
|
|
|
|
|
|
|
} |
51
|
58
|
|
|
|
|
184
|
$form = $phrase_parser->parse( $form ); |
52
|
|
|
|
|
|
|
|
53
|
58
|
100
|
|
|
|
399
|
if ( defined $value ) { |
54
|
7
|
|
|
|
|
131
|
$self->strict_forms->{$value} = $form; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
51
|
|
|
|
|
125
|
push @{ $self->regular_forms }, $form; |
|
51
|
|
|
|
|
895
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return { |
62
|
22
|
|
|
|
|
477
|
strict => $self->strict_forms, |
63
|
|
|
|
|
|
|
regular => $self->regular_forms, |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=encoding UTF-8 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Locale::Babelfish::Phrase::PluralFormsParser - Babelfish plurals syntax parser. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 VERSION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
version 2.10 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Returns { script_forms => {}, regular_forms = [] } |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Every plural form represented as AST. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 METHODS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 new |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$class->new() |
94
|
|
|
|
|
|
|
$class->new( $phrase ) |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Instantiates parser. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 init |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Initializes parser. Should not be called directly. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 parse |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$parser->parse() |
105
|
|
|
|
|
|
|
$parser->parse( $phrase ) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Parses specified phrase. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHORS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=over 4 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Akzhan Abdulin <akzhan@cpan.org> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Igor Mironov <grif@cpan.org> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Victor Efimov <efimov@reg.ru> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item * |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
REG.RU LLC |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item * |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Kirill Sysoev <k.sysoev@me.com> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Alexandr Tkach <tkach@reg.ru> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by REG.RU LLC. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This is free software, licensed under: |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The MIT (X11) License |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |