MDOM/Document/Gmake.pm

filter: Statementstmt 91.5% 259 / 283 Branchbran 87.1% 136 / 156 Conditioncond 78.7% 52 / 66 MC/DCmcdc 57.8% 22 / 38 Subroutinesub 91.3% 21 / 23 Podpod 0.0% 0 / 1 totaltotal 86.4% 490 / 567 SCAR 47.8
CC
103
Cov
89%
_tokenize
34.0
_parse_normal
32.8
_tokenize_normal
15.0
CRAP 119.1
« MDOM/Dumper.pm ↑ Summary MDOM/Token.pm »
1 package MDOM::Document::Gmake;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #use Smart::Comments;
7 #use Smart::Comments '###', '####';
8  
9 16 ▶use Text::Balanced qw( gen_extract_tagged );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Makefile::DOM;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 #use Data::Dump::Streamer;
12 16 ▶use base 'MDOM::Node';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 ▶use List::MoreUtils qw( before all any );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 16 my %_map;
17 BEGIN {
18 16 ▶ %_map = (
Subroutine BEGIN: called CC=1 SCAR=0.0
19 COMMENT => 1, # context for parsing multi-line comments
20 COMMAND => 2, # context for parsing multi-line commands
21 RULE => 3, # context for parsing rules
22 VOID => 4, # void context
23 UNKNOWN => 5, # context for parsing unexpected constructs
24 );
25 }
26  
27 16 ▶use constant \%_map;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 16 my %_rev_map = reverse %_map;
30  
31 16 my @keywords = qw(
32 vpath include sinclude
33 ifdef ifndef else endif
34 define endef export unexport
35 );
36  
37 16 my $extract_interp_1 = gen_extract_tagged('\$[(]', '[)]', '');
38 16 my $extract_interp_2 = gen_extract_tagged('\$[{]', '[}]', '');
39  
40 sub _extract_interp {
41 1523 ▶ my ($res) = $extract_interp_1->($_[0]);
Subroutine _extract_interp: called CC=2 SCAR=6.9
42 1523 ▶ if (!$res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 1501 22 1523
43 1501 ($res) = $extract_interp_2->($_[0]);
44 }
45 1523 $res;
46 }
47  
48 16 my ($context, $saved_context);
49  
50 sub new {
51 75 ▶ my $class = ref $_[0] ? ref shift : shift;
Subroutine new: called CC=6 SCAR=20.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 75 75
52 75 my $input = shift;
53 75 ▶ return undef if !defined $input;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 0 75 75
54 75 my $in;
55 75 ▶ if (ref $input) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input) { } 75 0 75
56 75 ▶ open $in, '<', $input or die;
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", $input or die 0 75 75
57 } else {
58 0 ▶ open $in, $input or
Branch: 1 branch
BranchTrueFalseTotal
open $in, $input or die "Can't open $input for reading: $!" 0 0 0
59 die "Can't open $input for reading: $!";
60 }
61 75 my $self = $class->SUPER::new;
62 75 $self->_tokenize($in);
63 75 $self;
64 }
65  
66 sub _tokenize {
67 75 ▶ my ($self, $fh) = @_;
Subroutine _tokenize: called CC=33 SCAR=35.3
68 75 $context = VOID;
69 75 my @tokens;
70 75 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 165 75 240
71 ### Tokenizing : $_
72 ### ...with context : $_rev_map{$context}
73 165 s/\r\n/\n/g;
74 165 ▶ $_ .= "\n" if !/\n$/s;
Branch: 1 branch
BranchTrueFalseTotal
unless /\n$/s 0 165 165
75 165 ▶ if ($context == VOID || $context == RULE) {
Branch: 4 branches
BranchTrueFalseTotal
if ($context == 4 or $context == 3) { } 131 34 165
elsif ($context == 1) { } 6 28 34
elsif ($context == 2) { } 8 20 28
elsif ($context == 5) { } 20 0 20
Condition100%3/3
$context == 4 or $context == 3
l!l&&r!l&&!r
824934
MC/DC100%2/2
$context == 4 or $context == 3
$context == 4 $context == 3
Truth table100%3/3
A or B
A= $context == 4B= $context == 3
ABresult
1X1
011
000
76 131 ▶ if ($context == VOID && s/(?x) ^ (\t\s*) (?= \# ) //) {
Branch: 2 branches
BranchTrueFalseTotal
if ($context == 4 and s/(?x) ^ (\t\s*) (?= \# ) //) { } 4 127 131
elsif ($context == 3 and s/^\t//) { } 33 94 127
Condition100%3/3
$context == 4 and s/(?x) ^ (\t\s*) (?= \# ) //
!ll&&!rl&&r
49784
MC/DC100%2/2
$context == 4 and s/(?x) ^ (\t\s*) (?= \# ) //
$context == 4 s/(?x) ^ (\t\s*) (?= \# ) //
Truth table100%3/3
A and B
A= $context == 4B= s/(?x) ^ (\t\s*) (?= \# ) //
ABresult
0X0
100
111
77 ### Found comment in VOID context...
78 4 @tokens = (
79 MDOM::Token::Whitespace->new($1),
80 _tokenize_comment($_)
81 );
82 4 ▶ if ($tokens[-1]->isa('MDOM::Token::Continuation')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-1]->isa("MDOM::Token::Continuation")) 1 3 4
83 ### Switching context to COMMENT...
84 1 $saved_context = $context;
85 1 $context = COMMENT;
86 1 $tokens[-2]->add_content("\\\n");
87 1 pop @tokens;
88 }
89 4 $self->__add_elements( @tokens );
90 }
91 ▶ elsif ($context == RULE and s/^\t//) {
Condition100%3/3
$context == 3 and s/^\t//
!ll&&!rl&&r
781633
MC/DC100%2/2
$context == 3 and s/^\t//
$context == 3 s/^\t//
Truth table100%3/3
A and B
A= $context == 3B= s/^\t//
ABresult
0X0
100
111
92 ### Found a command in RULE context...
93 33 @tokens = _tokenize_command($_);
94 #warn "*@tokens*";
95 ### Tokens for the command: @tokens
96 33 unshift @tokens, MDOM::Token::Separator->new("\t");
97 33 ▶ if ($tokens[-1]->isa('MDOM::Token::Continuation')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-1]->isa("MDOM::Token::Continuation")) 4 29 33
98 ### Switching context to COMMAND...
99 4 $saved_context = $context;
100 4 $context = COMMAND;
101 4 pop @tokens;
102 4 ▶ if ($tokens[-1]->class =~ /Bare$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-1]->class =~ /Bare$/) { } 3 1 4
103 3 $tokens[-1]->add_content("\\\n");
104 } else {
105 1 push @tokens, MDOM::Token::Bare->new("\\\n");
106 }
107 }
108 33 my $cmd = MDOM::Command->new;
109 33 $cmd->__add_elements(@tokens);
110 33 $self->__add_element($cmd);
111 ### command (post): $cmd
112 33 next;
113 } else {
114 94 @tokens = _tokenize_normal($_);
115 94 ▶ if (@tokens >= 2 &&
Branch: 2 branches
BranchTrueFalseTotal
if (@tokens >= 2 and $tokens[-1]->isa('MDOM::Token::Continuation') and $tokens[-2]->isa('MDOM::Token::Comment')) { } 2 92 94
elsif ($tokens[-1]->isa('MDOM::Token::Continuation')) { } 12 80 92
Condition100%6/6
@tokens >= 2 and $tokens[-1]->isa("MDOM::Token::Continuation") and $tokens[-2]->isa("MDOM::Token::Comment")
!ll&&!rl&&r
80122
@tokens >= 2 and $tokens[-1]->isa("MDOM::Token::Continuation")
!ll&&!rl&&r
77314
MC/DC100%3/3
@tokens >= 2 and $tokens[-1]->isa("MDOM::Token::Continuation") and $tokens[-2]->isa("MDOM::Token::Comment")
@tokens >= 2 $tokens[-1]->isa("MDOM::Token::Continuation") $tokens[-2]->isa("MDOM::Token::Comment")
Truth table100%4/4
A and B and C
A= @tokens >= 2B= $tokens[-1]->isa("MDOM::Token::Continuation")C= $tokens[-2]->isa("MDOM::Token::Comment")
ABCresult
0XX0
10X0
1100
1111
116 $tokens[-1]->isa('MDOM::Token::Continuation') &&
117 $tokens[-2]->isa('MDOM::Token::Comment')) {
118 ### Found a trailing comment...
119 ### Switching conext to COMMENT...
120 2 $saved_context = $context;
121 2 $context = COMMENT;
122 2 $tokens[-2]->add_content("\\\n");
123 2 pop @tokens;
124 2 $self->__add_elements( _parse_normal(@tokens) );
125 } elsif ($tokens[-1]->isa('MDOM::Token::Continuation')) {
126 ### Found a line continuation...
127 ### Switching context to UNKNOWN...
128 12 $saved_context = $context;
129 12 $context = UNKNOWN;
130 } else {
131 ### Parsing it as a normal line...
132 80 $self->__add_elements( _parse_normal(@tokens) );
133 }
134 }
135 } elsif ($context == COMMENT) {
136 6 @tokens = _tokenize_comment($_);
137 6 ▶ if ($tokens[-1]->isa('MDOM::Token::Continuation')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-1]->isa('MDOM::Token::Continuation')) { } 3 3 6
138 ### Slurping one more continued comment line...
139 3 $tokens[-2]->add_content("\\\n");
140 3 pop @tokens;
141 3 $self->last_token->add_content(join '', @tokens);
142 } else {
143 ### Completing comment slurping...
144 ### Switching back to context: _state_str($saved_context)
145 3 $context = $saved_context;
146 3 my $last = pop @tokens;
147 3 $self->last_token->add_content(join '', @tokens);
148 3 $self->last_token->parent->__add_element($last);
149 }
150 } elsif ($context == COMMAND) {
151 8 @tokens = _tokenize_command($_);
152 ### more tokens for the cmd: @tokens
153 8 ▶ if ($tokens[-1]->isa('MDOM::Token::Continuation')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-1]->isa('MDOM::Token::Continuation')) { } 4 4 8
154 ### Slurping one more continued command line...
155 4 $tokens[-2]->add_content("\\\n");
156 4 pop @tokens;
157 4 for my $token (@tokens) {
158 12 ▶ if ($token->class =~ /Interpolation/ or
Branch: 1 branch
BranchTrueFalseTotal
if ($token->class =~ /Interpolation/ or $self->last_token->class =~ /Interpolation/) { } 6 6 12
Condition100%3/3
$token->class =~ /Interpolation/ or $self->last_token->class =~ /Interpolation/
l!l&&r!l&&!r
336
MC/DC100%2/2
$token->class =~ /Interpolation/ or $self->last_token->class =~ /Interpolation/
$token->class =~ /Interpolation/ $self->last_token->class =~ /Interpolation/
Truth table100%3/3
A or B
A= $token->class =~ /Interpolation/B= $self->last_token->class =~ /Interpolation/
ABresult
1X1
011
000
159 $self->last_token->class =~ /Interpolation/) {
160 6 $self->last_token->parent->__add_element($token);
161 } else {
162 6 $self->last_token->add_content($token);
163 }
164 }
165 } else {
166 ### Completing command slurping: @tokens
167 ### Switching back to context: _state_str($saved_context)
168 4 $context = RULE;
169 4 my $last = pop @tokens;
170 ### last_token: $self->last_token
171 4 for my $token (@tokens) {
172 6 ▶ if ($token->class =~ /Interpolation/ or
Branch: 1 branch
BranchTrueFalseTotal
if ($token->class =~ /Interpolation/ or $self->last_token->class =~ /Interpolation/) { } 2 4 6
Condition66%2/3
$token->class =~ /Interpolation/ or $self->last_token->class =~ /Interpolation/
l!l&&r!l&&!r
204
MC/DC50%1/2
$token->class =~ /Interpolation/ or $self->last_token->class =~ /Interpolation/
$token->class =~ /Interpolation/ $self->last_token->class =~ /Interpolation/
Truth table66%2/3
A or B
A= $token->class =~ /Interpolation/B= $self->last_token->class =~ /Interpolation/
ABresult
1X1
011
000
173 $self->last_token->class =~ /Interpolation/) {
174 2 $self->last_token->parent->__add_element($token);
175 } else {
176 4 $self->last_token->add_content($token);
177 }
178 }
179 4 $self->last_token->parent->__add_element($last);
180 }
181 } elsif ($context == UNKNOWN) {
182 20 push @tokens, _tokenize_normal($_);
183 20 ▶ if (@tokens >= 2 && $tokens[-1]->isa('MDOM::Token::Continuation') &&
Branch: 2 branches
BranchTrueFalseTotal
if (@tokens >= 2 and $tokens[-1]->isa('MDOM::Token::Continuation') and $tokens[-2]->isa('MDOM::Token::Comment')) { } 0 20 20
elsif ($tokens[-1]->isa('MDOM::Token::Continuation')) { } 8 12 20
Condition66%4/6
@tokens >= 2 and $tokens[-1]->isa("MDOM::Token::Continuation") and $tokens[-2]->isa("MDOM::Token::Comment")
!ll&&!rl&&r
1280
@tokens >= 2 and $tokens[-1]->isa("MDOM::Token::Continuation")
!ll&&!rl&&r
0128
MC/DC0%0/3
@tokens >= 2 and $tokens[-1]->isa("MDOM::Token::Continuation") and $tokens[-2]->isa("MDOM::Token::Comment")
@tokens >= 2 $tokens[-1]->isa("MDOM::Token::Continuation") $tokens[-2]->isa("MDOM::Token::Comment")
Truth table50%2/4
A and B and C
A= @tokens >= 2B= $tokens[-1]->isa("MDOM::Token::Continuation")C= $tokens[-2]->isa("MDOM::Token::Comment")
ABCresult
0XX0
10X0
1100
1111
184 $tokens[-2]->isa('MDOM::Token::Comment')) {
185 0 $context = COMMENT;
186 0 $tokens[-2]->add_content("\\\n");
187 0 pop @tokens;
188 0 $self->__add_elements( _parse_normal(@tokens) );
189 } elsif ($tokens[-1]->isa('MDOM::Token::Continuation')) {
190 ### Do nothing here...stay in the UNKNOWN context...
191 } else {
192 12 $self->__add_elements( _parse_normal(@tokens) );
193 12 $context = $saved_context;
194 }
195 } else {
196 0 die "Unkown state: $context";
197 }
198 }
199 75 ▶ if ($context != RULE && $context != VOID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context != 3 and $context != 4) 0 75 75
Condition66%2/3
$context != 3 and $context != 4
!ll&&!rl&&r
41340
MC/DC0%0/2
$context != 3 and $context != 4
$context != 3 $context != 4
Truth table66%2/3
A and B
A= $context != 3B= $context != 4
ABresult
0X0
100
111
200 0 warn "unexpected end of input at line $.";
201 }
202 }
203  
204 sub _tokenize_normal {
205 114 ▶ local $_ = shift;
Subroutine _tokenize_normal: called CC=15 SCAR=27.1
206 114 my @tokens;
207 114 my $pending_token = '';
208 114 my $next_token;
209 ### TOKENIZING: $_
210 114 while (1) {
211 # "token = $pending_token";
212 #warn pos;
213 #warn '@tokens = ', _dump_tokens2(@tokens);
214 1327 ▶ if (/(?x) \G [\s\n]+ /gc) {
Branch: 9 branches
BranchTrueFalseTotal
if (/(?x) \G [\s\n]+ /cg) { } 286 1041 1327
elsif (/(?x) \G (?: :: | := | \?= | \+= | [=:;] )/cg) { } 77 964 1041
elsif (/(?x) \G \| /cg) { } 3 961 964
elsif (my $res = _extract_interp($_)) { } 15 946 961
elsif (/(?x) \G \$. /cg) { } 7 939 946
elsif (/(?x) \G \\ ([\#\\\n:]) /cgs) { } 24 915 939
elsif (/(?x) \G (\# [^\n]*) \\ \n/cgs) { } 2 913 915
elsif (/(?x) \G \# [^\n]* /cg) { } 12 901 913
elsif (/(?x) \G . /cg) { } 809 92 901
215 286 $next_token = MDOM::Token::Whitespace->new($&);
216 #push @tokens, $next_token;
217 }
218 elsif (/(?x) \G (?: :: | := | \?= | \+= | [=:;] )/gc) {
219 77 $next_token = MDOM::Token::Separator->new($&);
220 }
221 elsif (/(?x) \G \| /gc) {
222 # XXX This should be a separator...
223 3 $next_token = MDOM::Token::Bare->new($&);
224 }
225 elsif (my $res = _extract_interp($_)) {
226 15 $next_token = MDOM::Token::Interpolation->new($res);
227 }
228 elsif (/(?x) \G \$. /gc) {
229 7 $next_token = MDOM::Token::Interpolation->new($&);
230 }
231 elsif (/(?x) \G \\ ([\#\\\n:]) /gcs) {
232 24 my $c = $1;
233 24 ▶ if ($c eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") { } 20 4 24
234 20 ▶ push @tokens, MDOM::Token::Bare->new($pending_token)
Branch: 1 branch
BranchTrueFalseTotal
if $pending_token ne "" 1 19 20
235 if $pending_token ne '';
236 20 push @tokens, MDOM::Token::Continuation->new("\\\n");
237 20 return @tokens;
238 } else {
239 4 $pending_token .= "\\$c";
240 }
241 }
242 elsif (/(?x) \G (\# [^\n]*) \\ \n/sgc) {
243 2 my $s = $1;
244 2 ▶ push @tokens, MDOM::Token::Bare->new($pending_token) if $pending_token ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $pending_token ne "" 0 2 2
245 2 push @tokens, MDOM::Token::Comment->new($s);
246 2 push @tokens, MDOM::Token::Continuation->new("\\\n");
247 2 return @tokens;
248 } elsif (/(?x) \G \# [^\n]* /gc) {
249 12 $next_token = MDOM::Token::Comment->new($&);
250 } elsif (/(?x) \G . /gc) {
251 809 $pending_token .= $&;
252 } else {
253 92 last;
254 }
255 1213 ▶ if ($next_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token) 400 813 1213
256 400 ▶ if ($pending_token ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending_token ne "") 204 196 400
257 204 push @tokens, MDOM::Token::Bare->new($pending_token);
258 204 $pending_token = '';
259 }
260 400 push @tokens, $next_token;
261 400 $next_token = undef;
262 }
263 }
264 ### parse_normal result: @tokens
265 92 @tokens;
266 }
267  
268 sub _tokenize_command {
269 56 ▶ my $s = shift;
Subroutine _tokenize_command: called CC=14 SCAR=26.4
270 56 my @tokens;
271 56 my $pending_token = '';
272 56 my $next_token;
273 56 my $strlen = length $s;
274 56 ▶ while ($s =~ /(?x) \G (\s*) ([\@+\-]) /gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /(?x) \G (\s*) ([\@+\-]) /cg) 16 56 72
275 16 my ($whitespace, $modifier) = ($1, $2);
276 16 ▶ if ($whitespace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($whitespace) 7 9 16
277 7 push @tokens, MDOM::Token::Whitespace->new($whitespace);
278 }
279 16 push @tokens, MDOM::Token::Modifier->new($modifier);
280 }
281 56 while (1) {
282 607 my $last = 0;
283 607 ▶ if ($s =~ /(?x) \G \n /gc) {
Branch: 5 branches
BranchTrueFalseTotal
if ($s =~ /(?x) \G \n /cg) { } 45 562 607
elsif (my $res = _extract_interp($s)) { } 11 551 562
elsif ($s =~ /(?x) \G \$. /cg) { } 11 540 551
elsif ($s =~ /(?x) \G \\ ([\#\\\n:]) /cgs) { } 12 528 540
elsif ($s =~ /(?x) \G . /cg) { } 472 56 528
284 45 $next_token = MDOM::Token::Whitespace->new("\n");
285 #push @tokens, $next_token;
286 }
287 elsif (my $res = _extract_interp($s)) {
288 11 $next_token = MDOM::Token::Interpolation->new($res);
289 }
290 elsif ($s =~ /(?x) \G \$. /gc) {
291 11 $next_token = MDOM::Token::Interpolation->new($&);
292 }
293 elsif ($s =~ /(?x) \G \\ ([\#\\\n:]) /gcs) {
294 12 my $c = $1;
295 12 ▶ if ($c eq "\n" && pos $s == $strlen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n" and pos $s == $strlen) { } 8 4 12
Condition100%3/3
$c eq "\n" and pos $s == $strlen
!ll&&!rl&&r
228
MC/DC100%2/2
$c eq "\n" and pos $s == $strlen
$c eq "\n" pos $s == $strlen
Truth table100%3/3
A and B
A= $c eq "\n"B= pos $s == $strlen
ABresult
0X0
100
111
296 8 $next_token = MDOM::Token::Continuation->new("\\\n");
297 } else {
298 4 $pending_token .= "\\$c";
299 }
300 }
301 elsif ($s =~ /(?x) \G . /gc) {
302 472 $pending_token .= $&;
303 } else {
304 56 $last = 1;
305 }
306 607 ▶ if ($next_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token) 75 532 607
307 75 ▶ if ($pending_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending_token) 60 15 75
308 60 push @tokens, MDOM::Token::Bare->new($pending_token);
309 60 $pending_token = '';
310 }
311 75 push @tokens, $next_token;
312 75 $next_token = undef;
313 }
314 607 ▶ last if $last;
Branch: 1 branch
BranchTrueFalseTotal
if $last 56 551 607
315 }
316 56 ▶ if ($pending_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending_token) 0 56 56
317 0 push @tokens, MDOM::Token::Bare->new($pending_token);
318 0 $pending_token = '';
319 }
320 56 @tokens;
321 }
322  
323 sub _tokenize_comment {
324 10 ▶ local $_ = shift;
Subroutine _tokenize_comment: called CC=7 SCAR=20.4
325 10 my @tokens;
326 10 my $pending_token = '';
327 10 while (1) {
328 134 ▶ if (/(?x) \G \n /gc) {
Branch: 3 branches
BranchTrueFalseTotal
if (/(?x) \G \n /cg) { } 6 128 134
elsif (/(?x) \G \\ ([\\\n#:]) /cgs) { } 4 124 128
elsif (/(?x) \G . /cg) { } 124 0 124
329 6 ▶ push @tokens, MDOM::Token::Comment->new($pending_token) if $pending_token ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $pending_token ne "" 6 0 6
330 6 push @tokens, MDOM::Token::Whitespace->new("\n");
331 6 return @tokens;
332 #push @tokens, $next_token;
333 }
334 elsif (/(?x) \G \\ ([\\\n#:]) /gcs) {
335 4 my $c = $1;
336 4 ▶ if ($c eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") { } 4 0 4
337 4 ▶ push @tokens, MDOM::Token::Comment->new($pending_token) if $pending_token ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $pending_token ne "" 4 0 4
338 4 push @tokens, MDOM::Token::Continuation->new("\\\n");
339 4 return @tokens;
340 } else {
341 0 $pending_token .= "\\$c";
342 }
343 }
344 elsif (/(?x) \G . /gc) {
345 124 $pending_token .= $&;
346 }
347 else {
348 0 last;
349 }
350 }
351 0 @tokens;
352 }
353  
354 sub _parse_normal {
355 94 ▶ my @tokens = @_;
Subroutine _parse_normal: called CC=31 SCAR=34.9
356 ### fed to _parse_normal: @tokens
357 94 my @sep = grep { $_->isa('MDOM::Token::Separator') } @tokens;
358 #### Separators: @sep
359 94 ▶ if (@tokens == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens == 1) 8 86 94
360 8 return $tokens[0];
361 }
362 # filter out significant tokens:
363 86 my ($fst, $snd) = grep { $_->significant } @tokens;
364 86 my $is_directive;
365 86 ▶ if ($fst) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fst) 81 5 86
366 81 ▶ if ($fst eq '-include') {
Branch: 2 branches
BranchTrueFalseTotal
if ($fst eq '-include') { } 2 79 81
elsif ($fst eq 'override' and $snd and $snd eq 'define' or _is_keyword($fst)) { } 12 67 79
367 2 $fst->set_content('include');
368 2 unshift @tokens, MDOM::Token::Modifier->new('-');
369 2 $is_directive = 1;
370 }
371 ▶ elsif ($fst eq 'override' && $snd && $snd eq 'define' ||
Condition66%6/9
$fst eq "override" and $snd and $snd eq "define" or _is_keyword($fst)
l!l&&r!l&&!r
01267
$fst eq "override" and $snd and $snd eq "define"
!ll&&!rl&&r
7450
$fst eq "override" and $snd
!ll&&!rl&&r
7405
MC/DC25%1/4
$fst eq "override" and $snd and $snd eq "define" or _is_keyword($fst)
$fst eq "override" $snd $snd eq "define" _is_keyword($fst)
Truth table42%3/7
A and B and C or D
A= $fst eq "override"B= $sndC= $snd eq "define"D= _is_keyword($fst)
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
372 _is_keyword($fst)) {
373 12 $is_directive = 1;
374 }
375 81 ▶ if ($is_directive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_directive) 14 67 81
376 ##### Found directives...
377 14 my $node = MDOM::Directive->new;
378 14 $node->__add_elements(@tokens);
379 14 return $node;
380 }
381 }
382 72 ▶ if (@sep >= 2 && $sep[0] =~ /^::?$/ and $sep[1] eq ';') {
Branch: 5 branches
BranchTrueFalseTotal
if (@sep >= 2 and $sep[0] =~ /^::?$/ and $sep[1] eq ';') { } 9 63 72
elsif (@sep >= 2 and $sep[0] eq ':' and $sep[1] =~ /^::?$/) { } 2 61 63
elsif (@sep == 1 and $sep[0] =~ /^::?$/) { } 36 25 61
elsif (@sep and $sep[0] =~ /(?x) ^ (?: = | := | \+= | \?= ) $/) { } 15 10 25
elsif (&all(sub { $_->isa('MDOM::Token::Comment') or $_->isa('MDOM::Token::Whitespace'); } , @tokens)) { } 5 5 10
Condition83%5/6
@sep >= 2 and $sep[0] =~ /^::?$/ and $sep[1] eq ";"
!ll&&!rl&&r
6129
@sep >= 2 and $sep[0] =~ /^::?$/
!ll&&!rl&&r
61011
MC/DC66%2/3
@sep >= 2 and $sep[0] =~ /^::?$/ and $sep[1] eq ";"
@sep >= 2 $sep[0] =~ /^::?$/ $sep[1] eq ";"
Truth table75%3/4
A and B and C
A= @sep >= 2B= $sep[0] =~ /^::?$/C= $sep[1] eq ";"
ABCresult
0XX0
10X0
1100
1111
383 #### Found simple rule with inlined command...
384 9 my $rule = MDOM::Rule::Simple->new;
385 9 ▶ my @t = before { $_ eq ';' } @tokens;
Subroutine __ANON__: called CC=1 SCAR=0.0
386 9 $rule->__add_elements(@t);
387 9 splice @tokens, 0, scalar(@t);
388  
389 9 my @prefix = shift @tokens;
390 9 ▶ if ($tokens[0] && $tokens[0]->isa('MDOM::Token::Whitespace')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[0] and $tokens[0]->isa("MDOM::Token::Whitespace")) 6 3 9
Condition66%2/3
$tokens[0] and $tokens[0]->isa("MDOM::Token::Whitespace")
!ll&&!rl&&r
036
MC/DC50%1/2
$tokens[0] and $tokens[0]->isa("MDOM::Token::Whitespace")
$tokens[0] $tokens[0]->isa("MDOM::Token::Whitespace")
Truth table66%2/3
A and B
A= $tokens[0]B= $tokens[0]->isa("MDOM::Token::Whitespace")
ABresult
0X0
100
111
391 6 push @prefix, shift @tokens;
392 }
393  
394 9 @tokens = (@prefix, _tokenize_command(join '', @tokens));
395 9 ▶ if ($tokens[-1]->isa('MDOM::Token::Continuation')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-1]->isa("MDOM::Token::Continuation")) 0 9 9
396 0 $saved_context = $context;
397 0 $context = COMMAND;
398 }
399 9 my $cmd = MDOM::Command->new;
400 9 $cmd->__add_elements(@tokens);
401 9 $rule->__add_elements($cmd);
402 9 $saved_context = RULE;
403 9 ▶ $context = RULE if $context == VOID;
Branch: 1 branch
BranchTrueFalseTotal
if $context == 4 5 4 9
404 9 return $rule;
405 }
406 ▶ elsif (@sep >= 2 && $sep[0] eq ':' and $sep[1] =~ /^::?$/) {
Condition66%4/6
@sep >= 2 and $sep[0] eq ":" and $sep[1] =~ /^::?$/
!ll&&!rl&&r
6102
@sep >= 2 and $sep[0] eq ":"
!ll&&!rl&&r
6102
MC/DC33%1/3
@sep >= 2 and $sep[0] eq ":" and $sep[1] =~ /^::?$/
@sep >= 2 $sep[0] eq ":" $sep[1] =~ /^::?$/
Truth table50%2/4
A and B and C
A= @sep >= 2B= $sep[0] eq ":"C= $sep[1] =~ /^::?$/
ABCresult
0XX0
10X0
1100
1111
407 #### Found static pattern rule...
408 2 my $rule = MDOM::Rule::StaticPattern->new;
409 2 ▶ my @t = before { $_ eq ';' } @tokens;
Subroutine __ANON__: called CC=1 SCAR=0.0
410 2 $rule->__add_elements(@t);
411 2 splice @tokens, 0, scalar(@t);
412 2 ▶ if (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 1 1 2
413 1 my @prefix = shift @tokens;
414 1 ▶ if ($tokens[0] && $tokens[0]->isa('MDOM::Token::Whitespace')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[0] and $tokens[0]->isa("MDOM::Token::Whitespace")) 1 0 1
Condition33%1/3
$tokens[0] and $tokens[0]->isa("MDOM::Token::Whitespace")
!ll&&!rl&&r
001
MC/DC0%0/2
$tokens[0] and $tokens[0]->isa("MDOM::Token::Whitespace")
$tokens[0] $tokens[0]->isa("MDOM::Token::Whitespace")
Truth table33%1/3
A and B
A= $tokens[0]B= $tokens[0]->isa("MDOM::Token::Whitespace")
ABresult
0X0
100
111
415 1 push @prefix, shift @tokens;
416 }
417  
418 1 @tokens = (@prefix, _tokenize_command(join '', @tokens));
419 1 ▶ if ($tokens[-1]->isa('MDOM::Token::Continuation')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-1]->isa("MDOM::Token::Continuation")) 0 1 1
420 0 $saved_context = $context;
421 0 $context = COMMAND;
422 }
423 1 my $cmd = MDOM::Command->new;
424 1 $cmd->__add_elements(@tokens);
425 1 $rule->__add_elements($cmd);
426 }
427 2 $saved_context = RULE;
428 2 ▶ $context = RULE if $context == VOID;
Branch: 1 branch
BranchTrueFalseTotal
if $context == 4 2 0 2
429 2 return $rule;
430 }
431 ▶ elsif (@sep == 1 && $sep[0] =~ /^::?$/) {
Condition100%3/3
@sep == 1 and $sep[0] =~ /^::?$/
!ll&&!rl&&r
101536
MC/DC100%2/2
@sep == 1 and $sep[0] =~ /^::?$/
@sep == 1 $sep[0] =~ /^::?$/
Truth table100%3/3
A and B
A= @sep == 1B= $sep[0] =~ /^::?$/
ABresult
0X0
100
111
432 #### Found simple rule without inlined command...
433 36 my $rule = MDOM::Rule::Simple->new;
434 36 $rule->__add_elements(@tokens);
435 36 $saved_context = RULE;
436 36 ▶ $context = RULE if $context == VOID;
Branch: 1 branch
BranchTrueFalseTotal
if $context == 4 30 6 36
437 36 return $rule;
438 }
439 ▶ elsif (@sep && $sep[0] =~ /(?x) ^ (?: = | := | \+= | \?= ) $/) {
Condition66%2/3
@sep and $sep[0] =~ /(?x) ^ (?: = | := | \+= | \?= ) $/
!ll&&!rl&&r
10015
MC/DC50%1/2
@sep and $sep[0] =~ /(?x) ^ (?: = | := | \+= | \?= ) $/
@sep $sep[0] =~ /(?x) ^ (?: = | := | \+= | \?= ) $/
Truth table66%2/3
A and B
A= @sepB= $sep[0] =~ /(?x) ^ (?: = | := | \+= | \?= ) $/
ABresult
0X0
100
111
440 15 my $assign = MDOM::Assignment->new;
441 ### Assignment tokens: @tokens
442 15 $assign->__add_elements(@tokens);
443 15 $saved_context = VOID;
444 15 ▶ $context = VOID if $context == RULE;
Branch: 1 branch
BranchTrueFalseTotal
if $context == 3 1 14 15
445 15 return $assign;
446 }
447 elsif (all {
448 20 ▶ $_->isa('MDOM::Token::Comment') ||
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("MDOM::Token::Comment") or $_->isa("MDOM::Token::Whitespace") 15 5 20
449 $_->isa('MDOM::Token::Whitespace')
450 } @tokens) {
451 5 @tokens;
452 }
453 else {
454 #### Found unkown token sequence: @tokens
455 5 @tokens = _tokenize_command(join '', @tokens);
456 5 my $node = MDOM::Unknown->new;
457 5 $node->__add_elements(@tokens);
458 5 $node;
459 }
460 }
461  
462 sub _dump_tokens {
463 0 ▶ my @tokens = map { $_->clone } @_;
Subroutine _dump_tokens: not called CC=1 SCAR=6.9
464 warn "??? ", (join ' ',
465 0 map { s/\\/\\\\/g; s/\n/\\n/g; s/\t/\\t/g; "[$_]" } @tokens
466 ), "\n";
467 }
468  
469 sub _state_str {
470 0 ▶ $_rev_map{$saved_context}
Subroutine _state_str: not called CC=1 SCAR=6.9
471 }
472  
473 sub _is_keyword {
474 777 ▶ any { $_[0] eq $_ } @keywords;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _is_keyword: called CC=1 SCAR=0.0
475 }
476  
477 16 1;
478  
479 __END__
« MDOM/Dumper.pm ↑ Summary MDOM/Token.pm »