| 1 | package Zuzu::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 78 | ▶ | use feature qw(state); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 78 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 78 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 78 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 78 | our $VERSION = '0.007002'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 78 | ▶ | use Unicode::Normalize qw(NFC); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 78 | ▶ | use Zuzu::Value::Equality qw(equality_type); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 121636 | ▶ | sub nfc { NFC($_[0] // '') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nfc: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
$_[0] // ""
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub is_word_ident { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_word_ident: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | $s = nfc($s); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | return 0 if $s eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Unicode "word" chars, but must not start with digit. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | return ($s =~ /\A(?!\p{Nd})[\p{XID_Start}_][\p{XID_Continue}_]*\z/u) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 131231 | ▶ | sub is_keyword { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_keyword: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 131231 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 131231 | state $kw = { map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||
| 30 | let const function method static class trait extends with but | ||||||||||||||||||||||||||||||||||||||||||
| 31 | if else unless while for in return next last switch case default continue | ||||||||||||||||||||||||||||||||||||||||||
| 32 | true false null | ||||||||||||||||||||||||||||||||||||||||||
| 33 | and or xor nand nor xnor onlyif butnot not | ||||||||||||||||||||||||||||||||||||||||||
| 34 | eq ne gt ge lt le cmp eqi nei gti gei lti lei cmpi | ||||||||||||||||||||||||||||||||||||||||||
| 35 | mod abs sqrt floor ceil round int length uc lc typeof instanceof does can | ||||||||||||||||||||||||||||||||||||||||||
| 36 | union intersection subsetof supersetof equivalentof divides | ||||||||||||||||||||||||||||||||||||||||||
| 37 | from import as | ||||||||||||||||||||||||||||||||||||||||||
| 38 | try catch throw die do warn say print debug assert | ||||||||||||||||||||||||||||||||||||||||||
| 39 | new self super fn | ||||||||||||||||||||||||||||||||||||||||||
| 40 | async await spawn | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ) }; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 131231 | ▶ | return $kw->{$s} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | sub boolify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
boolify: called CC=10 SCAR=36.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | return 0 if !defined $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | return 0 if ref($v) && $v->can('is_truthy') && !$v->is_truthy; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $v and $v->can("is_truthy") and not $v->is_truthy
ref $v and $v->can("is_truthy")
MC/DC0%0/3
ref $v and $v->can("is_truthy") and not $v->is_truthy
ref $v
$v->can("is_truthy")
not $v->is_truthy
Truth table25%1/4
A and B and not(C)
A= ref $vB= $v->can("is_truthy")C= not $v->is_truthy
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | if ( !ref($v) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return 0 if equality_type($v) eq 'Number' && 0 + $v == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
equality_type($v) eq "Number" and 0 + $v == 0
MC/DC0%0/2
equality_type($v) eq "Number" and 0 + $v == 0
equality_type($v) eq "Number"
0 + $v == 0
Truth table0%0/3
A and B
A= equality_type($v) eq "Number"B= 0 + $v == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return 0 if equality_type($v) eq 'String' && $v eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
equality_type($v) eq "String" and $v eq ""
MC/DC0%0/2
equality_type($v) eq "String" and $v eq ""
equality_type($v) eq "String"
$v eq ""
Truth table0%0/3
A and B
A= equality_type($v) eq "String"B= $v eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | Zuzu::Util - utility functions shared by parser and runtime | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | Provides shared predicates and helpers for keyword checks, Unicode normalization, and truthiness/coercion. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =head2 nfc | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | Executes C<nfc> for this module. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | =head2 is_word_ident | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | Executes C<is_word_ident> for this module. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =head2 is_keyword | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | Executes C<is_keyword> for this module. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =head2 boolify | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | Executes C<boolify> for this module. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | B<< Zuzu::Util >> is copyright Toby Inkster. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | It is free software; you may redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 94 | the terms of either the Artistic License 1.0 or the GNU General Public | ||||||||||||||||||||||||||||||||||||||||||
| 95 | License version 2. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 78 | 1; | |||||||||||||||||||||||||||||||||||||||||