R3/SLG.pm

filter: Statementstmt 83.1% 795 / 956 Branchbran 65.8% 241 / 366 Conditioncond 58.2% 39 / 67 MC/DCmcdc 30.7% 12 / 39 Subroutinesub 87.0% 67 / 77 Podpod 0.0% 0 / 1 totaltotal 76.6% 1154 / 1506 CC 224 SCAR 42.3
CC
224
Cov
77%
registrations_find
168.0
resolve_action
54.8
registrations_set
39.0
CRAP 69.0
↑ Summary R3/Glade.pm »
1 # Marpa::R3 is Copyright (C) 2018, Jeffrey Kegler.
2 #
3 # This module is free software; you can redistribute it and/or modify it
4 # under the same terms as Perl 5.10.1. For more details, see the full text
5 # of the licenses in the directory LICENSES.
6 #
7 # This program is distributed in the hope that it will be
8 # useful, but it is provided "as is" and without any express
9 # or implied warranties. For details, see the full text of
10 # of the licenses in the directory LICENSES.
11  
12 package Marpa::R3::Grammar;
13  
14 104 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 104 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 104 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 104 ▶use vars qw($VERSION $STRING_VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 104 $VERSION = '4.001_053';
20 104 $STRING_VERSION = $VERSION;
21 ## no critic(BuiltinFunctions::ProhibitStringyEval)
22 104 $VERSION = eval $VERSION;
23 ## use critic
24  
25 package Marpa::R3::Internal_G;
26  
27 104 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 104 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # names of packages for strings
31 104 our $PACKAGE = 'Marpa::R3::Grammar';
32  
33 # The bare mininum Scanless grammer, suitable as a base
34 # for both metagrammar and user grammars.
35 sub pre_construct {
36 393 ▶ my ($class) = @_;
Subroutine pre_construct: called CC=1 SCAR=0.0
37 393 my $pre_slg = bless [], $class;
38 393 $pre_slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE] = \*STDERR;
39 393 $pre_slg->[Marpa::R3::Internal_G::CONSTANTS] = [];
40  
41 393 my $lua = Marpa::R3::Lua->new();
42 393 $pre_slg->[Marpa::R3::Internal_G::L] = $lua;
43  
44 393 my ($regix) = $lua->call_by_tag (-1,
45 ('@' .__FILE__ . ':' . __LINE__),
46 <<'END_OF_LUA', '');
47 local slg = _M.slg_new()
48 return slg.regix
49 END_OF_LUA
50  
51 393 $pre_slg->[Marpa::R3::Internal_G::REGIX] = $regix;
52 393 return $pre_slg;
53 }
54  
55 sub Marpa::R3::Internal::meta_grammar {
56  
57 102 ▶ my $meta_slg = pre_construct('Marpa::R3::Grammar');
Subroutine meta_grammar: called CC=1 SCAR=0.0
Pod undocumented
58  
59 102 state $hashed_metag = Marpa::R3::Internal::MetaG::hashed_grammar();
60 102 $meta_slg->[Marpa::R3::Internal_G::BLESS_PACKAGE] =
61 'Marpa::R3::Internal::MetaAST_Nodes';
62 102 Marpa::R3::Internal_G::hash_to_runtime( $meta_slg, $hashed_metag );
63 102 my $registrations = registrations_find($meta_slg );
64 102 registrations_set($meta_slg, $registrations );
65  
66 102 return $meta_slg;
67  
68 } ## end sub Marpa::R3::Internal::meta_grammar
69  
70 sub Marpa::R3::Grammar::new {
71 291 ▶ my ( $class, @hash_ref_args ) = @_;
Subroutine new: called CC=2 SCAR=6.9
72  
73 291 my $slg = pre_construct($class);
74  
75 291 my ( $flat_args, $error_message ) =
76 Marpa::R3::flatten_hash_args( \@hash_ref_args );
77 291 ▶ Marpa::R3::exception( sprintf $error_message, '$slg->new' )
Branch: 1 branch
BranchTrueFalseTotal
unless $flat_args 0 291 291
78 if not $flat_args;
79  
80 291 my $p_dsl = Marpa::R3::Internal_G::set( $slg, $flat_args );
81 291 my $ast = Marpa::R3::Internal::MetaAST->new($p_dsl);
82 288 my $hashed_ast = $ast->ast_to_hash($p_dsl);
83 275 Marpa::R3::Internal_G::hash_to_runtime( $slg, $hashed_ast);
84 270 my $registrations = registrations_find($slg );
85 269 registrations_set($slg, $registrations );
86 269 return $slg;
87 }
88  
89 sub Marpa::R3::Grammar::DESTROY {
90 # say STDERR "In Marpa::R3::Grammar::DESTROY before test";
91 271 ▶ my $slg = shift;
Subroutine DESTROY: called CC=2 SCAR=7.0
92 271 my $lua = $slg->[Marpa::R3::Internal_G::L];
93  
94 # If we are destroying the Perl interpreter, then all the Marpa
95 # objects will be destroyed, including Marpa's Lua interpreter.
96 # We do not need to worry about cleaning up the
97 # grammar is an orderly manner, because the Lua interpreter
98 # containing the grammar will be destroyed.
99 # In fact, the Lua interpreter may already have been destroyed,
100 # so this test is necessary to avoid a warning message.
101 271 ▶ return if not $lua;
Branch: 1 branch
BranchTrueFalseTotal
unless $lua 0 271 271
102 # say STDERR "In Marpa::R3::Grammar::DESTROY after test";
103  
104 271 my $regix = $slg->[Marpa::R3::Internal_G::REGIX];
105 271 $lua->call_by_tag($regix,
106 ('@' . __FILE__ . ':' . __LINE__),
107 <<'END_OF_LUA', 'i', $regix);
108 local grammar, regix = ...
109 _M.unregister(_M.registry, regix)
110 END_OF_LUA
111 }
112  
113 sub Marpa::R3::Grammar::set {
114 2 ▶ my ( $slg, @hash_ref_args ) = @_;
Subroutine set: called CC=4 SCAR=14.3
115 2 my ( $flat_args, $error_message ) =
116 Marpa::R3::flatten_hash_args( \@hash_ref_args );
117 2 ▶ Marpa::R3::exception( sprintf $error_message, '$slg->set' )
Branch: 1 branch
BranchTrueFalseTotal
unless $flat_args 0 2 2
118 if not $flat_args;
119  
120 2 my $value = $flat_args->{trace_file_handle};
121 2 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 0 2
122 2 $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE] = $value;
123 2 delete $flat_args->{trace_file_handle};
124 }
125  
126 2 my @bad_arguments = keys %{$flat_args};
127 2 ▶ if ( scalar @bad_arguments ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @bad_arguments) 0 2 2
128 0 Marpa::R3::exception(
129 q{Bad named argument(s) to $slg->set() method} . join q{ },
130 @bad_arguments );
131 }
132 2 return;
133 }
134  
135 sub Marpa::R3::Internal_G::set {
136 291 ▶ my ( $slg, $flat_args ) = @_;
Subroutine set: called CC=19 SCAR=36.6
137  
138 291 my $dsl = $flat_args->{'source'};
139 291 ▶ Marpa::R3::exception(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dsl 0 291 291
140 qq{Marpa::R3::Grammar::new() called without a 'source' argument})
141 if not defined $dsl;
142 291 my $dsl_ref_type = ref $dsl;
143 291 ▶ if ( $dsl_ref_type ne 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dsl_ref_type ne "SCALAR") 0 291 291
144 0 ▶ my $desc = $dsl_ref_type ? "a ref to $dsl_ref_type" : 'not a ref';
Branch: 1 branch
BranchTrueFalseTotal
$dsl_ref_type ? : 0 0 0
145 0 Marpa::R3::exception(
146 qq{'source' name argument to Marpa::R3::Grammar->new() is $desc\n},
147 " It should be a ref to a string\n"
148 );
149 }
150 291 ▶ if ( not defined ${$dsl} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined ${$dsl;}) 0 291 291
151 0 Marpa::R3::exception(
152 qq{'source' name argument to Marpa::R3::Grammar->new() is a ref to a an undef\n},
153 " It should be a ref to a string\n"
154 );
155 } ## end if ( $ref_type ne 'SCALAR' )
156 291 delete $flat_args->{'source'};
157  
158 291 my $value = $flat_args->{trace_file_handle};
159 291 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 291 291
160 0 $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE] = $value;
161 0 delete $flat_args->{'trace_file_handle'};
162 }
163  
164 291 my $trace_file_handle =
165 $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE];
166  
167 291 ▶ if ( exists $flat_args->{'trace_actions'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flat_args->{"trace_actions"}) 0 291 291
168 0 my $value = $flat_args->{'trace_actions'};
169 0 $slg->[Marpa::R3::Internal_G::TRACE_ACTIONS] = $value;
170 0 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) 0 0 0
171 0 ▶ say {$trace_file_handle} 'Setting trace_actions option'
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Setting trace_actions option" or Marpa::R3::exception("Cannot print: $Marpa::R3::Internal_G::ERRNO") 0 0 0
172 or Marpa::R3::exception("Cannot print: $ERRNO");
173 }
174 0 delete $flat_args->{'trace_actions'};
175 }
176  
177 291 ▶ if ( defined( exists $flat_args->{'bless_package'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined exists $flat_args->{"bless_package"}) 291 0 291
178 291 my $value = $flat_args->{'bless_package'};
179 291 $slg->[Marpa::R3::Internal_G::BLESS_PACKAGE] = $value;
180 291 delete $flat_args->{'bless_package'};
181 }
182  
183 291 ▶ if ( exists $flat_args->{'exhaustion'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flat_args->{"exhaustion"}) 4 287 291
184  
185 4 ▶ my $value = $flat_args->{'exhaustion'} // '';
Condition50%1/2
$flat_args->{"exhaustion"} // ""
l!l
40
MC/DC0%0/1
$flat_args->{"exhaustion"} // ""
$flat_args->{"exhaustion"}
Truth table50%1/2
A
A= $flat_args->{"exhaustion"}
Aresult
11
00
186  
187 4 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
188 <<'END_OF_LUA', 's', $value);
189 local slg, value = ...
190 local exhaustion_actions = {
191 fatal = true,
192 event = true
193 }
194 if not exhaustion_actions[value] then
195 if #value == 0 then value = 'undefined' end
196 error(string.format(
197 "'exhaustion' named arg value is %s \z
198 'event' or 'fatal'",
199 value
200 ))
201 end
202 slg.exhaustion_action = value
203 END_OF_LUA
204  
205 4 delete $flat_args->{'exhaustion'};
206  
207 }
208  
209 291 ▶ if ( exists $flat_args->{'rejection'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flat_args->{"rejection"}) 6 285 291
210  
211 6 ▶ my $value = $flat_args->{'rejection'} // '';
Condition50%1/2
$flat_args->{"rejection"} // ""
l!l
60
MC/DC0%0/1
$flat_args->{"rejection"} // ""
$flat_args->{"rejection"}
Truth table50%1/2
A
A= $flat_args->{"rejection"}
Aresult
11
00
212  
213 6 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
214 <<'END_OF_LUA', 's', $value);
215 local slg, value = ...
216 local rejection_actions = {
217 fatal = true,
218 event = true
219 }
220 if not rejection_actions[value] then
221 if #value == 0 then value = 'undefined' end
222 error(string.format(
223 "'rejection' named arg value is %s \z
224 'event' or 'fatal'",
225 value
226 ))
227 end
228 slg.rejection_action = value
229 END_OF_LUA
230  
231 6 delete $flat_args->{'rejection'};
232  
233 }
234  
235 291 ▶ if ( exists $flat_args->{'semantics_package'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flat_args->{"semantics_package"}) 42 249 291
236 42 my $value = $flat_args->{'semantics_package'};
237 42 $slg->[Marpa::R3::Internal_G::SEMANTICS_PACKAGE] = $value;
238 42 delete $flat_args->{'semantics_package'};
239 }
240  
241 291 ▶ if ( exists $flat_args->{'ranking_method'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flat_args->{"ranking_method"}) 18 273 291
242  
243 # Only allowed in new method
244 18 ▶ my $value = $flat_args->{'ranking_method'} // 'undefined';
Condition50%1/2
$flat_args->{"ranking_method"} // "undefined"
l!l
180
MC/DC0%0/1
$flat_args->{"ranking_method"} // "undefined"
$flat_args->{"ranking_method"}
Truth table50%1/2
A
A= $flat_args->{"ranking_method"}
Aresult
11
00
245  
246 18 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
247 <<'END_OF_LUA', 's', $value);
248 local slg, value = ...
249 if not _M.ranking_methods[value] then
250 local list = {}
251 for method,_ in pairs(_M.ranking_methods) do
252 list[#list+1] = string.format('%q', method)
253 end
254 error(string.format(
255 'ranking_method value is %q (should be one of %s)',
256 value, table.concat(list, ', ')
257 ))
258 end
259 slg.ranking_method = value
260 END_OF_LUA
261  
262 18 delete $flat_args->{'ranking_method'};
263 }
264  
265 291 ▶ if ( exists $flat_args->{'debug_level'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flat_args->{"debug_level"}) 0 291 291
266  
267 0 ▶ my $value = $flat_args->{'debug_level'} // 'undefined';
Condition0%0/2
$flat_args->{"debug_level"} // "undefined"
l!l
00
MC/DC0%0/1
$flat_args->{"debug_level"} // "undefined"
$flat_args->{"debug_level"}
Truth table0%0/2
A
A= $flat_args->{"debug_level"}
Aresult
11
00
268  
269 0 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
270 <<'END_OF_LUA', 'i', $value);
271 local slg, raw_value = ...
272 local value = math.tointeger(raw_value)
273 if not value then
274 _M.userX(
275 'debug_level value is %s -- it should be an integer',
276 inspect(value)
277 )
278 end
279 slg.debug_level = value
280 END_OF_LUA
281  
282 0 delete $flat_args->{'debug_level'};
283 }
284  
285 291 return $dsl;
286  
287 }
288  
289 # The object, in computing the hash, is to get as much
290 # precomputation in as possible, without using undue space.
291 # That means CPU-intensive processing should tend to be done
292 # before or during hash creation, and space-intensive processing
293 # should tend to be done here, in the code that converts the
294 # hash to its runtime equivalent.
295 sub Marpa::R3::Internal_G::hash_to_runtime {
296 377 ▶ my ( $slg, $hashed_source ) = @_;
Subroutine hash_to_runtime: called CC=4 SCAR=15.8
297  
298 377 my $trace_file_handle = $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE];
299 # Pre-lexer G1 processing
300  
301 $slg->coro_by_tag(
302 ( '@' . __FILE__ . ':' . __LINE__ ),
303 {
304 signature => 's',
305 args => [$hashed_source],
306 handlers => {
307 trace => sub {
308 0 ▶ my ($msg) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
309 0 say {$trace_file_handle} $msg;
310 0 return 'ok';
311 },
312 }
313 },
314 377 <<'END_OF_LUA');
315 local slg, source_hash = ...
316 _M.wrap(function ()
317 slg:seriable_to_runtime(source_hash)
318 end)
319 END_OF_LUA
320  
321 # For the Kollos interface, we need to create some kind
322 # of SLG method which allows access to the character_class,
323 # character_flags data. For now we just grab it from the
324 # structure
325 my ($character_pairs) = $slg->coro_by_tag(
326 ( '@' . __FILE__ . ':' . __LINE__ ),
327 {
328 signature => '',
329 args => [],
330 handlers => {
331 trace => sub {
332 0 ▶ my ($msg) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
333 0 say {$trace_file_handle} $msg;
334 0 return 'ok';
335 },
336 }
337 },
338 372 <<'END_OF_LUA');
339 local slg = ...
340 _M.wrap(function ()
341 local isys = slg.l0.isys
342 local character_pairs = {}
343 -- In reverse order, so when Perl pops them off,
344 -- they are back in symbol ID order
345 for isyid = #isys, 0, -1 do
346 local isy = isys[isyid]
347 local perl_re = isy.character_class
348 if perl_re then
349 local perl_re = isy.character_class
350 local flags = isy.character_flags
351 if flags then
352 perl_re = '(?' .. flags .. ')' .. perl_re
353 end
354 character_pairs[#character_pairs+1] = isyid
355 character_pairs[#character_pairs+1] = perl_re
356 end
357 end
358 return 'ok', character_pairs
359 end)
360 END_OF_LUA
361  
362 372 my @class_table;
363 CLASS_SYMBOL:
364 372 ▶ while (scalar @{$character_pairs}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$character_pairs;}) 7221 372 7593
365 7221 my $perl_re = pop @{$character_pairs};
366 7221 my $symbol_id = pop @{$character_pairs};
367 7221 my $compiled_re;
368 my $error;
369 7221 ▶ if ( not defined eval { $compiled_re = qr/$perl_re/xms; 1; } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined eval { do { $compiled_re = qr/$perl_re/msx; 1 } }) 0 7221 7221
370 0 $error = qq{Problem in evaluating character class: "$perl_re"\n};
371 0 $error .= $EVAL_ERROR;
372 }
373 7221 ▶ if ( not $compiled_re ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compiled_re) 0 7221 7221
374 0 $error =~ s/^/ /gxms; #indent all lines
375 0 Marpa::R3::exception(
376 "Failed belatedly to evaluate character class\n", $error );
377 }
378 7221 push @class_table, [ $symbol_id, $compiled_re ];
379 } ## end CLASS_SYMBOL: for my $class_symbol ( sort keys %{...})
380 372 $slg->[Marpa::R3::Internal_G::CHARACTER_CLASS_TABLE] = \@class_table;
381  
382 372 return $slg;
383  
384 }
385  
386 104 our $kwgen_code_template = <<'END_OF_TEMPLATE';
387 END_OF_TEMPLATE
388  
389 sub kwgen {
390 4992 ▶ my ($line, $perl_name, $kollos_name, $signature) = @_;
Subroutine kwgen: called CC=1 SCAR=0.0
391 4992 my $tag = '@' . __FILE__ . ':' . $line;
392 4992 my $code = sprintf( 'return _M.class_slg.%s(...)', $kollos_name );
393 # my $code = sprintf( 'io.stderr:write("Calling slg.%s ", table.concat(..., "")); return _M.class_slg.%s(...)', $kollos_name, $kollos_name );
394 104 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
395 4992 *{ 'Marpa::R3::Grammar::' . $perl_name }
396 = sub () {
397 21584 ▶ my ($slg, @args) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
398 21584 my ($retour) = $slg->call_by_tag($tag, $code, $signature, @args);
399 21584 return $retour;
400 4992 };
401 104 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
402 }
403  
404 sub kwgen_arr {
405 416 ▶ my ($line, $perl_name, $kollos_name, $signature) = @_;
Subroutine kwgen_arr: called CC=1 SCAR=0.0
406 416 my $tag = '@' . __FILE__ . ':' . $line;
407 416 my $code = sprintf( 'return _M.class_slg.%s(...)', $kollos_name );
408 # my $code = sprintf( 'io.stderr:write("Calling slg.%s ", table.concat(..., "")); return _M.class_slg.%s(...)', $kollos_name, $kollos_name );
409 104 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
410 416 *{ 'Marpa::R3::Grammar::' . $perl_name }
411 = sub () {
412 1683 ▶ my ($slg, @args) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
413 1683 my ($retour) = $slg->call_by_tag($tag, $code, $signature, @args);
414 1683 return @{$retour};
415 416 };
416 104 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
417 }
418  
419 sub kwgen_opt {
420 312 ▶ my ($line, $perl_name, $kollos_name, $signature, @defaults) = @_;
Subroutine kwgen_opt: called CC=1 SCAR=0.0
421 312 my $tag = '@' . __FILE__ . ':' . $line;
422 312 my $code = sprintf( 'return _M.class_slg.%s(...)', $kollos_name );
423 # my $code = sprintf( 'io.stderr:write("Calling slg.%s ", table.concat(..., "")); return _M.class_slg.%s(...)', $kollos_name, $kollos_name );
424 104 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
425 312 *{ 'Marpa::R3::Grammar::' . $perl_name }
426 = sub () {
427 8 ▶ my ($slg, @args) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.1
428 8 ▶ $args[$_] //= $defaults[$_] for 0 .. $#defaults;
Condition66%2/3
$args[$_] //= $defaults[$_]
l!l&&r!l&&!r
206
MC/DC50%1/2
$args[$_] //= $defaults[$_]
$args[$_] $defaults[$_]
Truth table66%2/3
A //= B
A= $args[$_]B= $defaults[$_]
ABresult
1X1
011
000
429 8 my ($retour) = $slg->call_by_tag($tag, $code, $signature, @args);
430 8 return $retour;
431 312 };
432 104 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
433 }
434  
435 sub Marpa::R3::Grammar::production_show {
436 94 ▶ my ($slg, $xprid, $options) = @_;
Subroutine production_show: called CC=3 SCAR=11.0
437 94 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 94 0 94
438 94 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 47 47 94
439 94 my $tag = '@' . __FILE__ . ':' . __LINE__;
440 94 my $code = <<'END_OF_CODE';
441 local slg, xprid, verbose, diag = ...
442 diag = diag ~= 0 -- convert diag to a boolean
443 return slg:xpr_show(xprid, { verbose = verbose, diag = diag })
444 END_OF_CODE
445 94 my ($retour) = $slg->call_by_tag($tag, $code, 'iii',
446 $xprid, $verbose, $diag);
447 94 return $retour;
448 }
449  
450 sub Marpa::R3::Grammar::symbols_show {
451 15 ▶ my ($slg, $options) = @_;
Subroutine symbols_show: called CC=3 SCAR=11.0
452 15 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 14 1 15
453 15 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 0 15 15
454 15 my $tag = '@' . __FILE__ . ':' . __LINE__;
455 15 my $code = <<'END_OF_CODE';
456 local slg, verbose, diag = ...
457 diag = diag ~= 0 -- convert diag to a boolean
458 return slg:symbols_show({ verbose = verbose, diag = diag })
459 END_OF_CODE
460 15 my ($retour) = $slg->call_by_tag($tag, $code, 'ii',
461 $verbose, $diag);
462 15 return $retour;
463 }
464  
465 sub Marpa::R3::Grammar::symbol_show {
466 41 ▶ my ($slg, $xsyid, $options) = @_;
Subroutine symbol_show: called CC=3 SCAR=11.2
467 41 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 41 0 41
468 41 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 0 41 41
469 41 my $tag = '@' . __FILE__ . ':' . __LINE__;
470 41 my $code = <<'END_OF_CODE';
471 local slg, xsyid, verbose, diag = ...
472 diag = diag ~= 0 -- convert diag to a boolean
473 return slg:symbol_show(xsyid, { verbose = verbose, diag = diag })
474 END_OF_CODE
475 41 my ($retour) = $slg->call_by_tag($tag, $code, 'iii',
476 $xsyid, $verbose, $diag);
477 41 return $retour;
478 }
479  
480 sub Marpa::R3::Grammar::lmg_rule_show {
481 0 ▶ my ($slg, $subg, $irlid, $options) = @_;
Subroutine lmg_rule_show: not called CC=3 SCAR=24.8
482 0 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 0 0 0
483 0 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 0 0 0
484 0 my $tag = '@' . __FILE__ . ':' . __LINE__;
485 0 my $code = <<'END_OF_CODE';
486 local slg, subg, irlid, verbose, diag = ...
487 diag = diag ~= 0 -- convert diag to a boolean
488 return slg:lmg_rule_show(subg, irlid, { verbose = verbose, diag = diag })
489 END_OF_CODE
490 0 my ($retour) = $slg->call_by_tag($tag, $code, 'siii',
491 $subg, $irlid, $verbose, $diag);
492 0 return $retour;
493 }
494  
495 sub Marpa::R3::Grammar::g1_rule_show {
496 151 ▶ my ($slg, $irlid, $options) = @_;
Subroutine g1_rule_show: called CC=3 SCAR=11.0
497 151 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 151 0 151
498 151 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 20 131 151
499 151 my $tag = '@' . __FILE__ . ':' . __LINE__;
500 151 my $code = <<'END_OF_CODE';
501 local slg, irlid, verbose, diag = ...
502 diag = diag ~= 0 -- convert diag to a boolean
503 return slg:g1_rule_show(irlid, { verbose = verbose, diag = diag })
504 END_OF_CODE
505 151 my ($retour) = $slg->call_by_tag($tag, $code, 'iii',
506 $irlid, $verbose, $diag);
507 151 return $retour;
508 }
509  
510 sub Marpa::R3::Grammar::l0_rule_show {
511 54 ▶ my ($slg, $irlid, $options) = @_;
Subroutine l0_rule_show: called CC=3 SCAR=11.0
512 54 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 54 0 54
513 54 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 27 27 54
514 54 my $tag = '@' . __FILE__ . ':' . __LINE__;
515 54 my $code = <<'END_OF_CODE';
516 local slg, irlid, verbose, diag = ...
517 diag = diag ~= 0 -- convert diag to a boolean
518 return slg:l0_rule_show(irlid, { verbose = verbose, diag = diag })
519 END_OF_CODE
520 54 my ($retour) = $slg->call_by_tag($tag, $code, 'iii',
521 $irlid, $verbose, $diag);
522 54 return $retour;
523 }
524  
525 sub Marpa::R3::Grammar::productions_show {
526 22 ▶ my ($slg, $options) = @_;
Subroutine productions_show: called CC=3 SCAR=11.0
527 22 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 20 2 22
528 22 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 1 21 22
529 22 my $tag = '@' . __FILE__ . ':' . __LINE__;
530 22 my $code = <<'END_OF_CODE';
531 local slg, verbose, diag = ...
532 diag = diag ~= 0 -- convert diag to a boolean
533 return slg:xprs_show({ verbose = verbose, diag = diag })
534 END_OF_CODE
535 22 my ($retour) = $slg->call_by_tag($tag, $code, 'ii',
536 $verbose, $diag);
537 22 return $retour;
538 }
539  
540 sub Marpa::R3::Grammar::lmg_rules_show {
541 0 ▶ my ($slg, $subg, $options) = @_;
Subroutine lmg_rules_show: not called CC=3 SCAR=24.8
542 0 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 0 0 0
543 0 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 0 0 0
544 0 my $tag = '@' . __FILE__ . ':' . __LINE__;
545 0 my $code = <<'END_OF_CODE';
546 local slg, subg, verbose, diag = ...
547 diag = diag ~= 0 -- convert diag to a boolean
548 return slg:lmg_rules_show(subg, { verbose = verbose, diag = diag })
549 END_OF_CODE
550 0 my ($retour) = $slg->call_by_tag($tag, $code, 'sii',
551 $subg, $verbose, $diag);
552 0 return $retour;
553 }
554  
555 sub Marpa::R3::Grammar::g1_rules_show {
556 11 ▶ my ($slg, $options) = @_;
Subroutine g1_rules_show: called CC=3 SCAR=11.0
557 11 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 9 2 11
558 11 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 1 10 11
559 11 my $tag = '@' . __FILE__ . ':' . __LINE__;
560 11 my $code = <<'END_OF_CODE';
561 local slg, verbose, diag = ...
562 diag = diag ~= 0 -- convert diag to a boolean
563 return slg:g1_rules_show({ verbose = verbose, diag = diag })
564 END_OF_CODE
565 11 my ($retour) = $slg->call_by_tag($tag, $code, 'ii',
566 $verbose, $diag);
567 11 return $retour;
568 }
569  
570 sub Marpa::R3::Grammar::l0_rules_show {
571 5 ▶ my ($slg, $options) = @_;
Subroutine l0_rules_show: called CC=3 SCAR=11.0
572 5 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 0 5 5
573 5 ▶ my $diag = $options->{diag} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'diag'} ? : 1 4 5
574 5 my $tag = '@' . __FILE__ . ':' . __LINE__;
575 5 my $code = <<'END_OF_LUA';
576 local slg, verbose, diag = ...
577 diag = diag ~= 0 -- convert diag to a boolean
578 return slg:l0_rules_show({ verbose = verbose, diag = diag })
579 END_OF_LUA
580 5 my ($retour) = $slg->call_by_tag($tag, $code, 'ii',
581 $verbose, $diag);
582 5 return $retour;
583 }
584  
585 # TODO: Census all uses of Marpa::R3::Grammar::g1_symbol_name
586 # in pod and tests, and make sure that they are appropriate --
587 # that is, that they should not be symbol_name() instead.
588  
589 104 kwgen(__LINE__, qw(highest_symbol_id highest_symbol_id), '');
590 104 kwgen(__LINE__, qw(lmg_highest_symbol_id lmg_highest_symbol_id i));
591 104 kwgen(__LINE__, qw(g1_highest_symbol_id g1_highest_symbol_id), '');
592 104 kwgen(__LINE__, qw(l0_highest_symbol_id l0_highest_symbol_id), '');
593  
594 104 kwgen(__LINE__, qw(start_symbol_id start_symbol_id), '');
595 104 kwgen(__LINE__, qw(lmg_start_symbol_id lmg_start_symbol_id s));
596 104 kwgen(__LINE__, qw(g1_start_symbol_id g1_start_symbol_id), '');
597 104 kwgen(__LINE__, qw(l0_start_symbol_id l0_start_symbol_id), '');
598  
599 104 kwgen(__LINE__, qw(g1_xsymbol_id g1_xsyid i));
600 104 kwgen(__LINE__, qw(l0_xsymbol_id l0_xsyid i));
601  
602 104 kwgen(__LINE__, qw(symbol_name symbol_name i));
603 104 kwgen(__LINE__, qw(lmg_symbol_name lmg_symbol_name si));
604 104 kwgen(__LINE__, qw(g1_symbol_name g1_symbol_name i));
605 104 kwgen(__LINE__, qw(l0_symbol_name l0_symbol_name i));
606  
607 104 kwgen(__LINE__, qw(symbol_display_form symbol_display_form i));
608 104 kwgen(__LINE__, qw(lmg_symbol_display_form lmg_symbol_display_form si));
609 104 kwgen(__LINE__, qw(g1_symbol_display_form g1_symbol_display_form i));
610 104 kwgen(__LINE__, qw(l0_symbol_display_form l0_symbol_display_form i));
611  
612 104 kwgen(__LINE__, qw(symbol_angled_form symbol_angled_form i));
613 104 kwgen(__LINE__, qw(lmg_symbol_angled_form lmg_symbol_angled_form si));
614 104 kwgen(__LINE__, qw(g1_symbol_angled_form g1_symbol_angled_form i));
615 104 kwgen(__LINE__, qw(l0_symbol_angled_form l0_symbol_angled_form i));
616  
617 104 kwgen(__LINE__, qw(symbol_dsl_form symbol_dsl_form i));
618 104 kwgen(__LINE__, qw(lmg_symbol_dsl_form lmg_symbol_dsl_form si));
619 104 kwgen(__LINE__, qw(g1_symbol_dsl_form g1_symbol_dsl_form i));
620 104 kwgen(__LINE__, qw(l0_symbol_dsl_form l0_symbol_dsl_form i));
621  
622 104 kwgen_opt(__LINE__, qw(lmg_symbols_show lmg_symbols_show si), 0, 0);
623 104 kwgen_opt(__LINE__, qw(g1_symbols_show g1_symbols_show i), 0);
624 104 kwgen_opt(__LINE__, qw(l0_symbols_show l0_symbols_show i), 0);
625  
626 104 kwgen(__LINE__, qw(lmg_symbol_by_name lmg_symbol_by_name si));
627 104 kwgen(__LINE__, qw(g1_symbol_by_name g1_symbol_by_name i));
628 104 kwgen(__LINE__, qw(l0_symbol_by_name l0_symbol_by_name i));
629  
630 104 kwgen(__LINE__, qw(g1_symbol_is_accessible g1_symbol_is_accessible i));
631 104 kwgen(__LINE__, qw(g1_symbol_is_nulling g1_symbol_is_nulling i));
632 104 kwgen(__LINE__, qw(g1_symbol_is_productive g1_symbol_is_productive i));
633  
634 104 kwgen(__LINE__, qw(production_dotted_show xpr_dotted_show ii));
635 104 kwgen(__LINE__, qw(lmg_dotted_rule_show lmg_dotted_rule_show sii));
636 104 kwgen(__LINE__, qw(g1_dotted_rule_show g1_dotted_rule_show ii));
637 104 kwgen(__LINE__, qw(l0_dotted_rule_show l0_dotted_rule_show ii));
638  
639 104 kwgen(__LINE__, qw(production_name xpr_name i));
640  
641 104 kwgen(__LINE__, qw(lmg_rule_to_production_id lmg_rule_to_xprid si));
642 104 kwgen(__LINE__, qw(g1_rule_to_production_id g1_rule_to_xprid i));
643 104 kwgen(__LINE__, qw(l0_rule_to_production_id l0_rule_to_xprid i));
644  
645 104 kwgen(__LINE__, qw(lmg_rule_to_production_dot lmg_rule_to_xpr_dots si));
646 104 kwgen(__LINE__, qw(g1_rule_to_production_dot g1_rule_to_xpr_dots i));
647 104 kwgen(__LINE__, qw(l0_rule_to_production_dot l0_rule_to_xpr_dots i));
648  
649 104 kwgen(__LINE__, qw(highest_production_id highest_xprid), '');
650 104 kwgen(__LINE__, qw(lmg_highest_rule_id lmg_highest_rule_id), '');
651 104 kwgen(__LINE__, qw(g1_highest_rule_id g1_highest_rule_id), '');
652 104 kwgen(__LINE__, qw(l0_highest_rule_id l0_highest_rule_id), '');
653  
654 104 kwgen_arr(__LINE__, qw(production_expand xpr_expand i));
655 104 kwgen_arr(__LINE__, qw(lmg_rule_expand lmg_irl_isyids si));
656 104 kwgen_arr(__LINE__, qw(g1_rule_expand g1_irl_isyids i));
657 104 kwgen_arr(__LINE__, qw(l0_rule_expand l0_irl_isyids i));
658  
659 104 kwgen(__LINE__, qw(production_length xpr_length i));
660  
661 sub Marpa::R3::Grammar::call_by_tag {
662 160891 ▶ my ( $slg, $tag, $codestr, $sig, @args ) = @_;
Subroutine call_by_tag: called CC=2 SCAR=7.0
663 160891 my $lua = $slg->[Marpa::R3::Internal_G::L];
664 160891 my $regix = $slg->[Marpa::R3::Internal_G::REGIX];
665 # $DB::single = 1 if not defined $lua;
666 # $DB::single = 1 if not defined $regix;
667 # $DB::single = 1 if not defined $tag;
668 # $DB::single = 1 if not defined $codestr;
669 # $DB::single = 1 if not defined $sig;
670 # $DB::single = 1 if grep { not defined $_ } @args;
671 160891 my @results;
672 my $eval_error;
673 160891 my $eval_ok;
674 {
675 160891 local $@;
676 160891 $eval_ok = eval {
677 # say STDERR "About to call_by_tag($regix, $tag, $codestr, $sig, @args)";;
678 160891 @results = $lua->call_by_tag($regix, $tag, $codestr, $sig, @args);
679 # say STDERR "Returned from call_by_tag($regix, $tag, $codestr, $sig, @args)";;
680 160891 return 1;
681 };
682 160891 $eval_error = $@;
683 }
684 160891 ▶ if ( not $eval_ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_ok) 0 160891 160891
685 0 Marpa::R3::exception($eval_error);
686 }
687  
688 160891 return @results;
689 }
690  
691 # not to be documented
692 sub Marpa::R3::Grammar::coro_by_tag {
693 1953 ▶ my ( $slg, $tag, $args, $codestr ) = @_;
Subroutine coro_by_tag: called CC=8 SCAR=21.0
694 1953 my $lua = $slg->[Marpa::R3::Internal_G::L];
695 1953 my $regix = $slg->[Marpa::R3::Internal_G::REGIX];
696 1953 ▶ my $handler = $args->{handlers} // {};
Condition50%1/2
$args->{"handlers"} // {}
l!l
19530
MC/DC0%0/1
$args->{"handlers"} // {}
$args->{"handlers"}
Truth table50%1/2
A
A= $args->{"handlers"}
Aresult
11
00
697 1953 my $resume_tag = $tag . '[R]';
698 1953 ▶ my $signature = $args->{signature} // '';
Condition50%1/2
$args->{"signature"} // ""
l!l
19530
MC/DC0%0/1
$args->{"signature"} // ""
$args->{"signature"}
Truth table50%1/2
A
A= $args->{"signature"}
Aresult
11
00
699 1953 ▶ my $p_args = $args->{args} // [];
Condition50%1/2
$args->{"args"} // []
l!l
19530
MC/DC0%0/1
$args->{"args"} // []
$args->{"args"}
Truth table50%1/2
A
A= $args->{"args"}
Aresult
11
00
700  
701 1953 my @results;
702 my $eval_error;
703 1953 my $eval_ok;
704 {
705 1953 local $@;
706 1953 $eval_ok = eval {
707 1953 $lua->call_by_tag( $regix, $tag, $codestr, $signature, @{$p_args} );
708 1953 my $coro_arg;
709 1953 CORO_CALL: while (1) {
710 1961 my ( $cmd, $yield_data ) =
711 $lua->call_by_tag( $regix, $resume_tag,
712 'local slg, coro_arg = ...; return _M.resume(coro_arg)',
713 's', $coro_arg );
714  
715 1956 ▶ if (not $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 1948 8 1956
716 1948 @results = @{$yield_data};
717 1948 return 1;
718 }
719 8 my $handler = $handler->{$cmd};
720 8 ▶ Marpa::R3::exception(qq{No coro handler for "$cmd"})
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 0 8 8
721 if not $handler;
722 8 ▶ $yield_data //= [];
Condition50%1/2
$yield_data //= []
l!l
80
MC/DC0%0/1
$yield_data //= []
$yield_data
Truth table50%1/2
A
A= $yield_data
Aresult
11
00
723 8 my $handler_cmd;
724 8 ($handler_cmd, $coro_arg) = $handler->(@{$yield_data});
725 }
726 0 return 1;
727 };
728 1953 $eval_error = $@;
729 }
730 1953 ▶ if ( not $eval_ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_ok) 5 1948 1953
731 5 Marpa::R3::exception($eval_error);
732 }
733 1948 return @results;
734 }
735  
736 sub Marpa::R3::Grammar::symbol_ids_gen {
737 2 ▶ my ($slg) = @_;
Subroutine symbol_ids_gen: called CC=1 SCAR=0.0
738 2 my $next = 1;
739 2 my $last = $slg->highest_symbol_id();
740 return sub () {
741 84 ▶ return if $next > $last;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 2 82 84
742 82 my $current;
743 82 ($current, $next) = ($next, $next+1);
744 82 return $current;
745 }
746 2 }
747  
748 sub Marpa::R3::Grammar::lmg_symbol_ids_gen {
749 0 ▶ my ($slg, $subg) = @_;
Subroutine lmg_symbol_ids_gen: not called CC=1 SCAR=6.9
750 0 my $next = 0;
751 0 my $last = $slg->lmg_highest_symbol_id($subg);
752 return sub () {
753 0 ▶ return if $next > $last;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 0 0 0
754 0 my $current;
755 0 ($current, $next) = ($next, $next+1);
756 0 return $current;
757 }
758 0 }
759  
760 sub Marpa::R3::Grammar::g1_symbol_ids_gen {
761 6 ▶ my ($slg) = @_;
Subroutine g1_symbol_ids_gen: called CC=1 SCAR=0.0
762 6 my $next = 0;
763 6 my $last = $slg->g1_highest_symbol_id();
764 return sub () {
765 65 ▶ return if $next > $last;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 4 61 65
766 61 my $current;
767 61 ($current, $next) = ($next, $next+1);
768 61 return $current;
769 }
770 6 }
771  
772 sub Marpa::R3::Grammar::l0_symbol_ids_gen {
773 2 ▶ my ($slg) = @_;
Subroutine l0_symbol_ids_gen: called CC=1 SCAR=0.0
774 2 my $next = 0;
775 2 my $last = $slg->l0_highest_symbol_id();
776 return sub () {
777 70 ▶ return if $next > $last;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 2 68 70
778 68 my $current;
779 68 ($current, $next) = ($next, $next+1);
780 68 return $current;
781 }
782 2 }
783  
784 sub Marpa::R3::Grammar::production_ids_gen {
785 3 ▶ my ($slg) = @_;
Subroutine production_ids_gen: called CC=1 SCAR=0.0
786 3 my $next = 1;
787 3 my $last = $slg->highest_production_id();
788 return sub () {
789 144 ▶ return if $next > $last;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 3 141 144
790 141 my $current;
791 141 ($current, $next) = ($next, $next+1);
792 141 return $current;
793 }
794 3 }
795  
796 sub Marpa::R3::Grammar::lmg_rule_ids_gen {
797 0 ▶ my ($slg, $subg) = @_;
Subroutine lmg_rule_ids_gen: not called CC=1 SCAR=6.9
798 0 my $next = 0;
799 0 my $last = $slg->lmg_highest_rule_id($subg);
800 return sub () {
801 0 ▶ return if $next > $last;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 0 0 0
802 0 my $current;
803 0 ($current, $next) = ($next, $next+1);
804 0 return $current;
805 }
806 0 }
807  
808 sub Marpa::R3::Grammar::g1_rule_ids_gen {
809 1862 ▶ my ($slg) = @_;
Subroutine g1_rule_ids_gen: called CC=1 SCAR=0.0
810 1862 my $next = 0;
811 1862 my $last = $slg->g1_highest_rule_id();
812 return sub () {
813 51914 ▶ return if $next > $last;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 1488 50426 51914
814 50426 my $current;
815 50426 ($current, $next) = ($next, $next+1);
816 50426 return $current;
817 }
818 1862 }
819  
820 sub Marpa::R3::Grammar::l0_rule_ids_gen {
821 4 ▶ my ($slg) = @_;
Subroutine l0_rule_ids_gen: called CC=1 SCAR=0.0
822 4 my $next = 0;
823 4 my $last = $slg->l0_highest_rule_id();
824 return sub () {
825 112 ▶ return if $next > $last;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 4 108 112
826 108 my $current;
827 108 ($current, $next) = ($next, $next+1);
828 108 return $current;
829 }
830 4 }
831  
832 # not to be documented
833 sub Marpa::R3::Grammar::nrls_show {
834 7 ▶ my ($slg) = @_;
Subroutine nrls_show: called CC=1 SCAR=0.0
835 7 my ($result) =
836 $slg->call_by_tag(
837 ('@' . __FILE__ . ':' . __LINE__),
838 <<'END_OF_LUA', '' );
839 local grammar = ...
840 local g1g = grammar.g1
841 local nrl_count = g1g:_nrl_count()
842 local pieces = {}
843 for nrl_id = 0, nrl_count - 1 do
844 pieces[#pieces+1] = g1g:brief_nrl(nrl_id)
845 end
846 pieces[#pieces+1] = ''
847 return table.concat(pieces, '\n')
848 END_OF_LUA
849 7 return $result;
850 }
851  
852 # not to be documented
853 sub Marpa::R3::Grammar::nsys_show {
854 4 ▶ my ($slg) = @_;
Subroutine nsys_show: called CC=1 SCAR=0.0
855 4 my ($result) =
856 $slg->call_by_tag(
857 ('@' . __FILE__ . ':' . __LINE__),
858 <<'END_OF_LUA', '' );
859 local grammar = ...
860 local g1g = grammar.g1
861 return g1g:nsys_show()
862 END_OF_LUA
863 4 return $result;
864 }
865  
866 # not to be documented
867 sub Marpa::R3::Grammar::ahms_show {
868 13 ▶ my ( $slg, $options ) = @_;
Subroutine ahms_show: called CC=3 SCAR=11.0
869 13 ▶ $options //= {};
Condition100%2/2
$options //= {}
l!l
112
MC/DC100%1/1
$options //= {}
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
870 13 ▶ my $verbose = $options->{verbose} or 0;
Branch: 1 branch
BranchTrueFalseTotal
my $verbose = $options->{"verbose"} or '???' 12 1 13
871  
872 13 my ($text) = $slg->call_by_tag(
873 ('@' . __FILE__ . ':' . __LINE__),
874 <<'END_OF_LUA', 'i', $verbose );
875 local grammar, verbose = ...
876 local g1g = grammar.g1
877 return g1g:ahms_show({verbose = verbose})
878 END_OF_LUA
879  
880 13 return $text;
881  
882 }
883  
884 # not to be documented
885 sub Marpa::R3::Grammar::dotted_nrl_show {
886 452 ▶ my ( $slg, $nrl_id, $dot_position ) = @_;
Subroutine dotted_nrl_show: called CC=1 SCAR=0.0
887 452 my ($result) =
888 $slg->call_by_tag(
889 ('@' . __FILE__ . ':' . __LINE__),
890 <<'END_OF_LUA', 'ii', $nrl_id, $dot_position );
891 local grammar, nrl_id, dot_position = ...
892 local g1g = grammar.g1
893 return g1g:_dotted_nrl_show(nrl_id, dot_position)
894 END_OF_LUA
895 452 return $result;
896 }
897  
898 # not to be documented
899 sub Marpa::R3::Grammar::briefer_ahm {
900 549 ▶ my ( $slg, $item_id ) = @_;
Subroutine briefer_ahm: called CC=1 SCAR=0.0
901  
902 549 my ($text) = $slg->call_by_tag(
903 ('@' . __FILE__ . ':' . __LINE__),
904 <<'END_OF_LUA', 'i', $item_id );
905 local grammar, item_id = ...
906 local g1g = grammar.g1
907 local irl_id = g1g:_ahm_nrl(item_id)
908 local dot_position = g1g:_ahm_position(item_id)
909 if (dot_position < 0 ) then
910 return string.format("R%d$", irl_id)
911 end
912 return string.format("R%d:%d", irl_id, dot_position)
913 END_OF_LUA
914  
915 549 return $text;
916  
917 }
918  
919 # not to be documented
920 sub Marpa::R3::Grammar::brief_nrl {
921 0 ▶ my ( $slg, $nrl_id ) = @_;
Subroutine brief_nrl: not called CC=1 SCAR=6.9
922 0 my ($text) = $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
923 <<'END_OF_LUA', 'i', $nrl_id );
924 local grammar, nrl_id = ...
925 local g1g = grammar.g1
926 return g1g:brief_nrl(nrl_id)
927 END_OF_LUA
928  
929 0 return $text;
930 }
931  
932 # not to be documented
933 sub Marpa::R3::Grammar::regix {
934 1 ▶ my ( $slg ) = @_;
Subroutine regix: called CC=1 SCAR=0.0
935 1 my $regix = $slg->[Marpa::R3::Internal_G::REGIX];
936 1 return $regix;
937 }
938  
939 sub registrations_find {
940 372 ▶ my ($slg) = @_;
Subroutine registrations_find: called CC=102 SCAR=51.2
941 372 my $trace_file_handle =
942 $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE];
943 372 ▶ my $trace_actions =
Condition50%1/2
$slg->[7] // 0
l!l
0372
MC/DC0%0/1
$slg->[7] // 0
$slg->[7]
Truth table50%1/2
A
A= $slg->[7]
Aresult
11
00
944 $slg->[Marpa::R3::Internal_G::TRACE_ACTIONS] // 0;
945  
946 372 my @closure_by_irlid = ();
947 372 my @semantics_by_irlid = ();
948 372 my @blessing_by_irlid = ();
949  
950 372 my ( $rule_resolutions, $lexeme_resolutions ) = resolve_grammar($slg);
951  
952 # Set the arrays, and perform various checks on the resolutions
953 # we received
954 {
955 371 ▶ RULE: for (my $iter = $slg->g1_rule_ids_gen(); defined ( my $irlid = $iter->());) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $irlid = &$iter())) 12190 371 12561
956 my ( $new_resolution, $closure, $semantics, $blessing ) =
957 12190 @{ $rule_resolutions->[$irlid] };
958 12190 my ($lhs_id) =
959 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
960 <<'END_OF_LUA', 'i>*', $irlid );
961 local grammar, irlid = ...
962 local g1g = grammar.g1
963 return g1g:rule_lhs(irlid)
964 END_OF_LUA
965  
966 REFINE_SEMANTICS: {
967  
968 12190 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ("[" eq substr($semantics, 0, 1) and "]" eq substr($semantics, -1, 1)) 10768 1422 12190
Condition66%2/3
"[" eq substr($semantics, 0, 1) and "]" eq substr($semantics, -1, 1)
!ll&&!rl&&r
1422010768
MC/DC50%1/2
"[" eq substr($semantics, 0, 1) and "]" eq substr($semantics, -1, 1)
"[" eq substr($semantics, 0, 1) "]" eq substr($semantics, -1, 1)
Truth table66%2/3
A and B
A= "[" eq substr($semantics, 0, 1)B= "]" eq substr($semantics, -1, 1)
ABresult
0X0
100
111
969 '[' eq substr $semantics,
970 0, 1 and ']' eq substr $semantics,
971 -1, 1
972 )
973 {
974 # Normalize array semantics
975 10768 $semantics =~ s/ //gxms;
976 10768 last REFINE_SEMANTICS;
977 } ## end if ( '[' eq substr $semantics, 0, 1 and ']' eq ...)
978  
979 state $allowed_semantics = {
980 1422 map { ; ( $_, 1 ) } qw(::array ::undef ::first ::!default),
981 q{}
982 };
983 1422 ▶ last REFINE_SEMANTICS if $allowed_semantics->{$semantics};
Branch: 1 branch
BranchTrueFalseTotal
if $allowed_semantics->{$semantics} 1422 0 1422
984 last REFINE_SEMANTICS
985 0 ▶ if $semantics =~ m/ \A rhs \d+ \z /xms;
Branch: 1 branch
BranchTrueFalseTotal
if $semantics =~ / \A rhs \d+ \z /msx 0 0 0
986  
987 0 Marpa::R3::exception(
988 q{Unknown semantics for rule },
989 $slg->g1_rule_show($irlid),
990 "\n",
991 qq{ Semantics were specified as "$semantics"\n}
992 );
993  
994 } ## end REFINE_SEMANTICS:
995  
996 12190 $semantics_by_irlid[$irlid] = $semantics;
997 12190 $blessing_by_irlid[$irlid] = $blessing;
998 12190 $closure_by_irlid[$irlid] = $closure;
999  
1000 CHECK_BLESSING: {
1001 12190 ▶ last CHECK_BLESSING if $blessing eq '::undef';
Branch: 1 branch
BranchTrueFalseTotal
if $blessing eq "::undef" 1452 10738 12190
1002 10738 ▶ if ($closure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closure) 0 10738 10738
1003 0 my $ref_type = Scalar::Util::reftype $closure;
1004 0 ▶ if ( $ref_type eq 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_type eq "SCALAR") 0 0 0
1005  
1006 # The constant's dump might be long so I repeat the error message
1007 0 Marpa::R3::exception(
1008 qq{Fatal error: Attempt to bless a rule that resolves to a scalar constant\n},
1009 qq{ Scalar constant is },
1010 Data::Dumper::Dumper($closure),
1011 qq{ Blessing is "$blessing"\n},
1012 q{ Rule is: },
1013 $slg->g1_rule_show($irlid),
1014 "\n",
1015 qq{ Cannot bless rule when it resolves to a scalar constant},
1016 "\n",
1017 );
1018 } ## end if ( $ref_type eq 'SCALAR' )
1019 0 last CHECK_BLESSING;
1020 } ## end if ($closure)
1021 10738 ▶ last CHECK_BLESSING if $semantics eq '::array';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::array" 70 10668 10738
1022 10668 ▶ last CHECK_BLESSING if ( substr $semantics, 0, 1 ) eq '[';
Branch: 1 branch
BranchTrueFalseTotal
if substr($semantics, 0, 1) eq "[" 10668 0 10668
1023 0 Marpa::R3::exception(
1024 qq{Cannot bless rule when the semantics are "$semantics"},
1025 q{ Rule is: },
1026 $slg->g1_rule_show($irlid),
1027 "\n",
1028 qq{ Blessing is "$blessing"\n},
1029 qq{ Semantics are "$semantics"\n}
1030 );
1031 } ## end CHECK_BLESSING:
1032  
1033 }
1034  
1035 } ## end CHECK_FOR_WHATEVER_CONFLICT
1036  
1037 # A LHS can be nullable via more than one rule,
1038 # and that means more than one semantics might be specified for
1039 # the nullable symbol. This logic deals with that.
1040 371 my @nullable_rule_ids_by_lhs = ();
1041 371 ▶ RULE: for (my $iter = $slg->g1_rule_ids_gen(); defined ( my $irlid = $iter->());) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $irlid = &$iter())) 12190 371 12561
1042  
1043 12190 my ( $lhs_id, $rule_is_nullable ) =
1044 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1045 <<'END_OF_LUA', 'i>*', $irlid );
1046 local grammar, irlid = ...
1047 local g1g = grammar.g1
1048 return g1g:rule_lhs(irlid), g1g:rule_is_nullable(irlid)
1049 END_OF_LUA
1050  
1051 12190 ▶ push @{ $nullable_rule_ids_by_lhs[$lhs_id] }, $irlid
Branch: 1 branch
BranchTrueFalseTotal
if $rule_is_nullable 554 11636 12190
1052 if $rule_is_nullable;
1053 }
1054  
1055 371 my @null_symbol_closures;
1056 LHS:
1057 371 ▶ for ( my $lhs_id = 0 ; $lhs_id <= $#nullable_rule_ids_by_lhs ; $lhs_id++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lhs_id <= $#nullable_rule_ids_by_lhs) 8121 371 8492
1058 8121 my $irlids = $nullable_rule_ids_by_lhs[$lhs_id];
1059 8121 my $resolution_rule;
1060  
1061 # No nullable rules for this LHS? No problem.
1062 8121 ▶ next LHS if not defined $irlids;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $irlids 7573 548 8121
1063 548 my $rule_count = scalar @{$irlids};
1064  
1065 # I am not sure if this test is necessary
1066 548 ▶ next LHS if $rule_count <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rule_count <= 0 0 548 548
1067  
1068 # Just one nullable rule? Then that's our semantics.
1069 548 ▶ if ( $rule_count == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_count == 1) 542 6 548
1070 542 $resolution_rule = $irlids->[0];
1071 my ( $resolution_name, $closure ) =
1072 542 @{ $rule_resolutions->[$resolution_rule] };
1073 542 ▶ if ($trace_actions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_actions) 0 542 542
1074 0 my $lhs_name = $slg->g1_symbol_display_form($lhs_id);
1075 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} qq[Nulled symbol "$lhs_name" ], qq[ resolved to "$resolution_name" from rule ], $slg->g1_rule_show($resolution_rule) or Marpa::R3::exception("print to trace handle failed") 0 0 0
1076 qq{Nulled symbol "$lhs_name" },
1077 qq{ resolved to "$resolution_name" from rule },
1078 $slg->g1_rule_show($resolution_rule)
1079 or Marpa::R3::exception('print to trace handle failed');
1080 } ## end if ($trace_actions)
1081 542 $null_symbol_closures[$lhs_id] = $resolution_rule;
1082 542 next LHS;
1083 } ## end if ( $rule_count == 1 )
1084  
1085 # More than one rule? Are any empty?
1086 # If so, use the semantics of the empty rule
1087 6 my ($empty_rules) =
1088 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1089 <<'END_OF_LUA', 'i>*', $irlids );
1090 local grammar, irlids = ...
1091 local g1g = grammar.g1
1092 local empty_rules = {}
1093 for ix = 1, #irlids do
1094 local irlid = irlids[ix]
1095 local rule_length = g1g:rule_length(irlid)
1096 if rule_length and rule_length == 0 then
1097 empty_rules[#empty_rules+1] = irlid
1098 end
1099 end
1100 return empty_rules
1101 END_OF_LUA
1102  
1103 6 ▶ if ( scalar @{$empty_rules} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$empty_rules;}) 5 1 6
1104 5 $resolution_rule = $empty_rules->[0];
1105 my ( $resolution_name, $closure ) =
1106 5 @{ $rule_resolutions->[$resolution_rule] };
1107 5 ▶ if ($trace_actions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_actions) 0 5 5
1108 0 my $lhs_name = $slg->g1_symbol_display_form($lhs_id);
1109 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} qq[Nulled symbol "$lhs_name" ], qq[ resolved to "$resolution_name" from rule ], $slg->g1_rule_show($resolution_rule) or Marpa::R3::exception("print to trace handle failed") 0 0 0
1110 qq{Nulled symbol "$lhs_name" },
1111 qq{ resolved to "$resolution_name" from rule },
1112 $slg->g1_rule_show($resolution_rule)
1113 or Marpa::R3::exception('print to trace handle failed');
1114 } ## end if ($trace_actions)
1115 5 $null_symbol_closures[$lhs_id] = $resolution_rule;
1116 5 next LHS;
1117 }
1118  
1119 # Multiple rules, none of them empty.
1120 my ( $first_resolution, @other_resolutions ) =
1121 1 map { $rule_resolutions->[$_] } @{$irlids};
1122  
1123 # Do they have more than one semantics?
1124 # If so, just call it an error and let the user sort it out.
1125 my ( $first_closure_name, undef, $first_semantics, $first_blessing ) =
1126 1 @{$first_resolution};
1127 1 OTHER_RESOLUTION: for my $other_resolution (@other_resolutions) {
1128 my ( $other_closure_name, undef, $other_semantics, $other_blessing )
1129 1 = @{$other_resolution};
1130  
1131 1 ▶ if ( $first_closure_name ne $other_closure_name
Branch: 1 branch
BranchTrueFalseTotal
if ($first_closure_name ne $other_closure_name or $first_semantics ne $other_semantics or $first_blessing ne $other_blessing) 0 1 1
Condition33%2/6
$first_closure_name ne $other_closure_name or $first_semantics ne $other_semantics or $first_blessing ne $other_blessing
l!l&&r!l&&!r
001
$first_closure_name ne $other_closure_name or $first_semantics ne $other_semantics
l!l&&r!l&&!r
001
MC/DC0%0/3
$first_closure_name ne $other_closure_name or $first_semantics ne $other_semantics or $first_blessing ne $other_blessing
$first_closure_name ne $other_closure_name $first_semantics ne $other_semantics $first_blessing ne $other_blessing
Truth table25%1/4
A or B or C
A= $first_closure_name ne $other_closure_nameB= $first_semantics ne $other_semanticsC= $first_blessing ne $other_blessing
ABCresult
1XX1
01X1
0011
0000
1132 or $first_semantics ne $other_semantics
1133 or $first_blessing ne $other_blessing )
1134 {
1135 0 Marpa::R3::exception(
1136 'When nulled, symbol ',
1137 $slg->g1_symbol_display_form($lhs_id),
1138 qq{ can have more than one semantics\n},
1139 qq{ Marpa needs there to be only one semantics\n},
1140 qq{ The rules involved are:\n},
1141 g1_show_rule_list( $slg, $irlids )
1142 );
1143 } ## end if ( $first_closure_name ne $other_closure_name or ...)
1144 } ## end OTHER_RESOLUTION: for my $other_resolution (@other_resolutions)
1145  
1146 # Multiple rules, but they all have one semantics.
1147 # So (obviously) use that semantics
1148 1 $resolution_rule = $irlids->[0];
1149 my ( $resolution_name, $closure ) =
1150 1 @{ $rule_resolutions->[$resolution_rule] };
1151 1 ▶ if ($trace_actions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_actions) 0 1 1
1152 0 my $lhs_name = $slg->g1_symbol_display_form($lhs_id);
1153 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} qq[Nulled symbol "$lhs_name" ], qq[ resolved to "$resolution_name" from rule ], $slg->g1_rule_show($resolution_rule) or Marpa::R3::exception("print to trace handle failed") 0 0 0
1154 qq{Nulled symbol "$lhs_name" },
1155 qq{ resolved to "$resolution_name" from rule },
1156 $slg->g1_rule_show($resolution_rule)
1157 or Marpa::R3::exception('print to trace handle failed');
1158 } ## end if ($trace_actions)
1159 1 $null_symbol_closures[$lhs_id] = $resolution_rule;
1160  
1161 } ## end LHS: for ( my $lhs_id = 0; $lhs_id <= $#nullable_rule_ids_by_lhs...)
1162  
1163 # Do consistency checks
1164  
1165 # Set the object values
1166 371 my $null_values = $slg->[Marpa::R3::Internal_G::NULL_VALUES] =
1167 \@null_symbol_closures;
1168  
1169 371 my @semantics_by_lexeme_id = ();
1170 371 my @blessing_by_lexeme_id = ();
1171  
1172 # Check the lexeme semantics
1173 {
1174 371 my ($highest_symbol_id) =
1175 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1176 <<'END_OF_LUA', '>*' );
1177 local grammar = ...
1178 local g1g = grammar.g1
1179 return g1g:highest_symbol_id()
1180 END_OF_LUA
1181  
1182 371 LEXEME: for my $lexeme_id ( 0 .. $highest_symbol_id ) {
1183  
1184 my ( $semantics, $blessing ) =
1185 14471 @{ $lexeme_resolutions->[$lexeme_id] };
1186 14471 ▶ $blessing = '::undef' if not defined $blessing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $blessing 0 14471 14471
1187 CHECK_SEMANTICS: {
1188 14471 ▶ if ( not $semantics ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($semantics) 0 14471 14471
1189 0 $semantics = '::!default';
1190 0 last CHECK_SEMANTICS;
1191 }
1192 14471 ▶ if ( ( substr $semantics, 0, 1 ) eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($semantics, 0, 1) eq "[") 7822 6649 14471
1193 7822 $semantics =~ s/ //gxms;
1194 7822 last CHECK_SEMANTICS;
1195 }
1196 state $allowed_semantics =
1197 6649 { map { ; ( $_, 1 ) } qw(::array ::undef ::!default ) };
1198  
1199 6649 ▶ if ( not $allowed_semantics->{$semantics} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allowed_semantics->{$semantics}) 0 6649 6649
1200 0 Marpa::R3::exception(
1201 q{Unknown semantics for lexeme },
1202 $slg->g1_symbol_display_form($lexeme_id),
1203 "\n",
1204 qq{ Semantics were specified as "$semantics"\n}
1205 );
1206 } ## end if ( not $allowed_semantics->{$semantics} )
1207  
1208 } ## end CHECK_SEMANTICS:
1209 14471 $semantics_by_lexeme_id[$lexeme_id] = $semantics;
1210 14471 $blessing_by_lexeme_id[$lexeme_id] = $blessing;
1211  
1212 }
1213  
1214 }
1215  
1216 # state $op_lua = Marpa::R3::Thin::op('lua');
1217 371 my ($op_lua) = $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1218 <<'END_OF_LUA', '' );
1219 return _M.defines.MARPA_OP_LUA
1220 END_OF_LUA
1221  
1222 371 my ($op_debug_key) = op_fn_key_by_name( $slg, "debug" );
1223 371 my ($op_noop_key) = op_fn_key_by_name( $slg, "noop" );
1224 371 my ($op_bail_key) = op_fn_key_by_name( $slg, "bail" );
1225 371 my ($op_bless_key) = op_fn_key_by_name( $slg, "bless" );
1226 371 my ($op_callback_key) = op_fn_key_by_name( $slg, "callback" );
1227 371 my ($result_is_undef_key) = op_fn_key_by_name( $slg, 'result_is_undef' );
1228 371 my ($result_is_constant_key) =
1229 op_fn_key_by_name( $slg, 'result_is_constant' );
1230 371 my ($result_is_token_value_key) =
1231 op_fn_key_by_name( $slg, "result_is_token_value" );
1232 371 my ($result_is_n_of_rhs_key) =
1233 op_fn_key_by_name( $slg, "result_is_n_of_rhs" );
1234 371 my ($result_is_n_of_sequence_key) =
1235 op_fn_key_by_name( $slg, "result_is_n_of_sequence" );
1236 371 my ($result_is_array_key) = op_fn_key_by_name( $slg, "result_is_array" );
1237 371 my ($op_push_constant_key) = op_fn_key_by_name( $slg, 'push_constant' );
1238 371 my ($op_push_undef_key) = op_fn_key_by_name( $slg, 'push_undef' );
1239 371 my ($op_push_one_key) = op_fn_key_by_name( $slg, 'push_one' );
1240 371 my ($op_push_values_key) = op_fn_key_by_name( $slg, 'push_values' );
1241 371 my ($op_push_g1_start_key) = op_fn_key_by_name( $slg, 'push_g1_start' );
1242 371 my ($op_push_g1_length_key) = op_fn_key_by_name( $slg, 'push_g1_length' );
1243 371 my ($op_push_start_key) = op_fn_key_by_name( $slg, 'push_start' );
1244 371 my ($op_push_length_key) = op_fn_key_by_name( $slg, 'push_length' );
1245  
1246 371 my @nulling_symbol_by_semantic_rule;
1247 371 NULLING_SYMBOL: for my $nulling_symbol ( 0 .. $#{$null_values} ) {
1248 8121 my $semantic_rule = $null_values->[$nulling_symbol];
1249 8121 ▶ next NULLING_SYMBOL if not defined $semantic_rule;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $semantic_rule 7573 548 8121
1250 548 $nulling_symbol_by_semantic_rule[$semantic_rule] = $nulling_symbol;
1251 } ## end NULLING_SYMBOL: for my $nulling_symbol ( 0 .. $#{$null_values} )
1252  
1253 371 my @work_list = ();
1254 371 ▶ RULE: for (my $iter = $slg->g1_rule_ids_gen(); defined ( my $irlid = $iter->());) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $irlid = &$iter())) 12190 371 12561
1255  
1256 12190 my $semantics = $semantics_by_irlid[$irlid];
1257 12190 my $blessing = $blessing_by_irlid[$irlid];
1258  
1259 12190 ▶ $semantics = '[name,values]' if $semantics eq '::!default';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::!default" 375 11815 12190
1260 12190 ▶ $semantics = '[values]' if $semantics eq '::array';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::array" 502 11688 12190
1261 12190 ▶ $semantics = '::rhs0' if $semantics eq '::first';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::first" 514 11676 12190
1262  
1263 12190 push @work_list, [ $irlid, undef, $semantics, $blessing ];
1264 }
1265  
1266 371 my ($highest_symbol_id) =
1267 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1268 <<'END_OF_LUA', '' );
1269 local grammar = ...
1270 return grammar.g1:highest_symbol_id()
1271 END_OF_LUA
1272  
1273 371 LEXEME: for my $lexeme_id ( 0 .. $highest_symbol_id ) {
1274  
1275 14471 my $semantics = $semantics_by_lexeme_id[$lexeme_id];
1276 14471 my $blessing = $blessing_by_lexeme_id[$lexeme_id];
1277  
1278 next LEXEME
1279 14471 ▶ if $semantics eq '::!default' and $blessing eq '::undef';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::!default" and $blessing eq "::undef" 1631 12840 14471
Condition100%3/3
$semantics eq "::!default" and $blessing eq "::undef"
!ll&&!rl&&r
782250181631
MC/DC100%2/2
$semantics eq "::!default" and $blessing eq "::undef"
$semantics eq "::!default" $blessing eq "::undef"
Truth table100%3/3
A and B
A= $semantics eq "::!default"B= $blessing eq "::undef"
ABresult
0X0
100
111
1280 12840 ▶ $semantics = '::value' if $semantics eq '::!default';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::!default" 5018 7822 12840
1281 12840 ▶ $semantics = '[value]' if $semantics eq '::array';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::array" 0 12840 12840
1282  
1283 12840 push @work_list, [ undef, $lexeme_id, $semantics, $blessing ];
1284 }
1285  
1286 # Registering operations is postponed to this point, because
1287 # the valuator must exist for this to happen. In the future,
1288 # it may be best to have a separate semantics object.
1289 371 my @nulling_closures = ();
1290 371 my @registrations = ();
1291  
1292 371 WORK_ITEM: for my $work_item (@work_list) {
1293 25030 my ( $irlid, $lexeme_id, $semantics, $blessing ) = @{$work_item};
1294  
1295 25030 my ( $closure, $rule_length,
1296 $is_sequence_rule,
1297 $is_discard_sequence_rule,
1298 $nulling_symbol_id );
1299 25030 ▶ if ( defined $irlid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $irlid) 12190 12840 25030
1300 12190 $nulling_symbol_id = $nulling_symbol_by_semantic_rule[$irlid];
1301 12190 $closure = $closure_by_irlid[$irlid];
1302  
1303 12190 ( $rule_length, $is_sequence_rule,
1304 $is_discard_sequence_rule ) =
1305 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1306 <<'END_OF_LUA', 'i', $irlid );
1307 local slg, irlid = ...
1308 local g1g = slg.g1
1309 local is_sequence_rule = g1g:sequence_min(irlid) and 1 or 0
1310 local irl = slg.g1.irls[irlid]
1311 local xpr = irl.xpr
1312 local is_discard_sequence = false
1313 if xpr and xpr.discard_separation and is_sequence_rule then
1314 is_discard_sequence = true
1315 end
1316 return g1g:rule_length(irlid), is_sequence_rule, is_discard_sequence
1317 END_OF_LUA
1318  
1319 } ## end if ( defined $irlid )
1320  
1321 # Determine the "fate" of the array of child values
1322 25030 my @array_fate = ();
1323 ARRAY_FATE: {
1324 25030 ▶ if ( defined $closure and ref $closure eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $closure and ref $closure eq "CODE") 345 24685 25030
Condition100%3/3
defined $closure and ref $closure eq "CODE"
!ll&&!rl&&r
2465431345
MC/DC100%2/2
defined $closure and ref $closure eq "CODE"
defined $closure ref $closure eq "CODE"
Truth table100%3/3
A and B
A= defined $closureB= ref $closure eq "CODE"
ABresult
0X0
100
111
1325 345 push @array_fate, $op_lua, $op_callback_key, $op_bail_key;
1326 345 last ARRAY_FATE;
1327  
1328 }
1329  
1330 24685 ▶ if ( ( substr $semantics, 0, 1 ) eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($semantics, 0, 1) eq "[") 19122 5563 24685
1331 19122 push @array_fate, $op_lua, $result_is_array_key, $op_bail_key;
1332 19122 last ARRAY_FATE;
1333 }
1334 } ## end ARRAY_FATE:
1335  
1336 25030 my @ops = ();
1337  
1338 SET_OPS: {
1339  
1340 25030 ▶ if ( $semantics eq '::undef' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($semantics eq "::undef") 31 24999 25030
1341 31 @ops = ( $op_lua, $result_is_undef_key, $op_bail_key );
1342 31 last SET_OPS;
1343 }
1344  
1345 CHECK_TYPE: {
1346 24999 ▶ last CHECK_TYPE if not defined $irlid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $irlid 12840 12159 24999
1347 12159 my $thingy_ref = $closure_by_irlid[$irlid];
1348 12159 ▶ last CHECK_TYPE if not defined $thingy_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thingy_ref 11814 345 12159
1349 345 my $ref_type = Scalar::Util::reftype $thingy_ref;
1350 345 ▶ if ( $ref_type eq q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_type eq "") 0 345 345
1351 0 my $rule_desc = $slg->g1_rule_show($irlid);
1352 0 Marpa::R3::exception(
1353 qq{An action resolved to a scalar.\n},
1354 qq{ This is not allowed.\n},
1355 qq{ A constant action must be a reference.\n},
1356 qq{ Rule was $rule_desc\n}
1357 );
1358 } ## end if ( $ref_type eq q{} )
1359  
1360 345 ▶ if ( $ref_type eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_type eq "CODE") 345 0 345
1361  
1362 # Set the nulling closure if this is the nulling symbol of a rule
1363 345 ▶ $nulling_closures[$nulling_symbol_id] = $thingy_ref
Branch: 1 branch
BranchTrueFalseTotal
if defined $nulling_symbol_id and defined $irlid 76 269 345
Condition66%2/3
defined $nulling_symbol_id and defined $irlid
!ll&&!rl&&r
269076
MC/DC50%1/2
defined $nulling_symbol_id and defined $irlid
defined $nulling_symbol_id defined $irlid
Truth table66%2/3
A and B
A= defined $nulling_symbol_idB= defined $irlid
ABresult
0X0
100
111
1364 if defined $nulling_symbol_id
1365 and defined $irlid;
1366 345 last CHECK_TYPE;
1367 } ## end if ( $ref_type eq 'CODE' )
1368  
1369 0 my $rule_desc = $slg->g1_rule_show($irlid);
1370 0 Marpa::R3::exception(
1371 qq{Constant action is not of an allowed type.\n},
1372 qq{ It was of type reference to $ref_type.\n},
1373 qq{ Rule was $rule_desc\n}
1374 );
1375 }
1376  
1377 # After this point, any closure will be a ref to 'CODE'
1378  
1379 24999 ▶ if ( defined $lexeme_id and $semantics eq '::value' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lexeme_id and $semantics eq "::value") 5018 19981 24999
Condition100%3/3
defined $lexeme_id and $semantics eq "::value"
!ll&&!rl&&r
1215978225018
MC/DC100%2/2
defined $lexeme_id and $semantics eq "::value"
defined $lexeme_id $semantics eq "::value"
Truth table100%3/3
A and B
A= defined $lexeme_idB= $semantics eq "::value"
ABresult
0X0
100
111
1380 5018 @ops = ( $op_lua, $result_is_token_value_key, $op_bail_key );
1381 5018 last SET_OPS;
1382 }
1383  
1384 PROCESS_SINGLETON_RESULT: {
1385 19981 ▶ last PROCESS_SINGLETON_RESULT if not defined $irlid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $irlid 7822 12159 19981
1386  
1387 12159 my $singleton;
1388 12159 ▶ if ( $semantics =~ m/\A [:][:] rhs (\d+) \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($semantics =~ /\A [:][:] rhs (\d+) \z/msx) 514 11645 12159
1389 514 $singleton = $1 + 0;
1390 }
1391  
1392 12159 ▶ last PROCESS_SINGLETON_RESULT if not defined $singleton;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $singleton 11645 514 12159
1393  
1394 514 my $singleton_element = $singleton;
1395 514 ▶ if ($is_discard_sequence_rule) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_discard_sequence_rule) 0 514 514
1396 0 @ops = (
1397 $op_lua, $result_is_n_of_sequence_key,
1398 $singleton_element
1399 );
1400 0 last SET_OPS;
1401 }
1402 514 ▶ if ($is_sequence_rule) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_sequence_rule) 0 514 514
1403 0 @ops =
1404 ( $op_lua, $result_is_n_of_rhs_key, $singleton_element );
1405 0 last SET_OPS;
1406 }
1407  
1408 514 my ($mask) = $slg->call_by_tag(
1409 ( '@' . __FILE__ . ':' . __LINE__ ),
1410 <<'END_OF_LUA', 'i>0', $irlid );
1411 local slg, irlid = ...
1412 return slg.g1.irls[irlid].mask
1413 END_OF_LUA
1414  
1415 my @elements =
1416 514 grep { $mask->[$_] } 0 .. ( $rule_length - 1 );
1417 514 ▶ if ( not scalar @elements ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @elements) 0 514 514
1418 0 my $original_semantics = $semantics_by_irlid[$irlid];
1419 0 Marpa::R3::exception(
1420 q{Impossible semantics for empty rule: },
1421 $slg->g1_rule_show($irlid),
1422 "\n",
1423 qq{ Semantics were specified as "$original_semantics"\n}
1424 );
1425 } ## end if ( not scalar @elements )
1426 514 $singleton_element = $elements[$singleton];
1427  
1428 514 ▶ if ( not defined $singleton_element ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $singleton_element) 0 514 514
1429 0 my $original_semantics = $semantics_by_irlid[$irlid];
1430 0 Marpa::R3::exception(
1431 q{Impossible semantics for rule: },
1432 $slg->g1_rule_show($irlid),
1433 "\n",
1434 qq{ Semantics were specified as "$original_semantics"\n}
1435 );
1436 } ## end if ( not defined $singleton_element )
1437 514 @ops = ( $op_lua, $result_is_n_of_rhs_key, $singleton_element );
1438 514 last SET_OPS;
1439 } ## end PROCESS_SINGLETON_RESULT:
1440  
1441 19467 ▶ if ( not @array_fate ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@array_fate) 0 19467 19467
1442 0 @ops = ( $op_lua, $result_is_undef_key, $op_bail_key );
1443 0 last SET_OPS;
1444 }
1445  
1446 # if here, @array_fate is non-empty
1447  
1448 19467 my @bless_ops = ();
1449 19467 ▶ if ( $blessing ne '::undef' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($blessing ne "::undef") 18440 1027 19467
1450 18440 push @bless_ops, $op_lua, $op_bless_key, \[$irlid, $lexeme_id, $blessing];
1451 }
1452  
1453 19467 ▶ Marpa::R3::exception(qq{Unknown semantics: "$semantics"})
Branch: 1 branch
BranchTrueFalseTotal
if substr($semantics, 0, 1) ne "[" 0 19467 19467
1454 if ( substr $semantics, 0, 1 ) ne '[';
1455  
1456 19467 my @push_ops = ();
1457 19467 my $array_descriptor = substr $semantics, 1, -1;
1458 19467 $array_descriptor =~ s/^\s*|\s*$//g;
1459 RESULT_DESCRIPTOR:
1460 19467 for my $result_descriptor ( split /[,]\s*/xms, $array_descriptor ) {
1461 56781 $result_descriptor =~ s/^\s*|\s*$//g;
1462 56781 ▶ if ( $result_descriptor eq 'g1start' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "g1start") 70 56711 56781
1463 70 push @push_ops, $op_lua, $op_push_g1_start_key,
1464 $op_bail_key;
1465 70 next RESULT_DESCRIPTOR;
1466 }
1467 56711 ▶ if ( $result_descriptor eq 'g1length' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "g1length") 70 56641 56711
1468 70 push @push_ops, $op_lua, $op_push_g1_length_key,
1469 $op_bail_key;
1470 70 next RESULT_DESCRIPTOR;
1471 }
1472 56641 ▶ if ( $result_descriptor eq 'start' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "start") 18319 38322 56641
1473 18319 push @push_ops, $op_lua, $op_push_start_key, $op_bail_key;
1474 18319 next RESULT_DESCRIPTOR;
1475 }
1476 38322 ▶ if ( $result_descriptor eq 'length' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "length") 18319 20003 38322
1477 18319 push @push_ops, $op_lua, $op_push_length_key, $op_bail_key;
1478 18319 next RESULT_DESCRIPTOR;
1479 }
1480  
1481 20003 ▶ if ( $result_descriptor eq 'lhs' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "lhs") 8 19995 20003
1482 8 ▶ if ( defined $irlid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $irlid) 3 5 8
1483  
1484 3 my ($lhs_id) = $slg->call_by_tag(
1485 ( '@' . __FILE__ . ':' . __LINE__ ),
1486 <<'END_OF_LUA', 'i>*', $irlid );
1487 local grammar, irlid = ...
1488 local g1g = grammar.g1
1489 return g1g:rule_lhs(irlid)
1490 END_OF_LUA
1491 3 push @push_ops, $op_lua, $op_push_constant_key,
1492 \$lhs_id;
1493 3 next RESULT_DESCRIPTOR;
1494 }
1495 5 ▶ if ( defined $lexeme_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lexeme_id) 5 0 5
1496 5 push @push_ops, $op_lua, $op_push_constant_key,
1497 \$lexeme_id;
1498 5 next RESULT_DESCRIPTOR;
1499 }
1500 0 push @push_ops, $op_lua, $op_push_undef_key, $op_bail_key;
1501 0 next RESULT_DESCRIPTOR;
1502 } ## end if ( $result_descriptor eq 'lhs' )
1503  
1504 19995 ▶ if ( $result_descriptor eq 'name' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "name") 505 19490 19995
1505 505 ▶ if ( defined $irlid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $irlid) 435 70 505
1506 435 my $production_id =
1507 $slg->g1_rule_to_production_id($irlid);
1508 435 my $name = $slg->production_name($production_id);
1509 435 push @push_ops, $op_lua, $op_push_constant_key, \$name;
1510 435 next RESULT_DESCRIPTOR;
1511 }
1512 70 ▶ if ( defined $lexeme_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lexeme_id) 70 0 70
1513 70 my $name = $slg->g1_symbol_name($lexeme_id);
1514 70 push @push_ops, $op_lua, $op_push_constant_key, \$name;
1515 70 next RESULT_DESCRIPTOR;
1516 }
1517 0 ▶ if ( defined $nulling_symbol_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nulling_symbol_id) 0 0 0
1518 0 my $name = $slg->g1_symbol_name($nulling_symbol_id);
1519 0 push @push_ops, $op_lua, $op_push_constant_key, \$name;
1520 0 next RESULT_DESCRIPTOR;
1521 }
1522 0 push @push_ops, $op_lua, $op_push_undef_key, $op_bail_key;
1523 0 next RESULT_DESCRIPTOR;
1524 } ## end if ( $result_descriptor eq 'name' )
1525  
1526 19490 ▶ if ( $result_descriptor eq 'symbol' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "symbol") 16 19474 19490
1527 16 ▶ if ( defined $irlid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $irlid) 6 10 16
1528 6 my ($name) = $slg->call_by_tag(
1529 ( '@' . __FILE__ . ':' . __LINE__ ),
1530 <<'END_OF_LUA', 'i>*', $irlid );
1531 local grammar, irlid = ...
1532 local g1g = grammar.g1
1533 local lhs_id = g1g:rule_lhs(irlid)
1534 return g1g:symbol_name(lhs_id)
1535 END_OF_LUA
1536 6 push @push_ops, $op_lua, $op_push_constant_key, \$name;
1537 6 next RESULT_DESCRIPTOR;
1538 } ## end if ( defined $irlid )
1539 10 ▶ if ( defined $lexeme_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lexeme_id) 10 0 10
1540 10 my $name = $slg->g1_symbol_name($lexeme_id);
1541 10 push @push_ops, $op_lua, $op_push_constant_key, \$name;
1542 10 next RESULT_DESCRIPTOR;
1543 }
1544 0 ▶ if ( defined $nulling_symbol_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nulling_symbol_id) 0 0 0
1545 0 my $name = $slg->g1_symbol_name($nulling_symbol_id);
1546 0 push @push_ops, $op_lua, $op_push_constant_key, \$name;
1547 0 next RESULT_DESCRIPTOR;
1548 }
1549 0 push @push_ops, $op_lua, $op_push_undef_key, $op_bail_key;
1550 0 next RESULT_DESCRIPTOR;
1551 } ## end if ( $result_descriptor eq 'symbol' )
1552  
1553 19474 ▶ if ( $result_descriptor eq 'rule' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "rule") 8 19466 19474
1554 8 ▶ if ( defined $irlid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $irlid) 3 5 8
1555 3 push @push_ops, $op_lua, $op_push_constant_key, \$irlid;
1556 3 next RESULT_DESCRIPTOR;
1557 }
1558 5 push @push_ops, $op_lua, $op_push_undef_key, $op_bail_key;
1559 5 next RESULT_DESCRIPTOR;
1560 } ## end if ( $result_descriptor eq 'rule' )
1561 19466 ▶ if ( $result_descriptor eq 'values'
Branch: 1 branch
BranchTrueFalseTotal
if ($result_descriptor eq "values" or $result_descriptor eq "value") 19466 0 19466
Condition66%2/3
$result_descriptor eq "values" or $result_descriptor eq "value"
l!l&&r!l&&!r
1162478420
MC/DC0%0/2
$result_descriptor eq "values" or $result_descriptor eq "value"
$result_descriptor eq "values" $result_descriptor eq "value"
Truth table66%2/3
A or B
A= $result_descriptor eq "values"B= $result_descriptor eq "value"
ABresult
1X1
011
000
1562 or $result_descriptor eq 'value' )
1563 {
1564 19466 ▶ if ( defined $lexeme_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lexeme_id) 7822 11644 19466
1565 7822 push @push_ops, $op_lua, $op_push_values_key, 1;
1566 7822 next RESULT_DESCRIPTOR;
1567 }
1568 11644 ▶ if ($is_sequence_rule) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_sequence_rule) 697 10947 11644
1569 697 ▶ push @push_ops, $op_lua, $op_push_values_key,
Branch: 1 branch
BranchTrueFalseTotal
$is_discard_sequence_rule ? : 223 474 697
1570 ( $is_discard_sequence_rule ? 2 : 1 );
1571 697 next RESULT_DESCRIPTOR;
1572 } ## end if ($is_sequence_rule)
1573  
1574 10947 my ($mask) = $slg->call_by_tag(
1575 ( '@' . __FILE__ . ':' . __LINE__ ),
1576 <<'END_OF_LUA', 'i>0', $irlid );
1577 local slg, irlid = ...
1578 return slg.g1.irls[irlid].mask
1579 END_OF_LUA
1580  
1581 10947 ▶ if ( $rule_length > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_length > 0) 10764 183 10947
1582 push @push_ops, map {
1583 10764 ▶ $mask->[$_]
Branch: 1 branch
BranchTrueFalseTotal
$mask->[$_] ? : 13142 6819 19961
1584 ? ( $op_lua, $op_push_one_key, $_ )
1585 : ()
1586 } 0 .. $rule_length - 1;
1587 }
1588 10947 next RESULT_DESCRIPTOR;
1589 } ## end if ( $result_descriptor eq 'values' or ...)
1590 Marpa::R3::exception(
1591 0 qq{Unknown result descriptor: "$result_descriptor"\n},
1592 qq{ The full semantics were "$semantics"}
1593 );
1594 } ## end RESULT_DESCRIPTOR: for my $result_descriptor ( split /[,]\s*/xms, ...)
1595 19467 @ops = ( @push_ops, @bless_ops, @array_fate );
1596  
1597 } ## end SET_OPS:
1598  
1599 25030 ▶ if ( defined $irlid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $irlid) 12190 12840 25030
1600 12190 push @registrations, [ 'rule', $irlid, @ops ];
1601 }
1602  
1603 25030 ▶ if ( defined $nulling_symbol_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nulling_symbol_id) 548 24482 25030
1604  
1605 548 push @registrations, [ 'nulling', $nulling_symbol_id, @ops ];
1606 } ## end if ( defined $nulling_symbol_id )
1607  
1608 25030 ▶ if ( defined $lexeme_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lexeme_id) 12840 12190 25030
1609 12840 push @registrations, [ 'token', $lexeme_id, @ops ];
1610 }
1611  
1612 } ## end WORK_ITEM: for my $work_item (@work_list)
1613  
1614 SLR_NULLING_GRAMMAR_HACK: {
1615  
1616 # A hack for nulling SLR grammars --
1617 # the nulling semantics of the start symbol should
1618 # be those of the symbol on the
1619 # RHS of the start rule --
1620 # so copy them.
1621  
1622 371 my $start_symbol_id = $slg->g1_symbol_by_name('[:start:]');
1623  
1624 371 my ($symbol_is_nullable) =
1625 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1626 <<'END_OF_LUA', 'i>*', $start_symbol_id );
1627 local grammar, irlid = ...
1628 local g1g = grammar.g1
1629 return (g1g:symbol_is_nullable(irlid) and 1 or 0)
1630 END_OF_LUA
1631  
1632 371 ▶ last SLR_NULLING_GRAMMAR_HACK if not $symbol_is_nullable;
Branch: 1 branch
BranchTrueFalseTotal
unless $symbol_is_nullable 0 371 371
1633  
1634 371 my $start_rhs_symbol_id;
1635 371 ▶ RULE: for (my $iter = $slg->g1_rule_ids_gen(); defined ( my $irlid = $iter->());) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $irlid = &$iter())) 1582 0 1582
1636 1582 my ( $lhs, $rhs0 ) = $slg->g1_rule_expand($irlid);
1637 1582 ▶ if ( $start_symbol_id == $lhs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_symbol_id == $lhs) 371 1211 1582
1638 371 $start_rhs_symbol_id = $rhs0;
1639 371 last RULE;
1640 }
1641 }
1642  
1643 371 REGISTRATION: for my $registration (@registrations) {
1644 24537 my ( $type, $nulling_symbol_id ) = @{$registration};
1645 24537 ▶ if ( $nulling_symbol_id == $start_rhs_symbol_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nulling_symbol_id == $start_rhs_symbol_id) 319 24218 24537
1646 319 my ( undef, undef, @ops ) = @{$registration};
1647 319 push @registrations, [ 'nulling', $start_symbol_id, @ops ];
1648 319 $nulling_closures[$start_symbol_id] =
1649 $nulling_closures[$start_rhs_symbol_id];
1650 319 last REGISTRATION;
1651 } ## end if ( $nulling_symbol_id == $start_rhs_symbol_id )
1652 } ## end REGISTRATION: for my $registration (@registrations)
1653 } ## end SLR_NULLING_GRAMMAR_HACK:
1654  
1655 371 $slg->[Marpa::R3::Internal_G::CLOSURE_BY_SYMBOL_ID] =
1656 \@nulling_closures;
1657 371 $slg->[Marpa::R3::Internal_G::CLOSURE_BY_RULE_ID] =
1658 \@closure_by_irlid;
1659  
1660 371 return \@registrations;
1661  
1662 }
1663  
1664 sub resolve_grammar {
1665  
1666 372 ▶ my ($slg) = @_;
Subroutine resolve_grammar: called CC=17 SCAR=33.9
1667  
1668 372 ▶ my $trace_actions =
Condition50%1/2
$slg->[7] // 0
l!l
0372
MC/DC0%0/1
$slg->[7] // 0
$slg->[7]
Truth table50%1/2
A
A= $slg->[7]
Aresult
11
00
1669 $slg->[Marpa::R3::Internal_G::TRACE_ACTIONS] // 0;
1670 372 my $trace_file_handle =
1671 $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE];
1672  
1673 372 my $resolve_error;
1674  
1675 372 my $default_action_resolution =
1676 resolve_action( $slg, undef, \$resolve_error );
1677 372 ▶ Marpa::R3::exception( "Could not resolve default action\n",
Branch: 1 branch
BranchTrueFalseTotal
unless $default_action_resolution 0 372 372
Condition0%0/2
$resolve_error // "Failed to resolve action"
l!l
00
MC/DC0%0/1
$resolve_error // "Failed to resolve action"
$resolve_error
Truth table0%0/2
A
A= $resolve_error
Aresult
11
00
1678 q{ }, ( $resolve_error // 'Failed to resolve action' ) )
1679 if not $default_action_resolution;
1680  
1681 372 my $rule_resolutions = [];
1682  
1683 372 ▶ RULE_ID: for (my $iter = $slg->g1_rule_ids_gen(); defined ( my $irlid = $iter->());) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $irlid = &$iter())) 12191 371 12562
1684  
1685 12191 my $rule_resolution = resolve_rule_by_id( $slg, $irlid );
1686 12190 ▶ $rule_resolution //= $default_action_resolution;
Condition66%2/3
$rule_resolution //= $default_action_resolution
l!l&&r!l&&!r
118153750
MC/DC0%0/2
$rule_resolution //= $default_action_resolution
$rule_resolution $default_action_resolution
Truth table66%2/3
A //= B
A= $rule_resolutionB= $default_action_resolution
ABresult
1X1
011
000
1687  
1688 12190 ▶ if ( not $rule_resolution ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rule_resolution) 0 12190 12190
1689 0 my $rule_desc = $slg->g1_rule_show($irlid);
1690  
1691 0 my ($action) =
1692 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1693 <<'END_OF_LUA', 'is>*', $irlid );
1694 local slg, irl_id, rule_desc = ...
1695 local action = slg.g1.irls[irl_id].action
1696 local message = string.format(
1697 "Could not resolve action\n Rule was %s\n",
1698 rule_desc)
1699 if action then
1700 message = message ..
1701 string.format(" Action was specified as %q\n", action)
1702 end
1703 error(message)
1704 END_OF_LUA
1705  
1706 } ## end if ( not $rule_resolution )
1707  
1708 DETERMINE_BLESSING: {
1709  
1710 12190 my $blessing = rule_blessing_find( $slg, $irlid );
1711 12190 my ( $closure_name, $closure, $semantics ) = @{$rule_resolution};
1712  
1713 12190 ▶ if ( $blessing ne '::undef' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($blessing ne "::undef") 10738 1452 12190
1714 10738 ▶ $semantics = '::array' if $semantics eq '::!default';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::!default" 0 10738 10738
1715 CHECK_SEMANTICS: {
1716 10738 ▶ last CHECK_SEMANTICS if $semantics eq '::array';
Branch: 1 branch
BranchTrueFalseTotal
if $semantics eq "::array" 70 10668 10738
1717 last CHECK_SEMANTICS
1718 10668 ▶ if ( substr $semantics, 0, 1 ) eq '[';
Branch: 1 branch
BranchTrueFalseTotal
if substr($semantics, 0, 1) eq "[" 10668 0 10668
1719 0 Marpa::R3::exception(
1720 qq{Attempt to bless, but improper semantics: "$semantics"\n},
1721 qq{ Blessing: "$blessing"\n},
1722 ' Rule: ',
1723 $slg->g1_rule_show($irlid)
1724 );
1725 } ## end CHECK_SEMANTICS:
1726 } ## end if ( $blessing ne '::undef' )
1727  
1728 $rule_resolution =
1729 12190 [ $closure_name, $closure, $semantics, $blessing ];
1730 } ## end DETERMINE_BLESSING:
1731  
1732 12190 $rule_resolutions->[$irlid] = $rule_resolution;
1733  
1734 }
1735  
1736 371 ▶ if ( $trace_actions >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_actions >= 2) 0 371 371
1737  
1738 0 my ($highest_irlid) =
1739 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1740 <<'END_OF_LUA', '>*' );
1741 local grammar = ...
1742 local g1g = grammar.g1
1743 return g1g:highest_rule_id()
1744 END_OF_LUA
1745  
1746 0 RULE: for my $rule_id ( 0 .. $highest_irlid ) {
1747 my ( $resolution_name, $closure ) =
1748 0 @{ $rule_resolutions->[$rule_id] };
1749 0 ▶ say {$trace_file_handle} 'Rule ',
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Rule ", $slg->g1_rule_show($rule_id), qq[ resolves to "$resolution_name"] or Marpa::R3::exception("print to trace handle failed") 0 0 0
1750 $slg->g1_rule_show($rule_id),
1751 qq{ resolves to "$resolution_name"}
1752 or Marpa::R3::exception('print to trace handle failed');
1753 }
1754 }
1755  
1756 371 my @lexeme_resolutions = ();
1757  
1758 371 my ($highest_symbol_id) =
1759 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1760 <<'END_OF_LUA', '>*' );
1761 local grammar = ...
1762 local g1g = grammar.g1
1763 return g1g:highest_symbol_id()
1764 END_OF_LUA
1765  
1766 371 SYMBOL: for my $lexeme_id ( 0 .. $highest_symbol_id ) {
1767  
1768 14471 my $semantics = lexeme_semantics_find( $slg, $lexeme_id );
1769 14471 ▶ if ( not defined $semantics ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $semantics) 0 14471 14471
1770 0 my $message =
1771 "Could not determine lexeme's semantics\n"
1772 . q{ Lexeme was }
1773 . $slg->g1_symbol_display_form($lexeme_id) . "\n";
1774 0 Marpa::R3::exception($message);
1775 } ## end if ( not defined $semantics )
1776 14471 my $blessing = lexeme_blessing_find( $slg, $lexeme_id );
1777 14471 ▶ if ( not defined $blessing ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $blessing) 0 14471 14471
1778 0 my $message =
1779 "Could not determine lexeme's blessing\n"
1780 . q{ Lexeme was }
1781 . $slg->g1_symbol_display_form($lexeme_id) . "\n";
1782 0 Marpa::R3::exception($message);
1783 } ## end if ( not defined $blessing )
1784 14471 $lexeme_resolutions[$lexeme_id] = [ $semantics, $blessing ];
1785  
1786 }
1787  
1788 371 return ( $rule_resolutions, \@lexeme_resolutions );
1789 }
1790  
1791 # Given the grammar and an action name, resolve it to a closure,
1792 # or return undef
1793 sub resolve_action {
1794 12188 ▶ my ( $slg, $closure_name, $p_error ) = @_;
Subroutine resolve_action: called CC=26 SCAR=40.0
1795 12188 my $trace_file_handle =
1796 $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE];
1797 12188 my $trace_actions = $slg->[Marpa::R3::Internal_G::TRACE_ACTIONS];
1798  
1799 # A reserved closure name;
1800 12188 ▶ return [ q{}, undef, '::!default' ] if not defined $closure_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $closure_name 372 11816 12188
1801  
1802 11816 ▶ if ( $closure_name eq q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closure_name eq "") 0 11816 11816
1803 0 ▶ ${$p_error} = q{The action string cannot be the empty string}
Branch: 1 branch
BranchTrueFalseTotal
if defined $p_error 0 0 0
1804 if defined $p_error;
1805 0 return;
1806 }
1807  
1808 11816 ▶ return [ q{}, \undef, $closure_name ] if $closure_name eq '::undef';
Branch: 1 branch
BranchTrueFalseTotal
if $closure_name eq "::undef" 31 11785 11816
1809 11785 ▶ if ( substr( $closure_name, 0, 2 ) eq q{::}
Branch: 1 branch
BranchTrueFalseTotal
if (substr($closure_name, 0, 2) eq "::" or substr($closure_name, 0, 1) eq "[") 11439 346 11785
Condition100%3/3
substr($closure_name, 0, 2) eq "::" or substr($closure_name, 0, 1) eq "["
l!l&&r!l&&!r
67110768346
MC/DC100%2/2
substr($closure_name, 0, 2) eq "::" or substr($closure_name, 0, 1) eq "["
substr($closure_name, 0, 2) eq "::" substr($closure_name, 0, 1) eq "["
Truth table100%3/3
A or B
A= substr($closure_name, 0, 2) eq "::"B= substr($closure_name, 0, 1) eq "["
ABresult
1X1
011
000
1810 or substr( $closure_name, 0, 1 ) eq '[' )
1811 {
1812 11439 return [ q{}, undef, $closure_name ];
1813 }
1814  
1815 346 my $fully_qualified_name;
1816 346 ▶ if ( $closure_name =~ /([:][:])|[']/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closure_name =~ /([:][:])|[']/msx) 211 135 346
1817 211 $fully_qualified_name = $closure_name;
1818 }
1819  
1820 346 ▶ if ( not $fully_qualified_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fully_qualified_name) 135 211 346
1821 135 my $resolve_package =
1822 $slg->[Marpa::R3::Internal_G::SEMANTICS_PACKAGE];
1823 135 ▶ if ( not defined $resolve_package ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $resolve_package) 0 135 135
1824 0 ${$p_error} = Marpa::R3::Internal::X->new(
1825 {
1826 message =>
1827 qq{Could not fully qualify "$closure_name": no semantics package},
1828 name => 'NO RESOLVE PACKAGE'
1829 }
1830 );
1831 0 return;
1832 } ## end if ( not defined $resolve_package )
1833 135 $fully_qualified_name = $resolve_package . q{::} . $closure_name;
1834 } ## end if ( not $fully_qualified_name )
1835  
1836 346 my $closure;
1837 my $type;
1838 TYPE: {
1839 104 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1840 346 $closure = *{$fully_qualified_name}{'CODE'};
1841 104 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1842 346 ▶ if ( defined $closure ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $closure) 345 1 346
1843 345 $type = 'CODE';
1844 345 last TYPE;
1845 }
1846 104 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1847 1 $closure = *{$fully_qualified_name}{'SCALAR'};
1848 104 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1849  
1850 # Currently $closure is always defined, but this
1851 # behavior is said to be subject to change in perlref
1852 1 ▶ if ( defined $closure and defined ${$closure} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $closure and defined ${$closure;}) 0 1 1
Condition33%1/3
defined $closure and defined ${$closure;}
!ll&&!rl&&r
010
MC/DC0%0/2
defined $closure and defined ${$closure;}
defined $closure defined ${$closure;}
Truth table33%1/3
A and B
A= defined $closureB= defined ${$closure;}
ABresult
0X0
100
111
1853 0 $type = 'SCALAR';
1854 0 Marpa::R3::exception(
1855 "$closure_name resolves to SCALAR, which is not yet implemented"
1856 );
1857 0 last TYPE;
1858 }
1859  
1860 1 $closure = undef;
1861 } ## end TYPE:
1862  
1863 346 ▶ if ( defined $closure ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $closure) 345 1 346
1864 345 ▶ if ($trace_actions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_actions) 0 345 345
1865 0 ▶ print {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
print {$trace_file_handle;} qq[Successful resolution of action "$closure_name" as $type ], "to ", $fully_qualified_name, "\n" or Marpa::R3::exception("Could not print to trace file") 0 0 0
1866 qq{Successful resolution of action "$closure_name" as $type },
1867 'to ', $fully_qualified_name, "\n"
1868 or Marpa::R3::exception('Could not print to trace file');
1869 } ## end if ($trace_actions)
1870 345 return [ $fully_qualified_name, $closure, '::array' ];
1871 } ## end if ( defined $closure )
1872  
1873 1 ▶ if ( $trace_actions or defined $p_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_actions or defined $p_error) 1 0 1
Condition33%1/3
$trace_actions or defined $p_error
l!l&&r!l&&!r
010
MC/DC0%0/2
$trace_actions or defined $p_error
$trace_actions defined $p_error
Truth table33%1/3
A or B
A= $trace_actionsB= defined $p_error
ABresult
1X1
011
000
1874 1 for my $slot (qw(ARRAY HASH IO FORMAT)) {
1875 104 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1876 4 ▶ if ( defined *{$fully_qualified_name}{$slot} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{$fully_qualified_name;}{$slot}) 0 4 4
1877 0 my $error =
1878 qq{Failed resolution of action "$closure_name" to $fully_qualified_name\n}
1879 . qq{ $fully_qualified_name is present as a $slot, but a $slot is not an acceptable resolution\n};
1880 0 ▶ if ($trace_actions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_actions) 0 0 0
1881 0 ▶ print {$trace_file_handle} $error
Branch: 1 branch
BranchTrueFalseTotal
print {$trace_file_handle;} $error or Marpa::R3::exception("Could not print to trace file") 0 0 0
1882 or Marpa::R3::exception('Could not print to trace file');
1883 }
1884 0 ▶ ${$p_error} = $error if defined $p_error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $p_error 0 0 0
1885 0 return;
1886 } ## end if ( defined *{$fully_qualified_name}{$slot} )
1887 } ## end for my $slot (qw(ARRAY HASH IO FORMAT))
1888 } ## end if ( $trace_actions or defined $p_error )
1889  
1890 {
1891 1 my $error =
1892 qq{Failed resolution of action "$closure_name" to $fully_qualified_name\n};
1893 1 ▶ ${$p_error} = $error if defined $p_error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $p_error 1 0 1
1894 1 ▶ if ($trace_actions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_actions) 0 1 1
1895 0 ▶ print {$trace_file_handle} $error
Branch: 1 branch
BranchTrueFalseTotal
print {$trace_file_handle;} $error or Marpa::R3::exception("Could not print to trace file") 0 0 0
1896 or Marpa::R3::exception('Could not print to trace file');
1897 }
1898 }
1899 1 return;
1900  
1901 }
1902  
1903 sub resolve_rule_by_id {
1904 12191 ▶ my ( $slg, $irlid ) = @_;
Subroutine resolve_rule_by_id: called CC=4 SCAR=13.9
1905  
1906 12191 my ($action_name) =
1907 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1908 <<'END_OF_LUA', 'i>*', $irlid );
1909 local slg, irl_id = ...
1910 return slg.g1.irls[irl_id].action
1911 END_OF_LUA
1912  
1913 12191 my $resolve_error;
1914 12191 ▶ return if not defined $action_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $action_name 375 11816 12191
1915 11816 my $resolution = resolve_action( $slg, $action_name, \$resolve_error );
1916  
1917 11816 ▶ if ( not $resolution ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resolution) 1 11815 11816
1918 1 my $rule_desc = $slg->g1_rule_show($irlid);
1919 1 ▶ Marpa::R3::exception(
Condition50%1/2
$resolve_error // "Failed to resolve action"
l!l
10
MC/DC0%0/1
$resolve_error // "Failed to resolve action"
$resolve_error
Truth table50%1/2
A
A= $resolve_error
Aresult
11
00
1920 "Could not resolve rule action named '$action_name'\n",
1921 " Rule was $rule_desc\n",
1922 q{ },
1923 ( $resolve_error // 'Failed to resolve action' )
1924 );
1925 } ## end if ( not $resolution )
1926 11815 return $resolution;
1927 } ## end sub resolve_rule_by_id
1928  
1929 # Find the blessing for a rule.
1930 sub rule_blessing_find {
1931 12190 ▶ my ( $slg, $irlid ) = @_;
Subroutine rule_blessing_find: called CC=1 SCAR=0.0
1932 12190 my ($blessing) =
1933 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1934 <<'END_OF_LUA', 'i', $irlid);
1935 local slg, irlid = ...
1936 local irl = slg.g1.irls[irlid]
1937 local blessing = '::undef'
1938 local xpr = irl.xpr
1939 if xpr then
1940 blessing = xpr.bless or '::undef'
1941 end
1942 return blessing
1943 END_OF_LUA
1944 12190 return $blessing;
1945 }
1946  
1947 # Find the semantics for a lexeme.
1948 sub lexeme_semantics_find {
1949 14471 ▶ my ( $slg, $lexeme_id ) = @_;
Subroutine lexeme_semantics_find: called CC=1 SCAR=0.0
1950  
1951 14471 my ($semantics) =
1952 $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1953 <<'END_OF_LUA', 'i>*', $lexeme_id);
1954 local slg, isyid = ...
1955 local xsy = slg.g1.xsys[isyid]
1956 if not xsy then return '::!default' end
1957 local semantics = xsy.lexeme_semantics
1958 return semantics or '::!default'
1959 END_OF_LUA
1960  
1961 14471 return $semantics;
1962 }
1963  
1964 # Find the blessing for a lexeme.
1965 sub lexeme_blessing_find {
1966 14471 ▶ my ( $slg, $lexeme_id ) = @_;
Subroutine lexeme_blessing_find: called CC=1 SCAR=0.0
1967  
1968 14471 my ($result) = $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1969 <<'END_OF_LUA', 'i', $lexeme_id );
1970 local slg, isyid = ...
1971 local xsy = slg.g1.xsys[isyid]
1972 if not xsy then return '::undef' end
1973 local blessing = xsy.blessing
1974 return blessing or '::undef'
1975 END_OF_LUA
1976  
1977 14471 return $result;
1978 }
1979  
1980 sub op_fn_key_by_name {
1981 7049 ▶ my ( $slg, $name ) = @_;
Subroutine op_fn_key_by_name: called CC=1 SCAR=0.0
1982 7049 my ($key) = $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1983 <<'END_OF_LUA', 's', $name );
1984 local recce, name = ...
1985 return _M.get_op_fn_key_by_name(name)
1986 END_OF_LUA
1987  
1988 7049 return $key;
1989 }
1990  
1991 sub op_fn_name_by_key {
1992 0 ▶ my ( $slg, $key ) = @_;
Subroutine op_fn_name_by_key: not called CC=1 SCAR=6.9
1993 0 my ($name) = $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
1994 <<'END_OF_LUA', 'i', $key );
1995 local recce, key = ...
1996 return _M.get_op_fn_name_by_key(key)
1997 END_OF_LUA
1998  
1999 0 return $name;
2000 }
2001  
2002 sub registrations_set {
2003 371 ▶ my ( $slg, $registrations ) = @_;
Subroutine registrations_set: called CC=13 SCAR=36.6
2004 371 my $trace_file_handle =
2005 $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE];
2006 371 ▶ my $trace_actions =
Condition50%1/2
$slg->[7] // 0
l!l
0371
MC/DC0%0/1
$slg->[7] // 0
$slg->[7]
Truth table50%1/2
A
A= $slg->[7]
Aresult
11
00
2007 $slg->[Marpa::R3::Internal_G::TRACE_ACTIONS] // 0;
2008  
2009 371 REGISTRATION: for my $registration ( @{$registrations} ) {
2010 25897 my ( $type, $id, @raw_ops ) = @{$registration};
2011 25897 my @ops = ();
2012 PRINT_TRACES: {
2013 25897 ▶ last PRINT_TRACES if $trace_actions <= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $trace_actions <= 2 25897 0 25897
2014 0 ▶ if ( $type eq 'nulling' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "nulling") 0 0 0
2015 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Registering semantics for nulling symbol: ", $slg->g1_symbol_display_form($id), "\n", " Semantics are ", $slg->show_semantics(@raw_ops) or Marpa::R3::exception("Cannot say to trace file handle") 0 0 0
2016 "Registering semantics for nulling symbol: ",
2017 $slg->g1_symbol_display_form($id),
2018 "\n", ' Semantics are ', $slg->show_semantics(@raw_ops)
2019 or Marpa::R3::exception('Cannot say to trace file handle');
2020 0 last PRINT_TRACES;
2021 } ## end if ( $type eq 'nulling' )
2022 0 ▶ if ( $type eq 'rule' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "rule") 0 0 0
2023 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Registering semantics for ${type}: ", $slg->g1_rule_show($id), " Semantics are ", $slg->show_semantics(@raw_ops) or Marpa::R3::exception("Cannot say to trace file handle") 0 0 0
2024 "Registering semantics for $type: ",
2025 $slg->g1_rule_show($id),
2026 ' Semantics are ', $slg->show_semantics(@raw_ops)
2027 or Marpa::R3::exception('Cannot say to trace file handle');
2028 0 last PRINT_TRACES;
2029 }
2030 0 ▶ if ( $type eq 'token' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "token") 0 0 0
2031 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Registering semantics for ${type}: ", $slg->g1_symbol_display_form($id), "\n", " Semantics are ", $slg->show_semantics(@raw_ops) or Marpa::R3::exception("Cannot say to trace file handle") 0 0 0
2032 "Registering semantics for $type: ",
2033 $slg->g1_symbol_display_form($id),
2034 "\n", ' Semantics are ', $slg->show_semantics(@raw_ops)
2035 or Marpa::R3::exception('Cannot say to trace file handle');
2036 0 last PRINT_TRACES;
2037 }
2038 0 ▶ say {$trace_file_handle} "Registration has unknown type: $type"
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Registration has unknown type: $type" or Marpa::R3::exception("Cannot say to trace file handle") 0 0 0
2039 or Marpa::R3::exception('Cannot say to trace file handle');
2040 } ## end PRINT_TRACES:
2041  
2042 25897 OP: for my $raw_op (@raw_ops) {
2043 316827 ▶ if ( ref $raw_op ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $raw_op) 19553 297274 316827
2044  
2045 19553 my $constants = $slg->[Marpa::R3::Internal_G::CONSTANTS];
2046 19553 my $next_ix = scalar @{$constants};
2047 19553 push @ops, $next_ix;
2048 $slg->[Marpa::R3::Internal_G::CONSTANTS]->[$next_ix]
2049 19553 = ${$raw_op};
2050 19553 next OP;
2051 }
2052 297274 push @ops, $raw_op;
2053 } ## end OP: for my $raw_op (@raw_ops)
2054  
2055 25897 my ($constant_ix) = $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ),
2056 << 'END_OF_LUA', 'sii', $type, $id, \@ops );
2057 local grammar, type, id, ops = ...
2058 if type == 'token' then
2059 grammar.token_semantics[id] = ops
2060 elseif type == 'nulling' then
2061 grammar.nulling_semantics[id] = ops
2062 elseif type == 'rule' then
2063 grammar.rule_semantics[id] = ops
2064 end
2065 END_OF_LUA
2066  
2067 25897 next REGISTRATION;
2068  
2069 # Marpa::R3::exception(
2070 # 'Registration: with unknown type: ',
2071 # Data::Dumper::Dumper($registration)
2072 # );
2073  
2074 } ## end REGISTRATION: for my $registration ( @{ $recce->[...]})
2075 }
2076  
2077 104 1;
2078  
2079 # vim: expandtab shiftwidth=4:
↑ Summary R3/Glade.pm »