line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Xslate::Syntax::TTerse; |
2
|
50
|
|
|
50
|
|
43360
|
use Mouse; |
|
50
|
|
|
|
|
390224
|
|
|
50
|
|
|
|
|
208
|
|
3
|
50
|
|
|
50
|
|
12809
|
use Text::Xslate::Util qw(p any_in); |
|
50
|
|
|
|
|
78
|
|
|
50
|
|
|
|
|
2559
|
|
4
|
50
|
|
|
50
|
|
202
|
use Scalar::Util (); |
|
50
|
|
|
|
|
61
|
|
|
50
|
|
|
|
|
107854
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends qw(Text::Xslate::Parser); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _build_identity_pattern { |
9
|
59
|
|
|
59
|
|
6191
|
return qr/(?: [A-Za-z_] [A-Za-z0-9_]* )/xms; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# [% ... %] and %% ... |
13
|
59
|
|
|
59
|
|
358
|
sub _build_line_start { '%%' } |
14
|
57
|
|
|
57
|
|
234
|
sub _build_tag_start { '[%' } |
15
|
57
|
|
|
57
|
|
369
|
sub _build_tag_end { '%]' } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
around trim_code => sub { |
18
|
|
|
|
|
|
|
my($super, $self, $code) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
if($code =~ /^\#/) { # multiline comments |
21
|
|
|
|
|
|
|
return ''; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return $super->($self, $code); |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init_symbols { |
28
|
59
|
|
|
59
|
0
|
80
|
my($parser) = @_; |
29
|
59
|
|
|
|
|
91
|
my $s; |
30
|
|
|
|
|
|
|
|
31
|
59
|
|
|
|
|
286
|
$parser->init_basic_operators(); |
32
|
|
|
|
|
|
|
|
33
|
59
|
|
|
|
|
175
|
$parser->symbol('$')->set_nud(\&nud_dollar); |
34
|
59
|
|
|
|
|
228
|
$parser->make_alias('~' => '_'); |
35
|
59
|
|
|
|
|
183
|
$parser->make_alias('|' => 'FILTER'); |
36
|
59
|
|
|
|
|
171
|
$parser->symbol('.')->set_led(\&led_dot); # redefine |
37
|
|
|
|
|
|
|
|
38
|
59
|
|
|
|
|
172
|
$parser->symbol('END') ->is_block_end(1); |
39
|
59
|
|
|
|
|
128
|
$parser->symbol('ELSE') ->is_block_end(1); |
40
|
59
|
|
|
|
|
121
|
$parser->symbol('ELSIF')->is_block_end(1); |
41
|
59
|
|
|
|
|
119
|
$parser->symbol('CASE') ->is_block_end(1); |
42
|
|
|
|
|
|
|
|
43
|
59
|
|
|
|
|
148
|
$parser->symbol('IN'); |
44
|
|
|
|
|
|
|
|
45
|
59
|
|
|
|
|
123
|
$s = $parser->symbol('IF'); |
46
|
59
|
|
|
|
|
154
|
$s->set_std(\&std_if); |
47
|
59
|
|
|
|
|
192
|
$s->can_be_modifier(1); |
48
|
59
|
|
|
|
|
120
|
$s = $parser->symbol('UNLESS'); |
49
|
59
|
|
|
|
|
148
|
$s->set_std(\&std_if); |
50
|
59
|
|
|
|
|
118
|
$s->can_be_modifier(1); |
51
|
|
|
|
|
|
|
|
52
|
59
|
|
|
|
|
127
|
$parser->symbol('FOREACH') ->set_std(\&std_for); |
53
|
59
|
|
|
|
|
130
|
$parser->symbol('FOR') ->set_std(\&std_for); |
54
|
59
|
|
|
|
|
135
|
$parser->symbol('WHILE') ->set_std(\&std_while); |
55
|
59
|
|
|
|
|
144
|
$parser->symbol('SWITCH') ->set_std(\&std_switch); |
56
|
59
|
|
|
|
|
124
|
$parser->symbol('CASE') ->set_std(\&std_case); |
57
|
|
|
|
|
|
|
|
58
|
59
|
|
|
|
|
122
|
$parser->symbol('INCLUDE') ->set_std(\&std_include); |
59
|
59
|
|
|
|
|
173
|
$parser->symbol('WITH'); |
60
|
|
|
|
|
|
|
|
61
|
59
|
|
|
|
|
132
|
$parser->symbol('GET') ->set_std(\&std_get); |
62
|
59
|
|
|
|
|
126
|
$parser->symbol('SET') ->set_std(\&std_set); |
63
|
59
|
|
|
|
|
127
|
$parser->symbol('DEFAULT') ->set_std(\&std_set); |
64
|
59
|
|
|
|
|
125
|
$parser->symbol('CALL') ->set_std(\&std_call); |
65
|
|
|
|
|
|
|
|
66
|
59
|
|
|
|
|
116
|
$parser->symbol('NEXT') ->set_std( $parser->can('std_next') ); |
67
|
59
|
|
|
|
|
140
|
$parser->symbol('LAST') ->set_std( $parser->can('std_last') ); |
68
|
|
|
|
|
|
|
|
69
|
59
|
|
|
|
|
133
|
$parser->symbol('MACRO') ->set_std(\&std_macro); |
70
|
59
|
|
|
|
|
128
|
$parser->symbol('BLOCK'); |
71
|
59
|
|
|
|
|
129
|
$parser->symbol('WRAPPER')->set_std(\&std_wrapper); |
72
|
59
|
|
|
|
|
117
|
$parser->symbol('INTO'); |
73
|
|
|
|
|
|
|
|
74
|
59
|
|
|
|
|
129
|
$parser->symbol('FILTER')->set_std(\&std_filter); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# unsupported directives |
77
|
59
|
|
|
|
|
233
|
my $nos = $parser->can('not_supported'); |
78
|
59
|
|
|
|
|
143
|
foreach my $keyword (qw( |
79
|
|
|
|
|
|
|
INSERT PROCESS PERL RAWPERL TRY THROW RETURN |
80
|
|
|
|
|
|
|
STOP CLEAR META TAGS DEBUG VIEW)) { |
81
|
767
|
|
|
|
|
1083
|
$parser->symbol($keyword)->set_std($nos); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# not supported, but ignored (synonym to CALL) |
85
|
59
|
|
|
|
|
158
|
$parser->symbol('USE')->set_std(\&std_call); |
86
|
|
|
|
|
|
|
|
87
|
59
|
|
|
|
|
70
|
foreach my $id(keys %{$parser->symbol_table}) { |
|
59
|
|
|
|
|
1023
|
|
88
|
6195
|
100
|
|
|
|
11549
|
if($id =~ /\A [A-Z]+ \z/xms) { # upper-cased keywords |
89
|
2242
|
|
|
|
|
4450
|
$parser->make_alias($id => lc $id)->set_nud(\&aliased_nud); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
59
|
|
|
|
|
374
|
$parser->make_alias('not' => 'NOT'); |
94
|
59
|
|
|
|
|
183
|
$parser->make_alias('and' => 'AND'); |
95
|
59
|
|
|
|
|
172
|
$parser->make_alias('or' => 'OR'); |
96
|
|
|
|
|
|
|
|
97
|
59
|
|
|
|
|
123
|
return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
around _build_iterator_element => sub { |
101
|
|
|
|
|
|
|
my($super, $parser) = @_; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $table = $super->($parser); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# make aliases |
106
|
|
|
|
|
|
|
$table->{first} = $table->{is_first}; |
107
|
|
|
|
|
|
|
$table->{last} = $table->{is_last}; |
108
|
|
|
|
|
|
|
$table->{next} = $table->{peek_next}; |
109
|
|
|
|
|
|
|
$table->{prev} = $table->{peek_prev}; |
110
|
|
|
|
|
|
|
$table->{max} = $table->{max_index}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return $table; |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub default_nud { |
116
|
85
|
|
|
85
|
0
|
85
|
my($parser, $symbol) = @_; |
117
|
85
|
|
|
|
|
153
|
return $symbol->clone( |
118
|
|
|
|
|
|
|
arity => 'variable', |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# same as default_nud, except for aliased symbols |
123
|
|
|
|
|
|
|
sub aliased_nud { |
124
|
2
|
|
|
2
|
0
|
2
|
my($parser, $symbol) = @_; |
125
|
2
|
|
|
|
|
10
|
return $symbol->clone( |
126
|
|
|
|
|
|
|
arity => 'name', |
127
|
|
|
|
|
|
|
id => lc( $symbol->id ), |
128
|
|
|
|
|
|
|
value => $symbol->id, |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub nud_dollar { |
133
|
28
|
|
|
28
|
0
|
51
|
my($parser, $symbol) = @_; |
134
|
28
|
|
|
|
|
297
|
my $expr; |
135
|
28
|
|
|
|
|
59
|
my $t = $parser->token; |
136
|
28
|
100
|
|
|
|
72
|
if($t->id eq "{") { |
137
|
6
|
|
|
|
|
13
|
$parser->advance("{"); |
138
|
6
|
|
|
|
|
16
|
$expr = $parser->expression(0); |
139
|
6
|
|
|
|
|
13
|
$parser->advance("}"); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
else { |
142
|
22
|
100
|
|
|
|
71
|
if(!any_in($t->arity, qw(name variable))) { |
143
|
1
|
|
|
|
|
5
|
$parser->_unexpected("a name", $t); |
144
|
|
|
|
|
|
|
} |
145
|
21
|
|
|
|
|
42
|
$parser->advance(); |
146
|
21
|
|
|
|
|
39
|
$expr = $t->clone( arity => 'variable' ); |
147
|
|
|
|
|
|
|
} |
148
|
27
|
|
|
|
|
265
|
return $expr; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub undefined_name { |
152
|
464
|
|
|
464
|
0
|
430
|
my($parser, $name) = @_; |
153
|
|
|
|
|
|
|
# undefined names are always variables |
154
|
464
|
|
|
|
|
1191
|
return $parser->symbol_table->{'(variable)'}->clone( |
155
|
|
|
|
|
|
|
id => $name, |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub is_valid_field { |
160
|
50
|
|
|
50
|
0
|
43
|
my($parser, $token) = @_; |
161
|
50
|
|
66
|
|
|
113
|
return $parser->SUPER::is_valid_field($token) |
162
|
|
|
|
|
|
|
|| $token->arity eq "variable"; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub led_dot { |
166
|
55
|
|
|
55
|
0
|
51
|
my($parser, $symbol, $left) = @_; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# special case: foo.$field, foo.${expr} |
169
|
55
|
100
|
|
|
|
159
|
if($parser->token->id eq '$') { |
170
|
5
|
|
|
|
|
16
|
return $symbol->clone( |
171
|
|
|
|
|
|
|
arity => "field", |
172
|
|
|
|
|
|
|
first => $left, |
173
|
|
|
|
|
|
|
second => $parser->expression( $symbol->lbp ), |
174
|
|
|
|
|
|
|
); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
50
|
|
|
|
|
140
|
return $parser->SUPER::led_dot($symbol, $left); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub led_assignment { |
181
|
26
|
|
|
26
|
0
|
141
|
my($parser, $symbol, $left) = @_; |
182
|
|
|
|
|
|
|
|
183
|
26
|
|
|
|
|
100
|
my $assign = $parser->led_infixr($symbol, $left); |
184
|
26
|
|
|
|
|
365
|
$assign->arity('assign'); |
185
|
26
|
|
|
|
|
90
|
$assign->is_statement(1); |
186
|
|
|
|
|
|
|
|
187
|
26
|
|
|
|
|
43
|
my $name = $assign->first; |
188
|
26
|
100
|
|
|
|
106
|
if(not $parser->find_or_create($name->id)->is_defined) { |
189
|
15
|
|
|
|
|
212
|
$parser->define($name); |
190
|
15
|
|
|
|
|
38
|
$assign->third('declare'); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
26
|
|
|
|
|
303
|
return $assign; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub assignment { |
197
|
590
|
|
|
590
|
0
|
532
|
my($parser, $id, $bp) = @_; |
198
|
|
|
|
|
|
|
|
199
|
590
|
|
|
|
|
860
|
$parser->symbol($id, $bp)->set_led(\&led_assignment); |
200
|
590
|
|
|
|
|
727
|
return; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub std_if { |
204
|
69
|
|
|
69
|
0
|
84
|
my($parser, $symbol, $expr) = @_; |
205
|
69
|
|
|
|
|
124
|
my $if = $symbol->clone(arity => "if"); |
206
|
|
|
|
|
|
|
|
207
|
69
|
|
|
|
|
819
|
my $is_modifier = defined $expr; |
208
|
|
|
|
|
|
|
|
209
|
69
|
100
|
|
|
|
234
|
$parser->new_scope() unless $is_modifier; # whole if block |
210
|
|
|
|
|
|
|
|
211
|
69
|
|
|
|
|
134
|
my $cond = $parser->expression(0); |
212
|
|
|
|
|
|
|
|
213
|
69
|
100
|
|
|
|
174
|
if($symbol->id eq 'UNLESS') { |
214
|
7
|
|
|
|
|
16
|
$cond = $parser->symbol('!')->clone( |
215
|
|
|
|
|
|
|
arity => 'unary', |
216
|
|
|
|
|
|
|
first => $cond, |
217
|
|
|
|
|
|
|
); |
218
|
|
|
|
|
|
|
} |
219
|
69
|
|
|
|
|
235
|
$if->first($cond); |
220
|
|
|
|
|
|
|
|
221
|
69
|
100
|
|
|
|
123
|
if($is_modifier) { |
222
|
17
|
|
|
|
|
42
|
$if->second([ $expr ]); |
223
|
17
|
|
|
|
|
38
|
return $if; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# then block |
227
|
|
|
|
|
|
|
{ |
228
|
52
|
|
|
|
|
42
|
$parser->new_scope(); |
|
52
|
|
|
|
|
114
|
|
229
|
52
|
|
|
|
|
115
|
$if->second( $parser->statements() ); |
230
|
52
|
|
|
|
|
133
|
$parser->pop_scope(); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
52
|
|
|
|
|
72
|
my $t = $parser->token; |
234
|
|
|
|
|
|
|
|
235
|
52
|
|
|
|
|
39
|
my $top_if = $if; |
236
|
|
|
|
|
|
|
|
237
|
52
|
|
|
|
|
126
|
while($t->id eq "ELSIF") { |
238
|
10
|
|
|
|
|
22
|
$parser->reserve($t); |
239
|
10
|
|
|
|
|
17
|
$parser->advance(); # "ELSIF" |
240
|
|
|
|
|
|
|
|
241
|
10
|
|
|
|
|
23
|
my $elsif = $t->clone(arity => "if"); |
242
|
10
|
|
|
|
|
124
|
$elsif->first( $parser->expression(0) ); |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
{ |
245
|
10
|
|
|
|
|
12
|
$parser->new_scope(); |
|
10
|
|
|
|
|
21
|
|
246
|
10
|
|
|
|
|
29
|
$elsif->second( $parser->statements() ); |
247
|
10
|
|
|
|
|
23
|
$parser->pop_scope(); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
10
|
|
|
|
|
26
|
$if->third([$elsif]); |
251
|
10
|
|
|
|
|
12
|
$if = $elsif; |
252
|
10
|
|
|
|
|
35
|
$t = $parser->token; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
52
|
100
|
|
|
|
120
|
if($t->id eq "ELSE") { |
256
|
16
|
|
|
|
|
24
|
my $else_line = $t->line; |
257
|
16
|
|
|
|
|
31
|
$parser->reserve($t); |
258
|
16
|
|
|
|
|
30
|
$t = $parser->advance(); # "ELSE" |
259
|
|
|
|
|
|
|
|
260
|
16
|
50
|
33
|
|
|
71
|
if($t->id eq "IF" and $t->line != $else_line) { |
261
|
0
|
|
|
|
|
0
|
Carp::carp(sprintf "%s: Parsing ELSE-IF sequense as ELSIF, but it is likely to be a misuse of ELSE-IF. Please insert semicolon as ELSE; IF, or write it in the same line (around input line %d)", ref $parser, $t->line); |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
{ |
265
|
16
|
|
|
|
|
12
|
$parser->new_scope(); |
|
16
|
|
|
|
|
28
|
|
266
|
16
|
50
|
|
|
|
53
|
$if->third( $t->id eq "IF" |
267
|
|
|
|
|
|
|
? [$parser->statement()] |
268
|
|
|
|
|
|
|
: $parser->statements()); |
269
|
16
|
|
|
|
|
29
|
$parser->pop_scope(); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
52
|
|
|
|
|
88
|
$parser->advance("END"); |
274
|
51
|
|
|
|
|
95
|
$parser->pop_scope(); |
275
|
51
|
|
|
|
|
258
|
return $top_if; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub std_switch { |
279
|
10
|
|
|
10
|
0
|
10
|
my($parser, $symbol) = @_; |
280
|
|
|
|
|
|
|
|
281
|
10
|
|
|
|
|
22
|
$parser->new_scope(); |
282
|
|
|
|
|
|
|
|
283
|
10
|
|
|
|
|
18
|
my $topic = $parser->symbol('$_')->clone(arity => 'variable' ); |
284
|
10
|
|
|
|
|
120
|
my $switch = $symbol->clone( |
285
|
|
|
|
|
|
|
arity => 'given', |
286
|
|
|
|
|
|
|
first => $parser->expression(0), |
287
|
|
|
|
|
|
|
second => [ $topic ], |
288
|
|
|
|
|
|
|
); |
289
|
|
|
|
|
|
|
|
290
|
10
|
|
|
|
|
140
|
local $parser->{in_given} = 1; |
291
|
|
|
|
|
|
|
|
292
|
10
|
|
|
|
|
12
|
my @cases; |
293
|
10
|
|
100
|
|
|
67
|
while(!($parser->token->id eq "END" or $parser->token->id eq '(end)')) { |
294
|
39
|
|
|
|
|
84
|
push @cases, $parser->statement(); |
295
|
|
|
|
|
|
|
} |
296
|
10
|
|
|
|
|
17
|
$switch->third( \@cases ); |
297
|
|
|
|
|
|
|
|
298
|
10
|
|
|
|
|
29
|
$parser->build_given_body($switch, "case"); |
299
|
|
|
|
|
|
|
|
300
|
9
|
|
|
|
|
14
|
$parser->advance("END"); |
301
|
9
|
|
|
|
|
19
|
$parser->pop_scope(); |
302
|
9
|
|
|
|
|
80
|
return $switch; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
sub std_case { |
306
|
19
|
|
|
19
|
0
|
18
|
my($parser, $symbol) = @_; |
307
|
19
|
50
|
|
|
|
43
|
if(!$parser->in_given) { |
308
|
0
|
|
|
|
|
0
|
$parser->_error("You cannot use $symbol statements outside switch statements"); |
309
|
|
|
|
|
|
|
} |
310
|
19
|
|
|
|
|
30
|
my $case = $symbol->clone(arity => "case"); |
311
|
|
|
|
|
|
|
|
312
|
19
|
100
|
|
|
|
237
|
if($parser->token->id ne "DEFAULT") { |
313
|
12
|
|
|
|
|
25
|
$case->first( $parser->expression(0) ); |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
else { |
316
|
7
|
|
|
|
|
14
|
$parser->advance(); |
317
|
|
|
|
|
|
|
} |
318
|
19
|
|
|
|
|
36
|
$case->second( $parser->statements() ); |
319
|
19
|
|
|
|
|
110
|
return $case; |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub iterator_name { |
323
|
35
|
|
|
35
|
0
|
85
|
return 'loop'; # always 'loop' |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
# FOR ... IN ...; ...; END |
327
|
|
|
|
|
|
|
sub std_for { |
328
|
35
|
|
|
35
|
0
|
37
|
my($parser, $symbol) = @_; |
329
|
|
|
|
|
|
|
|
330
|
35
|
|
|
|
|
83
|
my $proc = $symbol->clone(arity => "for"); |
331
|
|
|
|
|
|
|
|
332
|
35
|
|
|
|
|
416
|
my $var = $parser->token; |
333
|
35
|
50
|
|
|
|
105
|
if(!any_in($var->arity, qw(variable name))) { |
334
|
0
|
|
|
|
|
0
|
$parser->_unexpected("a variable name", $var); |
335
|
|
|
|
|
|
|
} |
336
|
35
|
|
|
|
|
72
|
$parser->advance(); |
337
|
35
|
|
|
|
|
72
|
$parser->advance("IN"); |
338
|
35
|
|
|
|
|
84
|
$proc->first( $parser->expression(0) ); |
339
|
35
|
|
|
|
|
88
|
$proc->second([$var]); |
340
|
|
|
|
|
|
|
|
341
|
35
|
|
|
|
|
83
|
$parser->new_scope(); |
342
|
35
|
|
|
|
|
98
|
$parser->define_iterator($var); |
343
|
|
|
|
|
|
|
|
344
|
35
|
|
|
|
|
80
|
$proc->third( $parser->statements() ); |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
# for-else |
347
|
35
|
100
|
|
|
|
110
|
if($parser->token->id eq 'ELSE') { |
348
|
3
|
|
|
|
|
7
|
$parser->reserve($parser->token); |
349
|
3
|
|
|
|
|
6
|
$parser->advance(); |
350
|
3
|
|
|
|
|
6
|
my $else = $parser->statements(); |
351
|
3
|
|
|
|
|
7
|
$proc = $symbol->clone( arity => 'for_else', |
352
|
|
|
|
|
|
|
first => $proc, |
353
|
|
|
|
|
|
|
second => $else, |
354
|
|
|
|
|
|
|
); |
355
|
|
|
|
|
|
|
} |
356
|
35
|
|
|
|
|
97
|
$parser->advance("END"); |
357
|
35
|
|
|
|
|
113
|
$parser->pop_scope(); |
358
|
35
|
|
|
|
|
150
|
return $proc; |
359
|
|
|
|
|
|
|
} |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
sub std_while { |
362
|
10
|
|
|
10
|
0
|
12
|
my($parser, $symbol) = @_; |
363
|
|
|
|
|
|
|
|
364
|
10
|
|
|
|
|
26
|
my $while = $symbol->clone(arity => "while"); |
365
|
|
|
|
|
|
|
|
366
|
10
|
|
|
|
|
141
|
$while->first( $parser->expression(0) ); |
367
|
10
|
|
|
|
|
26
|
$while->second([]); # no vars |
368
|
10
|
|
|
|
|
32
|
$parser->new_scope(); |
369
|
10
|
|
|
|
|
25
|
$while->third( $parser->statements() ); |
370
|
10
|
|
|
|
|
22
|
$parser->advance("END"); |
371
|
10
|
|
|
|
|
41
|
$parser->pop_scope(); |
372
|
10
|
|
|
|
|
46
|
return $while; |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
around std_include => sub { |
376
|
|
|
|
|
|
|
my($super, $self, $symbol) = @_; |
377
|
|
|
|
|
|
|
$symbol->id( lc $symbol->id ); |
378
|
|
|
|
|
|
|
return $self->$super( $symbol ); |
379
|
|
|
|
|
|
|
}; |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
sub localize_vars { |
382
|
28
|
|
|
28
|
0
|
26
|
my($parser, $symbol) = @_; |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
# should make 'WITH' optional? |
385
|
|
|
|
|
|
|
# my $t = $parser->token; |
386
|
|
|
|
|
|
|
# if($t->id eq "WITH" or $t->arity eq "variable") { |
387
|
|
|
|
|
|
|
# $parser->advance() if $t->id eq "WITH"; |
388
|
28
|
100
|
|
|
|
99
|
if($parser->token->id eq "WITH") { |
389
|
9
|
|
|
|
|
17
|
$parser->advance(); |
390
|
9
|
|
|
|
|
128
|
$parser->new_scope(); |
391
|
9
|
|
|
|
|
21
|
my $vars = $parser->set_list(); |
392
|
9
|
|
|
|
|
33
|
$parser->pop_scope(); |
393
|
9
|
|
|
|
|
16
|
return $vars; |
394
|
|
|
|
|
|
|
} |
395
|
19
|
|
|
|
|
43
|
return undef; |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
sub set_list { |
399
|
39
|
|
|
39
|
0
|
40
|
my($parser) = @_; |
400
|
39
|
|
|
|
|
37
|
my @args; |
401
|
39
|
|
|
|
|
35
|
while(1) { |
402
|
84
|
|
|
|
|
122
|
my $key = $parser->token; |
403
|
|
|
|
|
|
|
|
404
|
84
|
100
|
100
|
|
|
259
|
if(!(any_in($key->arity, qw(variable name)) |
405
|
|
|
|
|
|
|
&& $parser->next_token_is("="))) { |
406
|
39
|
|
|
|
|
53
|
last; |
407
|
|
|
|
|
|
|
} |
408
|
45
|
|
|
|
|
102
|
$parser->advance(); |
409
|
45
|
|
|
|
|
99
|
$parser->advance("="); |
410
|
|
|
|
|
|
|
|
411
|
45
|
|
|
|
|
115
|
my $value = $parser->expression(0); |
412
|
|
|
|
|
|
|
|
413
|
45
|
|
|
|
|
67
|
push @args, $key => $value; |
414
|
|
|
|
|
|
|
|
415
|
45
|
100
|
|
|
|
171
|
if($parser->token->id eq ",") { # , is optional |
416
|
3
|
|
|
|
|
6
|
$parser->advance(); |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
} |
419
|
|
|
|
|
|
|
|
420
|
39
|
|
|
|
|
68
|
return \@args; |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
sub std_get { |
424
|
5
|
|
|
5
|
0
|
5
|
my($parser, $symbol) = @_; |
425
|
|
|
|
|
|
|
|
426
|
5
|
|
|
|
|
13
|
my $stmt = $parser->print( $parser->expression(0) ); |
427
|
5
|
|
|
|
|
65
|
return $parser->finish_statement($stmt); |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
sub std_set { |
431
|
30
|
|
|
30
|
0
|
41
|
my($parser, $symbol) = @_; |
432
|
|
|
|
|
|
|
|
433
|
30
|
|
|
|
|
70
|
my $is_default = ($symbol->id eq 'DEFAULT'); |
434
|
|
|
|
|
|
|
|
435
|
30
|
|
|
|
|
76
|
my $set_list = $parser->set_list(); |
436
|
30
|
|
|
|
|
40
|
my @assigns; |
437
|
30
|
|
|
|
|
45
|
for(my $i = 0; $i < @{$set_list}; $i += 2) { |
|
63
|
|
|
|
|
148
|
|
438
|
33
|
|
|
|
|
48
|
my($name, $value) = @{$set_list}[$i, $i+1]; |
|
33
|
|
|
|
|
65
|
|
439
|
|
|
|
|
|
|
|
440
|
33
|
100
|
|
|
|
66
|
if($is_default) { # DEFAULT a = b -> a = a || b |
441
|
7
|
|
|
|
|
17
|
my $var = $parser->symbol('(variable)')->clone( |
442
|
|
|
|
|
|
|
id => $name->id, |
443
|
|
|
|
|
|
|
); |
444
|
|
|
|
|
|
|
|
445
|
7
|
|
|
|
|
97
|
$value = $parser->binary('||', $var, $value); |
446
|
|
|
|
|
|
|
} |
447
|
33
|
|
|
|
|
261
|
my $assign = $symbol->clone( |
448
|
|
|
|
|
|
|
id => '=', |
449
|
|
|
|
|
|
|
arity => 'assign', |
450
|
|
|
|
|
|
|
first => $name, |
451
|
|
|
|
|
|
|
second => $value, |
452
|
|
|
|
|
|
|
); |
453
|
|
|
|
|
|
|
|
454
|
33
|
100
|
|
|
|
567
|
if(not $parser->find_or_create($name->id)->is_defined) { |
455
|
32
|
|
|
|
|
456
|
$parser->define($name); |
456
|
32
|
|
|
|
|
66
|
$assign->third('declare'); |
457
|
|
|
|
|
|
|
} |
458
|
33
|
|
|
|
|
156
|
push @assigns, $assign; |
459
|
|
|
|
|
|
|
} |
460
|
30
|
|
|
|
|
170
|
return @assigns; |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
sub std_call { |
464
|
7
|
|
|
7
|
0
|
9
|
my($parser, $symbol) = @_; |
465
|
7
|
|
|
|
|
17
|
my $stmt = $parser->expression(0); |
466
|
7
|
|
|
|
|
19
|
return $parser->finish_statement($stmt); |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub std_macro { |
470
|
18
|
|
|
18
|
0
|
24
|
my($parser, $symbol) = @_; |
471
|
18
|
|
|
|
|
45
|
my $proc = $symbol->clone( |
472
|
|
|
|
|
|
|
arity => 'proc', |
473
|
|
|
|
|
|
|
id => 'macro', |
474
|
|
|
|
|
|
|
); |
475
|
|
|
|
|
|
|
|
476
|
18
|
|
|
|
|
256
|
my $name = $parser->token; |
477
|
18
|
50
|
|
|
|
60
|
if($name->arity ne "variable") { |
478
|
0
|
|
|
|
|
0
|
$parser->_error("a name", $name); |
479
|
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
|
481
|
18
|
|
|
|
|
65
|
$parser->define_function($name->id); |
482
|
|
|
|
|
|
|
|
483
|
18
|
|
|
|
|
41
|
$proc->first($name); |
484
|
18
|
|
|
|
|
41
|
$parser->advance(); |
485
|
|
|
|
|
|
|
|
486
|
18
|
|
|
|
|
75
|
$parser->new_scope(); |
487
|
|
|
|
|
|
|
|
488
|
18
|
|
|
|
|
54
|
my $paren = ($parser->token->id eq "("); |
489
|
|
|
|
|
|
|
|
490
|
18
|
100
|
|
|
|
54
|
$parser->advance("(") if $paren; |
491
|
|
|
|
|
|
|
|
492
|
18
|
|
|
|
|
31
|
my $t = $parser->token; |
493
|
18
|
|
|
|
|
19
|
my @vars; |
494
|
18
|
|
|
|
|
68
|
while($t->arity eq "variable") { |
495
|
9
|
|
|
|
|
14
|
push @vars, $t; |
496
|
9
|
|
|
|
|
28
|
$parser->define($t); |
497
|
|
|
|
|
|
|
|
498
|
9
|
|
|
|
|
21
|
$t = $parser->advance(); |
499
|
|
|
|
|
|
|
|
500
|
9
|
100
|
|
|
|
30
|
if($t->id eq ",") { |
501
|
1
|
|
|
|
|
2
|
$t = $parser->advance(); # "," |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
else { |
504
|
8
|
|
|
|
|
11
|
last; |
505
|
|
|
|
|
|
|
} |
506
|
|
|
|
|
|
|
} |
507
|
18
|
100
|
|
|
|
51
|
$parser->advance(")") if $paren; |
508
|
|
|
|
|
|
|
|
509
|
18
|
|
|
|
|
54
|
$proc->second(\@vars); |
510
|
|
|
|
|
|
|
|
511
|
18
|
|
|
|
|
38
|
$parser->advance("BLOCK"); |
512
|
18
|
|
|
|
|
71
|
$proc->third( $parser->statements() ); |
513
|
18
|
|
|
|
|
38
|
$parser->advance("END"); |
514
|
18
|
|
|
|
|
73
|
$parser->pop_scope(); |
515
|
18
|
|
|
|
|
119
|
return $proc; |
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
# WRAPPER "foo.tt" ... END |
520
|
|
|
|
|
|
|
# is |
521
|
|
|
|
|
|
|
# cascade "foo.tt" { content => lambda@xxx() } |
522
|
|
|
|
|
|
|
# macro content@xxx -> { ... } |
523
|
|
|
|
|
|
|
sub std_wrapper { |
524
|
10
|
|
|
10
|
0
|
11
|
my($parser, $symbol) = @_; |
525
|
|
|
|
|
|
|
|
526
|
10
|
|
|
|
|
33
|
my $base = $parser->barename(); |
527
|
10
|
|
|
|
|
12
|
my $into; |
528
|
10
|
100
|
|
|
|
33
|
if($parser->token->id eq "INTO") { |
529
|
1
|
|
|
|
|
3
|
my $t = $parser->advance(); |
530
|
1
|
50
|
|
|
|
5
|
if(!any_in($t->arity, qw(name variable))) { |
531
|
0
|
|
|
|
|
0
|
$parser->_unexpected("a variable name", $t); |
532
|
|
|
|
|
|
|
} |
533
|
1
|
|
|
|
|
3
|
$parser->advance(); |
534
|
1
|
|
|
|
|
2
|
$into = $t->id; |
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
else { |
537
|
9
|
|
|
|
|
10
|
$into = 'content'; |
538
|
|
|
|
|
|
|
} |
539
|
10
|
|
100
|
|
|
17
|
my $vars = $parser->localize_vars() || []; |
540
|
10
|
|
|
|
|
31
|
my $body = $parser->statements(); |
541
|
10
|
|
|
|
|
17
|
$parser->advance("END"); |
542
|
|
|
|
|
|
|
|
543
|
10
|
|
|
|
|
21
|
return $parser->wrap( |
544
|
|
|
|
|
|
|
$symbol, |
545
|
|
|
|
|
|
|
$base, |
546
|
|
|
|
|
|
|
$into, |
547
|
|
|
|
|
|
|
$vars, |
548
|
|
|
|
|
|
|
$body, |
549
|
|
|
|
|
|
|
); |
550
|
|
|
|
|
|
|
} |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
sub wrap { |
553
|
10
|
|
|
10
|
0
|
15
|
my($parser, $proto, $base, $into, $vars, $body) = @_; |
554
|
10
|
|
|
|
|
19
|
my $cascade = $proto->clone( |
555
|
|
|
|
|
|
|
arity => 'cascade', |
556
|
|
|
|
|
|
|
first => $base, |
557
|
|
|
|
|
|
|
); |
558
|
|
|
|
|
|
|
|
559
|
10
|
|
|
|
|
120
|
my $content = $parser->lambda($proto); |
560
|
10
|
|
|
|
|
133
|
$content->second([]); # args |
561
|
10
|
|
|
|
|
19
|
$content->third($body); |
562
|
|
|
|
|
|
|
|
563
|
10
|
|
|
|
|
30
|
my $call_content = $parser->call($content->first); |
564
|
|
|
|
|
|
|
|
565
|
10
|
|
|
|
|
116
|
my $into_name = $proto->clone( |
566
|
|
|
|
|
|
|
arity => 'literal', |
567
|
|
|
|
|
|
|
id => $into, |
568
|
|
|
|
|
|
|
); |
569
|
|
|
|
|
|
|
|
570
|
10
|
|
|
|
|
91
|
push @{$vars}, $into_name => $call_content; |
|
10
|
|
|
|
|
16
|
|
571
|
10
|
|
|
|
|
19
|
$cascade->third($vars); |
572
|
10
|
|
|
|
|
52
|
return( $cascade, $content ); |
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
# [% FILTER html %] |
576
|
|
|
|
|
|
|
# ... |
577
|
|
|
|
|
|
|
# [% END %] |
578
|
|
|
|
|
|
|
# is |
579
|
|
|
|
|
|
|
# : block filter_xxx | html -> { |
580
|
|
|
|
|
|
|
# ... |
581
|
|
|
|
|
|
|
# : } |
582
|
|
|
|
|
|
|
# in Kolon |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
sub std_filter { |
585
|
7
|
|
|
7
|
0
|
7
|
my($parser, $symbol) = @_; |
586
|
|
|
|
|
|
|
|
587
|
7
|
|
|
|
|
12
|
my $filter = $parser->expression(0); |
588
|
|
|
|
|
|
|
|
589
|
7
|
|
|
|
|
22
|
my $proc = $parser->lambda($symbol); |
590
|
|
|
|
|
|
|
|
591
|
7
|
|
|
|
|
88
|
$proc->second([]); |
592
|
7
|
|
|
|
|
15
|
$proc->third( $parser->statements() ); |
593
|
7
|
|
|
|
|
11
|
$parser->advance("END"); |
594
|
|
|
|
|
|
|
|
595
|
7
|
|
|
|
|
22
|
my $callmacro = $parser->call($proc->first); |
596
|
|
|
|
|
|
|
|
597
|
7
|
100
|
|
|
|
89
|
if($filter->id eq 'html') { |
598
|
|
|
|
|
|
|
# for compatibility with TT2 |
599
|
4
|
|
|
|
|
4
|
$filter = 'unmark_raw'; |
600
|
|
|
|
|
|
|
} |
601
|
7
|
|
|
|
|
20
|
my $callfilter = $parser->call($filter, $callmacro); |
602
|
7
|
|
|
|
|
79
|
return( $proc, $parser->print($callfilter) ); |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
|
605
|
50
|
|
|
50
|
|
271
|
no Mouse; |
|
50
|
|
|
|
|
69
|
|
|
50
|
|
|
|
|
287
|
|
606
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
607
|
|
|
|
|
|
|
__END__ |