|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
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
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Marpa::R3 exceptions and their methods  | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Adapted from CPAN's Exception::Class module  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Marpa::R3::X;  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
18
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
2202
 | 
 use 5.010001;  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
402
 | 
    | 
| 
19
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
673
 | 
 use warnings;  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
249
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3529
 | 
    | 
| 
20
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
675
 | 
 use strict;  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
256
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3124
 | 
    | 
| 
21
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
697
 | 
 use English qw( -no_match_vars );  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
286
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2709
 | 
    | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
23
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
44705
 | 
 use vars qw($VERSION $STRING_VERSION);  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
255
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9502
 | 
    | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 $VERSION        = '4.001_052';  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 $STRING_VERSION = $VERSION;  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 ## no critic(BuiltinFunctions::ProhibitStringyEval)  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 $VERSION = eval $VERSION;  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 ## use critic  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Marpa::R3::Internal::X;  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
32
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
755
 | 
 use warnings;  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
264
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3615
 | 
    | 
| 
33
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
667
 | 
 use strict;  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
261
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3077
 | 
    | 
| 
34
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
632
 | 
 use English qw( -no_match_vars );  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
279
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
620
 | 
    | 
| 
35
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
38428
 | 
 use Scalar::Util qw( blessed );  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
254
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7816
 | 
    | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 use overload  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # an exception is always true  | 
| 
40
 | 
101
 | 
 
 | 
 
 | 
  
101
  
 | 
 
 | 
116373
 | 
     bool => sub {1}, '""' => 'as_string', fallback => 1;  | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
  
0
  
 | 
 
 | 
99671
 | 
    | 
| 
 
 | 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
980
 | 
    | 
| 
 
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
    | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Create accessor routines  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub throw {  | 
| 
45
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
15
 | 
     my $proto = shift;  | 
| 
46
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
22
 | 
     $proto->rethrow if ref $proto;  | 
| 
47
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     die $proto->new(@_);  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub rethrow {  | 
| 
51
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
7
 | 
     my $self = shift;  | 
| 
52
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
29
 | 
     die $self;  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
56
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
14
 | 
     my ($class, $args)  = @_;  | 
| 
57
 | 
3
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
13
 | 
     $args //= { error => $_[0] };  | 
| 
58
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
     return bless $args, $class;  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub description {  | 
| 
62
 | 
  
0
  
 | 
 
 | 
 
 | 
  
0
  
 | 
 
 | 
0
 | 
     return 'Generic exception';  | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub as_string {  | 
| 
66
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
8
 | 
     my $self      = shift;  | 
| 
67
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
     my $string    = q{};  | 
| 
68
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
     my $to_string = $self->{to_string};  | 
| 
69
 | 
3
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
23
 | 
     if ( $to_string and ref $to_string eq 'CODE' ) {  | 
| 
70
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
         $string = &{$to_string}($self);  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
    | 
| 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     else {  | 
| 
73
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
       FIELD: for my $field ( sort keys %{$self} ) {  | 
| 
 
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
    | 
| 
74
 | 
  
0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             if ( $field eq 'try' ) {  | 
| 
75
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 my $try_to_string = $self->{try};  | 
| 
76
 | 
  
0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 if ( ref $try_to_string ne 'CODE' ) {  | 
| 
77
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                     $string .= qq{$field: [!not a CODE object!]\n};  | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 }  | 
| 
79
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 $string .= &{$try_to_string}($self);  | 
| 
 
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
    | 
| 
80
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 next FIELD;  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
82
 | 
  
0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             next FIELD if $field =~ /\A (slg|slr|tracer|msg|fatal) \z/;  | 
| 
83
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             my $value = $self->{$field};  | 
| 
84
 | 
  
0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             if ( not defined $value ) {  | 
| 
85
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 $string .= "$field: [not defined]\n";  | 
| 
86
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 next FIELD;  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
88
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             my $ref_type = ref $value;  | 
| 
89
 | 
  
0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             if ($ref_type) {  | 
| 
90
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 $string .= "$field: ref to $ref_type\n";  | 
| 
91
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 next FIELD;  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
93
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             $string .= "$field: $value\n";  | 
| 
94
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
96
 | 
3
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
20
 | 
     my $fatal = $self->{fatal} // 1;  | 
| 
97
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
     if ($fatal) {  | 
| 
98
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20
 | 
         $string =  | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             qq{========= Marpa::R3 Fatal error =========\n}  | 
| 
100
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
           . $string  | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
           . qq{=========================================\n};  | 
| 
102
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
103
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
     return $string;  | 
| 
104
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub caught {  | 
| 
107
 | 
  
0
  
 | 
 
 | 
 
 | 
  
0
  
 | 
 
 | 
 
 | 
     my $class = shift;  | 
| 
108
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $e = $@;  | 
| 
109
 | 
  
0
  
 | 
  
  0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
     return unless defined $e && blessed($e) && $e->isa($class);  | 
| 
 
 | 
 
 | 
 
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
110
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     return $e;  | 
| 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
113
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  |