lib/Lingy/Reader.pm

filter: Statementstmt 81.6% 178 / 218 Branchbran 78.2% 108 / 138 Conditioncond 74.3% 29 / 39 MC/DCmcdc 50.0% 13 / 26 Subroutinesub 90.9% 20 / 22 Podpod 0.0% 0 / 19 totaltotal 75.3% 348 / 462 CC 84 SCAR 24.6
CC
84
Cov
80%
read_hash_set
42.0
read_scalar
20.3
read_form
17.0
CRAP 11.7
« blib/lib/Lingy/RT.pm ↑ Summary lib/Lingy/Fn.pm »
1 53 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::Reader;
3  
4 53 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 53 our $feature_keyword = ':lingy.pl';
7  
8 53 my $tokenize_re = qr/
9 (?: # Ignore:
10 \#\!.* | # hashbang line
11 [\s,] | # whitespace, commas,
12 ;.* # comments
13 )*
14 ( # Capture all these tokens:
15 \#\_ | # Ignore next form
16 \#\' | # Var
17 \#\( | # Lambda
18 \#\{ | # HashSet
19 \#\? | # Reader conditional
20 ~@ | # Unquote-splice token
21 [\[\]{}()'`~^@] | # Single character tokens
22 \#? # Possibly a regex
23 "(?: # Quoted string
24 \\. | # Escaped char
25 [^\\"] # Any other char
26 )*"? | # Match if missing ending quote
27 # Other tokens
28 [^\s\[\]\{\}\(\)\'\"\`\,\;]*
29 )
30 /xo;
31  
32 100 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
33 100 my $class = shift;
34 100 bless {
35 tokens => [],
36 lambda => [],
37 ignore => 0,
38 @_,
39 }, $class;
40 }
41  
42 1366 ▶sub tokenize {
Subroutine tokenize: called CC=1 SCAR=0.0
Pod undocumented
43 [
44 1366 grep length,
45 $_[0] =~ /$tokenize_re/g
46 ];
47 }
48  
49 1366 ▶sub read_str {
Subroutine read_str: called CC=3 SCAR=11.0
Pod undocumented
50 1366 my ($self, $str, $repl) = @_;
51 1366 local $self->{repl} = $repl;
52 1366 my $tokens = $self->{tokens} = tokenize($str);
53 1366 my @forms;
54 1366 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 9322 1352 10674
55 9322 my $form = $self->read_form;
56 9308 ▶ if (defined $form) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $form) 9248 60 9308
57 9248 push @forms, $form;
58 }
59 }
60 1352 return @forms;
61 }
62  
63 190191 ▶sub read_form {
Subroutine read_form: called CC=17 SCAR=28.4
Pod undocumented
64 190191 my ($self) = @_;
65 190191 my $tokens = $self->{tokens};
66 0 ▶ while (not @$tokens) { $self->read_more }
Branch: 1 branch
BranchTrueFalseTotal
unless (@$tokens) 0 190191 190191
67 190191 local $_ = $tokens->[0];
68 190191 ▶ /^\($/ ? $self->read_list(LIST, ')') :
Branch: 15 branches
BranchTrueFalseTotal
/^\($/ ? : 42473 147718 190191
/^\[$/ ? : 13085 134633 147718
/^\{$/ ? : 3459 131174 134633
/^\#\{$/ ? : 387 130787 131174
/^'$/ ? : 2167 128620 130787
/^`$/ ? : 1597 127023 128620
/^~$/ ? : 2604 124419 127023
/^~\@$/ ? : 547 123872 124419
/^\@$/ ? : 5 123867 123872
/^\^$/ ? : 1095 122772 123867
/^#\'$/ ? : 1 122771 122772
/^#\($/ ? : 60 122711 122771
/^#_$/ ? : 69 122642 122711
/^#\?$/ ? : 7 122635 122642
/^%\d*$/ ? : 65 122570 122635
69 /^\[$/ ? $self->read_list(VECTOR, ']') :
70 /^\{$/ ? $self->read_hash('map') :
71 /^\#\{$/ ? $self->read_hash('set') :
72 /^'$/ ? $self->read_quote('quote') :
73 /^`$/ ? $self->read_quote('quasiquote') :
74 /^~$/ ? $self->read_quote('unquote') :
75 /^~\@$/ ? $self->read_quote('splice-unquote') :
76 /^\@$/ ? $self->read_quote('deref') :
77 /^\^$/ ? $self->with_meta :
78 /^#\'$/ ? $self->read_var :
79 /^#\($/ ? $self->read_lambda :
80 /^#_$/ ? $self->read_ignore :
81 /^#\?$/ ? $self->read_cond :
82 /^%\d*$/ ? $self->read_lambda_symbol :
83 $self->read_scalar;
84 }
85  
86 0 ▶sub read_more {
Subroutine read_more: not called CC=3 SCAR=24.8
Pod undocumented
87 0 my ($self) = @_;
88 0 ▶ if ($self->{repl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"repl"}) 0 0 0
89 0 my $line = Lingy::ReadLine->readline(1);
90 0 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 0 0 0
91 0 push @{$self->{tokens}}, @{tokenize($line)};
92 0 return 1;
93 }
94 }
95 0 return;
96 }
97  
98 55558 ▶sub read_list {
Subroutine read_list: called CC=4 SCAR=14.7
Pod undocumented
99 55558 my ($self, $type, $end) = @_;
100 55558 my $tokens = $self->{tokens};
101 55558 shift @$tokens;
102 55558 my $list = $type->new([]);
103 55558 while (1) {
104 55558 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 209782 0 209782
105 209782 ▶ if ($tokens->[0] eq $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] eq $end) 55558 154224 209782
106 55558 shift @$tokens;
107 55558 return $list;
108 }
109 154224 push @$list, $self->read_form;
110 }
111 0 ▶ $self->read_more and next;
Branch: 1 branch
BranchTrueFalseTotal
$self->read_more and next 0 0 0
112 0 err "Reached end of input in 'read_list'";
113 }
114 }
115  
116 1 ▶sub read_var {
Subroutine read_var: called CC=2 SCAR=7.0
Pod undocumented
117 1 my ($self) = @_;
118 1 shift @{$self->{tokens}};
119 1 my $var = shift @{$self->{tokens}};
120 1 ▶ if ($var !~ m</>) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($var =~ m[/]) 1 0 1
121 1 $var = RT->current_ns_name . "/$var";
122 }
123 1 VAR->new($var);
124 }
125  
126 60 ▶sub read_lambda {
Subroutine read_lambda: called CC=6 SCAR=18.2
Pod undocumented
127 60 my ($self) = @_;
128 60 my $tokens = $self->{tokens};
129 60 shift @$tokens;
130 60 push @{$self->{lambda}}, {
131 sym => {},
132 max => 0,
133 };
134 60 my $list = [];
135 60 outer: while (1) {
136 60 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 234 0 234
137 234 ▶ if ($tokens->[0] eq ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] eq ")") 60 174 234
138 60 shift @$tokens;
139 60 last outer;
140 }
141 174 push @$list, $self->read_form;
142 }
143 0 ▶ $self->read_more and next;
Branch: 1 branch
BranchTrueFalseTotal
$self->read_more and next 0 0 0
144 0 err "Reached end of input in 'read_list'";
145 }
146 60 my $lambda = pop @{$self->{lambda}};
147 60 my ($sym, $max) = @{$lambda}{'sym', 'max'};
148 60 my $syms = [];
149 60 ▶ for (my $i = 1; $i <= $lambda->{max}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $lambda->{"max"}) 67 60 127
150 67 ▶ push @$syms, $sym->{"%$i"} // symbol("p${i}_${\RT->nextID}");
Condition66%2/3
$$sym{"%$i"} // symbol("p${i}_${\RT()->nextID;}")
l!l&&r!l&&!r
6430
MC/DC0%0/2
$$sym{"%$i"} // symbol("p${i}_${\RT()->nextID;}")
$$sym{"%$i"} symbol("p${i}_${\RT()->nextID;}")
Truth table66%2/3
A // B
A= $$sym{"%$i"}B= symbol("p${i}_${\RT()->nextID;}")
ABresult
1X1
011
000
151 }
152  
153 60 LIST->new([
154 SYMBOL->new('fn*'),
155 VECTOR->new($syms),
156 LIST->new($list),
157 ]);
158 }
159  
160 65 ▶sub read_lambda_symbol {
Subroutine read_lambda_symbol: called CC=5 SCAR=16.1
Pod undocumented
161 65 my ($self) = @_;
162 65 my $token = shift @{$self->{tokens}};
163 65 ▶ return symbol($token) unless @{$self->{lambda}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"lambda"};} 0 65 65
164 65 ▶ $token = '%1' if $token eq '%';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "%" 54 11 65
165 65 my $num = substr($token, 1);
166 65 my $lambda = $self->{lambda}->[-1];
167 65 ▶ $lambda->{max} = $num if $num > $lambda->{max};
Branch: 1 branch
BranchTrueFalseTotal
if $num > $lambda->{"max"} 60 5 65
168 65 ▶ $lambda->{sym}{$token} //= symbol("p${num}_${\RT->nextID}");
Condition66%2/3
$lambda->{"sym"}{$token} //= symbol("p${num}_${\RT()->nextID;}")
l!l&&r!l&&!r
1640
MC/DC0%0/2
$lambda->{"sym"}{$token} //= symbol("p${num}_${\RT()->nextID;}")
$lambda->{"sym"}{$token} symbol("p${num}_${\RT()->nextID;}")
Truth table66%2/3
A //= B
A= $lambda->{"sym"}{$token}B= symbol("p${num}_${\RT()->nextID;}")
ABresult
1X1
011
000
169 }
170  
171 3846 ▶sub read_hash {
Subroutine read_hash: called CC=4 SCAR=14.6
Pod undocumented
172 3846 my ($self, $type) = @_;
173 3846 my $tokens = $self->{tokens};
174 3846 shift @$tokens;
175 3846 my $hash = [];
176 3846 while (1) {
177 3846 ▶ while (@$tokens > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens > 0) 21123 0 21123
178 21123 ▶ if ($tokens->[0] eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] eq "}") 3846 17277 21123
179 3846 shift @$tokens;
180 3846 my $method = "make_hash_$type";
181 3846 return $self->$method($hash);
182 }
183 17277 push @$hash, $self->read_form;
184 }
185 0 ▶ $self->read_more and next;
Branch: 1 branch
BranchTrueFalseTotal
$self->read_more and next 0 0 0
186 0 err "Reached end of input in 'read_hash'";
187 }
188 }
189  
190 4554 ▶sub make_hash_map {
Subroutine make_hash_map: called CC=6 SCAR=17.9
Pod undocumented
191 4554 my ($self, $data) = @_;
192 err "Map literal must contain an even number of forms"
193 4554 ▶ if @$data % 2 and not $self->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if @$data % 2 and not $self->{"ignore"} 1 4553 4554
Condition100%3/3
@$data % 2 and not $self->{"ignore"}
!ll&&!rl&&r
455211
MC/DC100%2/2
@$data % 2 and not $self->{"ignore"}
@$data % 2 not $self->{"ignore"}
Truth table100%3/3
A and not(B)
A= @$data % 2B= not $self->{"ignore"}
ABresult
0X0
100
111
194 4553 my %hash;
195 4553 ▶ for (my $i = 0; $i < @$data; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 11003 4552 15555
196 err "Duplicate key: '$data->[$i]'"
197 if $hash{$data->[$i]}++ and
198 11003 ▶ not $self->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $hash{$data->[$i]}++ and not $self->{"ignore"} 1 11002 11003
Condition100%3/3
$hash{$data->[$i]}++ and not $self->{"ignore"}
!ll&&!rl&&r
1100021
MC/DC100%2/2
$hash{$data->[$i]}++ and not $self->{"ignore"}
$hash{$data->[$i]}++ not $self->{"ignore"}
Truth table100%3/3
A and not(B)
A= $hash{$data->[$i]}++B= not $self->{"ignore"}
ABresult
0X0
100
111
199 }
200 4552 HASHMAP->new($data);
201 }
202  
203 387 ▶sub make_hash_set {
Subroutine make_hash_set: called CC=4 SCAR=13.9
Pod undocumented
204 387 my ($self, $data) = @_;
205 387 my %hash;
206 387 my $set = [];
207 387 for my $elem (@$data) {
208 err "Duplicate key: '$elem'"
209 if $hash{$elem}++ and
210 395 ▶ not $self->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $hash{$elem}++ and not $self->{"ignore"} 2 393 395
Condition100%3/3
$hash{$elem}++ and not $self->{"ignore"}
!ll&&!rl&&r
39212
MC/DC100%2/2
$hash{$elem}++ and not $self->{"ignore"}
$hash{$elem}++ not $self->{"ignore"}
Truth table100%3/3
A and not(B)
A= $hash{$elem}++B= not $self->{"ignore"}
ABresult
0X0
100
111
211 393 push @$set, $elem, $elem;
212 }
213 385 HASHSET->new($data);
214 }
215  
216 0 ▶sub read_hash_set {
Subroutine read_hash_set: not called CC=6 SCAR=37.4
Pod undocumented
217 0 my ($self) = @_;
218 0 my $tokens = $self->{tokens};
219 0 shift @$tokens;
220 0 my $hash = HASHSET->new([]);
221 0 my $i = 0;
222 0 while (1) {
223 0 ▶ while (@$tokens > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens > 0) 0 0 0
224 0 ▶ if ($tokens->[0] eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] eq "}") 0 0 0
225 0 shift @$tokens;
226 0 return $hash;
227 }
228 0 $i++;
229 0 my $val = $self->read_form;
230 0 my $key = HASHSET->_get_key($val);
231 err "Duplicate key: '$val'"
232 if exists $hash->{$key} and
233 0 ▶ not $self->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{$key} and not $self->{"ignore"} 0 0 0
Condition0%0/3
exists $hash->{$key} and not $self->{"ignore"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $hash->{$key} and not $self->{"ignore"}
exists $hash->{$key} not $self->{"ignore"}
Truth table0%0/3
A and not(B)
A= exists $hash->{$key}B= not $self->{"ignore"}
ABresult
0X0
100
111
234 0 $hash->{$key} = $val;
235 }
236 0 ▶ $self->read_more and next;
Branch: 1 branch
BranchTrueFalseTotal
$self->read_more and next 0 0 0
237 0 err "Reached end of input in 'read_hash_map'";
238 }
239 }
240  
241 53 my $string_re = qr/#?"((?:\\.|[^\\"])*)"/;
242 53 my $string_unescape = {
243 'n' => "\n",
244 't' => "\t",
245 '"' => '"',
246 '\\' => "\\",
247 };
248 53 my $regexp_unescape = {
249 'A' => "\\A",
250 'b' => "\\b",
251 'd' => "\\d",
252 'n' => "\\n",
253 'r' => "\\r",
254 's' => "\\s",
255 't' => "\\t",
256 'w' => "\\w",
257 'z' => "\\z",
258 '"' => '\\"',
259 '.' => '\\.',
260 '\\' => "\\\\",
261 '[' => "\\[",
262 ']' => "\\]",
263 '{' => "\\{",
264 '}' => "\\}",
265 '(' => "\\(",
266 ')' => "\\)",
267 '+' => "\\+",
268 '*' => "\\*",
269 '?' => "\\?",
270 '^' => "\\^",
271 '$' => "\\\$",
272 '|' => "\\|",
273 };
274 122570 ▶sub read_scalar {
Subroutine read_scalar: called CC=17 SCAR=30.1
Pod undocumented
275 122570 my ($self) = @_;
276 122570 my $scalar = local $_ = shift @{$self->{tokens}};
277  
278 122570 ▶ while (/^(#?)"/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(#?)"/) 7661 114909 122570
279 7661 my $is_regex = $1;
280 7661 ▶ if (/^$string_re$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^$string_re$/) 7661 0 7661
281 7661 s/^$string_re$/$1/;
282 7661 ▶ if (not $self->{ignore}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ignore"}) 7550 111 7661
283 7550 ▶ if ($is_regex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_regex) { } 10 7540 7550
284 10 s/\\(.)/
285 18 ▶ $regexp_unescape->{$1}
Condition33%1/3
$regexp_unescape->{$1} || err("Unsupported escape character '\\$1'")
l!l&&r!l&&!r
1800
MC/DC0%0/2
$regexp_unescape->{$1} || err("Unsupported escape character '\\$1'")
$regexp_unescape->{$1} err("Unsupported escape character '\\$1'")
Truth table33%1/3
A || B
A= $regexp_unescape->{$1}B= err("Unsupported escape character '\\$1'")
ABresult
1X1
011
000
286 or err("Unsupported escape character '\\$1'")
287 /ge;
288 } else {
289 7540 s/\\(.)/
290 111 ▶ $string_unescape->{$1}
Condition66%2/3
$string_unescape->{$1} || err("Unsupported escape character '\\$1'")
l!l&&r!l&&!r
10803
MC/DC0%0/2
$string_unescape->{$1} || err("Unsupported escape character '\\$1'")
$string_unescape->{$1} err("Unsupported escape character '\\$1'")
Truth table33%1/3
A || B
A= $string_unescape->{$1}B= err("Unsupported escape character '\\$1'")
ABresult
1X1
011
000
291 or err("Unsupported escape character '\\$1'")
292 /ge;
293 }
294 }
295 7658 ▶ return $is_regex ? REGEX->new($_) : STRING->new($_);
Branch: 1 branch
BranchTrueFalseTotal
$is_regex ? : 10 7648 7658
296 }
297 0 ▶ if ($self->{repl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"repl"}) 0 0 0
298 0 my $line = Lingy::ReadLine::readline(1);
299 0 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 0 0 0
300 0 $_ .= "\n$line";
301 0 next;
302 }
303 }
304 0 err "Reached end of input looking for '\"'";
305 }
306 114909 ▶ return nil if $_ eq 'nil';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "nil" 728 114181 114909
307 114181 ▶ return true if $_ eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "true" 2350 111831 114181
308 111831 ▶ return false if $_ eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "false" 679 111152 111831
309 111152 ▶ return KEYWORD->new($_) if /^:/;
Branch: 1 branch
BranchTrueFalseTotal
if /^:/ 9578 101574 111152
310 101574 ▶ return NUMBER->new($_) if /^-?\d+(?:\.\d+)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^-?\d+(?:\.\d+)?$/ 2743 98831 101574
311 98831 ▶ return CHARACTER->read($_) if /^\\/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\\/ 2 98829 98831
312 98829 ▶ err "Unmatched delimiter: '$_'" if /^[\)\]\}]$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[\)\]\}]$/ 4 98825 98829
313 98825 return $self->read_symbol($_);
314 }
315  
316 # Defined separately to allow subclassing:
317 98825 ▶sub read_symbol {
Subroutine read_symbol: called CC=4 SCAR=13.9
Pod undocumented
318 98825 my ($self, $symbol) = @_;
319 98825 ▶ if (my $ids = $self->{autogensym}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ids = $self->{"autogensym"}) 8998 89827 98825
320 8998 ▶ if ($symbol =~ m{^([^/]+)#$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ m[^([^/]+)#$]) 703 8295 8998
321 703 ▶ my $id = $ids->{$1} //= RT->nextID();
Condition66%2/3
$ids->{$1} //= RT()->nextID
l!l&&r!l&&!r
4322710
MC/DC0%0/2
$ids->{$1} //= RT()->nextID
$ids->{$1} RT()->nextID
Truth table66%2/3
A //= B
A= $ids->{$1}B= RT()->nextID
ABresult
1X1
011
000
322 703 $symbol =~ s/#$/__${id}__auto__/;
323 }
324 }
325 98825 symbol($symbol);
326 }
327  
328 6920 ▶sub read_quote {
Subroutine read_quote: called CC=2 SCAR=6.9
Pod undocumented
329 6920 my ($self, $quote) = @_;
330 6920 shift @{$self->{tokens}};
331 6920 my $form;
332 6920 ▶ if ($quote eq 'quasiquote') {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote eq 'quasiquote') { } 1597 5323 6920
333 1597 $self->{autogensym} = {};
334 1597 $form = $self->read_form;
335 1597 delete $self->{autogensym};
336 } else {
337 5323 $form = $self->read_form;
338 }
339 6920 return list([symbol($quote), $form]);
340 }
341  
342 1095 ▶sub with_meta {
Subroutine with_meta: called CC=7 SCAR=19.5
Pod undocumented
343 1095 my ($self) = @_;
344  
345 1095 my $tokens = $self->{tokens};
346 1095 my @meta;
347  
348 1095 ▶ while (@$tokens > 2 and $tokens->[0] eq '^') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens > 2 and $tokens->[0] eq "^") 1100 1095 2195
Condition100%3/3
@$tokens > 2 and $tokens->[0] eq "^"
!ll&&!rl&&r
110941100
MC/DC100%2/2
@$tokens > 2 and $tokens->[0] eq "^"
@$tokens > 2 $tokens->[0] eq "^"
Truth table100%3/3
A and B
A= @$tokens > 2B= $tokens->[0] eq "^"
ABresult
0X0
100
111
349 1100 shift @$tokens;
350 1100 my $meta = $self->read_form;
351 1100 my $type = ref($meta);
352 1100 ▶ if ($type eq SYMBOL or $type eq STRING) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'Lingy::Symbol' or $type eq 'Lingy::String') { } 169 931 1100
elsif ($type eq 'Lingy::Keyword') { } 436 495 931
elsif ($type eq 'Lingy::HashMap') { } 495 0 495
Condition100%3/3
$type eq "Lingy::Symbol" or $type eq "Lingy::String"
l!l&&r!l&&!r
1672931
MC/DC100%2/2
$type eq "Lingy::Symbol" or $type eq "Lingy::String"
$type eq "Lingy::Symbol" $type eq "Lingy::String"
Truth table100%3/3
A or B
A= $type eq "Lingy::Symbol"B= $type eq "Lingy::String"
ABresult
1X1
011
000
353 169 unshift @meta, KEYWORD->new(':tag'), $meta;
354 } elsif ($type eq KEYWORD) {
355 436 unshift @meta, $meta, true;
356 } elsif ($type eq HASHMAP) {
357 495 unshift @meta, %$meta;
358 } else {
359 0 err "Metadata must be Symbol,Keyword,String or Map"
360 }
361 }
362  
363 1095 my $meta = $self->make_hash_map(\@meta);
364  
365 1095 my $form = $self->read_form;
366  
367 1095 RT->meta->{"$form"} = $meta;
368  
369 1095 return $form;
370 }
371  
372 69 ▶sub read_ignore {
Subroutine read_ignore: called CC=2 SCAR=6.9
Pod undocumented
373 69 my ($self) = @_;
374 69 $self->{ignore}++;
375 69 my $tokens = $self->{tokens};
376 69 shift @$tokens;
377 69 ▶ while (not defined $self->read_form) {}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->read_form) 4 69 73
378 69 $self->{ignore}--;
379 69 return;
380 }
381  
382 7 ▶sub read_cond {
Subroutine read_cond: called CC=8 SCAR=20.8
Pod undocumented
383 7 my ($self) = @_;
384 7 my $tokens = $self->{tokens};
385 7 shift @$tokens;
386 7 ▶ err "read-cond body must be a list"
Branch: 1 branch
BranchTrueFalseTotal
unless @$tokens and $tokens->[0] eq "(" 1 6 7
Condition66%2/3
@$tokens and $tokens->[0] eq "("
!ll&&!rl&&r
016
MC/DC50%1/2
@$tokens and $tokens->[0] eq "("
@$tokens $tokens->[0] eq "("
Truth table66%2/3
A and B
A= @$tokensB= $tokens->[0] eq "("
ABresult
0X0
100
111
387 unless @$tokens and $tokens->[0] eq '(';
388 6 my $list = $self->read_form;
389 6 ▶ err "read-cond requires an even number of forms"
Branch: 1 branch
BranchTrueFalseTotal
if @$list % 2 1 5 6
390 if @$list % 2;
391 5 ▶ while (@$list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list) 7 1 8
392 7 my ($keyword, $form) = splice(@$list, 0, 2);
393 7 ▶ err "Feature should be a keyword: $keyword"
Branch: 1 branch
BranchTrueFalseTotal
unless $keyword->isa("Lingy::Keyword") 1 6 7
394 unless $keyword->isa(KEYWORD);
395 6 ▶ if ("$keyword" eq $feature_keyword or
Branch: 1 branch
BranchTrueFalseTotal
if ("$keyword" eq $Lingy::Reader::feature_keyword or "$keyword" eq ":default") 3 3 6
Condition100%3/3
"$keyword" eq $Lingy::Reader::feature_keyword or "$keyword" eq ":default"
l!l&&r!l&&!r
123
MC/DC100%2/2
"$keyword" eq $Lingy::Reader::feature_keyword or "$keyword" eq ":default"
"$keyword" eq $Lingy::Reader::feature_keyword "$keyword" eq ":default"
Truth table100%3/3
A or B
A= "$keyword" eq $Lingy::Reader::feature_keywordB= "$keyword" eq ":default"
ABresult
1X1
011
000
396 "$keyword" eq ':default'
397 ) {
398 3 return $form;
399 }
400 }
401 1 return;
402 }
403  
404 53 1;
« blib/lib/Lingy/RT.pm ↑ Summary lib/Lingy/Fn.pm »