blib/lib/Zuzu/Lexer.pm

filter: Statementstmt 89.3% 352 / 394 Branchbran 77.4% 189 / 244 Conditioncond 59.3% 95 / 160 MC/DCmcdc 39.3% 35 / 89 Subroutinesub 95.6% 22 / 23 Podpod 100% 1 / 1 totaltotal 76.1% 694 / 911 CC 181 SCAR 37.6
CC
181
Cov
80%
_can_start_regexp
100.0
next_token
61.8
_split_interpolated_source
51.8
CRAP 43.1
« blib/lib/Zuzu/Parser/_Impl.pm ↑ Summary lib/Zuzu/CLI.pm »
1 package Zuzu::Lexer;
2  
3 78 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 78 our $VERSION = '0.007002';
6  
7 78 ▶use Zuzu::Token ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 78 ▶use Zuzu::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 78 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶has 'src' => ( is => 'rw', default => sub { '' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
13 78 has 'filename' => ( is => 'rw' );
14 1451 ▶has 'pos' => ( is => 'rw', default => sub { 0 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
15 1451 ▶has 'line' => ( is => 'rw', default => sub { 1 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
16 1451 ▶has 'col' => ( is => 'rw', default => sub { 1 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
17 78 has 'last_token' => ( is => 'rw' );
18  
19 1451 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
20 1451 my ($orig, $class, @args) = @_;
21  
22 1451 my $args = $class->$orig(@args);
23 1451 ▶ $args->{src} = Zuzu::Util::nfc($args->{src} // '');
Condition50%1/2
$args->{"src"} // ""
l!l
14510
MC/DC0%0/1
$args->{"src"} // ""
$args->{"src"}
Truth table50%1/2
A
A= $args->{"src"}
Aresult
11
00
24  
25 1451 return $args;
26 78 };
27  
28 8723622 ▶sub _peek {
Subroutine _peek: called CC=2 SCAR=7.1
29 8723622 my ($self, $n) = @_;
30  
31 8723622 ▶ $n //= 1;
Condition50%1/2
$n //= 1
l!l
87236220
MC/DC0%0/1
$n //= 1
$n
Truth table50%1/2
A
A= $n
Aresult
11
00
32  
33 8723622 return substr($self->src, $self->pos, $n);
34 }
35  
36 1018656 ▶sub _eof { $_[0]->pos >= length($_[0]->src) }
Subroutine _eof: called CC=1 SCAR=0.0
37  
38 1005200 ▶sub _adv {
Subroutine _adv: called CC=4 SCAR=13.9
39 1005200 my ($self, $n) = @_;
40  
41 1005200 ▶ $n //= 1;
Condition50%1/2
$n //= 1
l!l
10052000
MC/DC0%0/1
$n //= 1
$n
Truth table50%1/2
A
A= $n
Aresult
11
00
42 1005200 for (1..$n) {
43 1569452 my $ch = substr($self->src, $self->pos, 1);
44 1569452 $self->pos( $self->pos + 1 );
45 1569452 ▶ if ( $ch eq "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\n") { } 63636 1505816 1569452
46 63636 $self->line( $self->line + 1 );
47 63636 $self->col(1);
48 }
49 else {
50 1505816 $self->col( $self->col + 1 );
51 }
52 }
53 }
54  
55 308516 ▶sub _mk {
Subroutine _mk: called CC=1 SCAR=0.0
56 308516 my ($self, $type, $value, $line, $col) = @_;
57  
58 308516 return Zuzu::Token->new(
59 type => $type,
60 value => $value,
61 file => $self->filename,
62 line => $line,
63 col => $col,
64 );
65 }
66  
67 308516 ▶sub _emit {
Subroutine _emit: called CC=2 SCAR=7.0
68 308516 my ( $self, $type, $value, $line, $col ) = @_;
69 308516 my $tok = $self->_mk( $type, $value, $line, $col );
70 308516 ▶ $self->last_token($tok) if $type ne 'EOF';
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "EOF" 308516 0 308516
71  
72 308516 return $tok;
73 }
74  
75 650 ▶sub _read_escape {
Subroutine _read_escape: called CC=11 SCAR=24.7
76 650 my ( $self, $kind, $line, $col ) = @_;
77  
78 650 ▶ die "Unterminated $kind literal at line $line, col $col" if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 650 650
79 650 my $e = $self->_peek(1);
80 650 my %simple = (
81 n => "\n",
82 t => "\t",
83 r => "\r",
84 '"' => '"',
85 "'" => "'",
86 '`' => '`',
87 '/' => '/',
88 '$' => '$',
89 '\\' => '\\',
90 );
91 650 ▶ if ( exists $simple{$e} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $simple{$e}) 644 6 650
92 644 $self->_adv(1);
93 644 return $simple{$e};
94 }
95 6 ▶ if ( $e eq 'x' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "x") 5 1 6
96 5 my $hex = $self->_peek(3);
97 5 ▶ die "Invalid $kind escape at line $line, col $col"
Branch: 1 branch
BranchTrueFalseTotal
unless $hex =~ /\Ax([0-9A-Fa-f]{2})\z/ 1 4 5
98 if $hex !~ /\Ax([0-9A-Fa-f]{2})\z/;
99 4 $self->_adv(3);
100 4 ▶ return $kind eq 'binary string' ? pack( 'C', hex($1) ) : chr( hex($1) );
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'binary string' ? : 2 2 4
101 }
102 1 ▶ if ( $e eq 'u' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "u") 1 0 1
103 1 ▶ die "Invalid $kind escape at line $line, col $col"
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "binary string" 0 1 1
104 if $kind eq 'binary string';
105 1 my $hex = $self->_peek(5);
106 1 ▶ die "Invalid $kind escape at line $line, col $col"
Branch: 1 branch
BranchTrueFalseTotal
unless $hex =~ /\Au([0-9A-Fa-f]{4})\z/ 0 1 1
107 if $hex !~ /\Au([0-9A-Fa-f]{4})\z/;
108 1 my $cp = hex($1);
109 1 ▶ die "Invalid $kind escape at line $line, col $col"
Branch: 1 branch
BranchTrueFalseTotal
if $cp >= 55296 and $cp <= 57343 0 1 1
Condition33%1/3
$cp >= 55296 and $cp <= 57343
!ll&&!rl&&r
100
MC/DC0%0/2
$cp >= 55296 and $cp <= 57343
$cp >= 55296 $cp <= 57343
Truth table33%1/3
A and B
A= $cp >= 55296B= $cp <= 57343
ABresult
0X0
100
111
110 if $cp >= 0xD800 and $cp <= 0xDFFF;
111 1 $self->_adv(5);
112 1 return chr($cp);
113 }
114  
115 0 die "Invalid $kind escape at line $line, col $col";
116 }
117  
118 11011 ▶sub _read_single_line_literal {
Subroutine _read_single_line_literal: called CC=5 SCAR=16.1
119 11011 my ( $self, $quote, $kind, $line, $col ) = @_;
120  
121 11011 $self->_adv(1);
122 11011 my $out = '';
123 11011 ▶ while ( !$self->_eof ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_eof) 105595 13 105608
124 105595 my $c = $self->_peek(1);
125 105595 ▶ last if $c eq $quote;
Branch: 1 branch
BranchTrueFalseTotal
if $c eq $quote 10997 94598 105595
126 94598 ▶ if ( $c eq "\\" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\\") 650 93948 94598
127 650 $self->_adv(1);
128 650 $out .= $self->_read_escape( $kind, $line, $col );
129 649 next;
130 }
131 93948 $out .= $c;
132 93948 $self->_adv(1);
133 }
134 11010 ▶ die "Unterminated $kind literal at line $line, col $col" if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 13 10997 11010
135 10997 $self->_adv(1);
136  
137 10997 return $out;
138 }
139  
140 707 ▶sub _split_interpolated_source {
Subroutine _split_interpolated_source: called CC=33 SCAR=39.5
141 707 my ( $self, $src, $line, $col, $kind, $allow_escaped_dollar ) = @_;
142  
143 707 my @parts;
144 707 my $text = '';
145 707 my $i = 0;
146 707 my $len = length $src;
147 707 ▶ while ( $i < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 14677 707 15384
148 14677 my $ch = substr( $src, $i, 1 );
149 14677 ▶ if ( $allow_escaped_dollar and $ch eq "\\" and $i + 1 < $len and substr( $src, $i + 1, 1 ) eq '$' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_escaped_dollar and $ch eq "\\" and $i + 1 < $len and substr($src, $i + 1, 1) eq "\$") 4 14673 14677
Condition100%9/9
$allow_escaped_dollar and $ch eq "\\" and $i + 1 < $len and substr($src, $i + 1, 1) eq "\$"
!ll&&!rl&&r
144672064
$allow_escaped_dollar and $ch eq "\\" and $i + 1 < $len
!ll&&!rl&&r
144652210
$allow_escaped_dollar and $ch eq "\\"
!ll&&!rl&&r
1914446212
MC/DC100%4/4
$allow_escaped_dollar and $ch eq "\\" and $i + 1 < $len and substr($src, $i + 1, 1) eq "\$"
$allow_escaped_dollar $ch eq "\\" $i + 1 < $len substr($src, $i + 1, 1) eq "\$"
Truth table100%5/5
A and B and C and D
A= $allow_escaped_dollarB= $ch eq "\\"C= $i + 1 < $lenD= substr($src, $i + 1, 1) eq "\$"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
150 4 $text .= '\\$';
151 4 $i += 2;
152 4 next;
153 }
154 14673 ▶ if ( $ch eq '$' and $i + 1 < $len and substr( $src, $i + 1, 1 ) eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\$" and $i + 1 < $len and substr($src, $i + 1, 1) eq "{") 482 14191 14673
Condition100%6/6
$ch eq "\$" and $i + 1 < $len and substr($src, $i + 1, 1) eq "{"
!ll&&!rl&&r
141892482
$ch eq "\$" and $i + 1 < $len
!ll&&!rl&&r
14057132484
MC/DC100%3/3
$ch eq "\$" and $i + 1 < $len and substr($src, $i + 1, 1) eq "{"
$ch eq "\$" $i + 1 < $len substr($src, $i + 1, 1) eq "{"
Truth table100%4/4
A and B and C
A= $ch eq "\$"B= $i + 1 < $lenC= substr($src, $i + 1, 1) eq "{"
ABCresult
0XX0
10X0
1100
1111
155 482 ▶ push @parts, { text => $text } if $text ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $text ne "" 427 55 482
156 482 $text = '';
157 482 $i += 2;
158 482 my $start = $i;
159 482 my $depth = 1;
160 482 my $quote;
161 482 my $line_comment = 0;
162 482 my $block_comment = 0;
163 482 ▶ while ( $i < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 3813 0 3813
164 3813 my $c = substr( $src, $i, 1 );
165 3813 ▶ my $next = $i + 1 < $len ? substr( $src, $i + 1, 1 ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$i + 1 < $len ? : 3670 143 3813
166 3813 ▶ if ($line_comment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_comment) 0 3813 3813
167 0 ▶ $line_comment = 0 if $c eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "\n" 0 0 0
168 0 $i++;
169 0 next;
170 }
171 3813 ▶ if ($block_comment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block_comment) 0 3813 3813
172 0 ▶ if ( $c eq '*' and $next eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "*" and $next eq "/") 0 0 0
Condition0%0/3
$c eq "*" and $next eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
$c eq "*" and $next eq "/"
$c eq "*" $next eq "/"
Truth table0%0/3
A and B
A= $c eq "*"B= $next eq "/"
ABresult
0X0
100
111
173 0 $i += 2;
174 0 $block_comment = 0;
175 0 next;
176 }
177 0 $i++;
178 0 next;
179 }
180 3813 ▶ if ( defined $quote ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $quote) 4 3809 3813
181 4 ▶ if ( $c eq "\\" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\\") 0 4 4
182 0 $i += 2;
183 0 next;
184 }
185 4 ▶ if ( $c eq $quote ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq $quote) 2 2 4
186 2 $quote = undef;
187 }
188 4 $i++;
189 4 next;
190 }
191 3809 ▶ if ( $c eq '"' or $c eq "'" or $c eq '`' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\"" or $c eq "'" or $c eq "`") 2 3807 3809
Condition66%4/6
$c eq "\"" or $c eq "'" or $c eq "`"
l!l&&r!l&&!r
203807
$c eq "\"" or $c eq "'"
l!l&&r!l&&!r
203807
MC/DC33%1/3
$c eq "\"" or $c eq "'" or $c eq "`"
$c eq "\"" $c eq "'" $c eq "`"
Truth table50%2/4
A or B or C
A= $c eq "\""B= $c eq "'"C= $c eq "`"
ABCresult
1XX1
01X1
0011
0000
192 2 $quote = $c;
193 2 $i++;
194 2 next;
195 }
196 3807 ▶ if ( $c eq '/' and $next eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/" and $next eq "/") 0 3807 3807
Condition33%1/3
$c eq "/" and $next eq "/"
!ll&&!rl&&r
380700
MC/DC0%0/2
$c eq "/" and $next eq "/"
$c eq "/" $next eq "/"
Truth table33%1/3
A and B
A= $c eq "/"B= $next eq "/"
ABresult
0X0
100
111
197 0 $line_comment = 1;
198 0 $i += 2;
199 0 next;
200 }
201 3807 ▶ if ( $c eq '/' and $next eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/" and $next eq "*") 0 3807 3807
Condition33%1/3
$c eq "/" and $next eq "*"
!ll&&!rl&&r
380700
MC/DC0%0/2
$c eq "/" and $next eq "*"
$c eq "/" $next eq "*"
Truth table33%1/3
A and B
A= $c eq "/"B= $next eq "*"
ABresult
0X0
100
111
202 0 $block_comment = 1;
203 0 $i += 2;
204 0 next;
205 }
206 3807 ▶ if ( $c eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "{") 14 3793 3807
207 14 $depth++;
208 14 $i++;
209 14 next;
210 }
211 3793 ▶ if ( $c eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "}") 496 3297 3793
212 496 $depth--;
213 496 ▶ last if $depth == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth == 0 482 14 496
214 14 $i++;
215 14 next;
216 }
217 3297 $i++;
218 }
219 482 ▶ die "Unterminated $kind interpolation at line $line, col $col" if $i >= $len;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $len 0 482 482
220 482 push @parts, { expr => substr( $src, $start, $i - $start ) };
221 482 $i++;
222 482 next;
223 }
224 14191 $text .= $ch;
225 14191 $i++;
226 }
227 707 ▶ push @parts, { text => $text } if $text ne '' or !@parts;
Branch: 1 branch
BranchTrueFalseTotal
if $text ne "" or not @parts 564 143 707
Condition66%2/3
$text ne "" or not @parts
l!l&&r!l&&!r
5640143
MC/DC50%1/2
$text ne "" or not @parts
$text ne "" not @parts
Truth table66%2/3
A or not(B)
A= $text ne ""B= not @parts
ABresult
1X1
011
000
228  
229 707 return \@parts;
230 }
231  
232 378 ▶sub _decode_interpolated_text_parts {
Subroutine _decode_interpolated_text_parts: called CC=13 SCAR=29.9
233 378 my ( $self, $parts, $kind, $line, $col ) = @_;
234  
235 378 for my $part ( @{$parts} ) {
236 1143 ▶ next if !exists $part->{text};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $part->{"text"} 481 662 1143
237 662 my $src = $part->{text};
238 662 my $out = '';
239 662 my $i = 0;
240 662 ▶ while ( $i < length $src ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $src) 10419 661 11080
241 10419 my $c = substr( $src, $i, 1 );
242 10419 ▶ if ( $c eq "\\" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\\") 5 10414 10419
243 5 $i++;
244 5 ▶ die "Unterminated $kind literal at line $line, col $col" if $i >= length $src;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= length $src 0 5 5
245 5 my $e = substr( $src, $i, 1 );
246 5 my %simple = (
247 n => "\n",
248 t => "\t",
249 r => "\r",
250 '"' => '"',
251 "'" => "'",
252 '`' => '`',
253 '/' => '/',
254 '$' => '$',
255 '\\' => '\\',
256 );
257 5 ▶ if ( exists $simple{$e} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $simple{$e}) 2 3 5
258 2 $out .= $simple{$e};
259 2 $i++;
260 2 next;
261 }
262 3 ▶ if ( $e eq 'x' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "x") 3 0 3
263 3 my $hex = substr( $src, $i, 3 );
264 3 ▶ die "Invalid $kind escape at line $line, col $col"
Branch: 1 branch
BranchTrueFalseTotal
unless $hex =~ /\Ax([0-9A-Fa-f]{2})\z/ 1 2 3
265 if $hex !~ /\Ax([0-9A-Fa-f]{2})\z/;
266 2 $out .= chr( hex($1) );
267 2 $i += 3;
268 2 next;
269 }
270 0 ▶ if ( $e eq 'u' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "u") 0 0 0
271 0 my $hex = substr( $src, $i, 5 );
272 0 ▶ die "Invalid $kind escape at line $line, col $col"
Branch: 1 branch
BranchTrueFalseTotal
unless $hex =~ /\Au([0-9A-Fa-f]{4})\z/ 0 0 0
273 if $hex !~ /\Au([0-9A-Fa-f]{4})\z/;
274 0 my $cp = hex($1);
275 0 ▶ die "Invalid $kind escape at line $line, col $col"
Branch: 1 branch
BranchTrueFalseTotal
if $cp >= 55296 and $cp <= 57343 0 0 0
Condition0%0/3
$cp >= 55296 and $cp <= 57343
!ll&&!rl&&r
000
MC/DC0%0/2
$cp >= 55296 and $cp <= 57343
$cp >= 55296 $cp <= 57343
Truth table0%0/3
A and B
A= $cp >= 55296B= $cp <= 57343
ABresult
0X0
100
111
276 if $cp >= 0xD800 and $cp <= 0xDFFF;
277 0 $out .= chr($cp);
278 0 $i += 5;
279 0 next;
280 }
281 0 die "Invalid $kind escape at line $line, col $col";
282 0 next;
283 }
284 10414 $out .= $c;
285 10414 $i++;
286 }
287 661 $part->{text} = $out;
288 }
289  
290 377 return $parts;
291 }
292  
293 1504 ▶sub _can_start_regexp {
Subroutine _can_start_regexp: called CC=25 SCAR=46.1
294 1504 my ( $self ) = @_;
295 1504 my $prev = $self->last_token;
296  
297 1504 ▶ return 1 if !defined $prev;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prev 0 1504 1504
298 1504 ▶ return 0 if $prev->is_NUMBER || $prev->is_STRING || $prev->is_type('BINARY_STRING') || $prev->is_type('TEMPLATE') || $prev->is_BOOL || $prev->is_NULL || $prev->is_IDENT || $prev->is_REGEXP || $prev->is_EMPTY_SET;
Branch: 1 branch
BranchTrueFalseTotal
if $prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING") or $prev->is_type("TEMPLATE") or $prev->is_BOOL or $prev->is_NULL or $prev->is_IDENT or $prev->is_REGEXP or $prev->is_EMPTY_SET 1177 327 1504
Condition70%17/24
$prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING") or $prev->is_type("TEMPLATE") or $prev->is_BOOL or $prev->is_NULL or $prev->is_IDENT or $prev->is_REGEXP or $prev->is_EMPTY_SET
l!l&&r!l&&!r
11770327
$prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING") or $prev->is_type("TEMPLATE") or $prev->is_BOOL or $prev->is_NULL or $prev->is_IDENT or $prev->is_REGEXP
l!l&&r!l&&!r
11770327
$prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING") or $prev->is_type("TEMPLATE") or $prev->is_BOOL or $prev->is_NULL or $prev->is_IDENT
l!l&&r!l&&!r
41173327
$prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING") or $prev->is_type("TEMPLATE") or $prev->is_BOOL or $prev->is_NULL
l!l&&r!l&&!r
401500
$prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING") or $prev->is_type("TEMPLATE") or $prev->is_BOOL
l!l&&r!l&&!r
401500
$prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING") or $prev->is_type("TEMPLATE")
l!l&&r!l&&!r
401500
$prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING")
l!l&&r!l&&!r
401500
$prev->is_NUMBER or $prev->is_STRING
l!l&&r!l&&!r
401500
MC/DC22%2/9
$prev->is_NUMBER or $prev->is_STRING or $prev->is_type("BINARY_STRING") or $prev->is_type("TEMPLATE") or $prev->is_BOOL or $prev->is_NULL or $prev->is_IDENT or $prev->is_REGEXP or $prev->is_EMPTY_SET
$prev->is_NUMBER $prev->is_STRING $prev->is_type("BINARY_STRING") $prev->is_type("TEMPLATE") $prev->is_BOOL $prev->is_NULL $prev->is_IDENT $prev->is_REGEXP $prev->is_EMPTY_SET
Truth table30%3/10
A or B or C or D or E or F or G or H or I
A= $prev->is_NUMBERB= $prev->is_STRINGC= $prev->is_type("BINARY_STRING")D= $prev->is_type("TEMPLATE")E= $prev->is_BOOLF= $prev->is_NULLG= $prev->is_IDENTH= $prev->is_REGEXPI= $prev->is_EMPTY_SET
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
299 327 ▶ if ( $prev->is_KW ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_KW) 0 327 327
300 0 ▶ my $kw = $prev->value // '';
Condition0%0/2
$prev->value // ""
l!l
00
MC/DC0%0/1
$prev->value // ""
$prev->value
Truth table0%0/2
A
A= $prev->value
Aresult
11
00
301 0 ▶ return 0 if $kw eq 'self' || $kw eq 'super' || $kw eq 'true' || $kw eq 'false' || $kw eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $kw eq "self" or $kw eq "super" or $kw eq "true" or $kw eq "false" or $kw eq "null" 0 0 0
Condition0%0/12
$kw eq "self" or $kw eq "super" or $kw eq "true" or $kw eq "false" or $kw eq "null"
l!l&&r!l&&!r
000
$kw eq "self" or $kw eq "super" or $kw eq "true" or $kw eq "false"
l!l&&r!l&&!r
000
$kw eq "self" or $kw eq "super" or $kw eq "true"
l!l&&r!l&&!r
000
$kw eq "self" or $kw eq "super"
l!l&&r!l&&!r
000
MC/DC0%0/5
$kw eq "self" or $kw eq "super" or $kw eq "true" or $kw eq "false" or $kw eq "null"
$kw eq "self" $kw eq "super" $kw eq "true" $kw eq "false" $kw eq "null"
Truth table0%0/6
A or B or C or D or E
A= $kw eq "self"B= $kw eq "super"C= $kw eq "true"D= $kw eq "false"E= $kw eq "null"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
302 }
303 327 ▶ if ( $prev->is_OP ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_OP) 327 0 327
304 327 ▶ my $op = $prev->value // '';
Condition50%1/2
$prev->value // ""
l!l
3270
MC/DC0%0/1
$prev->value // ""
$prev->value
Truth table50%1/2
A
A= $prev->value
Aresult
11
00
305 327 ▶ return 0 if $op eq ')' || $op eq ']' || $op eq '}';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq ")" or $op eq "]" or $op eq "}" 0 327 327
Condition33%2/6
$op eq ")" or $op eq "]" or $op eq "}"
l!l&&r!l&&!r
00327
$op eq ")" or $op eq "]"
l!l&&r!l&&!r
00327
MC/DC0%0/3
$op eq ")" or $op eq "]" or $op eq "}"
$op eq ")" $op eq "]" $op eq "}"
Truth table25%1/4
A or B or C
A= $op eq ")"B= $op eq "]"C= $op eq "}"
ABCresult
1XX1
01X1
0011
0000
306 327 ▶ return 0 if $op eq '++' || $op eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "++" or $op eq "--" 0 327 327
Condition33%1/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
00327
MC/DC0%0/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table33%1/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
307 }
308  
309 327 return 1;
310 }
311  
312 327 ▶sub _read_regexp_literal {
Subroutine _read_regexp_literal: called CC=15 SCAR=27.1
313 327 my ( $self, $line, $col ) = @_;
314  
315 327 $self->_adv(1); # leading /
316 327 my $start = $self->pos;
317 327 my $escaped = 0;
318 327 my $in_class = 0;
319  
320 327 ▶ while ( !$self->_eof ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_eof) 4078 0 4078
321 4078 my $c = $self->_peek(1);
322 4078 ▶ if ( !$escaped and !$in_class and $c eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $escaped || $in_class and $c eq "/") 327 3751 4078
Condition100%6/6
not $escaped || $in_class and $c eq "/"
!ll&&!rl&&r
19701781327
$escaped || $in_class
l!l&&r!l&&!r
19717732108
MC/DC100%3/3
not $escaped || $in_class and $c eq "/"
$escaped $in_class $c eq "/"
Truth table100%4/4
not(A || B) and C
A= $escapedB= $in_classC= $c eq "/"
ABCresult
1XX0
01X0
0000
0011
323 327 my $pattern = substr( $self->src, $start, $self->pos - $start );
324 327 $self->_adv(1);
325 327 my $flags = '';
326 327 ▶ while ( !$self->_eof ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_eof) 344 0 344
327 344 my $flag = $self->_peek(1);
328 344 ▶ last if $flag ne 'i' and $flag ne 'g';
Branch: 1 branch
BranchTrueFalseTotal
if $flag ne "i" and $flag ne "g" 327 17 344
Condition100%3/3
$flag ne "i" and $flag ne "g"
!ll&&!rl&&r
143327
MC/DC100%2/2
$flag ne "i" and $flag ne "g"
$flag ne "i" $flag ne "g"
Truth table100%3/3
A and B
A= $flag ne "i"B= $flag ne "g"
ABresult
0X0
100
111
329 17 ▶ last if index( $flags, $flag ) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($flags, $flag) != -1 0 17 17
330 17 $flags .= $flag;
331 17 $self->_adv(1);
332 }
333  
334 327 my $parts = $self->_split_interpolated_source( $pattern, $line, $col, 'regexp', 1 );
335 327 return $self->_emit( 'REGEXP', { pattern => $pattern, parts => $parts, flags => $flags }, $line, $col );
336 }
337 3751 ▶ if ( !$escaped and $c eq '[' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $escaped and $c eq '[') { } 303 3448 3751
elsif (not $escaped and $c eq ']') { } 303 3342 3645
Condition100%3/3
not $escaped and $c eq "["
!ll&&!rl&&r
1973251303
MC/DC100%2/2
not $escaped and $c eq "["
not $escaped $c eq "["
Truth table100%3/3
not(A) and B
A= not $escapedB= $c eq "["
ABresult
0X0
100
111
338 303 $in_class = 1;
339 }
340 ▶ elsif ( !$escaped and $c eq ']' ) {
Condition100%3/3
not $escaped and $c eq "]"
!ll&&!rl&&r
1972948303
MC/DC100%2/2
not $escaped and $c eq "]"
not $escaped $c eq "]"
Truth table100%3/3
not(A) and B
A= not $escapedB= $c eq "]"
ABresult
0X0
100
111
341 303 $in_class = 0;
342 }
343 3751 ▶ $escaped = !$escaped && $c eq "\\" ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!$escaped && $c eq '\\' ? : 197 3554 3751
Condition100%3/3
not $escaped and $c eq "\\"
!ll&&!rl&&r
1973357197
MC/DC100%2/2
not $escaped and $c eq "\\"
not $escaped $c eq "\\"
Truth table100%3/3
not(A) and B
A= not $escapedB= $c eq "\\"
ABresult
0X0
100
111
344 3751 $self->_adv(1);
345 }
346  
347 0 die "Unterminated regexp literal at line $line, col $col";
348 }
349  
350  
351 601334 ▶sub _skip_shebang_line {
Subroutine _skip_shebang_line: called CC=9 SCAR=22.9
352 601334 my ( $self ) = @_;
353  
354 601334 ▶ return 0 if $self->pos != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pos != 0 599883 1451 601334
355 1451 ▶ return 0 if $self->line != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->line != 1 0 1451 1451
356 1451 ▶ return 0 if $self->col != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->col != 1 0 1451 1451
357 1451 ▶ return 0 if $self->_peek(2) ne '#!';
Branch: 1 branch
BranchTrueFalseTotal
if $self->_peek(2) ne "#!" 1450 1 1451
358  
359 1 ▶ while ( !$self->_eof and $self->_peek(1) ne "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_eof and $self->_peek(1) ne "\n") 19 1 20
Condition66%2/3
not $self->_eof and $self->_peek(1) ne "\n"
!ll&&!rl&&r
0119
MC/DC50%1/2
not $self->_eof and $self->_peek(1) ne "\n"
not $self->_eof $self->_peek(1) ne "\n"
Truth table66%2/3
not(A) and B
A= not $self->_eofB= $self->_peek(1) ne "\n"
ABresult
0X0
100
111
360 19 $self->_adv(1);
361 }
362 1 ▶ $self->_adv(1) if !$self->_eof and $self->_peek(1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if not $self->_eof and $self->_peek(1) eq "\n" 1 0 1
Condition33%1/3
not $self->_eof and $self->_peek(1) eq "\n"
!ll&&!rl&&r
001
MC/DC0%0/2
not $self->_eof and $self->_peek(1) eq "\n"
not $self->_eof $self->_peek(1) eq "\n"
Truth table33%1/3
not(A) and B
A= not $self->_eofB= $self->_peek(1) eq "\n"
ABresult
0X0
100
111
363  
364 1 return 1;
365 }
366  
367 601333 ▶sub _skip_pod_section {
Subroutine _skip_pod_section: called CC=16 SCAR=29.3
368 601333 my ( $self ) = @_;
369  
370 601333 ▶ return 0 if $self->col != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->col != 1 547344 53989 601333
371 53989 ▶ return 0 if $self->_peek(1) ne '=';
Branch: 1 branch
BranchTrueFalseTotal
if $self->_peek(1) ne "=" 53869 120 53989
372  
373 120 my $rest = substr( $self->src, $self->pos );
374 120 ▶ return 0 if $rest !~ /\A=(\w+)/u;
Branch: 1 branch
BranchTrueFalseTotal
unless $rest =~ /\A=(\w+)/u 0 120 120
375  
376 120 my $word = $1;
377 120 ▶ return 0 if $word eq 'cut';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "cut" 0 120 120
378  
379 120 ▶ while ( !$self->_eof and $self->_peek(1) ne "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_eof and $self->_peek(1) ne "\n") 2132 120 2252
Condition66%2/3
not $self->_eof and $self->_peek(1) ne "\n"
!ll&&!rl&&r
01202132
MC/DC50%1/2
not $self->_eof and $self->_peek(1) ne "\n"
not $self->_eof $self->_peek(1) ne "\n"
Truth table66%2/3
not(A) and B
A= not $self->_eofB= $self->_peek(1) ne "\n"
ABresult
0X0
100
111
380 2132 $self->_adv(1);
381 }
382 120 ▶ $self->_adv(1) if !$self->_eof and $self->_peek(1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if not $self->_eof and $self->_peek(1) eq "\n" 120 0 120
Condition33%1/3
not $self->_eof and $self->_peek(1) eq "\n"
!ll&&!rl&&r
00120
MC/DC0%0/2
not $self->_eof and $self->_peek(1) eq "\n"
not $self->_eof $self->_peek(1) eq "\n"
Truth table33%1/3
not(A) and B
A= not $self->_eofB= $self->_peek(1) eq "\n"
ABresult
0X0
100
111
383  
384 120 ▶ while ( !$self->_eof ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_eof) 273081 1 273082
385 273081 my $line = substr( $self->src, $self->pos );
386 273081 ▶ if ( $self->col == 1 and $line =~ /\A=cut(?:\r?\n|\z)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->col == 1 and $line =~ /\A=cut(?:\r?\n|\z)/) 119 272962 273081
Condition100%3/3
$self->col == 1 and $line =~ /\A=cut(?:\r?\n|\z)/
!ll&&!rl&&r
26256910393119
MC/DC100%2/2
$self->col == 1 and $line =~ /\A=cut(?:\r?\n|\z)/
$self->col == 1 $line =~ /\A=cut(?:\r?\n|\z)/
Truth table100%3/3
A and B
A= $self->col == 1B= $line =~ /\A=cut(?:\r?\n|\z)/
ABresult
0X0
100
111
387 119 $self->_adv(4);
388 119 ▶ $self->_adv(1) if !$self->_eof and $self->_peek(1) eq "\r";
Branch: 1 branch
BranchTrueFalseTotal
if not $self->_eof and $self->_peek(1) eq "\r" 0 119 119
Condition33%1/3
not $self->_eof and $self->_peek(1) eq "\r"
!ll&&!rl&&r
01190
MC/DC0%0/2
not $self->_eof and $self->_peek(1) eq "\r"
not $self->_eof $self->_peek(1) eq "\r"
Truth table33%1/3
not(A) and B
A= not $self->_eofB= $self->_peek(1) eq "\r"
ABresult
0X0
100
111
389 119 ▶ $self->_adv(1) if !$self->_eof and $self->_peek(1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if not $self->_eof and $self->_peek(1) eq "\n" 119 0 119
Condition33%1/3
not $self->_eof and $self->_peek(1) eq "\n"
!ll&&!rl&&r
00119
MC/DC0%0/2
not $self->_eof and $self->_peek(1) eq "\n"
not $self->_eof $self->_peek(1) eq "\n"
Truth table33%1/3
not(A) and B
A= not $self->_eofB= $self->_peek(1) eq "\n"
ABresult
0X0
100
111
390  
391 119 last;
392 }
393  
394 272962 $self->_adv(1);
395 }
396  
397 120 return 1;
398 }
399  
400 309824 ▶sub next_token {
Subroutine next_token: called CC=56 SCAR=41.2
Pod documented
401 309824 my ($self) = @_;
402  
403 309824 ▶ while (!$self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_eof) 601334 1293 602627
404 601334 ▶ if ( $self->_skip_shebang_line ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_skip_shebang_line) 1 601333 601334
405 1 next;
406 }
407  
408 601333 ▶ if ( $self->_skip_pod_section ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_skip_pod_section) 120 601213 601333
409 120 next;
410 }
411  
412 601213 my $ch = $self->_peek(1);
413  
414 # whitespace
415 601213 ▶ if ($ch =~ /\s/u) { $self->_adv(1); next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /\s/u) 292629 308584 601213
416  
417 # // comment
418 308584 ▶ if ($self->_peek(2) eq '//') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek(2) eq "//") 35 308549 308584
419 35 ▶ while (!$self->_eof && $self->_peek(1) ne "\n") { $self->_adv(1); }
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_eof and $self->_peek(1) ne "\n") 1719 35 1754
Condition66%2/3
not $self->_eof and $self->_peek(1) ne "\n"
!ll&&!rl&&r
0351719
MC/DC50%1/2
not $self->_eof and $self->_peek(1) ne "\n"
not $self->_eof $self->_peek(1) ne "\n"
Truth table66%2/3
not(A) and B
A= not $self->_eofB= $self->_peek(1) ne "\n"
ABresult
0X0
100
111
420 35 next;
421 }
422  
423 # /* ... */ comment
424 308549 ▶ if ($self->_peek(2) eq '/*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek(2) eq "/*") 18 308531 308549
425 18 $self->_adv(2);
426 18 ▶ while (!$self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_eof) 836 12 848
427 836 ▶ last if $self->_peek(2) eq '*/';
Branch: 1 branch
BranchTrueFalseTotal
if $self->_peek(2) eq "*/" 6 830 836
428 830 $self->_adv(1);
429 }
430 18 ▶ $self->_adv(2) if !$self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_eof 6 12 18
431 18 next;
432 }
433  
434 308531 my ($line, $col) = ($self->line, $self->col);
435  
436 308531 ▶ if ( $ch eq '/' and $self->_can_start_regexp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "/" and $self->_can_start_regexp) 327 308204 308531
Condition100%3/3
$ch eq "/" and $self->_can_start_regexp
!ll&&!rl&&r
3070271177327
MC/DC100%2/2
$ch eq "/" and $self->_can_start_regexp
$ch eq "/" $self->_can_start_regexp
Truth table100%3/3
A and B
A= $ch eq "/"B= $self->_can_start_regexp
ABresult
0X0
100
111
437 327 return $self->_read_regexp_literal( $line, $col );
438 }
439 308204 ▶ if ( $self->_peek(2) eq '_=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek(2) eq "_=") 433 307771 308204
440 433 $self->_adv(2);
441  
442 433 return $self->_emit( 'OP', '_=', $line, $col );
443 }
444  
445 307771 ▶ if ( $ch eq '⊤' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\x{22a4}") 1 307770 307771
446 1 $self->_adv(1);
447  
448 1 return $self->_emit('BOOL', 1, $line, $col);
449 }
450 307770 ▶ if ( $ch eq '⊥' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\x{22a5}") 1 307769 307770
451 1 $self->_adv(1);
452  
453 1 return $self->_emit('BOOL', 0, $line, $col);
454 }
455  
456 # numbers: int/float, radix prefixes, uppercase-E exponent
457 307769 ▶ if ($ch =~ /[0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /[0-9]/) 6690 301079 307769
458 6690 my $rest = substr($self->src, $self->pos);
459 # Radix-prefixed integers (lowercase prefixes only). The
460 # token value is normalised to decimal.
461 6690 ▶ if ($rest =~ /\A(0x[0-9A-Fa-f]+|0b[01]+|0o[0-7]+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A(0x[0-9A-Fa-f]+|0b[01]+|0o[0-7]+)/) 3 6687 6690
462 3 my $lit = $1;
463 3 $self->_adv(length($lit));
464 3 my $digits = $lit;
465 3 $digits =~ s/\A0o/0/;
466 3 return $self->_emit('NUMBER', 0 + oct($digits), $line, $col);
467 }
468 6687 ▶ if ($rest =~ /\A([0-9]+(?:\.[0-9]+)?(?:E[+-]?[0-9]+)?)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A([0-9]+(?:\.[0-9]+)?(?:E[+-]?[0-9]+)?)/) 6687 0 6687
469 6687 my $num = $1;
470 6687 $self->_adv(length($num));
471  
472 6687 return $self->_emit('NUMBER', $num, $line, $col);
473 }
474 }
475  
476 # string "..." and """..."""
477 301079 ▶ if ($ch eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\"") 10997 290082 301079
478 10997 ▶ if ($self->_peek(3) eq '"""') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek(3) eq "\"\"\"") 1 10996 10997
479 1 $self->_adv(3);
480 1 my $start = $self->pos;
481 1 ▶ while (!$self->_eof && $self->_peek(3) ne '"""') { $self->_adv(1); }
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_eof and $self->_peek(3) ne "\"\"\"") 19 1 20
Condition66%2/3
not $self->_eof and $self->_peek(3) ne "\"\"\""
!ll&&!rl&&r
0119
MC/DC50%1/2
not $self->_eof and $self->_peek(3) ne "\"\"\""
not $self->_eof $self->_peek(3) ne "\"\"\""
Truth table66%2/3
not(A) and B
A= not $self->_eofB= $self->_peek(3) ne "\"\"\""
ABresult
0X0
100
111
482 1 ▶ die "Unterminated string literal at line $line, col $col" if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 1 1
483 1 my $val = substr($self->src, $start, $self->pos - $start);
484 1 $self->_adv(3);
485  
486 1 return $self->_emit('STRING', $val, $line, $col);
487 }
488 10996 my $out = $self->_read_single_line_literal( '"', 'string', $line, $col );
489 10982 return $self->_emit('STRING', $out, $line, $col);
490 }
491 290082 ▶ if ( $ch eq "'" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "'") 15 290067 290082
492 15 ▶ if ( $self->_peek(3) eq "'''" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek(3) eq "'''") 0 15 15
493 0 $self->_adv(3);
494 0 my $start = $self->pos;
495 0 ▶ while ( !$self->_eof and $self->_peek(3) ne "'''" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_eof and $self->_peek(3) ne "'''") 0 0 0
Condition0%0/3
not $self->_eof and $self->_peek(3) ne "'''"
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->_eof and $self->_peek(3) ne "'''"
not $self->_eof $self->_peek(3) ne "'''"
Truth table0%0/3
not(A) and B
A= not $self->_eofB= $self->_peek(3) ne "'''"
ABresult
0X0
100
111
496 0 $self->_adv(1);
497 }
498 0 ▶ die "Unterminated binary string literal at line $line, col $col" if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 0 0
499 0 my $val = substr( $self->src, $start, $self->pos - $start );
500 0 $self->_adv(3);
501  
502 0 return $self->_emit( 'BINARY_STRING', $val, $line, $col );
503 }
504 15 my $out = $self->_read_single_line_literal( "'", 'binary string', $line, $col );
505 15 return $self->_emit( 'BINARY_STRING', $out, $line, $col );
506 }
507 290067 ▶ if ( $ch eq '`' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "`") 380 289687 290067
508 380 ▶ if ( $self->_peek(3) eq '```' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek(3) eq "```") 2 378 380
509 2 $self->_adv(3);
510 2 my $start = $self->pos;
511 2 ▶ while ( !$self->_eof and $self->_peek(3) ne '```' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_eof and $self->_peek(3) ne "```") 44 2 46
Condition66%2/3
not $self->_eof and $self->_peek(3) ne "```"
!ll&&!rl&&r
0244
MC/DC50%1/2
not $self->_eof and $self->_peek(3) ne "```"
not $self->_eof $self->_peek(3) ne "```"
Truth table66%2/3
not(A) and B
A= not $self->_eofB= $self->_peek(3) ne "```"
ABresult
0X0
100
111
512 44 $self->_adv(1);
513 }
514 2 ▶ die "Unterminated template literal at line $line, col $col" if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 2 2
515 2 my $src = substr( $self->src, $start, $self->pos - $start );
516 2 $self->_adv(3);
517 2 my $parts = $self->_split_interpolated_source( $src, $line, $col, 'template', 0 );
518  
519 2 return $self->_emit( 'TEMPLATE', $parts, $line, $col );
520 }
521 378 $self->_adv(1);
522 378 my $start = $self->pos;
523 378 ▶ while ( !$self->_eof ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_eof) 15554 0 15554
524 15554 my $c = $self->_peek(1);
525 15554 ▶ last if $c eq '`';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "`" 378 15176 15554
526 15176 ▶ if ( $c eq "\\" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\\") 5 15171 15176
527 5 $self->_adv(1);
528 5 ▶ die "Unterminated template literal at line $line, col $col" if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 5 5
529 }
530 15176 $self->_adv(1);
531 }
532 378 ▶ die "Unterminated template literal at line $line, col $col" if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 378 378
533 378 my $src = substr( $self->src, $start, $self->pos - $start );
534 378 $self->_adv(1);
535 378 my $parts = $self->_split_interpolated_source( $src, $line, $col, 'template', 1 );
536 378 $self->_decode_interpolated_text_parts( $parts, 'template', $line, $col );
537  
538 377 return $self->_emit( 'TEMPLATE', $parts, $line, $col );
539 }
540  
541 # identifiers/keywords (unicode)
542 {
543 289687 my $rest = substr($self->src, $self->pos);
544 289687 ▶ if ($rest =~ /\A(?:([\p{XID_Start}][\p{XID_Continue}_]*)|(_[\p{XID_Continue}_]+))/u) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A(?:([\p{XID_Start}][\p{XID_Continue}_]*)|(_[\p{XID_Continue}_]+))/u) 120185 169502 289687
545 120185 ▶ my $id = defined($1) ? $1 : $2;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 112724 7461 120185
546 120185 $self->_adv(length($id));
547 120185 $id = Zuzu::Util::nfc($id);
548 120185 ▶ if ($id eq 'true' || $id eq '⊤') { return $self->_emit('BOOL', 1, $line, $col); }
Branch: 1 branch
BranchTrueFalseTotal
if ($id eq "true" or $id eq "\x{22a4}") 942 119243 120185
Condition66%2/3
$id eq "true" or $id eq "\x{22a4}"
l!l&&r!l&&!r
9420119243
MC/DC50%1/2
$id eq "true" or $id eq "\x{22a4}"
$id eq "true" $id eq "\x{22a4}"
Truth table66%2/3
A or B
A= $id eq "true"B= $id eq "\x{22a4}"
ABresult
1X1
011
000
549 119243 ▶ if ($id eq 'false' || $id eq '⊥') { return $self->_emit('BOOL', 0, $line, $col); }
Branch: 1 branch
BranchTrueFalseTotal
if ($id eq "false" or $id eq "\x{22a5}") 1034 118209 119243
Condition66%2/3
$id eq "false" or $id eq "\x{22a5}"
l!l&&r!l&&!r
10340118209
MC/DC50%1/2
$id eq "false" or $id eq "\x{22a5}"
$id eq "false" $id eq "\x{22a5}"
Truth table66%2/3
A or B
A= $id eq "false"B= $id eq "\x{22a5}"
ABresult
1X1
011
000
550 118209 ▶ if ($id eq 'null') { return $self->_emit('NULL', undef, $line, $col); }
Branch: 1 branch
BranchTrueFalseTotal
if ($id eq "null") 1828 116381 118209
551  
552 116381 ▶ if ( Zuzu::Util::is_keyword($id) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Zuzu::Util::is_keyword($id)) 37517 78864 116381
553 37517 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /\A(?:and|or|xor|xnor|nand|nor|onlyif|butnot)\z/ and $self->_peek(1) eq "?") 31 37486 37517
Condition100%3/3
$id =~ /\A(?:and|or|xor|xnor|nand|nor|onlyif|butnot)\z/ and $self->_peek(1) eq "?"
!ll&&!rl&&r
35783170331
MC/DC100%2/2
$id =~ /\A(?:and|or|xor|xnor|nand|nor|onlyif|butnot)\z/ and $self->_peek(1) eq "?"
$id =~ /\A(?:and|or|xor|xnor|nand|nor|onlyif|butnot)\z/ $self->_peek(1) eq "?"
Truth table100%3/3
A and B
A= $id =~ /\A(?:and|or|xor|xnor|nand|nor|onlyif|butnot)\z/B= $self->_peek(1) eq "?"
ABresult
0X0
100
111
554 $id =~ /\A(?:and|or|xor|xnor|nand|nor|onlyif|butnot)\z/
555 and $self->_peek(1) eq '?'
556 ) {
557 31 $self->_adv(1);
558 31 $id .= '?';
559 }
560  
561 37517 return $self->_emit('KW', $id, $line, $col);
562 }
563  
564 78864 return $self->_emit('IDENT', $id, $line, $col);
565 }
566 }
567  
568 169502 ▶ if ( $ch eq '∅' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\x{2205}") 4 169498 169502
569 4 $self->_adv(1);
570  
571 4 return $self->_emit('EMPTY_SET', '∅', $line, $col);
572 }
573  
574 169498 ▶ if ( $self->_peek(2) eq '^^' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek(2) eq "^^") 68 169430 169498
575 68 $self->_adv(2);
576  
577 68 return $self->_emit('IDENT', '^^', $line, $col);
578 }
579  
580 # operators / punct (try longest first)
581 169430 my @ops = (
582 '<<<', '>>>',
583 '{{', '}}',
584 '<=>', '**', '==', '!=', '<=', '>=', ':=', '~=', '+=', '-=', '*=', '/=',
585 '×=', '÷=', '**=', '_=', '?:=', '@@', '@?', '++', '--', '->', '→', '?:', '...',
586 '|>', '<|',
587 '⊂⊃',
588 '<<', '>>', '«', '»',
589 '{', '}', '(', ')', '[', ']', ',', ';', ':', '.', '?', '_', '@',
590 '+', '-', '*', '/', '<', '>', '=', '!', '~', '&', '|', '^',
591 '⌊', '⌋', '⌈', '⌉',
592 );
593 # plus unicode aliases you mentioned (not exhaustive)
594 169430 push @ops, qw( × ÷ ≠ ≤ ≥ ≡ ≢ ≶ ≷ ⋀ ⋁ ⊻ ⊼ ⊽ ↔ ⊨ ⊭ ¬ ∈ ∉ ⋃ ⋂ ⊂ ⊃ ∖ );
595 169430 push @ops, '\\';
596 169430 push @ops, qw(▷ ◁ ∣ ∤ );
597 # sort by length desc for greedy match
598 169430 @ops = sort { length($b) <=> length($a) } @ops;
599  
600 169430 for my $op (@ops) {
601 6827492 ▶ if ($self->_peek(length($op)) eq $op) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek(length $op) eq $op) 169391 6658101 6827492
602 169391 $self->_adv(length($op));
603 169391 ▶ if ( $op =~ /\A(?:⋀|⋁|⊻|↔|⊼|⊽|⊨|⊭)\z/ and $self->_peek(1) eq '?' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /\A(?:\x{22c0}|\x{22c1}|\x{22bb}|\x{2194}|\x{22bc}|\x{22bd}|\x{22a8}|\x{22ad})\z/ and $self->_peek(1) eq "?") 0 169391 169391
Condition66%2/3
$op =~ /\A(?:\x{22c0}|\x{22c1}|\x{22bb}|\x{2194}|\x{22bc}|\x{22bd}|\x{22a8}|\x{22ad})\z/ and $self->_peek(1) eq "?"
!ll&&!rl&&r
16938920
MC/DC0%0/2
$op =~ /\A(?:\x{22c0}|\x{22c1}|\x{22bb}|\x{2194}|\x{22bc}|\x{22bd}|\x{22a8}|\x{22ad})\z/ and $self->_peek(1) eq "?"
$op =~ /\A(?:\x{22c0}|\x{22c1}|\x{22bb}|\x{2194}|\x{22bc}|\x{22bd}|\x{22a8}|\x{22ad})\z/ $self->_peek(1) eq "?"
Truth table66%2/3
A and B
A= $op =~ /\A(?:\x{22c0}|\x{22c1}|\x{22bb}|\x{2194}|\x{22bc}|\x{22bd}|\x{22a8}|\x{22ad})\z/B= $self->_peek(1) eq "?"
ABresult
0X0
100
111
604 0 $self->_adv(1);
605 0 $op .= '?';
606 }
607  
608 169391 return $self->_emit('OP', $op, $line, $col);
609 }
610 }
611  
612 # single char fallback punct/op
613 39 $self->_adv(1);
614  
615 39 return $self->_emit('OP', $ch, $line, $col);
616 }
617  
618 1293 return Zuzu::Token->new(type => 'EOF', value => undef, file => $self->filename, line => $self->line, col => $self->col);
619 }
620  
621 =pod
622  
623 =head1 NAME
624  
625 Zuzu::Lexer - lexer that tokenizes ZuzuScript source text
626  
627 =head1 DESCRIPTION
628  
629 Scans normalized source text and emits C<Zuzu::Token> objects with source location metadata.
630  
631 =head1 INHERITANCE
632  
633 Inherits from C<Moo::Object>.
634  
635 =head1 ROLES
636  
637 None.
638  
639 =head1 ATTRIBUTES
640  
641 =head2 src
642  
643 Type: B<Str>.
644  
645 Unicode-normalized source text being lexed.
646  
647 =head2 filename
648  
649 Type: B<Maybe[Str]>.
650  
651 Filename attached to generated tokens and parser errors.
652  
653 =head2 pos
654  
655 Type: B<Int>.
656  
657 Current character offset in C<src>.
658  
659 =head2 line
660  
661 Type: B<Int>.
662  
663 1-based source line number used for diagnostics.
664  
665 =head2 col
666  
667 Type: B<Int>.
668  
669 1-based source column number used for diagnostics.
670  
671 =head1 METHODS
672  
673 =head2 new
674  
675 Constructs and returns a new instance of this class.
676  
677 =head2 next_token
678  
679 Consumes input and returns the next C<Zuzu::Token>.
680  
681 =head1 SEE ALSO
682  
683 Subclasses: none in this distribution.
684  
685 =head1 COPYRIGHT AND LICENCE
686  
687 B<< Zuzu::Lexer >> is copyright Toby Inkster.
688  
689 It is free software; you may redistribute it and/or modify it under
690 the terms of either the Artistic License 1.0 or the GNU General Public
691 License version 2.
692  
693 =cut
694  
695 78 1;
« blib/lib/Zuzu/Parser/_Impl.pm ↑ Summary lib/Zuzu/CLI.pm »