| 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
|
3
|
|
|
3
|
|
71086
|
use strict; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
73
|
|
|
23
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
57
|
|
|
24
|
3
|
|
|
3
|
|
26
|
use v5.10; |
|
|
3
|
|
|
|
|
9
|
|
|
25
|
3
|
|
|
3
|
|
965
|
use Regexp::Grammars; |
|
|
3
|
|
|
|
|
11688
|
|
|
|
3
|
|
|
|
|
19
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 Plosurin::Template::Grammar - template file grammar |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
qr{ |
|
30
|
|
|
|
|
|
|
my $r = qr{ |
|
31
|
|
|
|
|
|
|
<extends: Plosurin::Template::Grammar> |
|
32
|
|
|
|
|
|
|
<matchline> |
|
33
|
|
|
|
|
|
|
\A <File> \Z |
|
34
|
|
|
|
|
|
|
}xms; |
|
35
|
|
|
|
|
|
|
if ( $txt =~ $r) { |
|
36
|
|
|
|
|
|
|
... |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
|
40
|
|
|
|
|
|
|
qr{ |
|
41
|
|
|
|
|
|
|
<grammar: Plosurin::Template::Grammar> |
|
42
|
|
|
|
|
|
|
<objrule: Plo::File> |
|
43
|
|
|
|
|
|
|
<namespace>(?{ $MATCH{file} = $file//"linein"}) |
|
44
|
|
|
|
|
|
|
<[templates=template]>+ % <_sep=(\s+)> \s+ |
|
45
|
|
|
|
|
|
|
<objtoken: Plo::template> <header> <template_block> |
|
46
|
|
|
|
|
|
|
<rule: namespace> \{namespace <id>\} \n+ |
|
47
|
|
|
|
|
|
|
<rule: id> [\.\w]+ |
|
48
|
|
|
|
|
|
|
<rule: header> |
|
49
|
|
|
|
|
|
|
<javadoc_start> |
|
50
|
|
|
|
|
|
|
<[h_comment]>+ % (\s+) |
|
51
|
|
|
|
|
|
|
(?: <[h_params]>+ % (\s+) )? |
|
52
|
|
|
|
|
|
|
<javadoc_end> |
|
53
|
|
|
|
|
|
|
<rule: javadoc_start>\/\*\*? |
|
54
|
|
|
|
|
|
|
| \/\*\n<matchline><fatal:(?{say "JavaDoc must start with /**! at $file line $MATCH{matchline} : $CONTEXT" })> |
|
55
|
|
|
|
|
|
|
<rule: javadoc_end> \*\/ |
|
56
|
|
|
|
|
|
|
# | <matchline><fatal:(?{say "JavaDoc must end with */! at $file line $MATCH{matchline} : $CONTEXT" })> |
|
57
|
|
|
|
|
|
|
<rule: h_comment>\* <raw_str>? |
|
58
|
|
|
|
|
|
|
<rule: raw_str> [^@\n]+ |
|
59
|
|
|
|
|
|
|
<objrule: Plo::h_params> \* \@param<is_notreq=(\?)>? <id> <raw_str> |
|
60
|
|
|
|
|
|
|
<rule: template_block> |
|
61
|
|
|
|
|
|
|
<start_template> |
|
62
|
|
|
|
|
|
|
<raw_template=(.*?)> |
|
63
|
|
|
|
|
|
|
# <raw_template> |
|
64
|
|
|
|
|
|
|
<stop_template> |
|
65
|
|
|
|
|
|
|
<rule: raw_template> (!? <stop_template> ) .*? |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
<rule: start_template> \{template <name=(\.\w+)>\} |
|
68
|
|
|
|
|
|
|
| <matchline><fatal:(?{say "Bad template definition at $file line $MATCH{matchline} : $CONTEXT" })> |
|
69
|
|
|
|
|
|
|
<rule: stop_template> \{\/template\} |
|
70
|
|
|
|
|
|
|
}xms; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 Plosurin::Grammar - soy grammar |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
qr{ |
|
75
|
|
|
|
|
|
|
my $r = qr{ |
|
76
|
|
|
|
|
|
|
<extends: Plosurin::Grammar> |
|
77
|
|
|
|
|
|
|
\A <[content]>* \Z |
|
78
|
|
|
|
|
|
|
}xms; |
|
79
|
|
|
|
|
|
|
if ( $txt =~ $r) { |
|
80
|
|
|
|
|
|
|
... |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
qr{ |
|
86
|
|
|
|
|
|
|
<grammar: Plosurin::Grammar> |
|
87
|
|
|
|
|
|
|
# \A <[content]>* \Z |
|
88
|
|
|
|
|
|
|
<objtoken: Soy::Node=content><matchpos><matchline> |
|
89
|
|
|
|
|
|
|
(?: |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
<obj=raw_text> |
|
92
|
|
|
|
|
|
|
|<obj=command_print> |
|
93
|
|
|
|
|
|
|
|<obj=command_include> |
|
94
|
|
|
|
|
|
|
|<obj=command_if> |
|
95
|
|
|
|
|
|
|
|<obj=command_call_self> |
|
96
|
|
|
|
|
|
|
|<obj=command_call> |
|
97
|
|
|
|
|
|
|
|<obj=command_import> |
|
98
|
|
|
|
|
|
|
|<obj=raw_text_add> |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
) |
|
101
|
|
|
|
|
|
|
<objrule: Soy::raw_text=raw_text_add><matchpos>(.+?) |
|
102
|
|
|
|
|
|
|
# <require: (?{ length($CAPTURE) > 0 })> |
|
103
|
|
|
|
|
|
|
# <fatal:(?{say "May be command ? $MATCH{raw_text_add} at $MATCH{matchpos}"})> |
|
104
|
|
|
|
|
|
|
<objrule: Soy::command_print> |
|
105
|
|
|
|
|
|
|
\{<is_explicit=(print)>? <variable>\} |
|
106
|
|
|
|
|
|
|
<objrule: Soy::command_include> |
|
107
|
|
|
|
|
|
|
\{include <[attribute]>{2} % <_sep=(\s+)> \} |
|
108
|
|
|
|
|
|
|
|\{include <matchpos><fatal:(?{say "'Include' require 2 attrs at $MATCH{matchpos}"})> |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
<token: attribute> <name=(\w+)>=['"]<value=(?: ([^'"]+) )>['"] |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
<token: variable> \$?\w+ |
|
113
|
|
|
|
|
|
|
<objtoken: Soy::expression> .*? |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
<objrule: Soy::raw_text> [^\{]+ |
|
116
|
|
|
|
|
|
|
<objrule: Soy::command_if> \{if <expression>\} <[content]>+? |
|
117
|
|
|
|
|
|
|
(?: |
|
118
|
|
|
|
|
|
|
<[commands_elseif=command_elseif]>* |
|
119
|
|
|
|
|
|
|
<command_else> |
|
120
|
|
|
|
|
|
|
)? |
|
121
|
|
|
|
|
|
|
\{\/if\} |
|
122
|
|
|
|
|
|
|
<objrule: Soy::command_elseif><matchpos><matchline> \{elseif <expression>\} <[content]>+? |
|
123
|
|
|
|
|
|
|
<objrule: Soy::command_else><matchpos><matchline> \{else\} <[content]>+? |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#self-ending call block |
|
126
|
|
|
|
|
|
|
<objrule: Soy::command_call_self> \{call <tmpl_name=([\.\w]+)> <[attribute]>* % <_sep=(\s+)> \/\} |
|
127
|
|
|
|
|
|
|
<objrule: Soy::command_call> \{call <tmpl_name=([\.\w]+)> \} |
|
128
|
|
|
|
|
|
|
<[content=param]>* |
|
129
|
|
|
|
|
|
|
\{\/call\} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
<objtoken: Soy::Node=param> |
|
132
|
|
|
|
|
|
|
<matchpos><matchline> |
|
133
|
|
|
|
|
|
|
(?: <obj=command_param_self> | <obj=command_param> ) |
|
134
|
|
|
|
|
|
|
<objrule: Soy::command_param_self> \{param <name=variable> : <value=(.*?)> \/\} |
|
135
|
|
|
|
|
|
|
<objrule: Soy::command_param> \{param <name=(.*?)> \} |
|
136
|
|
|
|
|
|
|
<[content]>+? |
|
137
|
|
|
|
|
|
|
\{\/param\} |
|
138
|
|
|
|
|
|
|
# {import file="test.pod6" rule=":public"} |
|
139
|
|
|
|
|
|
|
# {import file="test.pod6" } |
|
140
|
|
|
|
|
|
|
<objrule: Soy::command_import> \{import <[attribute]>+ % <_sep=(\s+)> \/?\} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
}xms; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
|
145
|
|
|
|
|
|
|
__END__ |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Closure Templates Documentation L<http://code.google.com/closure/templates/docs/overview.html> |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Perl 6 implementation L<https://github.com/zag/plosurin> |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 AUTHOR |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Zahatski Aliaksandr, <zag@cpan.org> |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Copyright (C) 2011 by Zahatski Aliaksandr |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
163
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
|
166
|
|
|
|
|
|
|
|