| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#=============================================================================== |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# DESCRIPTION: grammars |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# AUTHOR: Aliaksandr P. Zahatski, <zahatski@gmail.com> |
|
6
|
|
|
|
|
|
|
#=============================================================================== |
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Plosurin::Grammar - Grammars for Closure Templates |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Regexp::Grammars; |
|
14
|
|
|
|
|
|
|
use Plosurin::Grammar; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Plosurin::Grammar - Grammars for Closure Templates |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
|
21
|
|
|
|
|
|
|
package Plosurin::Grammar; |
|
22
|
|
|
|
|
|
|
#use strict; |
|
23
|
|
|
|
|
|
|
#use warnings; |
|
24
|
4
|
|
|
4
|
|
130003
|
use v5.10; |
|
|
4
|
|
|
|
|
27
|
|
|
25
|
4
|
|
|
4
|
|
25
|
use Regexp::Grammars; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
23
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 Plosurin::Template::Grammar - template file grammar |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
qr{ |
|
31
|
|
|
|
|
|
|
my $r = qr{ |
|
32
|
|
|
|
|
|
|
<extends: Plosurin::Template::Grammar> |
|
33
|
|
|
|
|
|
|
<matchline> |
|
34
|
|
|
|
|
|
|
\A <File> \Z |
|
35
|
|
|
|
|
|
|
}xms; |
|
36
|
|
|
|
|
|
|
if ( $txt =~ $r) { |
|
37
|
|
|
|
|
|
|
... |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
|
41
|
|
|
|
|
|
|
qr{ |
|
42
|
|
|
|
|
|
|
<grammar: Plosurin::Template::Grammar> |
|
43
|
|
|
|
|
|
|
<objrule: Plo::File> |
|
44
|
|
|
|
|
|
|
<namespace>(?{ $MATCH{file} = $file//"linein"}) |
|
45
|
|
|
|
|
|
|
<[templates=template]>+ % <_sep=(\s+)> \s+ |
|
46
|
|
|
|
|
|
|
<objtoken: Plo::template> <header> <template_block> |
|
47
|
|
|
|
|
|
|
<rule: namespace> \{namespace <id>\} \n+ |
|
48
|
|
|
|
|
|
|
<rule: id> [\.\w]+ |
|
49
|
|
|
|
|
|
|
<rule: header> |
|
50
|
|
|
|
|
|
|
<javadoc_start> |
|
51
|
|
|
|
|
|
|
<[h_comment]>+ % (\s+) |
|
52
|
|
|
|
|
|
|
(?: <[h_params]>+ % (\s+) )? |
|
53
|
|
|
|
|
|
|
<javadoc_end> |
|
54
|
|
|
|
|
|
|
<rule: javadoc_start>\/\*\*? |
|
55
|
|
|
|
|
|
|
| \/\*\n<matchline><fatal:(?{say "JavaDoc must start with /**! at $file line $MATCH{matchline} : $CONTEXT" })> |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
<rule: javadoc_end> \*\/ |
|
58
|
|
|
|
|
|
|
# | <matchline><fatal:(?{say "JavaDoc must end with */! at $file line $MATCH{matchline} : $CONTEXT" })> |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
<rule: h_comment> \* <raw_str>? |
|
61
|
|
|
|
|
|
|
<rule: raw_str> [^@\n]+ |
|
62
|
|
|
|
|
|
|
<objrule: Plo::h_params> \* \@param<is_notreq=(\?)>? <id> <raw_str> |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
<rule: template_block> |
|
65
|
|
|
|
|
|
|
<matchpos> |
|
66
|
|
|
|
|
|
|
<matchline> |
|
67
|
|
|
|
|
|
|
<start_template> |
|
68
|
|
|
|
|
|
|
<raw_template=(.*?)> |
|
69
|
|
|
|
|
|
|
<stop_template> |
|
70
|
|
|
|
|
|
|
<rule: raw_template> (!? <stop_template> ) .*? |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
<rule: start_template> \{template <name=(\.\w+)>\} |
|
73
|
|
|
|
|
|
|
| <matchline><fatal:(?{say "Bad template definition at $file line $MATCH{matchline} : $CONTEXT" })> |
|
74
|
|
|
|
|
|
|
<rule: stop_template> \{\/template\} |
|
75
|
|
|
|
|
|
|
}xms; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 Plosurin::Grammar - soy grammar |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $r = qr{ |
|
80
|
|
|
|
|
|
|
<extends: Plosurin::Grammar> |
|
81
|
|
|
|
|
|
|
\A <[content]>* \Z |
|
82
|
|
|
|
|
|
|
}xms; |
|
83
|
|
|
|
|
|
|
if ( $txt =~ $r) { |
|
84
|
|
|
|
|
|
|
... |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
qr{ |
|
90
|
|
|
|
|
|
|
<grammar: Plosurin::Grammar> |
|
91
|
|
|
|
|
|
|
# \A <[content]>* \Z |
|
92
|
|
|
|
|
|
|
<objtoken: Soy::Node=content> |
|
93
|
|
|
|
|
|
|
<matchpos> |
|
94
|
|
|
|
|
|
|
<matchline> |
|
95
|
|
|
|
|
|
|
(?: |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
<obj=raw_text> |
|
98
|
|
|
|
|
|
|
|<obj=command_include> |
|
99
|
|
|
|
|
|
|
|<obj=command_if> |
|
100
|
|
|
|
|
|
|
|<obj=command_call_self> |
|
101
|
|
|
|
|
|
|
|<obj=command_call> |
|
102
|
|
|
|
|
|
|
|<obj=command_import> |
|
103
|
|
|
|
|
|
|
|<obj=command_foreach> |
|
104
|
|
|
|
|
|
|
|<obj=command_print> |
|
105
|
|
|
|
|
|
|
|<obj=raw_text_add> |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
) |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
<objrule: Soy::raw_text=raw_text_add> |
|
110
|
|
|
|
|
|
|
<matchpos> (.+?) |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# <require: (?{ length($CAPTURE) > 0 })> |
|
113
|
|
|
|
|
|
|
# <fatal:(?{say "May be command ? $MATCH{raw_text_add} at $MATCH{matchpos}"})> |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
<objrule: Soy::command_print> |
|
116
|
|
|
|
|
|
|
\{<is_explicit=(print)>? <expression>\} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
<objrule: Soy::command_include> |
|
119
|
|
|
|
|
|
|
\{include <[attribute]>{2} % <_sep=(\s+)> \} |
|
120
|
|
|
|
|
|
|
|\{include |
|
121
|
|
|
|
|
|
|
<matchpos> |
|
122
|
|
|
|
|
|
|
<fatal:(?{say "'Include' require 2 attrs at $MATCH{matchpos}"})> |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
<token: attribute> |
|
125
|
|
|
|
|
|
|
<name=(\w+)> |
|
126
|
|
|
|
|
|
|
= |
|
127
|
|
|
|
|
|
|
['"] <value=(?: ([^'"]+) )> ['"] |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
<token: variable> \$?\w+ |
|
130
|
|
|
|
|
|
|
<objtoken: Soy::expressiong = expression > .*? |
|
131
|
|
|
|
|
|
|
<objrule: Soy::raw_text> [^\{]+ |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
<objrule: Soy::command_if> |
|
135
|
|
|
|
|
|
|
\{if <expression>\} <[content]>+? |
|
136
|
|
|
|
|
|
|
(?: |
|
137
|
|
|
|
|
|
|
<[commands_elseif=command_elseif]>* |
|
138
|
|
|
|
|
|
|
<command_else> |
|
139
|
|
|
|
|
|
|
)? |
|
140
|
|
|
|
|
|
|
\{\/if\} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
<objrule: Soy::command_elseif> |
|
143
|
|
|
|
|
|
|
<matchpos> |
|
144
|
|
|
|
|
|
|
<matchline> |
|
145
|
|
|
|
|
|
|
\{elseif <expression>\} |
|
146
|
|
|
|
|
|
|
<[content]>+? |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
<objrule: Soy::command_else> |
|
149
|
|
|
|
|
|
|
<matchpos> |
|
150
|
|
|
|
|
|
|
<matchline> |
|
151
|
|
|
|
|
|
|
\{else\} |
|
152
|
|
|
|
|
|
|
<[content]>+? |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#self-ending call block |
|
155
|
|
|
|
|
|
|
<objrule: Soy::command_call_self> |
|
156
|
|
|
|
|
|
|
\{call |
|
157
|
|
|
|
|
|
|
<tmpl_name=([\.\w]+)> |
|
158
|
|
|
|
|
|
|
<[attribute]>* % <_sep=(\s+)> |
|
159
|
|
|
|
|
|
|
\/\} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
<objrule: Soy::command_call> |
|
162
|
|
|
|
|
|
|
\{call <tmpl_name=([\.\w]+)> \} |
|
163
|
|
|
|
|
|
|
<[content=param]>* |
|
164
|
|
|
|
|
|
|
\{\/call\} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
<objtoken: Soy::Node=param> |
|
167
|
|
|
|
|
|
|
<matchpos> |
|
168
|
|
|
|
|
|
|
<matchline> |
|
169
|
|
|
|
|
|
|
(?: |
|
170
|
|
|
|
|
|
|
<obj=command_param_self> |
|
171
|
|
|
|
|
|
|
| <obj=command_param> |
|
172
|
|
|
|
|
|
|
) |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
<objrule: Soy::command_param_self> |
|
175
|
|
|
|
|
|
|
\{param |
|
176
|
|
|
|
|
|
|
<name=variable> : <value=(.*?)> |
|
177
|
|
|
|
|
|
|
\/\} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
<objrule: Soy::command_param> |
|
180
|
|
|
|
|
|
|
\{param <name=(.*?)> \} |
|
181
|
|
|
|
|
|
|
<[content]>+? |
|
182
|
|
|
|
|
|
|
\{\/param\} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# {import file="test.pod6" rule=":public"} |
|
185
|
|
|
|
|
|
|
# {import file="test.pod6" } |
|
186
|
|
|
|
|
|
|
<objrule: Soy::command_import> |
|
187
|
|
|
|
|
|
|
\{import <[attribute]>+ % <_sep=(\s+)> \/?\} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
#{foreach ...}...{ifempty}...{/foreach} |
|
190
|
|
|
|
|
|
|
<objrule: Soy::command_foreach> |
|
191
|
|
|
|
|
|
|
\{foreach <local_var=expression> in <expression> \} |
|
192
|
|
|
|
|
|
|
<[content]>+? |
|
193
|
|
|
|
|
|
|
(?: |
|
194
|
|
|
|
|
|
|
<command_foreach_ifempty> |
|
195
|
|
|
|
|
|
|
)? |
|
196
|
|
|
|
|
|
|
\{\/foreach\} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
<objrule: Soy::command_foreach_ifempty> |
|
199
|
|
|
|
|
|
|
<matchpos> |
|
200
|
|
|
|
|
|
|
<matchline> |
|
201
|
|
|
|
|
|
|
\{ifempty\}<[content]>+? |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
}xms; |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 Plosurin::Exp::Grammar - Expression grammar |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
qr{ |
|
211
|
|
|
|
|
|
|
<grammar: Plosurin::Exp::Grammar> |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
#level |
|
214
|
|
|
|
|
|
|
#ternary |
|
215
|
|
|
|
|
|
|
<rule: expr> <Main=add> \? <True=add> \: <False=add> |
|
216
|
|
|
|
|
|
|
| <MATCH=list> |
|
217
|
|
|
|
|
|
|
| <MATCH=map> |
|
218
|
|
|
|
|
|
|
| <MATCH=add> |
|
219
|
|
|
|
|
|
|
#list and map |
|
220
|
|
|
|
|
|
|
<objrule: Exp::list>\[ <[expr]>* % (,) \] |
|
221
|
|
|
|
|
|
|
<objrule: Exp::map>\[ <[content=keyval]>* % (,) \] |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
<objrule: Exp::keyval> <key> : <val=expr> |
|
224
|
|
|
|
|
|
|
<token: key> <MATCH=String> | <MATCH=Var> | <MATCH=Digit> |
|
225
|
|
|
|
|
|
|
#level |
|
226
|
|
|
|
|
|
|
<objrule: Exp::add> |
|
227
|
|
|
|
|
|
|
<a=mult> <op=([+-])> <b=expr> |
|
228
|
|
|
|
|
|
|
| <MATCH=mult> |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
<objrule: Exp::mult> |
|
231
|
|
|
|
|
|
|
<a=term> <op=([*/])> <b=mult> |
|
232
|
|
|
|
|
|
|
| <MATCH=term> |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
<objrule: term> |
|
235
|
|
|
|
|
|
|
<MATCH=Literal> |
|
236
|
|
|
|
|
|
|
| <Sign=([+-])> \( <expr>\) #unary |
|
237
|
|
|
|
|
|
|
| \( <MATCH=expr> \) |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
<token: Literal> |
|
240
|
|
|
|
|
|
|
<MATCH=Bool> | |
|
241
|
|
|
|
|
|
|
<MATCH=Var> | |
|
242
|
|
|
|
|
|
|
<MATCH=String> | |
|
243
|
|
|
|
|
|
|
<MATCH=Digit> |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
<token: Ident> |
|
246
|
|
|
|
|
|
|
<MATCH=([a-z,A-Z_](?: [a-zA-Z_0-9])* )> |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
<objtoken: Exp::Var> |
|
249
|
|
|
|
|
|
|
\$ <Ident> |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
<objtoken: Exp::Bool> |
|
252
|
|
|
|
|
|
|
true | false |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
<objtoken: Exp::Digit> |
|
255
|
|
|
|
|
|
|
[+-]? \d++ (?: \. \d++ )?+ |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
<objtoken: Exp::String> |
|
258
|
|
|
|
|
|
|
\' |
|
259
|
|
|
|
|
|
|
<value=( |
|
260
|
|
|
|
|
|
|
(?: |
|
261
|
|
|
|
|
|
|
[^'\\\n\r] |
|
262
|
|
|
|
|
|
|
| \\ [nrtbf'"] |
|
263
|
|
|
|
|
|
|
# TODO \ua3ce |
|
264
|
|
|
|
|
|
|
| \s |
|
265
|
|
|
|
|
|
|
)*)> |
|
266
|
|
|
|
|
|
|
\' |
|
267
|
|
|
|
|
|
|
}xms; |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
1; |
|
270
|
|
|
|
|
|
|
__END__ |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Closure Templates Documentation L<http://code.google.com/closure/templates/docs/overview.html> |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Perl 6 implementation L<https://github.com/zag/plosurin> |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 AUTHOR |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Zahatski Aliaksandr, <zag@cpan.org> |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Copyright (C) 2011 by Zahatski Aliaksandr |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
288
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=cut |
|
291
|
|
|
|
|
|
|
|