line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Translate::Fluent::Parser; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
2519
|
use parent qw'Exporter'; |
|
6
|
|
|
|
|
1736
|
|
|
6
|
|
|
|
|
33
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
6
|
|
|
|
|
|
|
parse_file |
7
|
|
|
|
|
|
|
parse_string |
8
|
|
|
|
|
|
|
); |
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
2664
|
use Translate::Fluent::ResourceSet; |
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
200
|
|
11
|
6
|
|
|
6
|
|
2802
|
use Translate::Fluent::Elements; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
213
|
|
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
7300
|
use Regexp::Grammars; |
|
6
|
|
|
|
|
134146
|
|
|
6
|
|
|
|
|
76
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $fluent_parser = qr< |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
<[Resource]>* |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
[\x{20}\t] |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
| | | |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
<.line_end> |
27
|
|
|
|
|
|
|
| <.line_end> |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
<.ws>* = <.ws>* (( <[Attribute]>*)|<[Attribute]>+) |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
- <.ws>* = <.ws>* <[Attribute]>* |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
<.ws>* <.line_end> |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
(<.comment_char>)* |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
<[next_junk_line]>* |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
<.not_new_line> <.line_end> |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
<.ws>* <.junk_starter> <.not_new_line> <.line_end> |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
[^\n]* |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
[^\#\-a-zA-Z\n\s\.]+ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
<[PatternElement]>+ |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
| | | |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
<.non_special>+ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
<.blank_block> <.ws>+ ? |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
\{ <.blank>* ( | ) <.blank>* \} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
<.blank_block> <.ws>+ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
| |
78
|
|
|
|
|
|
|
| |
79
|
|
|
|
|
|
|
| |
80
|
|
|
|
|
|
|
| |
81
|
|
|
|
|
|
|
| |
82
|
|
|
|
|
|
|
| |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
<.blank>? \-\> <.blank>? |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
<[variant]>* <[variant]>* |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
<.line_end> <.blank>? <.ws>? |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
<.line_end> <.blank>? \* <.ws>? |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
\[ <.blank>? ( | ) <.blank>? \] |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
<.quote> <.quote> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
<.quoted_char>* |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
\-? [0-9]+ (\. [0-9]+)? |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
<.blank>? \( <.blank>? <.blank>? \) |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
(<[Argument]> <.blank>? , <.blank>? )* <[Argument]>? |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
| |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
<.blank>? : <.blank>? (|) |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
? |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
\- ? ? |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
\$ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
\. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
<.line_end> <.ws>* \. <.ws>* = <.ws>* |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
(<.ws>* <.line_end>)+ |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
[^\"\\] | \\[\"\\] | \\u[0-9a-fA-F]{4} | \\u[0-9a-fA-F]{6} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
[^\n\{\}\[\*\.\s\#] |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
[^\n] |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
[a-zA-Z][a-zA-Z0-9_-]* |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
\#\#\# | \#\# | \# |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
[^\n\{\}\"] |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
\n | \z |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
(<.ws> | <.line_end>)+ |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
\" |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
>sx; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub parse_file { |
172
|
7
|
|
|
7
|
1
|
2335
|
my ($fname) = @_; |
173
|
|
|
|
|
|
|
|
174
|
7
|
|
|
|
|
31
|
local $/ = undef; |
175
|
|
|
|
|
|
|
|
176
|
7
|
100
|
|
|
|
429
|
open my $fh, '<', $fname or die "Error opening file '$fname': $!\n"; |
177
|
|
|
|
|
|
|
|
178
|
6
|
|
|
|
|
244
|
my $text = <$fh>; |
179
|
|
|
|
|
|
|
|
180
|
6
|
|
|
|
|
34
|
return parse_string( $text ); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub parse_string { |
185
|
20
|
|
|
20
|
1
|
63
|
my ($str) = @_; |
186
|
|
|
|
|
|
|
|
187
|
20
|
|
|
|
|
452
|
my $reset = Translate::Fluent::ResourceSet->new(); |
188
|
|
|
|
|
|
|
|
189
|
20
|
50
|
|
|
|
723
|
if ( $str =~ $fluent_parser ) { |
190
|
20
|
|
|
|
|
76
|
my %entries; |
191
|
|
|
|
|
|
|
|
192
|
20
|
|
|
|
|
38
|
for my $elm (@{ $/{Resource} } ) { |
|
20
|
|
|
|
|
82
|
|
193
|
223
|
100
|
|
|
|
612
|
next unless $elm->{Entry}; |
194
|
|
|
|
|
|
|
|
195
|
70
|
|
|
|
|
126
|
my ($type) = keys %{ $elm->{Entry} }; |
|
70
|
|
|
|
|
230
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $resobj = Translate::Fluent::Elements->create( |
198
|
70
|
|
|
|
|
344
|
$type => $elm->{Entry}->{ $type } |
199
|
|
|
|
|
|
|
); |
200
|
|
|
|
|
|
|
|
201
|
70
|
|
|
|
|
290
|
$reset->add_resource( $resobj ); |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
$reset = undef |
207
|
20
|
100
|
|
|
|
838
|
unless keys %{ $reset->resources }; |
|
20
|
|
|
|
|
146
|
|
208
|
|
|
|
|
|
|
|
209
|
20
|
|
|
|
|
289
|
return $reset; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
__END__ |