Blatte/Parser.pm

filter: Statementstmt 93.2% 343 / 368 Branchbran 63.4% 132 / 208 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 92.5% 25 / 27 Podpod 18.1% 4 / 22 totaltotal 79.2% 507 / 640 CC 109 SCAR 20.8
CC
109
Cov
82%
eof
20.0
any_let_expr
11.8
while_expr
11.4
CRAP 8.0
« Blatte/Compiler.pm ↑ Summary Blatte/Builtins.pm »
1 package Blatte::Parser;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use Blatte;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Blatte::Syntax;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Blatte::Ws;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶use vars qw($identifier_regex);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 12 $identifier_regex = qr/[A-Za-z][A-Za-z0-9_]*(?![A-Za-z0-9_])/;
12  
13 12 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 12 my $type = shift;
15 12 bless { special_forms => [\&define_expr,
16 \&set_expr,
17 \&lambda_expr,
18 \&any_let_expr,
19 \&if_expr,
20 \&cond_expr,
21 \&while_expr,
22 \&and_expr,
23 \&or_expr] }, $type;
24 }
25  
26 0 ▶sub add_special_form {
Subroutine add_special_form: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my $self = shift;
28 0 push(@{$self->{special_forms}}, @_);
29 }
30  
31 43 ▶sub parse {
Subroutine parse: called CC=2 SCAR=7.0
Pod documented
32 43 my($self, $input_arg) = @_;
33 43 my $expr = $self->expr($input_arg);
34 43 ▶ return undef unless defined($expr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 43 43
35 43 sprintf("&Blatte::wrapws('%s',\n %s)",
36 &Blatte::wsof($expr), $expr->transform(16));
37 }
38  
39 252 ▶sub expr {
Subroutine expr: called CC=11 SCAR=24.0
Pod documented
40 252 my($self, $input_arg) = @_;
41  
42 252 my $input = $input_arg;
43 252 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 209 43 252
44 209 $input = $$input;
45 }
46  
47 252 my $ws = &consume_whitespace(\$input);
48  
49 252 ▶ return undef if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 252 252
50  
51 252 my $syntax;
52  
53 252 ▶ if (substr($input, 0, 1) eq '{') {
Branch: 4 branches
BranchTrueFalseTotal
if (substr($input, 0, 1) eq '{') { } 57 195 252
elsif ($input =~ /^\\\"([^\\]+|\\[^\"])*\\\"/g) { } 1 194 195
elsif ($input =~ /^\\($Blatte::Parser::identifier_regex)/go) { } 42 152 194
elsif ($input =~ /^([^\\{}\s]+|\\[\\{}])+/g) { } 94 58 152
54 57 $input = substr($input, 1);
55  
56 57 $syntax = $self->special_form(\$input);
57 57 ▶ $syntax = new Blatte::Syntax::List($self->list_subexprs(\$input))
Branch: 1 branch
BranchTrueFalseTotal
unless defined $syntax 35 22 57
58 unless defined $syntax;
59  
60 57 &consume_whitespace(\$input);
61 57 ▶ return undef if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 57 57
62 57 ▶ return undef if (substr($input, 0, 1) ne '}');
Branch: 1 branch
BranchTrueFalseTotal
if substr($input, 0, 1) ne "}" 0 57 57
63 57 $input = substr($input, 1);
64 } elsif ($input =~ /^\\\"([^\\]+|\\[^\"])*\\\"/g) {
65 1 my $str = substr($input, 0, pos($input));
66 1 $input = substr($input, pos($input));
67 1 $str = substr($str, 2, length($str) - 4);
68 1 $str =~ s/\\(.)/$1/g;
69 1 $syntax = new Blatte::Syntax::Literal($str);
70 } elsif ($input =~ /^\\($identifier_regex)/go) {
71 42 my $name = $1;
72 42 $input = substr($input, pos($input));
73 42 $syntax = new Blatte::Syntax::VarRef($name);
74 } elsif ($input =~ /^([^\\{}\s]+|\\[\\{}])+/g) {
75 94 my $atom = substr($input, 0, pos($input));
76 94 $input = substr($input, pos($input));
77 94 $atom =~ s/\\(.)/$1/g;
78 94 $syntax = new Blatte::Syntax::Literal($atom);
79 } else {
80 58 return undef;
81 }
82  
83 194 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 151 43 194
84 151 $$input_arg = $input;
85 }
86  
87 194 return &Blatte::wrapws($ws, $syntax);
88 }
89  
90 35 ▶sub list_subexprs {
Subroutine list_subexprs: called CC=6 SCAR=18.0
Pod undocumented
91 35 my($self, $input_arg) = @_;
92  
93 35 my $input = $input_arg;
94 35 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 35 0 35
95 35 $input = $$input_arg;
96 }
97  
98 35 my @subexprs;
99 35 while (1) {
100 135 my $ws = &consume_whitespace(\$input);
101 135 ▶ if ($input =~ /^\\($identifier_regex)=/go) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /^\\($Blatte::Parser::identifier_regex)=/go) { } 2 133 135
102 2 my $name = $1;
103 2 $input = substr($input, pos($input));
104  
105 2 my $expr = $self->expr(\$input);
106 2 ▶ return undef unless defined($expr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 2 2
107  
108 2 push(@subexprs,
109 new Blatte::Syntax::Assignment($name, &Blatte::unwrapws($expr)));
110 } else {
111 133 $input = ($ws . $input);
112 133 my $expr = $self->expr(\$input);
113 133 ▶ last unless defined($expr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 35 98 133
114 98 push(@subexprs, $expr);
115 }
116 }
117  
118 35 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 35 0 35
119 35 $$input_arg = $input;
120 }
121  
122 35 return @subexprs;
123 }
124  
125 57 ▶sub special_form {
Subroutine special_form: called CC=6 SCAR=18.0
Pod undocumented
126 57 my($self, $input_arg) = @_;
127  
128 57 my $input = $input_arg;
129 57 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 57 0 57
130 57 $input = $$input_arg;
131 }
132  
133 57 my $syntax;
134 57 foreach my $formfn (@{$self->{special_forms}}) {
135 399 $syntax = &$formfn($self, \$input);
136 399 ▶ last if defined($syntax);
Branch: 1 branch
BranchTrueFalseTotal
if defined $syntax 22 377 399
137 }
138  
139 57 ▶ return undef unless defined($syntax);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $syntax 35 22 57
140  
141 22 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 22 0 22
142 22 $$input_arg = $input;
143 }
144  
145 22 return $syntax;
146 }
147  
148 57 ▶sub define_expr {
Subroutine define_expr: called CC=5 SCAR=16.2
Pod undocumented
149 57 my($self, $input_arg) = @_;
150  
151 57 my $input = $input_arg;
152 57 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 57 0 57
153 57 $input = $$input;
154 }
155  
156 57 my $syntax = $self->define_var_expr(\$input);
157 57 ▶ $syntax = $self->define_fn_expr(\$input) unless defined($syntax);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $syntax 54 3 57
158  
159 57 ▶ return undef unless defined($syntax);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $syntax 50 7 57
160  
161 7 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 7 0 7
162 7 $$input_arg = $input;
163 }
164  
165 7 return $syntax;
166 }
167  
168 57 ▶sub define_var_expr {
Subroutine define_var_expr: called CC=6 SCAR=18.0
Pod undocumented
169 57 my($self, $input_arg) = @_;
170  
171 57 my $input = $input_arg;
172 57 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 57 0 57
173 57 $input = $$input_arg;
174 }
175  
176 57 &consume_whitespace(\$input);
177 57 ▶ return undef unless ($input =~ /^\\define(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\define(?![A-Za-z0-9_])/ 50 7 57
178 7 $input = substr($input, 7);
179  
180 7 &consume_whitespace(\$input);
181 7 ▶ return undef unless ($input =~ /^\\($identifier_regex)/go);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\($Blatte::Parser::identifier_regex)/go 4 3 7
182 3 my $name = $1;
183 3 $input = substr($input, pos($input));
184  
185 3 my $expr = $self->expr(\$input);
186 3 ▶ return undef unless defined($expr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 3 3
187  
188 3 my $syntax = new Blatte::Syntax::DefineVar($name, $expr);
189  
190 3 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 3 0 3
191 3 $$input_arg = $input;
192 }
193  
194 3 return $syntax;
195 }
196  
197 54 ▶sub define_fn_expr {
Subroutine define_fn_expr: called CC=9 SCAR=23.4
Pod undocumented
198 54 my($self, $input_arg) = @_;
199  
200 54 my $input = $input_arg;
201 54 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 54 0 54
202 54 $input = $$input_arg;
203 }
204  
205 54 &consume_whitespace(\$input);
206 54 ▶ return undef unless ($input =~ /^\\define(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\define(?![A-Za-z0-9_])/ 50 4 54
207 4 $input = substr($input, 7);
208  
209 4 &consume_whitespace(\$input);
210 4 ▶ if (($input eq '') || (substr($input, 0, 1) ne '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input eq "" or substr($input, 0, 1) ne "{") 0 4 4
Condition33%1/3
$input eq "" or substr($input, 0, 1) ne "{"
l!l&&r!l&&!r
004
MC/DC0%0/2
$input eq "" or substr($input, 0, 1) ne "{"
$input eq "" substr($input, 0, 1) ne "{"
Truth table33%1/3
A or B
A= $input eq ""B= substr($input, 0, 1) ne "{"
ABresult
1X1
011
000
211 0 return undef;
212 }
213 4 $input = substr($input, 1);
214  
215 4 &consume_whitespace(\$input);
216 4 ▶ return undef unless ($input =~ /^\\($identifier_regex)/go);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\($Blatte::Parser::identifier_regex)/go 0 4 4
217 4 my $name = $1;
218 4 $input = substr($input, pos($input));
219  
220 4 my @params = $self->params(\$input);
221  
222 4 &consume_whitespace(\$input);
223 4 ▶ if (($input eq '') || (substr($input, 0, 1) ne '}')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input eq "" or substr($input, 0, 1) ne "}") 0 4 4
Condition33%1/3
$input eq "" or substr($input, 0, 1) ne "}"
l!l&&r!l&&!r
004
MC/DC0%0/2
$input eq "" or substr($input, 0, 1) ne "}"
$input eq "" substr($input, 0, 1) ne "}"
Truth table33%1/3
A or B
A= $input eq ""B= substr($input, 0, 1) ne "}"
ABresult
1X1
011
000
224 0 return undef;
225 }
226 4 $input = substr($input, 1);
227  
228 4 my @exprs = $self->exprs(\$input);
229  
230 4 my $syntax = new Blatte::Syntax::DefineFn($name, \@params, \@exprs);
231  
232 4 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 4 0 4
233 4 $$input_arg = $input;
234 }
235  
236 4 return $syntax;
237 }
238  
239 50 ▶sub set_expr {
Subroutine set_expr: called CC=6 SCAR=18.1
Pod undocumented
240 50 my($self, $input_arg) = @_;
241  
242 50 my $input = $input_arg;
243 50 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 50 0 50
244 50 $input = $$input_arg;
245 }
246  
247 50 &consume_whitespace(\$input);
248 50 ▶ return undef unless ($input =~ /^\\set!(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\set!(?![A-Za-z0-9_])/ 49 1 50
249 1 $input = substr($input, 5);
250  
251 1 &consume_whitespace(\$input);
252 1 ▶ return undef unless ($input =~ /^\\($identifier_regex)/go);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\($Blatte::Parser::identifier_regex)/go 0 1 1
253 1 my $name = $1;
254 1 $input = substr($input, pos($input));
255  
256 1 my $expr = $self->expr(\$input);
257 1 ▶ return undef unless defined($expr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 1 1
258  
259 1 my $syntax = new Blatte::Syntax::SetVar($name, $expr);
260  
261 1 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 1 0 1
262 1 $$input_arg = $input;
263 }
264  
265 1 return $syntax;
266 }
267  
268 49 ▶sub lambda_expr {
Subroutine lambda_expr: called CC=9 SCAR=22.7
Pod undocumented
269 49 my($self, $input_arg) = @_;
270  
271 49 my $input = $input_arg;
272 49 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 49 0 49
273 49 $input = $$input_arg;
274 }
275  
276 49 &consume_whitespace(\$input);
277 49 ▶ return undef unless ($input =~ /^\\lambda(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\lambda(?![A-Za-z0-9_])/ 48 1 49
278  
279 1 $input = substr($input, 7);
280  
281 1 &consume_whitespace(\$input);
282 1 ▶ if (($input eq '') || (substr($input, 0, 1) ne '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input eq "" or substr($input, 0, 1) ne "{") 0 1 1
Condition33%1/3
$input eq "" or substr($input, 0, 1) ne "{"
l!l&&r!l&&!r
001
MC/DC0%0/2
$input eq "" or substr($input, 0, 1) ne "{"
$input eq "" substr($input, 0, 1) ne "{"
Truth table33%1/3
A or B
A= $input eq ""B= substr($input, 0, 1) ne "{"
ABresult
1X1
011
000
283 0 return undef;
284 }
285 1 $input = substr($input, 1);
286  
287 1 my @params = $self->params(\$input);
288  
289 1 &consume_whitespace(\$input);
290 1 ▶ return undef if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 1 1
291 1 ▶ return undef if (substr($input, 0, 1) ne '}');
Branch: 1 branch
BranchTrueFalseTotal
if substr($input, 0, 1) ne "}" 0 1 1
292 1 $input = substr($input, 1);
293  
294 1 my @exprs;
295 1 ▶ while (defined(my $expr = $self->expr(\$input))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $expr = $self->expr(\$input))) 1 1 2
296 1 push(@exprs, $expr);
297 }
298  
299 1 my $syntax = new Blatte::Syntax::Lambda(\@params, \@exprs);
300  
301 1 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 1 0 1
302 1 $$input_arg = $input;
303 }
304  
305 1 return $syntax;
306 }
307  
308 5 ▶sub params {
Subroutine params: called CC=6 SCAR=17.9
Pod undocumented
309 5 my($self, $input_arg) = @_;
310  
311 5 my $input = $input_arg;
312 5 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 5 0 5
313 5 $input = $$input_arg;
314 }
315  
316 5 my @params;
317 5 while (1) {
318 13 &consume_whitespace(\$input);
319 13 ▶ if ($input =~ /^\\($identifier_regex)/g) {
Branch: 3 branches
BranchTrueFalseTotal
if ($input =~ /^\\($Blatte::Parser::identifier_regex)/g) { } 5 8 13
elsif ($input =~ /^\\=($Blatte::Parser::identifier_regex)/g) { } 2 6 8
elsif ($input =~ /^\\&($Blatte::Parser::identifier_regex)/g) { } 1 5 6
320 5 my $name = $1;
321 5 $input = substr($input, pos($input));
322 5 push(@params, new Blatte::Syntax::Param::Positional($name));
323 } elsif ($input =~ /^\\=($identifier_regex)/g) {
324 2 my $name = $1;
325 2 $input = substr($input, pos($input));
326 2 push(@params, new Blatte::Syntax::Param::Named($name));
327 } elsif ($input =~ /^\\&($identifier_regex)/g) {
328 1 my $name = $1;
329 1 $input = substr($input, pos($input));
330 1 push(@params, new Blatte::Syntax::Param::Rest($name));
331 } else {
332 5 last;
333 }
334 }
335  
336 5 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 5 0 5
337 5 $$input_arg = $input;
338 }
339  
340 5 return @params;
341 }
342  
343 48 ▶sub any_let_expr {
Subroutine any_let_expr: called CC=11 SCAR=24.7
Pod undocumented
344 48 my($self, $input_arg) = @_;
345  
346 48 my $input = $input_arg;
347 48 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 48 0 48
348 48 $input = $$input_arg;
349 }
350  
351 48 &consume_whitespace(\$input);
352 48 ▶ return undef unless ($input =~ /^\\(letrec|let\*?)(?![A-Za-z0-9_])/g);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\(letrec|let\*?)(?![A-Za-z0-9_])/g 42 6 48
353 6 my $keyword = $1;
354 6 $input = substr($input, pos($input));
355  
356 6 &consume_whitespace(\$input);
357 6 ▶ return undef if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 6 6
358 6 ▶ return undef if (substr($input, 0, 1) ne '{');
Branch: 1 branch
BranchTrueFalseTotal
if substr($input, 0, 1) ne "{" 0 6 6
359 6 $input = substr($input, 1);
360  
361 6 my @clauses = $self->let_clauses(\$input);
362 6 ▶ return undef unless @clauses;
Branch: 1 branch
BranchTrueFalseTotal
unless @clauses 0 6 6
363  
364 6 &consume_whitespace(\$input);
365 6 ▶ return undef if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 6 6
366 6 ▶ return undef if (substr($input, 0, 1) ne '}');
Branch: 1 branch
BranchTrueFalseTotal
if substr($input, 0, 1) ne "}" 0 6 6
367 6 $input = substr($input, 1);
368  
369 6 my @exprs = $self->exprs(\$input);
370  
371 6 my $syntax;
372 6 ▶ if ($keyword eq 'let') {
Branch: 2 branches
BranchTrueFalseTotal
if ($keyword eq 'let') { } 4 2 6
elsif ($keyword eq 'let*') { } 2 0 2
373 4 $syntax = new Blatte::Syntax::Let(\@clauses, \@exprs);
374 } elsif ($keyword eq 'let*') {
375 2 $syntax = new Blatte::Syntax::LetStar(\@clauses, \@exprs);
376 } else { # letrec
377 0 $syntax = new Blatte::Syntax::Letrec(\@clauses, \@exprs);
378 }
379  
380 6 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 6 0 6
381 6 $$input_arg = $input;
382 }
383  
384 6 return $syntax;
385 }
386  
387 6 ▶sub let_clauses {
Subroutine let_clauses: called CC=9 SCAR=22.4
Pod undocumented
388 6 my($self, $input_arg) = @_;
389  
390 6 my $input = $input_arg;
391 6 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 6 0 6
392 6 $input = $$input_arg;
393 }
394  
395 6 my @clauses;
396 6 while (1) {
397 15 &consume_whitespace(\$input);
398 15 ▶ last if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 15 15
399 15 ▶ last if (substr($input, 0, 1) ne '{');
Branch: 1 branch
BranchTrueFalseTotal
if substr($input, 0, 1) ne "{" 6 9 15
400 9 $input = substr($input, 1);
401  
402 9 &consume_whitespace(\$input);
403 9 ▶ return undef unless ($input =~ /^\\($identifier_regex)/go);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\($Blatte::Parser::identifier_regex)/go 0 9 9
404 9 my $name = $1;
405 9 $input = substr($input, pos($input));
406  
407 9 my $expr = $self->expr(\$input);
408 9 ▶ return undef unless defined($expr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 9 9
409  
410 9 &consume_whitespace(\$input);
411 9 ▶ return undef if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 9 9
412 9 ▶ return undef if (substr($input, 0, 1) ne '}');
Branch: 1 branch
BranchTrueFalseTotal
if substr($input, 0, 1) ne "}" 0 9 9
413  
414 9 $input = substr($input, 1);
415  
416 9 push(@clauses, new Blatte::Syntax::LetClause($name, $expr));
417 }
418  
419 6 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 6 0 6
420 6 $$input_arg = $input;
421 }
422  
423 6 return @clauses;
424 }
425  
426 42 ▶sub if_expr {
Subroutine if_expr: called CC=6 SCAR=18.1
Pod undocumented
427 42 my($self, $input_arg) = @_;
428  
429 42 my $input = $input_arg;
430 42 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 42 0 42
431 42 $input = $$input_arg;
432 }
433  
434 42 &consume_whitespace(\$input);
435 42 ▶ return undef unless ($input =~ /^\\if(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\if(?![A-Za-z0-9_])/ 40 2 42
436 2 $input = substr($input, 3);
437  
438 2 my $test = $self->expr(\$input);
439 2 ▶ return undef unless defined($test);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $test 0 2 2
440  
441 2 my $then = $self->expr(\$input);
442 2 ▶ return undef unless defined($then);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $then 0 2 2
443  
444 2 my @else = $self->exprs(\$input);
445  
446 2 my $syntax = new Blatte::Syntax::If($test, $then, @else);
447  
448 2 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 2 0 2
449 2 $$input_arg = $input;
450 }
451  
452 2 return $syntax;
453 }
454  
455 40 ▶sub cond_expr {
Subroutine cond_expr: called CC=9 SCAR=22.3
Pod undocumented
456 40 my($self, $input_arg) = @_;
457  
458 40 my $input = $input_arg;
459 40 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 40 0 40
460 40 $input = $$input_arg;
461 }
462  
463 40 &consume_whitespace(\$input);
464 40 ▶ return undef unless ($input =~ /^\\cond(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\cond(?![A-Za-z0-9_])/ 38 2 40
465 2 $input = substr($input, 5);
466  
467 2 my @clauses;
468 2 while (1) {
469 9 &consume_whitespace(\$input);
470 9 ▶ last if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 9 9
471 9 ▶ last if (substr($input, 0, 1) ne '{');
Branch: 1 branch
BranchTrueFalseTotal
if substr($input, 0, 1) ne "{" 2 7 9
472 7 $input = substr($input, 1);
473  
474 7 my $test = $self->expr(\$input);
475 7 ▶ return undef unless defined($test);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $test 0 7 7
476  
477 7 my @actions = $self->exprs(\$input);
478  
479 7 &consume_whitespace(\$input);
480 7 ▶ return undef if ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "" 0 7 7
481 7 ▶ return undef if (substr($input, 0, 1) ne '}');
Branch: 1 branch
BranchTrueFalseTotal
if substr($input, 0, 1) ne "}" 0 7 7
482 7 $input = substr($input, 1);
483  
484 7 push(@clauses, new Blatte::Syntax::CondClause($test, @actions));
485 }
486  
487 2 my $syntax = new Blatte::Syntax::Cond(@clauses);
488  
489 2 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 2 0 2
490 2 $$input_arg = $input;
491 }
492  
493 2 return $syntax;
494 }
495  
496 38 ▶sub while_expr {
Subroutine while_expr: called CC=5 SCAR=24.4
Pod undocumented
497 38 my($self, $input_arg) = @_;
498  
499 38 my $input = $input_arg;
500 38 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 38 0 38
501 38 $input = $$input_arg;
502 }
503  
504 38 &consume_whitespace(\$input);
505 38 ▶ return undef unless ($input =~ /^\\while(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\while(?![A-Za-z0-9_])/ 38 0 38
506 0 $input = substr($input, 6);
507  
508 0 my $test = $self->expr(\$input);
509 0 ▶ return undef unless defined($test);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $test 0 0 0
510  
511 0 my @body = $self->exprs(\$input);
512  
513 0 my $syntax = new Blatte::Syntax::While($test, @body);
514  
515 0 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 0 0 0
516 0 $$input_arg = $input;
517 }
518  
519 0 return $syntax;
520 }
521  
522 38 ▶sub and_expr {
Subroutine and_expr: called CC=5 SCAR=16.2
Pod undocumented
523 38 my($self, $input_arg) = @_;
524  
525 38 my $input = $input_arg;
526 38 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 38 0 38
527 38 $input = $$input_arg;
528 }
529  
530 38 &consume_whitespace(\$input);
531 38 ▶ return undef unless ($input =~ /^\\and(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\and(?![A-Za-z0-9_])/ 37 1 38
532 1 $input = substr($input, 4);
533  
534 1 my @exprs = $self->exprs(\$input);
535 1 ▶ return undef unless @exprs;
Branch: 1 branch
BranchTrueFalseTotal
unless @exprs 0 1 1
536  
537 1 my $syntax = new Blatte::Syntax::And(@exprs);
538  
539 1 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 1 0 1
540 1 $$input_arg = $input;
541 }
542  
543 1 return $syntax;
544 }
545  
546 37 ▶sub or_expr {
Subroutine or_expr: called CC=5 SCAR=16.2
Pod undocumented
547 37 my($self, $input_arg) = @_;
548  
549 37 my $input = $input_arg;
550 37 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 37 0 37
551 37 $input = $$input_arg;
552 }
553  
554 37 &consume_whitespace(\$input);
555 37 ▶ return undef unless ($input =~ /^\\or(?![A-Za-z0-9_])/);
Branch: 1 branch
BranchTrueFalseTotal
unless $input =~ /^\\or(?![A-Za-z0-9_])/ 35 2 37
556 2 $input = substr($input, 4);
557  
558 2 my @exprs = $self->exprs(\$input);
559 2 ▶ return undef unless @exprs;
Branch: 1 branch
BranchTrueFalseTotal
unless @exprs 0 2 2
560  
561 2 my $syntax = new Blatte::Syntax::Or(@exprs);
562  
563 2 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 2 0 2
564 2 $$input_arg = $input;
565 }
566  
567 2 return $syntax;
568 }
569  
570 22 ▶sub exprs {
Subroutine exprs: called CC=4 SCAR=13.9
Pod undocumented
571 22 my($self, $input_arg) = @_;
572  
573 22 my $input = $input_arg;
574 22 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 22 0 22
575 22 $input = $$input_arg;
576 }
577  
578 22 my @exprs;
579 22 while (1) {
580 48 my $expr = $self->expr(\$input);
581 48 ▶ last unless defined($expr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 22 26 48
582 26 push(@exprs, $expr);
583 }
584  
585 22 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 22 0 22
586 22 $$input_arg = $input;
587 }
588  
589 22 return @exprs;
590 }
591  
592 993 ▶sub consume_whitespace {
Subroutine consume_whitespace: called CC=4 SCAR=13.9
Pod documented
593 993 my $ref = shift;
594 993 my $str = $$ref;
595 993 my $ws = '';
596  
597 993 while (1) {
598 1209 ▶ if ($str =~ /^\s+/g) {
Branch: 3 branches
BranchTrueFalseTotal
if ($str =~ /^\s+/g) { } 215 994 1209
elsif ($str =~ /^\\;.*/g) { } 0 994 994
elsif ($str =~ m[^\\/]) { } 1 993 994
599 215 $ws .= substr($str, 0, pos($str));
600 215 $str = substr($str, pos($str));
601 } elsif ($str =~ /^\\;.*/g) {
602 0 $str = substr($str, pos($str));
603 } elsif ($str =~ /^\\\//) {
604 1 $ws = '';
605 1 $str = substr($str, 2);
606 } else {
607 993 $$ref = $str;
608 993 return $ws;
609 }
610 }
611 }
612  
613 0 ▶sub eof {
Subroutine eof: not called CC=4 SCAR=30.0
Pod documented
614 0 my($self, $input_arg) = @_;
615  
616 0 my $input = $input_arg;
617 0 ▶ if (ref($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) 0 0 0
618 0 $input = $$input_arg;
619 }
620  
621 0 &consume_whitespace(\$input);
622 0 ▶ return undef unless ($input eq '');
Branch: 1 branch
BranchTrueFalseTotal
unless $input eq "" 0 0 0
623  
624 0 ▶ if (ref($input_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input_arg) 0 0 0
625 0 $$input_arg = $input;
626 }
627  
628 0 return 1;
629 }
630  
631 12 1;
632  
633 __END__
« Blatte/Compiler.pm ↑ Summary Blatte/Builtins.pm »