| 1 | # Copyright 2022 Jeffrey Kegler | ||||||||||||||||||||
| 2 | # This file is part of Marpa::R2. Marpa::R2 is free software: you can | ||||||||||||||||||||
| 3 | # redistribute it and/or modify it under the terms of the GNU Lesser | ||||||||||||||||||||
| 4 | # General Public License as published by the Free Software Foundation, | ||||||||||||||||||||
| 5 | # either version 3 of the License, or (at your option) any later version. | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # Marpa::R2 is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||||
| 10 | # Lesser General Public License for more details. | ||||||||||||||||||||
| 11 | # | ||||||||||||||||||||
| 12 | # You should have received a copy of the GNU Lesser | ||||||||||||||||||||
| 13 | # General Public License along with Marpa::R2. If not, see | ||||||||||||||||||||
| 14 | # http://www.gnu.org/licenses/. | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | package Marpa::R2; | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 150 | ▶ | use 5.010001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 150 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 150 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 150 | ▶ | use vars qw($VERSION $STRING_VERSION @ISA $DEBUG); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 150 | $VERSION = '13.003_000'; | |||||||||||||||||||
| 24 | 150 | $STRING_VERSION = $VERSION; | |||||||||||||||||||
| 25 | ## no critic (BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||
| 26 | 150 | $VERSION = eval $VERSION; | |||||||||||||||||||
| 27 | ## use critic | ||||||||||||||||||||
| 28 | 150 | $DEBUG = 0; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 150 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 150 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 150 | ▶ | use XSLoader; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 150 | ▶ | use Marpa::R2::Version; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 150 | $Marpa::R2::USING_XS = 1; | |||||||||||||||||||
| 37 | 150 | $Marpa::R2::USING_PP = 0; | |||||||||||||||||||
| 38 | 150 | $Marpa::R2::LIBMARPA_FILE = '[built-in]'; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | LOAD_EXPLICIT_LIBRARY: { | ||||||||||||||||||||
| 41 | 150 | ▶ | last LOAD_EXPLICIT_LIBRARY if not $ENV{'MARPA_AUTHOR_TEST'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | my $file = $ENV{MARPA_LIBRARY}; | |||||||||||||||||||
| 43 | 0 | ▶ | last LOAD_EXPLICIT_LIBRARY if not $file; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | require DynaLoader; | |||||||||||||||||||
| 46 | package DynaLoader; | ||||||||||||||||||||
| 47 | 0 | my $bs = $file; | |||||||||||||||||||
| 48 | 0 | $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; # look for .bs 'beside' the library | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | ▶ | if (-s $bs) { # only read file if it's not empty | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | # print STDERR "BS: $bs ($^O, $dlsrc)\n" if $dl_debug; | ||||||||||||||||||||
| 52 | 0 | eval { do $bs; }; | |||||||||||||||||||
| 53 | 0 | ▶ | warn "$bs: $@\n" if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | my $bootname = "marpa_g_new"; | |||||||||||||||||||
| 57 | 0 | @DynaLoader::dl_require_symbols = ($bootname); | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | my $libref = dl_load_file($file, 0) or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | require Carp; | |||||||||||||||||||
| 61 | 0 | Carp::croak("Can't load libmarpa library: '$file'" . dl_error()); | |||||||||||||||||||
| 62 | }; | ||||||||||||||||||||
| 63 | 0 | push(@DynaLoader::dl_librefs,$libref); # record loaded object | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | my @unresolved = dl_undef_symbols(); | |||||||||||||||||||
| 66 | 0 | ▶ | if (@unresolved) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 0 | require Carp; | |||||||||||||||||||
| 68 | 0 | Carp::carp("Undefined symbols present after loading $file: @unresolved\n"); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | dl_find_symbol($libref, $bootname) or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | require Carp; | |||||||||||||||||||
| 73 | 0 | Carp::croak("Can't find '$bootname' symbol in $file\n"); | |||||||||||||||||||
| 74 | }; | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | push(@DynaLoader::dl_shared_objects, $file); # record files loaded | |||||||||||||||||||
| 77 | 0 | $Marpa::R2::LIBMARPA_FILE = $file; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 150 | XSLoader::load( 'Marpa::R2', $Marpa::R2::STRING_VERSION ); | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 150 | ▶ | if ( not $ENV{'MARPA_AUTHOR_TEST'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 150 | $Marpa::R2::DEBUG = 0; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||
| 86 | 0 | Marpa::R2::Thin::debug_level_set(1); | |||||||||||||||||||
| 87 | 0 | $Marpa::R2::DEBUG = 1; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | sub version_ok { | ||||||||||||||||||||
| 91 | 1500 | ▶ | my ($sub_module_version) = @_; | ||||||||||||||||||
|
Subroutine
version_ok: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||
| 92 | 1500 | ▶ | return 'not defined' if not defined $sub_module_version; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 1500 | ▶ | return "$sub_module_version does not match Marpa::R2::VERSION " . $VERSION | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | if $sub_module_version != $VERSION; | ||||||||||||||||||||
| 95 | 1500 | return; | |||||||||||||||||||
| 96 | } ## end sub version_ok | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | # Set up the error values | ||||||||||||||||||||
| 99 | 150 | my @error_names = Marpa::R2::Thin::error_names(); | |||||||||||||||||||
| 100 | 150 | ▶ | for ( my $error = 0; $error <= $#error_names; ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 15000 | my $current_error = $error; | |||||||||||||||||||
| 102 | 15000 | (my $name = $error_names[$error] ) =~ s/\A MARPA_ERR_//xms; | |||||||||||||||||||
| 103 | 150 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 104 | 15000 | *{ "Marpa::R2::Error::$name" } = \$current_error; | |||||||||||||||||||
| 105 | # This shuts up the "used only once" warning | ||||||||||||||||||||
| 106 | 15000 | my $dummy = eval q{$} . 'Marpa::R2::Error::' . $name; | |||||||||||||||||||
| 107 | 15000 | $error++; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 150 | my $version_result; | |||||||||||||||||||
| 111 | 150 | require Marpa::R2::Internal; | |||||||||||||||||||
| 112 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::Internal::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 113 | and die 'Marpa::R2::Internal::VERSION ', $version_result; | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 150 | require Marpa::R2::Grammar; | |||||||||||||||||||
| 116 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::Grammar::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 117 | and die 'Marpa::R2::Grammar::VERSION ', $version_result; | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 150 | require Marpa::R2::Recognizer; | |||||||||||||||||||
| 120 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::Recognizer::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | and die 'Marpa::R2::Recognizer::VERSION ', $version_result; | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 150 | require Marpa::R2::Value; | |||||||||||||||||||
| 124 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::Value::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | and die 'Marpa::R2::Value::VERSION ', $version_result; | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 150 | require Marpa::R2::MetaG; | |||||||||||||||||||
| 128 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::MetaG::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | and die 'Marpa::R2::MetaG::VERSION ', $version_result; | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 150 | require Marpa::R2::SLG; | |||||||||||||||||||
| 132 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::Scanless::G::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | and die 'Marpa::R2::Scanless::G::VERSION ', $version_result; | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 150 | require Marpa::R2::SLR; | |||||||||||||||||||
| 136 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::Scanless::R::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 137 | and die 'Marpa::R2::Scanless::R::VERSION ', $version_result; | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 150 | require Marpa::R2::MetaAST; | |||||||||||||||||||
| 140 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::MetaAST::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 141 | and die 'Marpa::R2::MetaAST::VERSION ', $version_result; | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 150 | require Marpa::R2::Stuifzand; | |||||||||||||||||||
| 144 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::Stuifzand::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 145 | and die 'Marpa::R2::Stuifzand::VERSION ', $version_result; | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 150 | require Marpa::R2::ASF; | |||||||||||||||||||
| 148 | 150 | ▶ | ( $version_result = version_ok($Marpa::R2::ASF::VERSION) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 149 | and die 'Marpa::R2::ASF::VERSION ', $version_result; | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | sub Marpa::R2::exception { | ||||||||||||||||||||
| 152 | 45 | ▶ | my $exception = join q{}, @_; | ||||||||||||||||||
|
Subroutine
exception: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||
| 153 | 45 | $exception =~ s/ \n* \z /\n/xms; | |||||||||||||||||||
| 154 | 45 | ▶ | die($exception) if $Marpa::R2::JUST_DIE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 155 | 45 | CALLER: for ( my $i = 0; 1; $i++) { | |||||||||||||||||||
| 156 | 163 | my ($package ) = caller($i); | |||||||||||||||||||
| 157 | 163 | ▶ | last CALLER if not $package; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 163 | ▶ | last CALLER if not 'Marpa::R2::' eq substr $package, 0, 11; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | 118 | $Carp::Internal{ $package } = 1; | |||||||||||||||||||
| 160 | } | ||||||||||||||||||||
| 161 | 45 | Carp::croak($exception, q{Marpa::R2 exception}); | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | package Marpa::R2::Internal::X; | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | use overload ( | ||||||||||||||||||||
| 167 | q{""} => sub { | ||||||||||||||||||||
| 168 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 169 | 0 | ▶ | return $self->{message} // $self->{fallback_message}; | ||||||||||||||||||
|
Condition0%0/3
$self->{"message"} // $self->{"fallback_message"}
MC/DC0%0/2
$self->{"message"} // $self->{"fallback_message"}
$self->{"message"}
$self->{"fallback_message"}
Truth table0%0/3
A // B
A= $self->{"message"}B= $self->{"fallback_message"}
| |||||||||||||||||||||
| 170 | }, | ||||||||||||||||||||
| 171 | 150 | fallback => 1 | |||||||||||||||||||
| 172 | 150 | ▶ | ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | sub new { | ||||||||||||||||||||
| 175 | 0 | ▶ | my ( $class, @hash_ref_args ) = @_; | ||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 176 | 0 | my %x_object = (); | |||||||||||||||||||
| 177 | 0 | for my $hash_ref_arg (@hash_ref_args) { | |||||||||||||||||||
| 178 | 0 | ▶ | if ( ref $hash_ref_arg ne "HASH" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 179 | 0 | my $ref_type = ref $hash_ref_arg; | |||||||||||||||||||
| 180 | 0 | ▶ | my $ref_desc = $ref_type ? "ref to $ref_type" : "not a ref"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 181 | 0 | die | |||||||||||||||||||
| 182 | "Internal error: args to Marpa::R2::Internal::X->new is $ref_desc -- it should be hash ref"; | ||||||||||||||||||||
| 183 | } ## end if ( ref $hash_ref_arg ne "HASH" ) | ||||||||||||||||||||
| 184 | 0 | $x_object{$_} = $hash_ref_arg->{$_} for keys %{$hash_ref_arg}; | |||||||||||||||||||
| 185 | } ## end for my $hash_ref_arg (@hash_ref_args) | ||||||||||||||||||||
| 186 | 0 | my $name = $x_object{name}; | |||||||||||||||||||
| 187 | 0 | ▶ | die("Internal error: an excepion must have a name") if not $name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 188 | 0 | $x_object{fallback_message} = qq{Exception "$name" thrown}; | |||||||||||||||||||
| 189 | 0 | return bless \%x_object, $class; | |||||||||||||||||||
| 190 | } ## end sub new | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | sub name { | ||||||||||||||||||||
| 193 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 194 | 0 | return $self->{name}; | |||||||||||||||||||
| 195 | } | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | 150 | 1; | |||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | # vim: set expandtab shiftwidth=4: | ||||||||||||||||||||