UDC/Grammar.pm

filter: Statementstmt 74.1% 69 / 93 Branchbran 68.3% 41 / 60 Conditioncond 45.1% 14 / 31 MC/DCmcdc 20.0% 4 / 20 Subroutinesub 77.2% 17 / 22 Podpod 0.0% 0 / 13 totaltotal 60.6% 145 / 239 CC 42 SCAR 24.5
CC
42
Cov
67%
can_follow_primary
24.9
can_be_standalone
20.0
can_precede_number
14.3
CRAP 11.6
« UDC/Parser.pm ↑ Summary UDC.pm »
1 package Business::UDC::Grammar;
2  
3 12 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use List::Util 1.33 qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 Readonly::Array our @EXPORT_OK => qw(can_be_standalone can_follow_operator
11 can_follow_primary can_follow_term can_precede_number
12 can_start_expression_with describe_token_type group_subtype is_modifier_token
13 is_operator_token is_primary_token is_valid_operator operator_info);
14 12 Readonly::Hash our %DESC => (
15 ALPHA_SPEC => 'direct alphabetical specification',
16 APOS_AUX => 'apostrophe auxiliary',
17 AUX_DOT => 'dot auxiliary',
18 AUX_GROUP => 'parenthesized auxiliary',
19 AUX_LANG => 'language auxiliary',
20 AUX_TIME => 'quoted time auxiliary',
21 FORM => 'special auxiliary subdivision',
22 LBRACK => 'left subgroup bracket',
23 NUMBER => 'main UDC number',
24 OP => 'operator',
25 PARTIAL_FORM => 'partial form for range shorthand',
26 PARTIAL_NUMBER => 'partial number for range shorthand',
27 RBRACK => 'right subgroup bracket',
28 WHITESPACE => 'whitespace',
29 );
30 12 Readonly::Hash our %TOKEN_RULES => (
31 ALPHA_SPEC => {
32 standalone => 0,
33 primary => 0,
34 modifier => 1,
35 },
36 APOS_AUX => {
37 standalone => 0,
38 primary => 0,
39 modifier => 1,
40 },
41 AUX_DOT => {
42 standalone => 0,
43 primary => 0,
44 modifier => 1,
45 },
46 AUX_GROUP => {
47 standalone => 1,
48 primary => 1,
49 modifier => 1,
50 },
51 AUX_LANG => {
52 standalone => 1,
53 primary => 1,
54 modifier => 1,
55 },
56 AUX_TIME => {
57 standalone => 1,
58 primary => 1,
59 modifier => 1,
60 },
61 FORM => {
62 standalone => 0,
63 primary => 0,
64 modifier => 1,
65 },
66 NUMBER => {
67 standalone => 1,
68 primary => 1,
69 modifier => 0,
70 },
71 OP => {
72 standalone => 0,
73 primary => 0,
74 modifier => 0,
75 },
76 PARTIAL_FORM => {
77 standalone => 0,
78 primary => 0,
79 modifier => 0,
80 },
81 PARTIAL_NUMBER => {
82 standalone => 0,
83 primary => 0,
84 modifier => 0,
85 },
86 );
87 12 Readonly::Hash our %OPERATORS => (
88 '+' => {
89 name => 'addition',
90 precedence => 10,
91 associativity => 'left',
92 right_types => [qw(AUX_GROUP AUX_LANG AUX_TIME NUMBER)],
93 },
94 ':' => {
95 name => 'relation',
96 precedence => 20,
97 associativity => 'left',
98 right_types => [qw(AUX_GROUP AUX_LANG AUX_TIME NUMBER)],
99 },
100 '::' => {
101 name => 'fixed_relation',
102 precedence => 20,
103 associativity => 'left',
104 right_types => [qw(AUX_GROUP AUX_LANG AUX_TIME NUMBER)],
105 },
106 '/' => {
107 name => 'consecutive_extension',
108 precedence => 15,
109 associativity => 'left',
110 right_types => [qw(APOS_AUX AUX_DOT AUX_GROUP AUX_LANG AUX_TIME FORM NUMBER)],
111 },
112 );
113  
114 12 our $VERSION = 0.12;
115  
116 0 ▶sub can_be_standalone {
Subroutine can_be_standalone: not called CC=4 SCAR=30.0
Pod undocumented
117 0 my $type = shift;
118  
119 0 ▶ if (! $TOKEN_RULES{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Business::UDC::Grammar::TOKEN_RULES{$type}) 0 0 0
120 0 return 0;
121 }
122  
123 0 ▶ if ($type eq 'AUX_GROUP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "AUX_GROUP") 0 0 0
124 0 return 1;
125 }
126  
127 0 ▶ return $TOKEN_RULES{$type}{'standalone'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$Business::UDC::Grammar::TOKEN_RULES{$type}{'standalone'} ? : 0 0 0
128 }
129  
130 33 ▶sub can_follow_operator {
Subroutine can_follow_operator: called CC=4 SCAR=14.3
Pod undocumented
131 33 my ($op, $type) = @_;
132  
133 33 ▶ if (! is_valid_operator($op)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_valid_operator($op)) 0 33 33
134 0 return 0;
135 }
136  
137 33 ▶ my %allowed = map { $_ => 1 } @{$OPERATORS{$op}{'right_types'} || []};
Condition50%1/2
$Business::UDC::Grammar::OPERATORS{$op}{'right_types'} || []
l!l
330
MC/DC0%0/1
$Business::UDC::Grammar::OPERATORS{$op}{'right_types'} || []
$Business::UDC::Grammar::OPERATORS{$op}{'right_types'}
Truth table50%1/2
A
A= $Business::UDC::Grammar::OPERATORS{$op}{'right_types'}
Aresult
11
00
138  
139 33 ▶ return $allowed{$type} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$allowed{$type} ? : 31 2 33
140 }
141  
142 108 ▶sub can_follow_primary {
Subroutine can_follow_primary: called CC=18 SCAR=32.1
Pod undocumented
143 108 my ($type, $value, $primary_type, $primary_value) = @_;
144  
145 108 ▶ if (! is_modifier_token($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_modifier_token($type)) 43 65 108
146 43 return 0;
147 }
148  
149 65 ▶ if ($type eq 'FORM') {
Branch: 7 branches
BranchTrueFalseTotal
if ($type eq 'FORM') { } 14 51 65
elsif ($type eq 'AUX_DOT') { } 3 48 51
elsif ($type eq 'AUX_GROUP') { } 20 28 48
elsif ($type eq 'AUX_TIME') { } 5 23 28
elsif ($type eq 'AUX_LANG') { } 1 22 23
elsif ($type eq 'ALPHA_SPEC') { } 14 8 22
elsif ($type eq 'APOS_AUX') { } 8 0 8
150 14 ▶ if (defined $primary_type
Branch: 1 branch
BranchTrueFalseTotal
if (defined $primary_type and &any(sub { $primary_type eq $_; } , "ALPHA_SPEC", "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")) 14 0 14
Condition33%1/3
defined $primary_type and &any(sub { $primary_type eq $_; } , "ALPHA_SPEC", "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $primary_type and &any(sub { $primary_type eq $_; } , "ALPHA_SPEC", "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
defined $primary_type &any(sub { $primary_type eq $_; } , "ALPHA_SPEC", "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
Truth table33%1/3
A and B
A= defined $primary_typeB= &any(sub { $primary_type eq $_; } , "ALPHA_SPEC", "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
ABresult
0X0
100
111
151 78 ▶ && any { $primary_type eq $_ } qw(ALPHA_SPEC APOS_AUX AUX_DOT AUX_GROUP AUX_LANG AUX_TIME FORM NUMBER SUBGROUP)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
152  
153 14 return 1;
154 }
155 0 return 0;
156 } elsif ($type eq 'AUX_DOT') {
157 3 ▶ if (defined $primary_type
Branch: 1 branch
BranchTrueFalseTotal
if (defined $primary_type and &any(sub { $primary_type eq $_; } , "NUMBER", "AUX_GROUP", "SUBGROUP")) 3 0 3
Condition33%1/3
defined $primary_type and &any(sub { $primary_type eq $_; } , "NUMBER", "AUX_GROUP", "SUBGROUP")
!ll&&!rl&&r
003
MC/DC0%0/2
defined $primary_type and &any(sub { $primary_type eq $_; } , "NUMBER", "AUX_GROUP", "SUBGROUP")
defined $primary_type &any(sub { $primary_type eq $_; } , "NUMBER", "AUX_GROUP", "SUBGROUP")
Truth table33%1/3
A and B
A= defined $primary_typeB= &any(sub { $primary_type eq $_; } , "NUMBER", "AUX_GROUP", "SUBGROUP")
ABresult
0X0
100
111
158 7 ▶ && any { $primary_type eq $_ } qw(NUMBER AUX_GROUP SUBGROUP)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
159  
160 3 return 1;
161 }
162 0 return 0;
163 } elsif ($type eq 'AUX_GROUP') {
164 20 my $subtype = group_subtype($value);
165 20 ▶ if ($subtype eq 'AUX_FORM') {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtype eq "AUX_FORM") 5 15 20
166 5 return 1;
167 }
168  
169 # XXX
170 15 return 1;
171 } elsif ($type eq 'AUX_TIME') {
172 5 return 1;
173 } elsif ($type eq 'AUX_LANG') {
174 1 return 1;
175 } elsif ($type eq 'ALPHA_SPEC') {
176 14 ▶ if (defined $primary_type
Branch: 1 branch
BranchTrueFalseTotal
if (defined $primary_type and &any(sub { $primary_type eq $_; } , "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")) 14 0 14
Condition33%1/3
defined $primary_type and &any(sub { $primary_type eq $_; } , "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $primary_type and &any(sub { $primary_type eq $_; } , "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
defined $primary_type &any(sub { $primary_type eq $_; } , "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
Truth table33%1/3
A and B
A= defined $primary_typeB= &any(sub { $primary_type eq $_; } , "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
ABresult
0X0
100
111
177 59 ▶ && any { $primary_type eq $_ } qw(AUX_GROUP AUX_LANG AUX_TIME FORM NUMBER SUBGROUP)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
178  
179 14 return 1;
180 }
181 0 return 0;
182 } elsif ($type eq 'APOS_AUX') {
183 8 ▶ if (defined $primary_type
Branch: 1 branch
BranchTrueFalseTotal
if (defined $primary_type and &any(sub { $primary_type eq $_; } , "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")) 8 0 8
Condition33%1/3
defined $primary_type and &any(sub { $primary_type eq $_; } , "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
!ll&&!rl&&r
008
MC/DC0%0/2
defined $primary_type and &any(sub { $primary_type eq $_; } , "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
defined $primary_type &any(sub { $primary_type eq $_; } , "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
Truth table33%1/3
A and B
A= defined $primary_typeB= &any(sub { $primary_type eq $_; } , "APOS_AUX", "AUX_DOT", "AUX_GROUP", "AUX_LANG", "AUX_TIME", "FORM", "NUMBER", "SUBGROUP")
ABresult
0X0
100
111
184 46 ▶ && any { $primary_type eq $_ } qw(APOS_AUX AUX_DOT AUX_GROUP AUX_LANG AUX_TIME FORM NUMBER SUBGROUP)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
185  
186 8 return 1;
187 }
188 0 return 0;
189 }
190  
191 0 return 0;
192 }
193  
194 0 ▶sub can_follow_term {
Subroutine can_follow_term: not called CC=1 SCAR=6.9
Pod undocumented
195 0 my $type = shift;
196  
197 0 return is_operator_token($type);
198 }
199  
200 4 ▶sub can_precede_number {
Subroutine can_precede_number: called CC=8 SCAR=26.6
Pod undocumented
201 4 my ($type, $value) = @_;
202  
203 4 ▶ return 0 unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 4 4
204  
205 4 ▶ if ($type eq 'SUBGROUP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "SUBGROUP") 1 3 4
206 1 return 1;
207 }
208  
209 3 ▶ if ($type eq 'AUX_GROUP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "AUX_GROUP") 3 0 3
210 3 my $subtype = group_subtype($value);
211 3 ▶ return $subtype eq 'AUX_FORM' || $subtype eq 'AUX_OTHER' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$subtype eq 'AUX_FORM' || $subtype eq 'AUX_OTHER' ? : 3 0 3
Condition66%2/3
$subtype eq "AUX_FORM" or $subtype eq "AUX_OTHER"
l!l&&r!l&&!r
210
MC/DC0%0/2
$subtype eq "AUX_FORM" or $subtype eq "AUX_OTHER"
$subtype eq "AUX_FORM" $subtype eq "AUX_OTHER"
Truth table66%2/3
A or B
A= $subtype eq "AUX_FORM"B= $subtype eq "AUX_OTHER"
ABresult
1X1
011
000
212 }
213  
214 0 ▶ if ($type eq 'AUX_TIME' || $type eq 'AUX_LANG') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "AUX_TIME" or $type eq "AUX_LANG") 0 0 0
Condition0%0/3
$type eq "AUX_TIME" or $type eq "AUX_LANG"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "AUX_TIME" or $type eq "AUX_LANG"
$type eq "AUX_TIME" $type eq "AUX_LANG"
Truth table0%0/3
A or B
A= $type eq "AUX_TIME"B= $type eq "AUX_LANG"
ABresult
1X1
011
000
215 0 return 0;
216 }
217  
218 0 return 0;
219 }
220  
221 0 ▶sub can_start_expression_with {
Subroutine can_start_expression_with: not called CC=1 SCAR=6.9
Pod undocumented
222 0 my $type = shift;
223  
224 0 return can_be_standalone($type);
225 }
226  
227 0 ▶sub describe_token_type {
Subroutine describe_token_type: not called CC=2 SCAR=17.9
Pod undocumented
228 0 my $type = shift;
229  
230 0 ▶ return $DESC{$type} || 'unknown token';
Condition0%0/2
$Business::UDC::Grammar::DESC{$type} || 'unknown token'
l!l
00
MC/DC0%0/1
$Business::UDC::Grammar::DESC{$type} || 'unknown token'
$Business::UDC::Grammar::DESC{$type}
Truth table0%0/2
A
A= $Business::UDC::Grammar::DESC{$type}
Aresult
11
00
231 }
232  
233 23 ▶sub group_subtype {
Subroutine group_subtype: called CC=4 SCAR=14.0
Pod undocumented
234 23 my $value = shift;
235  
236 23 ▶ if (! defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 23 23
237 0 return 'UNKNOWN';
238 }
239  
240 # Common auxiliaries of form: (0...)
241 23 ▶ return 'AUX_FORM' if $value =~ /^\(0(?:[^)]*)\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^\(0(?:[^)]*)\)$/ 7 16 23
242  
243 # Place and other special auxiliaries typically begin with non-zero digit
244 16 ▶ return 'AUX_OTHER' if $value =~ /^\([1-9][^)]*\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^\([1-9][^)]*\)$/ 15 1 16
245  
246 1 return 'UNKNOWN';
247 }
248  
249 108 ▶sub is_modifier_token {
Subroutine is_modifier_token: called CC=3 SCAR=11.0
Pod undocumented
250 108 my $type = shift;
251  
252 108 ▶ return ($TOKEN_RULES{$type} && $TOKEN_RULES{$type}{'modifier'}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$Business::UDC::Grammar::TOKEN_RULES{$type} && $Business::UDC::Grammar::TOKEN_RULES{$type}{'modifier'} ? : 65 43 108
Condition100%3/3
$Business::UDC::Grammar::TOKEN_RULES{$type} and $Business::UDC::Grammar::TOKEN_RULES{$type}{"modifier"}
!ll&&!rl&&r
53865
MC/DC100%2/2
$Business::UDC::Grammar::TOKEN_RULES{$type} and $Business::UDC::Grammar::TOKEN_RULES{$type}{"modifier"}
$Business::UDC::Grammar::TOKEN_RULES{$type} $Business::UDC::Grammar::TOKEN_RULES{$type}{"modifier"}
Truth table100%3/3
A and B
A= $Business::UDC::Grammar::TOKEN_RULES{$type}B= $Business::UDC::Grammar::TOKEN_RULES{$type}{"modifier"}
ABresult
0X0
100
111
253 }
254  
255 44 ▶sub is_operator_token {
Subroutine is_operator_token: called CC=3 SCAR=11.1
Pod undocumented
256 44 my $type = shift;
257  
258 44 ▶ return (defined $type && $type eq 'OP') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $type && $type eq 'OP' ? : 35 9 44
Condition66%2/3
defined $type and $type eq "OP"
!ll&&!rl&&r
0935
MC/DC50%1/2
defined $type and $type eq "OP"
defined $type $type eq "OP"
Truth table66%2/3
A and B
A= defined $typeB= $type eq "OP"
ABresult
0X0
100
111
259 }
260  
261 95 ▶sub is_primary_token {
Subroutine is_primary_token: called CC=3 SCAR=11.1
Pod undocumented
262 95 my $type = shift;
263  
264 95 ▶ return ($TOKEN_RULES{$type} && $TOKEN_RULES{$type}{'primary'}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$Business::UDC::Grammar::TOKEN_RULES{$type} && $Business::UDC::Grammar::TOKEN_RULES{$type}{'primary'} ? : 85 10 95
Condition66%2/3
$Business::UDC::Grammar::TOKEN_RULES{$type} and $Business::UDC::Grammar::TOKEN_RULES{$type}{"primary"}
!ll&&!rl&&r
01085
MC/DC50%1/2
$Business::UDC::Grammar::TOKEN_RULES{$type} and $Business::UDC::Grammar::TOKEN_RULES{$type}{"primary"}
$Business::UDC::Grammar::TOKEN_RULES{$type} $Business::UDC::Grammar::TOKEN_RULES{$type}{"primary"}
Truth table66%2/3
A and B
A= $Business::UDC::Grammar::TOKEN_RULES{$type}B= $Business::UDC::Grammar::TOKEN_RULES{$type}{"primary"}
ABresult
0X0
100
111
265 }
266  
267 68 ▶sub is_valid_operator {
Subroutine is_valid_operator: called CC=2 SCAR=7.2
Pod undocumented
268 68 my $op = shift;
269  
270 68 ▶ return exists $OPERATORS{$op} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $Business::UDC::Grammar::OPERATORS{$op} ? : 68 0 68
271 }
272  
273 0 ▶sub operator_info {
Subroutine operator_info: not called CC=1 SCAR=6.9
Pod undocumented
274 0 my $op = shift;
275  
276 0 return $OPERATORS{$op};
277 }
278  
279 12 1;
280  
281 __END__
« UDC/Parser.pm ↑ Summary UDC.pm »