| 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::Grammar; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 150 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 150 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # There's a problem with this perlcritic check | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # as of 9 Aug 2010 | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 150 | ▶ | no warnings qw(recursion qw); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 150 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 150 | ▶ | use vars qw($VERSION $STRING_VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 150 | $VERSION = '13.003_000'; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 150 | $STRING_VERSION = $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 31 | ## no critic(BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 150 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 33 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | package Marpa::R2::Internal::Grammar; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 150 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 150 | ▶ | use Marpa::R2::Thin::Trace; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 150 | our %DEFAULT_SYMBOLS_RESERVED; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 150 | %DEFAULT_SYMBOLS_RESERVED = map { ($_, 1) } split //xms, '}]>)'; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | sub Marpa::R2::uncaught_error { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my ($error) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uncaught_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # This would be Carp::confess, but in the testing | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # the stack trace includes the hoped for error | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # message, which causes spurious success reports. | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | Carp::croak( "libmarpa reported an error which Marpa::R2 did not catch\n", | |||||||||||||||||||||||||||||||||||||||||
| 51 | $error ); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } ## end sub Marpa::R2::uncaught_error | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | package Marpa::R2::Internal::Grammar; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | sub Marpa::R2::Grammar::new { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 672 | ▶ | my ( $class, @arg_hashes ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 672 | my $grammar = []; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 672 | bless $grammar, $class; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # set the defaults and the default defaults | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 672 | $grammar->[Marpa::R2::Internal::Grammar::TRACE_FILE_HANDLE] = *STDERR; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 672 | $grammar->[Marpa::R2::Internal::Grammar::TRACE_RULES] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 672 | $grammar->[Marpa::R2::Internal::Grammar::WARNINGS] = 1; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 672 | $grammar->[Marpa::R2::Internal::Grammar::INACCESSIBLE_OK] = {}; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 672 | $grammar->[Marpa::R2::Internal::Grammar::UNPRODUCTIVE_OK] = {}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 672 | $grammar->[Marpa::R2::Internal::Grammar::INFINITE_ACTION] = 'fatal'; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 672 | $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS] = []; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 672 | $grammar->[Marpa::R2::Internal::Grammar::RULES] = []; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 672 | $grammar->[Marpa::R2::Internal::Grammar::RULE_ID_BY_TAG] = {}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 672 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C] = | |||||||||||||||||||||||||||||||||||||||||
| 76 | Marpa::R2::Thin::G->new( { if => 1 } ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 672 | $grammar->[Marpa::R2::Internal::Grammar::TRACER] = | |||||||||||||||||||||||||||||||||||||||||
| 78 | Marpa::R2::Thin::Trace->new($grammar_c); | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 672 | $grammar->set(@arg_hashes); | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 666 | return $grammar; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } ## end sub Marpa::R2::Grammar::new | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | sub Marpa::R2::Grammar::tracer { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 1776 | ▶ | return $_[0]->[Marpa::R2::Internal::Grammar::TRACER]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tracer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | sub Marpa::R2::Grammar::thin { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 1171 | ▶ | return $_[0]->[Marpa::R2::Internal::Grammar::C]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
thin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | sub Marpa::R2::Grammar::thin_symbol { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my ( $grammar, $symbol_name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
thin_symbol: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return $grammar->[Marpa::R2::Internal::Grammar::TRACER] | |||||||||||||||||||||||||||||||||||||||||
| 96 | ->symbol_by_name($symbol_name); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | sub Marpa::R2::Grammar::set { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 695 | ▶ | my ( $grammar, @arg_hashes ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=66 SCAR=58.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # set trace_fh even if no tracing, because we may turn it on in this method | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 695 | my $trace_fh = | |||||||||||||||||||||||||||||||||||||||||
| 104 | $grammar->[Marpa::R2::Internal::Grammar::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 695 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 695 | for my $args (@arg_hashes) { | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 705 | my $ref_type = ref $args; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 705 | ▶ | if ( not $ref_type ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | Carp::croak( | |||||||||||||||||||||||||||||||||||||||||
| 112 | 'Marpa::R2::Grammar expects args as ref to HASH; arg was non-reference' | ||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 705 | ▶ | if ( $ref_type ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | Carp::croak( | |||||||||||||||||||||||||||||||||||||||||
| 117 | "Marpa::R2::Grammar expects args as ref to HASH, got ref to $ref_type instead" | ||||||||||||||||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | state $grammar_options = { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 705 | map { ( $_, 1 ) } | |||||||||||||||||||||||||||||||||||||||||
| 123 | qw{ _internal_ | ||||||||||||||||||||||||||||||||||||||||||
| 124 | action_object | ||||||||||||||||||||||||||||||||||||||||||
| 125 | actions | ||||||||||||||||||||||||||||||||||||||||||
| 126 | bless_package | ||||||||||||||||||||||||||||||||||||||||||
| 127 | infinite_action | ||||||||||||||||||||||||||||||||||||||||||
| 128 | default_action | ||||||||||||||||||||||||||||||||||||||||||
| 129 | default_empty_action | ||||||||||||||||||||||||||||||||||||||||||
| 130 | default_rank | ||||||||||||||||||||||||||||||||||||||||||
| 131 | inaccessible_ok | ||||||||||||||||||||||||||||||||||||||||||
| 132 | rules | ||||||||||||||||||||||||||||||||||||||||||
| 133 | source | ||||||||||||||||||||||||||||||||||||||||||
| 134 | start | ||||||||||||||||||||||||||||||||||||||||||
| 135 | symbols | ||||||||||||||||||||||||||||||||||||||||||
| 136 | terminals | ||||||||||||||||||||||||||||||||||||||||||
| 137 | trace_file_handle | ||||||||||||||||||||||||||||||||||||||||||
| 138 | unproductive_ok | ||||||||||||||||||||||||||||||||||||||||||
| 139 | warnings | ||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 705 | ▶ | if (my @bad_options = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 3058 | grep { not exists $grammar_options->{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 145 | 705 | keys %{$args} | |||||||||||||||||||||||||||||||||||||||||
| 146 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | Carp::croak( 'Unknown option(s) for Marpa::R2::Grammar: ', | |||||||||||||||||||||||||||||||||||||||||
| 149 | join q{ }, @bad_options ); | ||||||||||||||||||||||||||||||||||||||||||
| 150 | } ## end if ( my @bad_options = grep { not exists $grammar_options...}) | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | # First pass options: These affect processing of other | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # options and are expected to take force for the other | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # options, even if specified afterwards | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 705 | ▶ | if ( defined( my $value = $args->{'_internal_'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 562 | $grammar->[Marpa::R2::Internal::Grammar::INTERNAL] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 705 | ▶ | if ( defined( my $value = $args->{'trace_file_handle'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 286 | $trace_fh = | |||||||||||||||||||||||||||||||||||||||||
| 162 | $grammar->[Marpa::R2::Internal::Grammar::TRACE_FILE_HANDLE] = | ||||||||||||||||||||||||||||||||||||||||||
| 163 | $value; | ||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 705 | ▶ | if ( defined( my $value = $args->{'default_rank'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 'default_rank option not allowed after grammar is precomputed' | ||||||||||||||||||||||||||||||||||||||||||
| 169 | ) if $grammar_c->is_precomputed(); | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $grammar_c->default_rank_set($value); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } ## end if ( defined( my $value = $args->{'default_rank'} ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | # Second pass options | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 705 | ▶ | if ( defined( my $value = $args->{'symbols'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 564 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 'symbols option not allowed after grammar is precomputed') | ||||||||||||||||||||||||||||||||||||||||||
| 179 | if $grammar_c->is_precomputed(); | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 564 | ▶ | Marpa::R2::exception('symbols value must be REF to HASH') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | if ref $value ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 564 | for my $symbol ( sort keys %{$value} ) { | |||||||||||||||||||||||||||||||||||||||||
| 183 | 21017 | my $properties = $value->{$symbol}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 21017 | assign_user_symbol( $grammar, $symbol, $properties ); | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | } ## end if ( defined( my $value = $args->{'symbols'} ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 705 | ▶ | if ( defined( my $value = $args->{'terminals'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 61 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 'terminals option not allowed after grammar is precomputed') | ||||||||||||||||||||||||||||||||||||||||||
| 191 | if $grammar_c->is_precomputed(); | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 61 | ▶ | Marpa::R2::exception('terminals value must be REF to ARRAY') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | if ref $value ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 61 | for my $symbol ( @{$value} ) { | |||||||||||||||||||||||||||||||||||||||||
| 195 | 128 | assign_user_symbol( $grammar, $symbol, { terminal => 1 } ); | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } ## end if ( defined( my $value = $args->{'terminals'} ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 705 | ▶ | if ( defined( my $value = $args->{'start'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 669 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 'start option not allowed after grammar is precomputed') | ||||||||||||||||||||||||||||||||||||||||||
| 202 | if $grammar_c->is_precomputed(); | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 669 | $grammar->[Marpa::R2::Internal::Grammar::START_NAME] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } ## end if ( defined( my $value = $args->{'start'} ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 705 | my $stuifzand_source; | |||||||||||||||||||||||||||||||||||||||||
| 207 | my $deprecated_source; | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 705 | ▶ | if ( defined( my $value = $args->{'source'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 'source option not allowed after grammar is precomputed') | ||||||||||||||||||||||||||||||||||||||||||
| 212 | if $grammar_c->is_precomputed(); | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 3 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | q{"source" named argument must be string or ref to SCALAR} | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ) if ref $value ne 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | $stuifzand_source = $value; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 705 | ▶ | if ( defined( my $value = $args->{'rules'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 669 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 'rules option not allowed after grammar is precomputed') | ||||||||||||||||||||||||||||||||||||||||||
| 222 | if $grammar_c->is_precomputed(); | ||||||||||||||||||||||||||||||||||||||||||
| 223 | DO_RULES: { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | ## These hacks are for previous method of specifying Stuifzand | ||||||||||||||||||||||||||||||||||||||||||
| 225 | ## grammars. They are now deprecated and undocumented. | ||||||||||||||||||||||||||||||||||||||||||
| 226 | ## Eventually they may be eliminated. | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 669 | ▶ | if ( ref $value eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $value eq "ARRAY" and scalar @{$value;} == 1 and not ref $value->[0]
ref $value eq "ARRAY" and scalar @{$value;} == 1
MC/DC0%0/3
ref $value eq "ARRAY" and scalar @{$value;} == 1 and not ref $value->[0]
ref $value eq "ARRAY"
scalar @{$value;} == 1
not ref $value->[0]
Truth table75%3/4
A and B and not(C)
A= ref $value eq "ARRAY"B= scalar @{$value;} == 1C= not ref $value->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 658 | and scalar @{$value} == 1 | |||||||||||||||||||||||||||||||||||||||||
| 229 | and not ref $value->[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 230 | { | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $value = $value->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } ## end if ( ref $value eq 'ARRAY' and scalar @{$value} == 1...) | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 669 | ▶ | if ( not ref $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 11 | $deprecated_source = \$value; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 669 | ▶ | if (defined $deprecated_source and defined $stuifzand_source) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $deprecated_source and defined $stuifzand_source
MC/DC0%0/2
defined $deprecated_source and defined $stuifzand_source
defined $deprecated_source
defined $stuifzand_source
Truth table66%2/3
A and B
A= defined $deprecated_sourceB= defined $stuifzand_source
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 238 | qq{Attempt to specify BNF via both 'rules' and 'source' named arguments\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 239 | q{ You must use one or the other}, | ||||||||||||||||||||||||||||||||||||||||||
| 240 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 669 | ▶ | if (defined $deprecated_source) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 11 | $stuifzand_source = $deprecated_source; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 11 | last DO_RULES; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 658 | ▶ | q{"rules" named argument must be string or ref to ARRAY} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | ) if ref $value ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 658 | ▶ | $grammar->[Marpa::R2::Internal::Grammar::INTERFACE] //= | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$grammar->[10] //= "standard"
MC/DC0%0/1
$grammar->[10] //= "standard"
$grammar->[10]
Truth table50%1/2
A
A= $grammar->[10]
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 'standard'; | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 658 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | qq{Attempt to use the standard interface with a grammar that is already using the BNF interface\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 253 | q{ Mixing the BNF and standard interface is not allowed} | ||||||||||||||||||||||||||||||||||||||||||
| 254 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 255 | if $grammar->[Marpa::R2::Internal::Grammar::INTERFACE] ne | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 'standard'; | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 658 | add_user_rules( $grammar, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 258 | } ## end DO_RULES: | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } ## end if ( defined( my $value = $args->{'rules'} ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 699 | ▶ | if ( defined $stuifzand_source ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 14 | ▶ | $grammar->[Marpa::R2::Internal::Grammar::INTERFACE] //= | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$grammar->[10] //= "stuifzand"
MC/DC0%0/1
$grammar->[10] //= "stuifzand"
$grammar->[10]
Truth table50%1/2
A
A= $grammar->[10]
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 'stuifzand'; | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 14 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | qq{Attempt to use the standard interface with a grammar that is already using the BNF interface\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | q{ Mixing the BNF and standard interface is not allowed} | ||||||||||||||||||||||||||||||||||||||||||
| 267 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 268 | if $grammar->[Marpa::R2::Internal::Grammar::INTERFACE] ne | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 'stuifzand'; | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 14 | my $parse_result = | |||||||||||||||||||||||||||||||||||||||||
| 271 | Marpa::R2::Internal::Stuifzand::parse_rules( | ||||||||||||||||||||||||||||||||||||||||||
| 272 | $stuifzand_source ); | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 14 | for my $rule ( @{ $parse_result->{rules} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 274 | 405 | add_user_rule( $grammar, $rule ); | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | } ## end if ( defined $stuifzand_source ) | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 699 | ▶ | if ( exists $args->{'default_empty_action'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 9 | my $value = $args->{'default_empty_action'}; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 9 | $grammar->[Marpa::R2::Internal::Grammar::DEFAULT_EMPTY_ACTION] = | |||||||||||||||||||||||||||||||||||||||||
| 281 | $value; | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 699 | ▶ | if ( defined( my $value = $args->{'actions'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 17 | $grammar->[Marpa::R2::Internal::Grammar::ACTIONS] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 699 | ▶ | if ( defined( my $value = $args->{'bless_package'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 120 | $grammar->[Marpa::R2::Internal::Grammar::BLESS_PACKAGE] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 699 | ▶ | if ( defined( my $value = $args->{'action_object'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 14 | $grammar->[Marpa::R2::Internal::Grammar::ACTION_OBJECT] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 699 | ▶ | if ( defined( my $value = $args->{'default_action'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 67 | $grammar->[Marpa::R2::Internal::Grammar::DEFAULT_ACTION] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 699 | ▶ | if ( defined( my $value = $args->{'infinite_action'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 9 | ▶ | if ( $value && $grammar_c->is_precomputed() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$value and $grammar_c->is_precomputed
MC/DC0%0/2
$value and $grammar_c->is_precomputed
$value
$grammar_c->is_precomputed
Truth table33%1/3
A and B
A= $valueB= $grammar_c->is_precomputed
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | say {$trace_fh} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | '"infinite_action" option is useless after grammar is precomputed' | ||||||||||||||||||||||||||||||||||||||||||
| 304 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | state $allowed_values = | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 9 | { map { ( $_, 1 ) } qw(warn quiet fatal) }; | |||||||||||||||||||||||||||||||||||||||||
| 308 | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||||
| 309 | q{infinite_action must be 'warn', 'quiet' or 'fatal'}) | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 9 | ▶ | if not exists $allowed_values->{$value}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 9 | $grammar->[Marpa::R2::Internal::Grammar::INFINITE_ACTION] = | |||||||||||||||||||||||||||||||||||||||||
| 312 | $value; | ||||||||||||||||||||||||||||||||||||||||||
| 313 | } ## end if ( defined( my $value = $args->{'infinite_action'}...)) | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 699 | ▶ | if ( defined( my $value = $args->{'warnings'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 8 | ▶ | if ( $value && $grammar_c->is_precomputed() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value and $grammar_c->is_precomputed
MC/DC0%0/2
$value and $grammar_c->is_precomputed
$value
$grammar_c->is_precomputed
Truth table66%2/3
A and B
A= $valueB= $grammar_c->is_precomputed
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | say {$trace_fh} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | q{"warnings" option is useless after grammar is precomputed} | ||||||||||||||||||||||||||||||||||||||||||
| 319 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 8 | $grammar->[Marpa::R2::Internal::Grammar::WARNINGS] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } ## end if ( defined( my $value = $args->{'warnings'} ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 699 | ▶ | if ( defined( my $value = $args->{'inaccessible_ok'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if ( $value && $grammar_c->is_precomputed() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$value and $grammar_c->is_precomputed
MC/DC0%0/2
$value and $grammar_c->is_precomputed
$value
$grammar_c->is_precomputed
Truth table0%0/3
A and B
A= $valueB= $grammar_c->is_precomputed
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | say {$trace_fh} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | q{"inaccessible_ok" option is useless after grammar is precomputed} | ||||||||||||||||||||||||||||||||||||||||||
| 328 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | } ## end if ( $value && $grammar_c->is_precomputed() ) | ||||||||||||||||||||||||||||||||||||||||||
| 331 | GIVEN_REF_VALUE: { | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my $ref_value = ref $value; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if ( $ref_value eq q{} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | $value //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$value //= {}
MC/DC0%0/1
$value //= {}
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | last GIVEN_REF_VALUE; | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if ( $ref_value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $value = { map { ( $_, 1 ) } @{$value} }; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | last GIVEN_REF_VALUE; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | 'value of inaccessible_ok option must be boolean or an array ref' | |||||||||||||||||||||||||||||||||||||||||
| 343 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 344 | } ## end GIVEN_REF_VALUE: | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $grammar->[Marpa::R2::Internal::Grammar::INACCESSIBLE_OK] = | |||||||||||||||||||||||||||||||||||||||||
| 346 | $value; | ||||||||||||||||||||||||||||||||||||||||||
| 347 | } ## end if ( defined( my $value = $args->{'inaccessible_ok'}...)) | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 699 | ▶ | if ( defined( my $value = $args->{'unproductive_ok'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if ( $value && $grammar_c->is_precomputed() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$value and $grammar_c->is_precomputed
MC/DC0%0/2
$value and $grammar_c->is_precomputed
$value
$grammar_c->is_precomputed
Truth table0%0/3
A and B
A= $valueB= $grammar_c->is_precomputed
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | say {$trace_fh} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | q{"unproductive_ok" option is useless after grammar is precomputed} | ||||||||||||||||||||||||||||||||||||||||||
| 353 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | GIVEN_REF_VALUE: { | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $ref_value = ref $value; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if ( $ref_value eq q{} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | $value //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$value //= {}
MC/DC0%0/1
$value //= {}
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | last GIVEN_REF_VALUE; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ( $ref_value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $value = { map { ( $_, 1 ) } @{$value} }; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | last GIVEN_REF_VALUE; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | 'value of unproductive_ok option must be boolean or an array ref' | |||||||||||||||||||||||||||||||||||||||||
| 367 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 368 | } ## end GIVEN_REF_VALUE: | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $grammar->[Marpa::R2::Internal::Grammar::UNPRODUCTIVE_OK] = | |||||||||||||||||||||||||||||||||||||||||
| 370 | $value; | ||||||||||||||||||||||||||||||||||||||||||
| 371 | } ## end if ( defined( my $value = $args->{'unproductive_ok'}...)) | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | } ## end for my $args (@arg_hashes) | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 689 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } ## end sub Marpa::R2::Grammar::set | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | sub Marpa::R2::Grammar::symbol_reserved_set { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | my ( $grammar, $final_character, $boolean ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbol_reserved_set: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if ( length $final_character != 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | Marpa::R2::exception( 'symbol_reserved_set(): "', | |||||||||||||||||||||||||||||||||||||||||
| 382 | $final_character, '" is not a symbol' ); | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if ( $final_character eq ']' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | return if $boolean; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 387 | q{symbol_reserved_set(): Attempt to unreserve ']'; this is not allowed} | ||||||||||||||||||||||||||||||||||||||||||
| 388 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } ## end if ( $final_character eq ']' ) ([) | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if ( not exists $DEFAULT_SYMBOLS_RESERVED{$final_character} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 392 | qq{symbol_reserved_set(): "$final_character" is not a reservable symbol} | ||||||||||||||||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | # Return a value to make perlcritic happy | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | return $DEFAULT_SYMBOLS_RESERVED{$final_character} = $boolean ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | } ## end sub Marpa::R2::Grammar::symbol_reserved_set | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | sub Marpa::R2::Grammar::precompute { | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 108 | ▶ | my $grammar = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
precompute: called CC=40 SCAR=40.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 108 | my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 108 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 108 | my $trace_fh = | |||||||||||||||||||||||||||||||||||||||||
| 405 | $grammar->[Marpa::R2::Internal::Grammar::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 108 | my $problems = $grammar->[Marpa::R2::Internal::Grammar::PROBLEMS]; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 108 | ▶ | if ($problems) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 410 | Marpa::R2::Grammar::show_problems($grammar), | ||||||||||||||||||||||||||||||||||||||||||
| 411 | "Second attempt to precompute grammar with fatal problems\n", | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 'Marpa::R2 cannot proceed' | ||||||||||||||||||||||||||||||||||||||||||
| 413 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 414 | } ## end if ($problems) | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 108 | ▶ | return $grammar if $grammar_c->is_precomputed(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 108 | set_start_symbol($grammar); | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | # Catch errors in precomputation | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 107 | my $precompute_error_code = $Marpa::R2::Error::NONE; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 107 | $grammar_c->throw_set(0); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 107 | my $precompute_result = $grammar_c->precompute(); | |||||||||||||||||||||||||||||||||||||||||
| 424 | 107 | $grammar_c->throw_set(1); | |||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 107 | ▶ | if ( $precompute_result < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 12 | ($precompute_error_code) = $grammar_c->error(); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 12 | ▶ | if ( not defined $precompute_error_code ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 430 | 'libmarpa error, but no error code returned'); | ||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | # If already precomputed, just return success | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 12 | ▶ | return $grammar | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | if $precompute_error_code == $Marpa::R2::Error::PRECOMPUTED; | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | # Cycles are not necessarily errors, | ||||||||||||||||||||||||||||||||||||||||||
| 438 | # and get special handling | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 12 | ▶ | $precompute_error_code = $Marpa::R2::Error::NONE | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | if $precompute_error_code == $Marpa::R2::Error::GRAMMAR_HAS_CYCLE; | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | } ## end if ( $precompute_result < 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 107 | ▶ | if ( $precompute_error_code != $Marpa::R2::Error::NONE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | # Report the errors, then return failure | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 4 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::NO_RULES ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 450 | 'Attempted to precompute grammar with no rules'); | ||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 4 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::NULLING_TERMINAL ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | my @nulling_terminals = (); | |||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | my $event_count = $grammar_c->event_count(); | |||||||||||||||||||||||||||||||||||||||||
| 455 | EVENT: | ||||||||||||||||||||||||||||||||||||||||||
| 456 | 1 | ▶ | for ( my $event_ix = 0; $event_ix < $event_count; $event_ix++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | my ( $event_type, $value ) = $grammar_c->event($event_ix); | |||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | ▶ | if ( $event_type eq 'MARPA_EVENT_NULLING_TERMINAL' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | push @nulling_terminals, $grammar->symbol_name($value); | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | } ## end EVENT: for ( my $event_ix = 0; $event_ix < $event_count; ...) | ||||||||||||||||||||||||||||||||||||||||||
| 462 | my @nulling_terminal_messages = | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 1 | map {qq{Nulling symbol "$_" is also a terminal\n}} | |||||||||||||||||||||||||||||||||||||||||
| 464 | @nulling_terminals; | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | Marpa::R2::exception( @nulling_terminal_messages, | |||||||||||||||||||||||||||||||||||||||||
| 466 | 'A terminal symbol cannot also be a nulling symbol' ); | ||||||||||||||||||||||||||||||||||||||||||
| 467 | } ## end if ( $precompute_error_code == ...) | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 3 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::COUNTED_NULLABLE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | my @counted_nullables = (); | |||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | my $event_count = $grammar_c->event_count(); | |||||||||||||||||||||||||||||||||||||||||
| 471 | EVENT: | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | ▶ | for ( my $event_ix = 0; $event_ix < $event_count; $event_ix++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | my ( $event_type, $value ) = $grammar_c->event($event_ix); | |||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | ▶ | if ( $event_type eq 'MARPA_EVENT_COUNTED_NULLABLE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | push @counted_nullables, $grammar->symbol_name($value); | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } ## end EVENT: for ( my $event_ix = 0; $event_ix < $event_count; ...) | ||||||||||||||||||||||||||||||||||||||||||
| 478 | my @counted_nullable_messages = map { | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | q{Nullable symbol "} | |||||||||||||||||||||||||||||||||||||||||
| 480 | . $_ | ||||||||||||||||||||||||||||||||||||||||||
| 481 | . qq{" is on RHS of counted rule\n} | ||||||||||||||||||||||||||||||||||||||||||
| 482 | } @counted_nullables; | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | Marpa::R2::exception( @counted_nullable_messages, | |||||||||||||||||||||||||||||||||||||||||
| 484 | 'Counted nullables confuse Marpa -- please rewrite the grammar' | ||||||||||||||||||||||||||||||||||||||||||
| 485 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 486 | } ## end if ( $precompute_error_code == ...) | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 2 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::NO_START_SYMBOL ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | Marpa::R2::exception('No start symbol'); | |||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::START_NOT_LHS ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | my $name = $grammar->[Marpa::R2::Internal::Grammar::START_NAME]; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 1 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 494 | qq{Start symbol "$name" not on LHS of any rule}); | ||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::UNPRODUCTIVE_START ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | { | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | my $name = $grammar->[Marpa::R2::Internal::Grammar::START_NAME]; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | Marpa::R2::exception(qq{Unproductive start symbol: "$name"}); | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | Marpa::R2::uncaught_error( scalar $grammar_c->error() ); | |||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | } ## end if ( $precompute_error_code != $Marpa::R2::Error::NONE) | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | # Shadow all the new rules | ||||||||||||||||||||||||||||||||||||||||||
| 507 | { | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 103 | my $highest_rule_id = $grammar_c->highest_rule_id(); | |||||||||||||||||||||||||||||||||||||||||
| 509 | RULE: | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 103 | ▶ | for ( my $rule_id = 0; $rule_id <= $highest_rule_id; $rule_id++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 1968 | ▶ | next RULE if defined $rules->[$rule_id]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | # The Marpa::R2 logic assumes no "gaps" in the rule numbering, | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # which is currently the case for Libmarpa, | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # but not guaranteed. | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | shadow_rule( $grammar, $rule_id ); | |||||||||||||||||||||||||||||||||||||||||
| 517 | } ## end RULE: for ( my $rule_id = 0; $rule_id <= $highest_rule_id; ...) | ||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 103 | my $infinite_action = | |||||||||||||||||||||||||||||||||||||||||
| 521 | $grammar->[Marpa::R2::Internal::Grammar::INFINITE_ACTION]; | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | # Above I went through the error events | ||||||||||||||||||||||||||||||||||||||||||
| 524 | # Here I go through the events for situations where there was no | ||||||||||||||||||||||||||||||||||||||||||
| 525 | # hard error returned from libmarpa | ||||||||||||||||||||||||||||||||||||||||||
| 526 | 103 | my $loop_rule_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 527 | { | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 103 | my $event_count = $grammar_c->event_count(); | |||||||||||||||||||||||||||||||||||||||||
| 529 | EVENT: | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 103 | ▶ | for ( my $event_ix = 0; $event_ix < $event_count; $event_ix++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 8 | my ( $event_type, $value ) = $grammar_c->event($event_ix); | |||||||||||||||||||||||||||||||||||||||||
| 532 | 8 | ▶ | if ( $event_type ne 'MARPA_EVENT_LOOP_RULES' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 534 | qq{Unknown grammar precomputation event; type="$event_type"} | ||||||||||||||||||||||||||||||||||||||||||
| 535 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 8 | $loop_rule_count = $value; | |||||||||||||||||||||||||||||||||||||||||
| 538 | } ## end EVENT: for ( my $event_ix = 0; $event_ix < $event_count; ...) | ||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 103 | ▶ | if ( $loop_rule_count and $infinite_action ne 'quiet' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$loop_rule_count and $infinite_action ne "quiet"
MC/DC100%2/2
$loop_rule_count and $infinite_action ne "quiet"
$loop_rule_count
$infinite_action ne "quiet"
Truth table100%3/3
A and B
A= $loop_rule_countB= $infinite_action ne "quiet"
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | my @loop_rules = | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 6 | grep { $grammar_c->rule_is_loop($_) } ( 0 .. $#{$rules} ); | |||||||||||||||||||||||||||||||||||||||||
| 544 | 6 | for my $rule_id (@loop_rules) { | |||||||||||||||||||||||||||||||||||||||||
| 545 | 16 | ▶ | print {$trace_fh} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 'Cycle found involving rule: ', | ||||||||||||||||||||||||||||||||||||||||||
| 547 | $grammar->brief_rule($rule_id), "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 548 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 549 | } ## end for my $rule_id (@loop_rules) | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 6 | ▶ | Marpa::R2::exception('Cycles in grammar, fatal error') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | if $infinite_action eq 'fatal'; | ||||||||||||||||||||||||||||||||||||||||||
| 552 | } ## end if ( $loop_rule_count and $infinite_action ne 'quiet') | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | # A bit hackish here: INACCESSIBLE_OK is not a HASH ref iff | ||||||||||||||||||||||||||||||||||||||||||
| 555 | # it is a Boolean TRUE indicating that all inaccessibles are OK. | ||||||||||||||||||||||||||||||||||||||||||
| 556 | # A Boolean FALSE will have been replaced with an empty hash. | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 103 | ▶ | if ($grammar->[Marpa::R2::Internal::Grammar::WARNINGS] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$grammar->[9] and ref(my $ok = $grammar->[19]) eq "HASH"
MC/DC50%1/2
$grammar->[9] and ref(my $ok = $grammar->[19]) eq "HASH"
$grammar->[9]
ref(my $ok = $grammar->[19]) eq "HASH"
Truth table66%2/3
A and B
A= $grammar->[9]B= ref(my $ok = $grammar->[19]) eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | and ref( | ||||||||||||||||||||||||||||||||||||||||||
| 559 | my $ok = $grammar->[Marpa::R2::Internal::Grammar::INACCESSIBLE_OK] | ||||||||||||||||||||||||||||||||||||||||||
| 560 | ) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 561 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 562 | { | ||||||||||||||||||||||||||||||||||||||||||
| 563 | SYMBOL: | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 102 | for my $symbol ( | |||||||||||||||||||||||||||||||||||||||||
| 565 | 102 | @{ Marpa::R2::Grammar::inaccessible_symbols($grammar) } ) | |||||||||||||||||||||||||||||||||||||||||
| 566 | { | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | # Inaccessible internal symbols may be created | ||||||||||||||||||||||||||||||||||||||||||
| 569 | # from inaccessible use symbols -- ignore these. | ||||||||||||||||||||||||||||||||||||||||||
| 570 | # This assumes that Marpa's logic | ||||||||||||||||||||||||||||||||||||||||||
| 571 | # is correct and that | ||||||||||||||||||||||||||||||||||||||||||
| 572 | # it is not creating inaccessible symbols from | ||||||||||||||||||||||||||||||||||||||||||
| 573 | # accessible ones. | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 14 | ▶ | next SYMBOL if $symbol =~ /\]/xms; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | ▶ | next SYMBOL if $ok->{$symbol}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 2 | ▶ | say {$trace_fh} "Inaccessible symbol: $symbol" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 578 | } ## end SYMBOL: for my $symbol ( @{ ...}) | ||||||||||||||||||||||||||||||||||||||||||
| 579 | } ## end if ( $grammar->[Marpa::R2::Internal::Grammar::WARNINGS...]) | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | # A bit hackish here: UNPRODUCTIVE_OK is not a HASH ref iff | ||||||||||||||||||||||||||||||||||||||||||
| 582 | # it is a Boolean TRUE indicating that all inaccessibles are OK. | ||||||||||||||||||||||||||||||||||||||||||
| 583 | # A Boolean FALSE will have been replaced with an empty hash. | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 103 | ▶ | if ($grammar->[Marpa::R2::Internal::Grammar::WARNINGS] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$grammar->[9] and ref(my $ok = $grammar->[20]) eq "HASH"
MC/DC50%1/2
$grammar->[9] and ref(my $ok = $grammar->[20]) eq "HASH"
$grammar->[9]
ref(my $ok = $grammar->[20]) eq "HASH"
Truth table66%2/3
A and B
A= $grammar->[9]B= ref(my $ok = $grammar->[20]) eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | and ref( | ||||||||||||||||||||||||||||||||||||||||||
| 586 | my $ok = $grammar->[Marpa::R2::Internal::Grammar::UNPRODUCTIVE_OK] | ||||||||||||||||||||||||||||||||||||||||||
| 587 | ) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 588 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 589 | { | ||||||||||||||||||||||||||||||||||||||||||
| 590 | SYMBOL: | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 102 | for my $symbol ( | |||||||||||||||||||||||||||||||||||||||||
| 592 | 102 | @{ Marpa::R2::Grammar::unproductive_symbols($grammar) } ) | |||||||||||||||||||||||||||||||||||||||||
| 593 | { | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | # Unproductive internal symbols may be created | ||||||||||||||||||||||||||||||||||||||||||
| 596 | # from unproductive use symbols -- ignore these. | ||||||||||||||||||||||||||||||||||||||||||
| 597 | # This assumes that Marpa's logic | ||||||||||||||||||||||||||||||||||||||||||
| 598 | # is correct and that | ||||||||||||||||||||||||||||||||||||||||||
| 599 | # it is not creating unproductive symbols from | ||||||||||||||||||||||||||||||||||||||||||
| 600 | # productive ones. | ||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | next SYMBOL if $symbol =~ /\]/xms; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | next SYMBOL if $ok->{$symbol}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | say {$trace_fh} "Unproductive symbol: $symbol" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 605 | } ## end SYMBOL: for my $symbol ( @{ ...}) | ||||||||||||||||||||||||||||||||||||||||||
| 606 | } ## end if ( $grammar->[Marpa::R2::Internal::Grammar::WARNINGS...]) | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | # If we are using scannerless parsing, set that up | ||||||||||||||||||||||||||||||||||||||||||
| 609 | 103 | ▶ | Marpa::R2::exception("Internal error; precompute called for SLIF grammar") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | if $grammar->[Marpa::R2::Internal::Grammar::CHARACTER_CLASSES]; | ||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||
| 612 | 103 | return $grammar; | |||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | } ## end sub Marpa::R2::Grammar::precompute | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | # A custom precompute for SLIF grammars | ||||||||||||||||||||||||||||||||||||||||||
| 617 | sub Marpa::R2::Internal::Grammar::slif_precompute { | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 554 | ▶ | my $grammar = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slif_precompute: called CC=43 SCAR=54.3
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 554 | my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||||||||||||||||||||||||
| 621 | 554 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 622 | 554 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 623 | 554 | my $trace_fh = | |||||||||||||||||||||||||||||||||||||||||
| 624 | $grammar->[Marpa::R2::Internal::Grammar::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | 554 | my $problems = $grammar->[Marpa::R2::Internal::Grammar::PROBLEMS]; | |||||||||||||||||||||||||||||||||||||||||
| 627 | 554 | ▶ | if ($problems) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 629 | Marpa::R2::Grammar::show_problems($grammar), | ||||||||||||||||||||||||||||||||||||||||||
| 630 | "Second attempt to precompute grammar with fatal problems\n", | ||||||||||||||||||||||||||||||||||||||||||
| 631 | 'Marpa::R2 cannot proceed' | ||||||||||||||||||||||||||||||||||||||||||
| 632 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 633 | } ## end if ($problems) | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 554 | ▶ | return if $grammar_c->is_precomputed(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | 554 | ▶ | if ($grammar_c->force_valued() < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | Marpa::R2::uncaught_error( scalar $grammar_c->error() ); | |||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | 554 | set_start_symbol($grammar); | |||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||
| 642 | # Catch errors in precomputation | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 554 | my $precompute_error_code = $Marpa::R2::Error::NONE; | |||||||||||||||||||||||||||||||||||||||||
| 644 | 554 | $grammar_c->throw_set(0); | |||||||||||||||||||||||||||||||||||||||||
| 645 | 554 | my $precompute_result = $grammar_c->precompute(); | |||||||||||||||||||||||||||||||||||||||||
| 646 | 554 | $grammar_c->throw_set(1); | |||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||
| 648 | 554 | ▶ | if ( $precompute_result < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 649 | 2 | ($precompute_error_code) = $grammar_c->error(); | |||||||||||||||||||||||||||||||||||||||||
| 650 | 2 | ▶ | if ( not defined $precompute_error_code ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 652 | 'libmarpa error, but no error code returned'); | ||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | # If already precomputed, let higher level know | ||||||||||||||||||||||||||||||||||||||||||
| 656 | 2 | ▶ | return $precompute_error_code | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | if $precompute_error_code == $Marpa::R2::Error::PRECOMPUTED; | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | # Cycles are not necessarily errors, | ||||||||||||||||||||||||||||||||||||||||||
| 660 | # and get special handling | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 2 | ▶ | $precompute_error_code = $Marpa::R2::Error::NONE | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | if $precompute_error_code == $Marpa::R2::Error::GRAMMAR_HAS_CYCLE; | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | } ## end if ( $precompute_result < 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 554 | ▶ | if ( $precompute_error_code != $Marpa::R2::Error::NONE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | # Report the errors, then return failure | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | 2 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::NO_RULES ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 672 | 'Attempted to precompute grammar with no rules'); | ||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||
| 674 | 2 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::NULLING_TERMINAL ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | my @nulling_terminals = (); | |||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | my $event_count = $grammar_c->event_count(); | |||||||||||||||||||||||||||||||||||||||||
| 677 | EVENT: | ||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | ▶ | for ( my $event_ix = 0; $event_ix < $event_count; $event_ix++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | my ( $event_type, $value ) = $grammar_c->event($event_ix); | |||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | if ( $event_type eq 'MARPA_EVENT_NULLING_TERMINAL' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | push @nulling_terminals, $grammar->symbol_name($value); | |||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||
| 683 | } ## end EVENT: for ( my $event_ix = 0; $event_ix < $event_count; ...) | ||||||||||||||||||||||||||||||||||||||||||
| 684 | my @nulling_terminal_messages = | ||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | map {qq{Nulling symbol "$_" is also a terminal\n}} | |||||||||||||||||||||||||||||||||||||||||
| 686 | @nulling_terminals; | ||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | Marpa::R2::exception( @nulling_terminal_messages, | |||||||||||||||||||||||||||||||||||||||||
| 688 | 'A terminal symbol cannot also be a nulling symbol' ); | ||||||||||||||||||||||||||||||||||||||||||
| 689 | } ## end if ( $precompute_error_code == ...) | ||||||||||||||||||||||||||||||||||||||||||
| 690 | 2 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::COUNTED_NULLABLE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | 1 | my @counted_nullables = (); | |||||||||||||||||||||||||||||||||||||||||
| 692 | 1 | my $event_count = $grammar_c->event_count(); | |||||||||||||||||||||||||||||||||||||||||
| 693 | EVENT: | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 1 | ▶ | for ( my $event_ix = 0; $event_ix < $event_count; $event_ix++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 1 | my ( $event_type, $value ) = $grammar_c->event($event_ix); | |||||||||||||||||||||||||||||||||||||||||
| 696 | 1 | ▶ | if ( $event_type eq 'MARPA_EVENT_COUNTED_NULLABLE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 697 | 1 | push @counted_nullables, $grammar->symbol_name($value); | |||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||
| 699 | } ## end EVENT: for ( my $event_ix = 0; $event_ix < $event_count; ...) | ||||||||||||||||||||||||||||||||||||||||||
| 700 | my @counted_nullable_messages = map { | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 1 | q{Nullable symbol "} | |||||||||||||||||||||||||||||||||||||||||
| 702 | . $_ | ||||||||||||||||||||||||||||||||||||||||||
| 703 | . qq{" is on RHS of counted rule\n} | ||||||||||||||||||||||||||||||||||||||||||
| 704 | } @counted_nullables; | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 1 | Marpa::R2::exception( @counted_nullable_messages, | |||||||||||||||||||||||||||||||||||||||||
| 706 | 'Counted nullables confuse Marpa -- please rewrite the grammar' | ||||||||||||||||||||||||||||||||||||||||||
| 707 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 708 | } ## end if ( $precompute_error_code == ...) | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 1 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::NO_START_SYMBOL ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | Marpa::R2::exception('No start symbol'); | |||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 1 | ▶ | if ( $precompute_error_code == $Marpa::R2::Error::START_NOT_LHS ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | my $name = $grammar->[Marpa::R2::Internal::Grammar::START_NAME]; | |||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 716 | qq{Start symbol "$name" not on LHS of any rule}); | ||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 1 | ▶ | return $precompute_error_code | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | if $precompute_error_code | ||||||||||||||||||||||||||||||||||||||||||
| 721 | == $Marpa::R2::Error::UNPRODUCTIVE_START; | ||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | Marpa::R2::uncaught_error( scalar $grammar_c->error() ); | |||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | } ## end if ( $precompute_error_code != $Marpa::R2::Error::NONE) | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | # Shadow all the new rules | ||||||||||||||||||||||||||||||||||||||||||
| 728 | { | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 552 | my $highest_rule_id = $grammar_c->highest_rule_id(); | |||||||||||||||||||||||||||||||||||||||||
| 730 | RULE: | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 552 | ▶ | for ( my $rule_id = 0; $rule_id <= $highest_rule_id; $rule_id++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | 33577 | ▶ | next RULE if defined $rules->[$rule_id]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | # The Marpa::R2 logic assumes no "gaps" in the rule numbering, | ||||||||||||||||||||||||||||||||||||||||||
| 735 | # which is currently the case for Libmarpa, | ||||||||||||||||||||||||||||||||||||||||||
| 736 | # but not guaranteed. | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | shadow_rule( $grammar, $rule_id ); | |||||||||||||||||||||||||||||||||||||||||
| 738 | } ## end RULE: for ( my $rule_id = 0; $rule_id <= $highest_rule_id; ...) | ||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | 552 | my $infinite_action = | |||||||||||||||||||||||||||||||||||||||||
| 742 | $grammar->[Marpa::R2::Internal::Grammar::INFINITE_ACTION]; | ||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | # Above I went through the error events | ||||||||||||||||||||||||||||||||||||||||||
| 745 | # Here I go through the events for situations where there was no | ||||||||||||||||||||||||||||||||||||||||||
| 746 | # hard error returned from libmarpa | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 552 | my $loop_rule_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 748 | { | ||||||||||||||||||||||||||||||||||||||||||
| 749 | 552 | my $event_count = $grammar_c->event_count(); | |||||||||||||||||||||||||||||||||||||||||
| 750 | EVENT: | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 552 | ▶ | for ( my $event_ix = 0; $event_ix < $event_count; $event_ix++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | my ( $event_type, $value ) = $grammar_c->event($event_ix); | |||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | if ( $event_type ne 'MARPA_EVENT_LOOP_RULES' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 755 | qq{Unknown grammar precomputation event; type="$event_type"} | ||||||||||||||||||||||||||||||||||||||||||
| 756 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | $loop_rule_count = $value; | |||||||||||||||||||||||||||||||||||||||||
| 759 | } ## end EVENT: for ( my $event_ix = 0; $event_ix < $event_count; ...) | ||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 552 | ▶ | if ( $loop_rule_count and $infinite_action ne 'quiet' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$loop_rule_count and $infinite_action ne "quiet"
MC/DC0%0/2
$loop_rule_count and $infinite_action ne "quiet"
$loop_rule_count
$infinite_action ne "quiet"
Truth table33%1/3
A and B
A= $loop_rule_countB= $infinite_action ne "quiet"
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | my @loop_rules = | ||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | grep { $grammar_c->rule_is_loop($_) } ( 0 .. $#{$rules} ); | |||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | for my $rule_id (@loop_rules) { | |||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | print {$trace_fh} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 767 | 'Cycle found involving rule: ', | ||||||||||||||||||||||||||||||||||||||||||
| 768 | $grammar->brief_rule($rule_id), "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 769 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 770 | } ## end for my $rule_id (@loop_rules) | ||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | Marpa::R2::exception('Cycles in grammar, fatal error') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | if $infinite_action eq 'fatal'; | ||||||||||||||||||||||||||||||||||||||||||
| 773 | } ## end if ( $loop_rule_count and $infinite_action ne 'quiet') | ||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | my $default_if_inaccessible = | ||||||||||||||||||||||||||||||||||||||||||
| 776 | $grammar->[Marpa::R2::Internal::Grammar::INTERNAL]->{if_inaccessible} | ||||||||||||||||||||||||||||||||||||||||||
| 777 | 552 | ▶ | // 'warn'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$grammar->[11]{"if_inaccessible"} // "warn"
MC/DC0%0/1
$grammar->[11]{"if_inaccessible"} // "warn"
$grammar->[11]{"if_inaccessible"}
Truth table50%1/2
A
A= $grammar->[11]{"if_inaccessible"}
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | SYMBOL: | ||||||||||||||||||||||||||||||||||||||||||
| 779 | 552 | for my $symbol_id ( grep { !$grammar_c->symbol_is_accessible($_) } | |||||||||||||||||||||||||||||||||||||||||
| 780 | 552 | ( 0 .. $#{$symbols} ) ) | |||||||||||||||||||||||||||||||||||||||||
| 781 | { | ||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 7 | my $symbol = $symbols->[$symbol_id]; | |||||||||||||||||||||||||||||||||||||||||
| 784 | 7 | my $symbol_name = $grammar->symbol_name($symbol_id); | |||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | # Inaccessible internal symbols may be created | ||||||||||||||||||||||||||||||||||||||||||
| 787 | # from inaccessible use symbols -- ignore these. | ||||||||||||||||||||||||||||||||||||||||||
| 788 | # This assumes that Marpa's logic | ||||||||||||||||||||||||||||||||||||||||||
| 789 | # is correct and that | ||||||||||||||||||||||||||||||||||||||||||
| 790 | # it is not creating inaccessible symbols from | ||||||||||||||||||||||||||||||||||||||||||
| 791 | # accessible ones. | ||||||||||||||||||||||||||||||||||||||||||
| 792 | 7 | ▶ | next SYMBOL if $symbol_name =~ /\]/xms; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | 7 | ▶ | my $treatment = | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$symbol->[7] // $default_if_inaccessible
MC/DC0%0/2
$symbol->[7] // $default_if_inaccessible
$symbol->[7]
$default_if_inaccessible
Truth table33%1/3
A // B
A= $symbol->[7]B= $default_if_inaccessible
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | $symbol->[Marpa::R2::Internal::Symbol::IF_INACCESSIBLE] // | ||||||||||||||||||||||||||||||||||||||||||
| 795 | $default_if_inaccessible; | ||||||||||||||||||||||||||||||||||||||||||
| 796 | 7 | ▶ | next SYMBOL if $treatment eq 'ok'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 797 | 2 | my $message = "Inaccessible symbol: $symbol_name"; | |||||||||||||||||||||||||||||||||||||||||
| 798 | 2 | ▶ | Marpa::R2::exception($message) if $treatment eq 'fatal'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | ▶ | say {$trace_fh} $message | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 801 | } ## end for my $symbol_id ( grep { !$grammar_c->...}) | ||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | # A bit hackish here: UNPRODUCTIVE_OK is not a HASH ref iff | ||||||||||||||||||||||||||||||||||||||||||
| 804 | # it is a Boolean TRUE indicating that all inaccessibles are OK. | ||||||||||||||||||||||||||||||||||||||||||
| 805 | # A Boolean FALSE will have been replaced with an empty hash. | ||||||||||||||||||||||||||||||||||||||||||
| 806 | 550 | ▶ | if ($grammar->[Marpa::R2::Internal::Grammar::WARNINGS] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$grammar->[9] and ref(my $ok = $grammar->[20]) eq "HASH"
MC/DC0%0/2
$grammar->[9] and ref(my $ok = $grammar->[20]) eq "HASH"
$grammar->[9]
ref(my $ok = $grammar->[20]) eq "HASH"
Truth table33%1/3
A and B
A= $grammar->[9]B= ref(my $ok = $grammar->[20]) eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | and ref( | ||||||||||||||||||||||||||||||||||||||||||
| 808 | my $ok = $grammar->[Marpa::R2::Internal::Grammar::UNPRODUCTIVE_OK] | ||||||||||||||||||||||||||||||||||||||||||
| 809 | ) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 810 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 811 | { | ||||||||||||||||||||||||||||||||||||||||||
| 812 | SYMBOL: | ||||||||||||||||||||||||||||||||||||||||||
| 813 | 550 | for my $symbol ( | |||||||||||||||||||||||||||||||||||||||||
| 814 | 550 | @{ Marpa::R2::Grammar::unproductive_symbols($grammar) } ) | |||||||||||||||||||||||||||||||||||||||||
| 815 | { | ||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | # Unproductive internal symbols may be created | ||||||||||||||||||||||||||||||||||||||||||
| 818 | # from unproductive use symbols -- ignore these. | ||||||||||||||||||||||||||||||||||||||||||
| 819 | # This assumes that Marpa's logic | ||||||||||||||||||||||||||||||||||||||||||
| 820 | # is correct and that | ||||||||||||||||||||||||||||||||||||||||||
| 821 | # it is not creating unproductive symbols from | ||||||||||||||||||||||||||||||||||||||||||
| 822 | # productive ones. | ||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | ▶ | next SYMBOL if $symbol =~ /\]/xms; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | next SYMBOL if $ok->{$symbol}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | ▶ | say {$trace_fh} "Unproductive symbol: $symbol" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 826 | or Marpa::R2::exception("Could not print: $ERRNO"); | ||||||||||||||||||||||||||||||||||||||||||
| 827 | } ## end SYMBOL: for my $symbol ( @{ ...}) | ||||||||||||||||||||||||||||||||||||||||||
| 828 | } ## end if ( $grammar->[Marpa::R2::Internal::Grammar::WARNINGS...]) | ||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 550 | my $cc_hash = $grammar->[Marpa::R2::Internal::Grammar::CHARACTER_CLASSES]; | |||||||||||||||||||||||||||||||||||||||||
| 831 | 550 | ▶ | if ( defined $cc_hash ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | my $class_table = | |||||||||||||||||||||||||||||||||||||||||
| 833 | $grammar->[Marpa::R2::Internal::Grammar::CHARACTER_CLASS_TABLE] = | ||||||||||||||||||||||||||||||||||||||||||
| 834 | []; | ||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | for my $cc_symbol ( sort keys %{$cc_hash} ) { | |||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | my $cc_components = $cc_hash->{$cc_symbol}; | |||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | push @{$class_table}, | |||||||||||||||||||||||||||||||||||||||||
| 838 | [ $grammar->thin_symbol($cc_symbol), $cc_components ]; | ||||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||||
| 840 | } ## end if ( defined $cc_hash ) | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | # Save some memory | ||||||||||||||||||||||||||||||||||||||||||
| 843 | 550 | $grammar->[Marpa::R2::Internal::Grammar::CHARACTER_CLASSES] = undef; | |||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | 550 | return ; | |||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||
| 847 | } ## end sub Marpa::R2::Grammar::slif_precompute | ||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | sub Marpa::R2::Grammar::show_problems { | ||||||||||||||||||||||||||||||||||||||||||
| 850 | 1 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_problems: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | 1 | my $problems = $grammar->[Marpa::R2::Internal::Grammar::PROBLEMS]; | |||||||||||||||||||||||||||||||||||||||||
| 853 | 1 | ▶ | if ($problems) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | my $problem_count = scalar @{$problems}; | |||||||||||||||||||||||||||||||||||||||||
| 855 | return | ||||||||||||||||||||||||||||||||||||||||||
| 856 | "Grammar has $problem_count problems:\n" | ||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | . ( join "\n", @{$problems} ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 858 | } ## end if ($problems) | ||||||||||||||||||||||||||||||||||||||||||
| 859 | 1 | return "Grammar has no problems\n"; | |||||||||||||||||||||||||||||||||||||||||
| 860 | } ## end sub Marpa::R2::Grammar::show_problems | ||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | # Return DSL form of symbol | ||||||||||||||||||||||||||||||||||||||||||
| 863 | # Does no checking | ||||||||||||||||||||||||||||||||||||||||||
| 864 | sub Marpa::R2::Grammar::symbol_dsl_form { | ||||||||||||||||||||||||||||||||||||||||||
| 865 | 59 | ▶ | my ( $grammar, $symbol_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbol_dsl_form: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 866 | 59 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 867 | 59 | my $symbol = $symbols->[$symbol_id]; | |||||||||||||||||||||||||||||||||||||||||
| 868 | 59 | return $symbol->[Marpa::R2::Internal::Symbol::DSL_FORM]; | |||||||||||||||||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||
| 871 | # Return description of symbol | ||||||||||||||||||||||||||||||||||||||||||
| 872 | # Does no checking | ||||||||||||||||||||||||||||||||||||||||||
| 873 | sub Marpa::R2::Grammar::symbol_description { | ||||||||||||||||||||||||||||||||||||||||||
| 874 | 59 | ▶ | my ( $grammar, $symbol_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbol_description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 59 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 876 | 59 | my $symbol = $symbols->[$symbol_id]; | |||||||||||||||||||||||||||||||||||||||||
| 877 | 59 | return $symbol->[Marpa::R2::Internal::Symbol::DESCRIPTION]; | |||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | # Return display form of symbol | ||||||||||||||||||||||||||||||||||||||||||
| 881 | # Does lots of checking and makes use of alternatives. | ||||||||||||||||||||||||||||||||||||||||||
| 882 | sub Marpa::R2::Grammar::symbol_in_display_form { | ||||||||||||||||||||||||||||||||||||||||||
| 883 | 3902 | ▶ | my ( $grammar, $symbol_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbol_in_display_form: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 884 | 3902 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 885 | 3902 | my $symbol = $symbols->[$symbol_id]; | |||||||||||||||||||||||||||||||||||||||||
| 886 | 3902 | ▶ | return "<!No symbol with ID $symbol_id!>" if not defined $symbol; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 887 | 3902 | my $text = $symbol->[Marpa::R2::Internal::Symbol::DISPLAY_FORM]; | |||||||||||||||||||||||||||||||||||||||||
| 888 | 3902 | ▶ | return $text if defined $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 889 | 3082 | ▶ | $text = $symbol->[Marpa::R2::Internal::Symbol::DSL_FORM] // | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$symbol->[4] // $grammar->symbol_name($symbol_id)
MC/DC0%0/2
$symbol->[4] // $grammar->symbol_name($symbol_id)
$symbol->[4]
$grammar->symbol_name($symbol_id)
Truth table33%1/3
A // B
A= $symbol->[4]B= $grammar->symbol_name($symbol_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | $grammar->symbol_name($symbol_id); | ||||||||||||||||||||||||||||||||||||||||||
| 891 | 3082 | ▶ | return ($text =~ m/\s/xms) ? "<$text>" : $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||
| 894 | sub Marpa::R2::Grammar::show_symbol { | ||||||||||||||||||||||||||||||||||||||||||
| 895 | 75 | ▶ | my ( $grammar, $symbol ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_symbol: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 896 | 75 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 897 | 75 | my $text = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 898 | 75 | my $symbol_id = $symbol->[Marpa::R2::Internal::Symbol::ID]; | |||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||
| 900 | 75 | my $name = $grammar->symbol_name($symbol_id); | |||||||||||||||||||||||||||||||||||||||||
| 901 | 75 | $text .= "$symbol_id: $name"; | |||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | 75 | my @tag_list = (); | |||||||||||||||||||||||||||||||||||||||||
| 904 | 75 | ▶ | $grammar_c->symbol_is_productive($symbol_id) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 905 | or push @tag_list, 'unproductive'; | ||||||||||||||||||||||||||||||||||||||||||
| 906 | 75 | ▶ | $grammar_c->symbol_is_accessible($symbol_id) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 907 | or push @tag_list, 'inaccessible'; | ||||||||||||||||||||||||||||||||||||||||||
| 908 | 75 | ▶ | $grammar_c->symbol_is_nulling($symbol_id) and push @tag_list, 'nulling'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | 75 | ▶ | $grammar_c->symbol_is_terminal($symbol_id) and push @tag_list, 'terminal'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||
| 911 | 75 | ▶ | $text .= join q{ }, q{,}, @tag_list if scalar @tag_list; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 912 | 75 | $text .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 913 | 75 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | } ## end sub Marpa::R2::Grammar::show_symbol | ||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | sub Marpa::R2::Grammar::show_symbols { | ||||||||||||||||||||||||||||||||||||||||||
| 918 | 11 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_symbols: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | 11 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 920 | 11 | my $text = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 921 | 11 | for my $symbol_ref ( @{$symbols} ) { | |||||||||||||||||||||||||||||||||||||||||
| 922 | 75 | $text .= $grammar->show_symbol($symbol_ref); | |||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||
| 924 | 11 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 925 | } ## end sub Marpa::R2::Grammar::show_symbols | ||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | sub Marpa::R2::Grammar::show_nulling_symbols { | ||||||||||||||||||||||||||||||||||||||||||
| 928 | 2 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_nulling_symbols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 929 | 2 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 930 | 2 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 931 | 2 | return join q{ }, sort map { $grammar->symbol_name($_) } | |||||||||||||||||||||||||||||||||||||||||
| 932 | 2 | grep { $grammar_c->symbol_is_nulling($_) } ( 0 .. $#{$symbols} ); | |||||||||||||||||||||||||||||||||||||||||
| 933 | } ## end sub Marpa::R2::Grammar::show_nulling_symbols | ||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||
| 935 | sub Marpa::R2::Grammar::show_productive_symbols { | ||||||||||||||||||||||||||||||||||||||||||
| 936 | 2 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_productive_symbols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 937 | 2 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 938 | 2 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 939 | 8 | return join q{ }, sort map { $grammar->symbol_name($_) } | |||||||||||||||||||||||||||||||||||||||||
| 940 | 2 | grep { $grammar_c->symbol_is_productive($_) } ( 0 .. $#{$symbols} ); | |||||||||||||||||||||||||||||||||||||||||
| 941 | } ## end sub Marpa::R2::Grammar::show_productive_symbols | ||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||
| 943 | sub Marpa::R2::Grammar::show_accessible_symbols { | ||||||||||||||||||||||||||||||||||||||||||
| 944 | 2 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_accessible_symbols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 945 | 2 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 946 | 2 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 947 | 8 | return join q{ }, sort map { $grammar->symbol_name($_) } | |||||||||||||||||||||||||||||||||||||||||
| 948 | 2 | grep { $grammar_c->symbol_is_accessible($_) } ( 0 .. $#{$symbols} ); | |||||||||||||||||||||||||||||||||||||||||
| 949 | } ## end sub Marpa::R2::Grammar::show_accessible_symbols | ||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||
| 951 | sub Marpa::R2::Grammar::inaccessible_symbols { | ||||||||||||||||||||||||||||||||||||||||||
| 952 | 102 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inaccessible_symbols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 953 | 102 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 954 | 102 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 955 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 956 | 14 | sort map { $grammar->symbol_name($_) } | |||||||||||||||||||||||||||||||||||||||||
| 957 | 1747 | grep { !$grammar_c->symbol_is_accessible($_) } | |||||||||||||||||||||||||||||||||||||||||
| 958 | 102 | ( 0 .. $#{$symbols} ) | |||||||||||||||||||||||||||||||||||||||||
| 959 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 960 | } ## end sub Marpa::R2::Grammar::inaccessible_symbols | ||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||
| 962 | sub Marpa::R2::Grammar::unproductive_symbols { | ||||||||||||||||||||||||||||||||||||||||||
| 963 | 652 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unproductive_symbols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 964 | 652 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 965 | 652 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 966 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 967 | 0 | sort map { $grammar->symbol_name($_) } | |||||||||||||||||||||||||||||||||||||||||
| 968 | 34769 | grep { !$grammar_c->symbol_is_productive($_) } | |||||||||||||||||||||||||||||||||||||||||
| 969 | 652 | ( 0 .. $#{$symbols} ) | |||||||||||||||||||||||||||||||||||||||||
| 970 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 971 | } ## end sub Marpa::R2::Grammar::unproductive_symbols | ||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||
| 973 | sub Marpa::R2::Grammar::start_symbol { | ||||||||||||||||||||||||||||||||||||||||||
| 974 | 1 | ▶ | my ( $grammar ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_symbol: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 975 | 1 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 976 | 1 | return $grammar_c->start_symbol(); | |||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | sub Marpa::R2::Grammar::rule_name { | ||||||||||||||||||||||||||||||||||||||||||
| 980 | 659 | ▶ | my ( $grammar, $rule_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rule_name: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 981 | 659 | my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||||||||||||||||||||||||
| 982 | 659 | my $rule = $rules->[$rule_id]; | |||||||||||||||||||||||||||||||||||||||||
| 983 | 659 | ▶ | return "Non-existent rule $rule_id" if not defined $rule; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 984 | 659 | my $name = $rule->[Marpa::R2::Internal::Rule::NAME]; | |||||||||||||||||||||||||||||||||||||||||
| 985 | 659 | ▶ | return $name if defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 986 | 1 | my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER]; | |||||||||||||||||||||||||||||||||||||||||
| 987 | 1 | my ( $lhs_id ) = $tracer->rule_expand($rule_id); | |||||||||||||||||||||||||||||||||||||||||
| 988 | 1 | return $grammar->symbol_name($lhs_id); | |||||||||||||||||||||||||||||||||||||||||
| 989 | } ## end sub Marpa::R2::Grammar::rule_name | ||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||
| 991 | # Undocumented -- assumes it is called internally, | ||||||||||||||||||||||||||||||||||||||||||
| 992 | # by the SLIF | ||||||||||||||||||||||||||||||||||||||||||
| 993 | sub Marpa::R2::Grammar::tag { | ||||||||||||||||||||||||||||||||||||||||||
| 994 | 23137 | ▶ | my ( $grammar, $rule_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 995 | 23137 | my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||||||||||||||||||||||||
| 996 | 23137 | my $rule = $rules->[$rule_id]; | |||||||||||||||||||||||||||||||||||||||||
| 997 | 23137 | return $rule->[Marpa::R2::Internal::Rule::SLIF_TAG]; | |||||||||||||||||||||||||||||||||||||||||
| 998 | } ## end sub Marpa::R2::Grammar::rule_name | ||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||
| 1000 | sub Marpa::R2::Grammar::brief_rule { | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | 131 | ▶ | my ( $grammar, $rule_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
brief_rule: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1002 | 131 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1003 | 131 | my ( $lhs, @rhs ) = $grammar->rule($rule_id); | |||||||||||||||||||||||||||||||||||||||||
| 1004 | 131 | my $minimum = $grammar_c->sequence_min($rule_id); | |||||||||||||||||||||||||||||||||||||||||
| 1005 | 131 | ▶ | my $quantifier = defined $minimum ? $minimum <= 0 ? q{*} : q{+} : q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1006 | 131 | return ( join q{ }, "$rule_id:", $lhs, '->', @rhs ) . $quantifier; | |||||||||||||||||||||||||||||||||||||||||
| 1007 | } ## end sub Marpa::R2::Grammar::brief_rule | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||
| 1009 | sub Marpa::R2::Grammar::show_rule { | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | 87 | ▶ | my ( $grammar, $rule ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_rule: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||
| 1012 | 87 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1013 | 87 | my $rule_id = $rule->[Marpa::R2::Internal::Rule::ID]; | |||||||||||||||||||||||||||||||||||||||||
| 1014 | 87 | my @comment = (); | |||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||
| 1016 | 87 | ▶ | $grammar_c->rule_length($rule_id) == 0 and push @comment, 'empty'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1017 | 87 | ▶ | $grammar->rule_is_used($rule_id) or push @comment, '!used'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1018 | 87 | ▶ | $grammar_c->rule_is_productive($rule_id) or push @comment, 'unproductive'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1019 | 87 | ▶ | $grammar_c->rule_is_accessible($rule_id) or push @comment, 'inaccessible'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1020 | 87 | ▶ | $rule->[Marpa::R2::Internal::Rule::DISCARD_SEPARATION] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1021 | and push @comment, 'discard_sep'; | ||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||
| 1023 | 87 | my $text = $grammar->brief_rule($rule_id); | |||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||
| 1025 | 87 | ▶ | if (@comment) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1026 | 20 | $text .= q{ } . ( join q{ }, q{/*}, @comment, q{*/} ); | |||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||
| 1029 | 87 | return $text .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||
| 1031 | } # sub show_rule | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||
| 1033 | sub Marpa::R2::Grammar::show_rules { | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | 16 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_rules: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1035 | 16 | my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||||||||||||||||||||||||
| 1036 | 16 | my $text; | |||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||
| 1038 | 16 | for my $rule ( @{$rules} ) { | |||||||||||||||||||||||||||||||||||||||||
| 1039 | 87 | $text .= $grammar->show_rule($rule); | |||||||||||||||||||||||||||||||||||||||||
| 1040 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1041 | 16 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 1042 | } ## end sub Marpa::R2::Grammar::show_rules | ||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||
| 1044 | # This logic deals with gaps in the rule numbering. | ||||||||||||||||||||||||||||||||||||||||||
| 1045 | # Currently there are none, but Libmarpa does not | ||||||||||||||||||||||||||||||||||||||||||
| 1046 | # guarantee this. | ||||||||||||||||||||||||||||||||||||||||||
| 1047 | sub Marpa::R2::Grammar::rule_ids { | ||||||||||||||||||||||||||||||||||||||||||
| 1048 | 5032 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rule_ids: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1049 | 5032 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1050 | 5032 | return 0 .. $grammar_c->highest_rule_id(); | |||||||||||||||||||||||||||||||||||||||||
| 1051 | } ## end sub Marpa::R2::Grammar::rule_ids | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||
| 1053 | # This logic deals with gaps in the symbol numbering. | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | # Currently there are none, but Libmarpa does not | ||||||||||||||||||||||||||||||||||||||||||
| 1055 | # guarantee this. | ||||||||||||||||||||||||||||||||||||||||||
| 1056 | sub Marpa::R2::Grammar::symbol_ids { | ||||||||||||||||||||||||||||||||||||||||||
| 1057 | 6 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbol_ids: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1058 | 6 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1059 | 6 | return 0 .. $grammar_c->highest_symbol_id(); | |||||||||||||||||||||||||||||||||||||||||
| 1060 | } ## end sub Marpa::R2::Grammar::rule_ids | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||
| 1062 | # Returns empty array if not such rule | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | sub Marpa::R2::Grammar::rule { | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | 49971 | ▶ | my ( $grammar, $rule_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rule: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1065 | 49971 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 1066 | 49971 | my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER]; | |||||||||||||||||||||||||||||||||||||||||
| 1067 | 49971 | my @symbol_names = (); | |||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||
| 1069 | 49971 | my @symbols = $tracer->rule_expand($rule_id); | |||||||||||||||||||||||||||||||||||||||||
| 1070 | 49971 | SYMBOL_ID: for my $symbol_id (@symbols) { | |||||||||||||||||||||||||||||||||||||||||
| 1071 | ## The name of the symbols, before the BNF rewrites | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | 124857 | ▶ | my $name = | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$symbols->[$symbol_id][5] // $grammar->symbol_name($symbol_id)
MC/DC0%0/2
$symbols->[$symbol_id][5] // $grammar->symbol_name($symbol_id)
$symbols->[$symbol_id][5]
$grammar->symbol_name($symbol_id)
Truth table33%1/3
A // B
A= $symbols->[$symbol_id][5]B= $grammar->symbol_name($symbol_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 1073 | $symbols->[$symbol_id]->[Marpa::R2::Internal::Symbol::LEGACY_NAME] | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | // $grammar->symbol_name($symbol_id); | ||||||||||||||||||||||||||||||||||||||||||
| 1075 | 124857 | push @symbol_names, $name; | |||||||||||||||||||||||||||||||||||||||||
| 1076 | } ## end SYMBOL_ID: for my $symbol_id (@symbol_ids) | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | 49971 | return @symbol_names; | |||||||||||||||||||||||||||||||||||||||||
| 1078 | } ## end sub Marpa::R2::Grammar::rule | ||||||||||||||||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||||||||||||||||
| 1080 | # Internal, for use with in coordinating thin and thick | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | # interfaces. NOT DOCUMENTED. | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | sub Marpa::R2::Grammar::_rule_mask { | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | 9350 | ▶ | my ( $grammar, $rule_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rule_mask: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1084 | 9350 | my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||||||||||||||||||||||||
| 1085 | 9350 | my $rule = $rules->[$rule_id]; | |||||||||||||||||||||||||||||||||||||||||
| 1086 | 9350 | return $rule->[Marpa::R2::Internal::Rule::MASK]; | |||||||||||||||||||||||||||||||||||||||||
| 1087 | } ## end sub Marpa::R2::Grammar::rule | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||
| 1089 | # Deprecated and for removal | ||||||||||||||||||||||||||||||||||||||||||
| 1090 | # Used in blog post, and part of | ||||||||||||||||||||||||||||||||||||||||||
| 1091 | # CPAN version 2.023_008 but | ||||||||||||||||||||||||||||||||||||||||||
| 1092 | # never documented in any CPAN version | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | sub Marpa::R2::Grammar::bnf_rule { | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | 0 | ▶ | goto &Marpa::R2::Grammar::rule; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bnf_rule: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1095 | } ## end sub Marpa::R2::Grammar::bnf_rule | ||||||||||||||||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||||||||||||||||
| 1097 | sub Marpa::R2::Grammar::show_dotted_rule { | ||||||||||||||||||||||||||||||||||||||||||
| 1098 | 31 | ▶ | my ( $grammar, $rule_id, $dot_position ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_dotted_rule: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1099 | 31 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1100 | 31 | my ( $lhs, @rhs ) = $grammar->rule($rule_id); | |||||||||||||||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||||||||||||||||
| 1102 | 31 | my $minimum = $grammar_c->sequence_min($rule_id); | |||||||||||||||||||||||||||||||||||||||||
| 1103 | 31 | ▶ | if (defined $minimum) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1104 | 1 | ▶ | my $quantifier = $minimum <= 0 ? q{*} : q{+} ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1105 | 1 | $rhs[0] .= $quantifier; | |||||||||||||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1107 | 31 | ▶ | $dot_position = 0 if $dot_position < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1108 | 31 | splice @rhs, $dot_position, 0, q{.}; | |||||||||||||||||||||||||||||||||||||||||
| 1109 | 31 | return join q{ }, $lhs, q{->}, @rhs; | |||||||||||||||||||||||||||||||||||||||||
| 1110 | } ## end sub Marpa::R2::Grammar::show_dotted_rule | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||
| 1112 | # Used by lexers to check that symbol is a terminal | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | sub Marpa::R2::Grammar::check_terminal { | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | 1 | ▶ | my ( $grammar, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_terminal: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1115 | 1 | ▶ | return 0 if not defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1116 | 1 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1117 | 1 | my $symbol_id = | |||||||||||||||||||||||||||||||||||||||||
| 1118 | $grammar->[Marpa::R2::Internal::Grammar::TRACER] | ||||||||||||||||||||||||||||||||||||||||||
| 1119 | ->symbol_by_name($name); | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | 1 | ▶ | return 0 if not defined $symbol_id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1121 | 1 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 1122 | 1 | my $symbol = $symbols->[$symbol_id]; | |||||||||||||||||||||||||||||||||||||||||
| 1123 | 1 | ▶ | return $grammar_c->symbol_is_terminal($symbol_id) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1124 | } ## end sub Marpa::R2::Grammar::check_terminal | ||||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||
| 1126 | sub Marpa::R2::Grammar::symbol_name { | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | 172700 | ▶ | my ( $grammar, $id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbol_name: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1128 | 172700 | my $symbol_name = | |||||||||||||||||||||||||||||||||||||||||
| 1129 | $grammar->[Marpa::R2::Internal::Grammar::TRACER]->symbol_name($id); | ||||||||||||||||||||||||||||||||||||||||||
| 1130 | 172700 | ▶ | return defined $symbol_name ? $symbol_name : '[SYMBOL#' . $id . ']'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1131 | } ## end sub Marpa::R2::Grammar::symbol_name | ||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||
| 1133 | sub shadow_symbol { | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | 34851 | ▶ | my ( $grammar, $symbol_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shadow_symbol: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1135 | 34851 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 1136 | 34851 | my $symbol = $symbols->[$symbol_id] = []; | |||||||||||||||||||||||||||||||||||||||||
| 1137 | 34851 | $symbol->[Marpa::R2::Internal::Symbol::ID] = $symbol_id; | |||||||||||||||||||||||||||||||||||||||||
| 1138 | 34851 | return $symbol; | |||||||||||||||||||||||||||||||||||||||||
| 1139 | } ## end sub shadow_symbol | ||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||
| 1141 | # Create the structure which "shadows" the libmarpa rule | ||||||||||||||||||||||||||||||||||||||||||
| 1142 | sub shadow_rule { | ||||||||||||||||||||||||||||||||||||||||||
| 1143 | 35595 | ▶ | my ( $grammar, $rule_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shadow_rule: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1144 | 35595 | my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||||||||||||||||||||||||
| 1145 | 35595 | my $new_rule = $rules->[$rule_id] = []; | |||||||||||||||||||||||||||||||||||||||||
| 1146 | 35595 | $new_rule->[Marpa::R2::Internal::Rule::ID] = $rule_id; | |||||||||||||||||||||||||||||||||||||||||
| 1147 | 35595 | return $new_rule; | |||||||||||||||||||||||||||||||||||||||||
| 1148 | } ## end sub shadow_rule | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||
| 1150 | sub assign_symbol { | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | 132975 | ▶ | my ( $grammar, $name, $options ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assign_symbol: called CC=14 SCAR=31.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||||||
| 1153 | 132975 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1154 | 132975 | my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER]; | |||||||||||||||||||||||||||||||||||||||||
| 1155 | 132975 | my $symbol_id = $tracer->symbol_by_name($name); | |||||||||||||||||||||||||||||||||||||||||
| 1156 | 132975 | ▶ | if ( defined $symbol_id ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1157 | 98124 | my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||||||||||||||||||||||||
| 1158 | 98124 | return $symbols->[$symbol_id]; | |||||||||||||||||||||||||||||||||||||||||
| 1159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1160 | 34851 | $symbol_id = $tracer->symbol_new($name); | |||||||||||||||||||||||||||||||||||||||||
| 1161 | 34851 | my $symbol = shadow_symbol( $grammar, $symbol_id ); | |||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||
| 1163 | 34851 | PROPERTY: for my $property ( sort keys %{$options} ) { | |||||||||||||||||||||||||||||||||||||||||
| 1164 | 62434 | ▶ | if ( $property eq 'semantics' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1165 | 0 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1166 | 0 | $symbol->[Marpa::R2::Internal::Symbol::LEXEME_SEMANTICS] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1167 | 0 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | 62434 | ▶ | if ( $property eq 'bless' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1170 | 0 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1171 | 0 | $symbol->[Marpa::R2::Internal::Symbol::BLESSING] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1172 | 0 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | 62434 | ▶ | if ( $property eq 'terminal' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1175 | 103 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1176 | 103 | $grammar_c->symbol_is_terminal_set( $symbol_id, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 1177 | 103 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1179 | 62331 | ▶ | if ( $property eq 'rank' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1181 | 0 | ▶ | Marpa::R2::exception(qq{Symbol "$name": rank must be an integer}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not &Scalar::Util::looks_like_number($value) or int $value != $value
MC/DC0%0/2
not &Scalar::Util::looks_like_number($value) or int $value != $value
not &Scalar::Util::looks_like_number($value)
int $value != $value
Truth table0%0/3
not(A) or B
A= not &Scalar::Util::looks_like_number($value)B= int $value != $value
| |||||||||||||||||||||||||||||||||||||||||||
| 1182 | if not Scalar::Util::looks_like_number($value) | ||||||||||||||||||||||||||||||||||||||||||
| 1183 | or int($value) != $value; | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | 0 | $grammar_c->symbol_rank_set($symbol_id) = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1186 | } ## end if ( $property eq 'rank' ) | ||||||||||||||||||||||||||||||||||||||||||
| 1187 | 62331 | ▶ | if ( $property eq 'description' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1188 | 21010 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1189 | 21010 | $symbol->[Marpa::R2::Internal::Symbol::DESCRIPTION] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1190 | 21010 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1192 | 41321 | ▶ | if ( $property eq 'dsl_form' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1193 | 20251 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1194 | 20251 | $symbol->[Marpa::R2::Internal::Symbol::DSL_FORM] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1195 | 20251 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | 21070 | ▶ | if ( $property eq 'legacy_name' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1198 | 60 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1199 | 60 | $symbol->[Marpa::R2::Internal::Symbol::LEGACY_NAME] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1200 | 60 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | 21010 | ▶ | if ( $property eq 'display_form' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1203 | 21010 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1204 | 21010 | $symbol->[Marpa::R2::Internal::Symbol::DISPLAY_FORM] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1205 | 21010 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1207 | 0 | ▶ | if ( $property eq 'if_inaccessible' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | my $value = $options->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | $symbol->[Marpa::R2::Internal::Symbol::IF_INACCESSIBLE] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | next PROPERTY; | |||||||||||||||||||||||||||||||||||||||||
| 1211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | Marpa::R2::exception(qq{Unknown symbol property "$property"}); | |||||||||||||||||||||||||||||||||||||||||
| 1213 | } ## end PROPERTY: for my $property ( keys %{$options} ) | ||||||||||||||||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||||||||||||||||
| 1215 | 34851 | return $symbol; | |||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||
| 1217 | } ## end sub assign_symbol | ||||||||||||||||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||||||||||||||||
| 1219 | sub assign_user_symbol { | ||||||||||||||||||||||||||||||||||||||||||
| 1220 | 26138 | ▶ | my $grammar = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assign_user_symbol: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 1221 | 26138 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1222 | 26138 | my $options = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1223 | 26138 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||
| 1225 | 26138 | ▶ | if ( my $type = ref $name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1226 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 1227 | "Symbol name was ref to $type; it must be a scalar string"); | ||||||||||||||||||||||||||||||||||||||||||
| 1228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1229 | 26138 | ▶ | if ( not $grammar->[Marpa::R2::Internal::Grammar::INTERNAL] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1230 | 5128 | my $final_symbol = substr $name, -1; | |||||||||||||||||||||||||||||||||||||||||
| 1231 | 5128 | ▶ | if ( $DEFAULT_SYMBOLS_RESERVED{$final_symbol} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 1233 | qq{Symbol name $name ends in "$final_symbol": that's not allowed} | ||||||||||||||||||||||||||||||||||||||||||
| 1234 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1236 | } ## end if ( not $grammar->[Marpa::R2::Internal::Grammar::INTERNAL...]) | ||||||||||||||||||||||||||||||||||||||||||
| 1237 | 26138 | my $symbol = assign_symbol( $grammar, $name, $options ); | |||||||||||||||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||||||||||||||||
| 1239 | 26138 | return $symbol; | |||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||
| 1241 | } ## end sub assign_user_symbol | ||||||||||||||||||||||||||||||||||||||||||
| 1242 | |||||||||||||||||||||||||||||||||||||||||||
| 1243 | # add one or more rules | ||||||||||||||||||||||||||||||||||||||||||
| 1244 | sub add_user_rules { | ||||||||||||||||||||||||||||||||||||||||||
| 1245 | 658 | ▶ | my ( $grammar, $rules ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_user_rules: called CC=8 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||
| 1247 | 658 | my @hash_rules = (); | |||||||||||||||||||||||||||||||||||||||||
| 1248 | 658 | RULE: for my $rule ( @{$rules} ) { | |||||||||||||||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||||||||||||||||
| 1250 | # Translate other rule formats into hash rules | ||||||||||||||||||||||||||||||||||||||||||
| 1251 | 35211 | my $ref_rule = ref $rule; | |||||||||||||||||||||||||||||||||||||||||
| 1252 | 35211 | ▶ | if ( $ref_rule eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1253 | 34992 | push @hash_rules, $rule; | |||||||||||||||||||||||||||||||||||||||||
| 1254 | 34992 | next RULE; | |||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | 219 | ▶ | if ( $ref_rule eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1257 | 219 | my $arg_count = @{$rule}; | |||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||
| 1259 | 219 | ▶ | if ( $arg_count > 4 or $arg_count < 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$arg_count > 4 or $arg_count < 1
MC/DC0%0/2
$arg_count > 4 or $arg_count < 1
$arg_count > 4
$arg_count < 1
Truth table33%1/3
A or B
A= $arg_count > 4B= $arg_count < 1
| |||||||||||||||||||||||||||||||||||||||||||
| 1260 | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||||
| 1261 | "Rule has $arg_count arguments: " | ||||||||||||||||||||||||||||||||||||||||||
| 1262 | . join( ', ', | ||||||||||||||||||||||||||||||||||||||||||
| 1263 | 0 | ▶ | map { defined $_ ? $_ : 'undef' } @{$rule} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1264 | . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1265 | . 'Rule must have from 1 to 4 arguments' | ||||||||||||||||||||||||||||||||||||||||||
| 1266 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1267 | } ## end if ( $arg_count > 4 or $arg_count < 1 ) | ||||||||||||||||||||||||||||||||||||||||||
| 1268 | 219 | my ( $lhs, $rhs, $action ) = @{$rule}; | |||||||||||||||||||||||||||||||||||||||||
| 1269 | 219 | push @hash_rules, | |||||||||||||||||||||||||||||||||||||||||
| 1270 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1271 | lhs => $lhs, | ||||||||||||||||||||||||||||||||||||||||||
| 1272 | rhs => $rhs, | ||||||||||||||||||||||||||||||||||||||||||
| 1273 | action => $action, | ||||||||||||||||||||||||||||||||||||||||||
| 1274 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1275 | 219 | next RULE; | |||||||||||||||||||||||||||||||||||||||||
| 1276 | } ## end if ( $ref_rule eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||
| 1277 | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||||
| 1278 | 0 | 'Invalid rule: ', | |||||||||||||||||||||||||||||||||||||||||
| 1279 | Data::Dumper->new( [$rule], ['Invalid_Rule'] )->Indent(2) | ||||||||||||||||||||||||||||||||||||||||||
| 1280 | ->Terse(1)->Maxdepth(2)->Dump, | ||||||||||||||||||||||||||||||||||||||||||
| 1281 | 'Rule must be ref to HASH or ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 1282 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1283 | |||||||||||||||||||||||||||||||||||||||||||
| 1284 | } # RULE | ||||||||||||||||||||||||||||||||||||||||||
| 1285 | |||||||||||||||||||||||||||||||||||||||||||
| 1286 | 658 | for my $hash_rule (@hash_rules) { | |||||||||||||||||||||||||||||||||||||||||
| 1287 | 35196 | add_user_rule( $grammar, $hash_rule ); | |||||||||||||||||||||||||||||||||||||||||
| 1288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||||||||||||||||
| 1290 | 652 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1291 | |||||||||||||||||||||||||||||||||||||||||||
| 1292 | } ## end sub add_user_rules | ||||||||||||||||||||||||||||||||||||||||||
| 1293 | |||||||||||||||||||||||||||||||||||||||||||
| 1294 | sub add_user_rule { | ||||||||||||||||||||||||||||||||||||||||||
| 1295 | 35601 | ▶ | my ( $grammar, $options ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_user_rule: called CC=59 SCAR=43.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||||||||||||||||
| 1297 | 35601 | ▶ | Marpa::R2::exception('Missing argument to add_user_rule') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $grammar and defined $options
MC/DC0%0/2
defined $grammar and defined $options
defined $grammar
defined $options
Truth table33%1/3
A and B
A= defined $grammarB= defined $options
| |||||||||||||||||||||||||||||||||||||||||||
| 1298 | if not defined $grammar | ||||||||||||||||||||||||||||||||||||||||||
| 1299 | or not defined $options; | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||
| 1301 | 35601 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1302 | 35601 | my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER]; | |||||||||||||||||||||||||||||||||||||||||
| 1303 | 35601 | my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||||||||||||||||||||||||
| 1304 | 35601 | my $default_rank = $grammar_c->default_rank(); | |||||||||||||||||||||||||||||||||||||||||
| 1305 | |||||||||||||||||||||||||||||||||||||||||||
| 1306 | 35601 | my ( $lhs_name, $rhs_names, $action, $blessing ); | |||||||||||||||||||||||||||||||||||||||||
| 1307 | 35601 | my ( $min, $separator_name ); | |||||||||||||||||||||||||||||||||||||||||
| 1308 | 35601 | my $rank; | |||||||||||||||||||||||||||||||||||||||||
| 1309 | 35601 | my $null_ranking; | |||||||||||||||||||||||||||||||||||||||||
| 1310 | 35601 | my $rule_name; | |||||||||||||||||||||||||||||||||||||||||
| 1311 | 35601 | my $slif_tag; | |||||||||||||||||||||||||||||||||||||||||
| 1312 | 35601 | my $mask; | |||||||||||||||||||||||||||||||||||||||||
| 1313 | 35601 | my $proper_separation = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1314 | 35601 | my $keep_separation = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1315 | 35601 | my $description; | |||||||||||||||||||||||||||||||||||||||||
| 1316 | |||||||||||||||||||||||||||||||||||||||||||
| 1317 | 35601 | OPTION: for my $option ( keys %{$options} ) { | |||||||||||||||||||||||||||||||||||||||||
| 1318 | 158838 | my $value = $options->{$option}; | |||||||||||||||||||||||||||||||||||||||||
| 1319 | 158838 | ▶ | if ( $option eq 'name' ) { $rule_name = $value; next OPTION; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1320 | 147206 | ▶ | if ( $option eq 'tag' ) { $slif_tag = $value; next OPTION; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1321 | 133233 | ▶ | if ( $option eq 'rhs' ) { $rhs_names = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1322 | 97636 | ▶ | if ( $option eq 'lhs' ) { $lhs_name = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1323 | 62035 | ▶ | if ( $option eq 'action' ) { $action = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1324 | 50995 | ▶ | if ( $option eq 'bless' ) { $blessing = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1325 | 41630 | ▶ | if ( $option eq 'rank' ) { $rank = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1326 | 41566 | ▶ | if ( $option eq 'null_ranking' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1327 | 4 | $null_ranking = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1328 | 4 | next OPTION; | |||||||||||||||||||||||||||||||||||||||||
| 1329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1330 | 41562 | ▶ | if ( $option eq 'min' ) { $min = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1331 | 39587 | ▶ | if ( $option eq 'separator' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1332 | 368 | $separator_name = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1333 | 368 | next OPTION; | |||||||||||||||||||||||||||||||||||||||||
| 1334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | 39219 | ▶ | if ( $option eq 'proper' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1336 | 262 | $proper_separation = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1337 | 262 | next OPTION; | |||||||||||||||||||||||||||||||||||||||||
| 1338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1339 | 38957 | ▶ | if ( $option eq 'keep' ) { $keep_separation = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1340 | 38942 | ▶ | if ( $option eq 'mask' ) { $mask = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1341 | 16869 | ▶ | if ( $option eq 'description' ) { $description = $value; next OPTION } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1342 | 0 | Marpa::R2::exception("Unknown user rule option: $option"); | |||||||||||||||||||||||||||||||||||||||||
| 1343 | } ## end OPTION: for my $option ( keys %{$options} ) | ||||||||||||||||||||||||||||||||||||||||||
| 1344 | |||||||||||||||||||||||||||||||||||||||||||
| 1345 | 35601 | ▶ | if ( defined $min and not Scalar::Util::looks_like_number($min) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $min and not &Scalar::Util::looks_like_number($min)
MC/DC0%0/2
defined $min and not &Scalar::Util::looks_like_number($min)
defined $min
not &Scalar::Util::looks_like_number($min)
Truth table66%2/3
A and not(B)
A= defined $minB= not &Scalar::Util::looks_like_number($min)
| |||||||||||||||||||||||||||||||||||||||||||
| 1346 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 1347 | q{"min" must be undefined or a valid Perl number}); | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | 35601 | my $stuifzand_interface = | |||||||||||||||||||||||||||||||||||||||||
| 1350 | $grammar->[Marpa::R2::Internal::Grammar::INTERFACE] eq 'stuifzand'; | ||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||
| 1352 | 35601 | ▶ | my $grammar_is_internal = $stuifzand_interface | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$stuifzand_interface || $grammar->[11]
MC/DC100%2/2
$stuifzand_interface || $grammar->[11]
$stuifzand_interface
$grammar->[11]
Truth table100%3/3
A || B
A= $stuifzand_interfaceB= $grammar->[11]
| |||||||||||||||||||||||||||||||||||||||||||
| 1353 | || $grammar->[Marpa::R2::Internal::Grammar::INTERNAL]; | ||||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||
| 1355 | 35601 | ▶ | my $lhs = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1356 | $grammar_is_internal | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | ? assign_symbol( $grammar, $lhs_name ) | ||||||||||||||||||||||||||||||||||||||||||
| 1358 | : assign_user_symbol( $grammar, $lhs_name ); | ||||||||||||||||||||||||||||||||||||||||||
| 1359 | 35601 | ▶ | $rhs_names //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rhs_names //= []
MC/DC100%1/1
$rhs_names //= []
$rhs_names
Truth table100%2/2
A
A= $rhs_names
| |||||||||||||||||||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||||||||||||||||
| 1361 | 35601 | my @rule_problems = (); | |||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||
| 1363 | 35601 | my $rhs_ref_type = ref $rhs_names; | |||||||||||||||||||||||||||||||||||||||||
| 1364 | 35601 | ▶ | if ( not $rhs_ref_type or $rhs_ref_type ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $rhs_ref_type or $rhs_ref_type ne "ARRAY"
MC/DC0%0/2
not $rhs_ref_type or $rhs_ref_type ne "ARRAY"
not $rhs_ref_type
$rhs_ref_type ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not $rhs_ref_typeB= $rhs_ref_type ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 1365 | 0 | ▶ | my $problem = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1366 | "RHS is not ref to ARRAY\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1367 | . ' Type of rhs is ' | ||||||||||||||||||||||||||||||||||||||||||
| 1368 | . ( $rhs_ref_type ? $rhs_ref_type : 'not a ref' ) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | 0 | my $d = Data::Dumper->new( [$rhs_names], ['rhs'] ); | |||||||||||||||||||||||||||||||||||||||||
| 1370 | 0 | $problem .= $d->Dump(); | |||||||||||||||||||||||||||||||||||||||||
| 1371 | 0 | push @rule_problems, $problem; | |||||||||||||||||||||||||||||||||||||||||
| 1372 | } ## end if ( not $rhs_ref_type or $rhs_ref_type ne 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||
| 1373 | 35601 | ▶ | if ( not defined $lhs_name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1374 | 0 | push @rule_problems, "Missing LHS\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||
| 1377 | 35601 | ▶ | if ( defined $rank | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $rank and !&Scalar::Util::looks_like_number($rank) || int $rank != $rank
not &Scalar::Util::looks_like_number($rank) or int $rank != $rank
MC/DC0%0/3
defined $rank and !&Scalar::Util::looks_like_number($rank) || int $rank != $rank
defined $rank
not &Scalar::Util::looks_like_number($rank)
int $rank != $rank
Truth table50%2/4
A and not(B) or C
A= defined $rankB= not &Scalar::Util::looks_like_number($rank)C= int $rank != $rank
| |||||||||||||||||||||||||||||||||||||||||||
| 1378 | and | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | ( not Scalar::Util::looks_like_number($rank) or int($rank) != $rank ) | ||||||||||||||||||||||||||||||||||||||||||
| 1380 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 1381 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1382 | 0 | push @rule_problems, "Rank must be undefined or an integer\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1383 | } ## end if ( defined $rank and ( not Scalar::Util::looks_like_number...)) | ||||||||||||||||||||||||||||||||||||||||||
| 1384 | 35601 | ▶ | $rank //= $default_rank; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rank //= $default_rank
MC/DC0%0/2
$rank //= $default_rank
$rank
$default_rank
Truth table66%2/3
A //= B
A= $rankB= $default_rank
| |||||||||||||||||||||||||||||||||||||||||||
| 1385 | |||||||||||||||||||||||||||||||||||||||||||
| 1386 | 35601 | ▶ | $null_ranking //= 'low'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$null_ranking //= "low"
MC/DC100%1/1
$null_ranking //= "low"
$null_ranking
Truth table100%2/2
A
A= $null_ranking
| |||||||||||||||||||||||||||||||||||||||||||
| 1387 | 35601 | ▶ | if ( $null_ranking ne 'high' and $null_ranking ne 'low' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$null_ranking ne "high" and $null_ranking ne "low"
MC/DC0%0/2
$null_ranking ne "high" and $null_ranking ne "low"
$null_ranking ne "high"
$null_ranking ne "low"
Truth table66%2/3
A and B
A= $null_ranking ne "high"B= $null_ranking ne "low"
| |||||||||||||||||||||||||||||||||||||||||||
| 1388 | 0 | push @rule_problems, | |||||||||||||||||||||||||||||||||||||||||
| 1389 | "Null Ranking must be undefined, 'high' or 'low'\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||||||||||||||||
| 1392 | 35601 | ▶ | if ( scalar @rule_problems ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1393 | 0 | my %dump_options = %{$options}; | |||||||||||||||||||||||||||||||||||||||||
| 1394 | 0 | delete $dump_options{grammar}; | |||||||||||||||||||||||||||||||||||||||||
| 1395 | 0 | my $msg = ( scalar @rule_problems ) | |||||||||||||||||||||||||||||||||||||||||
| 1396 | . " problem(s) in the following rule:\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1397 | 0 | my $d = Data::Dumper->new( [ \%dump_options ], ['rule'] ); | |||||||||||||||||||||||||||||||||||||||||
| 1398 | 0 | $msg .= $d->Dump(); | |||||||||||||||||||||||||||||||||||||||||
| 1399 | 0 | for my $problem_number ( 0 .. $#rule_problems ) { | |||||||||||||||||||||||||||||||||||||||||
| 1400 | 0 | $msg | |||||||||||||||||||||||||||||||||||||||||
| 1401 | .= 'Problem ' | ||||||||||||||||||||||||||||||||||||||||||
| 1402 | . ( $problem_number + 1 ) . q{: } | ||||||||||||||||||||||||||||||||||||||||||
| 1403 | . $rule_problems[$problem_number] . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1404 | } ## end for my $problem_number ( 0 .. $#rule_problems ) | ||||||||||||||||||||||||||||||||||||||||||
| 1405 | 0 | Marpa::R2::exception($msg); | |||||||||||||||||||||||||||||||||||||||||
| 1406 | } ## end if ( scalar @rule_problems ) | ||||||||||||||||||||||||||||||||||||||||||
| 1407 | |||||||||||||||||||||||||||||||||||||||||||
| 1408 | my $rhs = [ | ||||||||||||||||||||||||||||||||||||||||||
| 1409 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | 75861 | ▶ | $grammar_is_internal | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1411 | ? assign_symbol( $grammar, $_ ) | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | : assign_user_symbol( $grammar, $_ ); | ||||||||||||||||||||||||||||||||||||||||||
| 1413 | 35601 | } @{$rhs_names} | |||||||||||||||||||||||||||||||||||||||||
| 1414 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||||||||||||||||
| 1416 | # Is this is an ordinary, non-counted rule? | ||||||||||||||||||||||||||||||||||||||||||
| 1417 | 35601 | ▶ | my $is_ordinary_rule = scalar @{$rhs_names} == 0 || !defined $min; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
scalar @{$rhs_names;} == 0 || !defined($min)
MC/DC100%2/2
scalar @{$rhs_names;} == 0 || !defined($min)
scalar @{$rhs_names;} == 0
!defined($min)
Truth table100%3/3
A || not(B)
A= scalar @{$rhs_names;} == 0B= !defined($min)
| |||||||||||||||||||||||||||||||||||||||||||
| 1418 | 35601 | ▶ | if ( defined $separator_name and $is_ordinary_rule ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $separator_name and $is_ordinary_rule
MC/DC0%0/2
defined $separator_name and $is_ordinary_rule
defined $separator_name
$is_ordinary_rule
Truth table66%2/3
A and B
A= defined $separator_nameB= $is_ordinary_rule
| |||||||||||||||||||||||||||||||||||||||||||
| 1419 | 0 | ▶ | if ( defined $separator_name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1420 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 1421 | 'separator defined for rule without repetitions'); | ||||||||||||||||||||||||||||||||||||||||||
| 1422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | } ## end if ( defined $separator_name and $is_ordinary_rule ) | ||||||||||||||||||||||||||||||||||||||||||
| 1424 | |||||||||||||||||||||||||||||||||||||||||||
| 1425 | 35601 | my @rhs_ids = map { $_->[Marpa::R2::Internal::Symbol::ID] } @{$rhs}; | |||||||||||||||||||||||||||||||||||||||||
| 1426 | 35601 | my $lhs_id = $lhs->[Marpa::R2::Internal::Symbol::ID]; | |||||||||||||||||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||||||||||||||||
| 1428 | 35601 | my $base_rule_id; | |||||||||||||||||||||||||||||||||||||||||
| 1429 | 35601 | my $separator_id = -1; | |||||||||||||||||||||||||||||||||||||||||
| 1430 | |||||||||||||||||||||||||||||||||||||||||||
| 1431 | 35601 | ▶ | if ($is_ordinary_rule) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1432 | |||||||||||||||||||||||||||||||||||||||||||
| 1433 | # Capture errors | ||||||||||||||||||||||||||||||||||||||||||
| 1434 | 33626 | $grammar_c->throw_set(0); | |||||||||||||||||||||||||||||||||||||||||
| 1435 | 33626 | $base_rule_id = $grammar_c->rule_new( $lhs_id, \@rhs_ids ); | |||||||||||||||||||||||||||||||||||||||||
| 1436 | 33626 | $grammar_c->throw_set(1); | |||||||||||||||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||||||||||||||||
| 1438 | } ## end if ($is_ordinary_rule) | ||||||||||||||||||||||||||||||||||||||||||
| 1439 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1440 | Marpa::R2::exception('Only one rhs symbol allowed for counted rule') | ||||||||||||||||||||||||||||||||||||||||||
| 1441 | 1975 | ▶ | if scalar @{$rhs_names} != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1442 | |||||||||||||||||||||||||||||||||||||||||||
| 1443 | # create the separator symbol, if we're using one | ||||||||||||||||||||||||||||||||||||||||||
| 1444 | 1975 | ▶ | if ( defined $separator_name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1445 | 368 | ▶ | my $separator = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1446 | $grammar_is_internal | ||||||||||||||||||||||||||||||||||||||||||
| 1447 | ? assign_symbol( $grammar, $separator_name ) | ||||||||||||||||||||||||||||||||||||||||||
| 1448 | : assign_user_symbol( $grammar, $separator_name ); | ||||||||||||||||||||||||||||||||||||||||||
| 1449 | 368 | $separator_id = $separator->[Marpa::R2::Internal::Symbol::ID]; | |||||||||||||||||||||||||||||||||||||||||
| 1450 | } ## end if ( defined $separator_name ) | ||||||||||||||||||||||||||||||||||||||||||
| 1451 | |||||||||||||||||||||||||||||||||||||||||||
| 1452 | 1975 | $grammar_c->throw_set(0); | |||||||||||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||||||||||
| 1454 | # The original rule for a sequence rule is | ||||||||||||||||||||||||||||||||||||||||||
| 1455 | # not actually used in parsing, | ||||||||||||||||||||||||||||||||||||||||||
| 1456 | # but some of the rewritten sequence rules are its | ||||||||||||||||||||||||||||||||||||||||||
| 1457 | # semantic equivalents. | ||||||||||||||||||||||||||||||||||||||||||
| 1458 | |||||||||||||||||||||||||||||||||||||||||||
| 1459 | 1975 | $base_rule_id = $grammar_c->sequence_new( | |||||||||||||||||||||||||||||||||||||||||
| 1460 | $lhs_id, | ||||||||||||||||||||||||||||||||||||||||||
| 1461 | $rhs_ids[0], | ||||||||||||||||||||||||||||||||||||||||||
| 1462 | { separator => $separator_id, | ||||||||||||||||||||||||||||||||||||||||||
| 1463 | proper => $proper_separation, | ||||||||||||||||||||||||||||||||||||||||||
| 1464 | min => $min, | ||||||||||||||||||||||||||||||||||||||||||
| 1465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1466 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1467 | 1975 | $grammar_c->throw_set(1); | |||||||||||||||||||||||||||||||||||||||||
| 1468 | } ## end else [ if ($is_ordinary_rule) ] | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | |||||||||||||||||||||||||||||||||||||||||||
| 1470 | 35601 | ▶ | if ( not defined $base_rule_id or $base_rule_id < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $base_rule_id or $base_rule_id < 0
MC/DC50%1/2
not defined $base_rule_id or $base_rule_id < 0
not defined $base_rule_id
$base_rule_id < 0
Truth table66%2/3
not(A) or B
A= not defined $base_rule_idB= $base_rule_id < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 1471 | 6 | my $rule_description = rule_describe( $lhs_name, $rhs_names ); | |||||||||||||||||||||||||||||||||||||||||
| 1472 | 6 | my ( $error_code, $error_string ) = $grammar_c->error(); | |||||||||||||||||||||||||||||||||||||||||
| 1473 | 6 | ▶ | $error_code //= -1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$error_code //= -1
MC/DC0%0/1
$error_code //= -1
$error_code
Truth table50%1/2
A
A= $error_code
| |||||||||||||||||||||||||||||||||||||||||||
| 1474 | 6 | ▶ | my $problem_description = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1475 | $error_code == $Marpa::R2::Error::DUPLICATE_RULE | ||||||||||||||||||||||||||||||||||||||||||
| 1476 | ? 'Duplicate rule' | ||||||||||||||||||||||||||||||||||||||||||
| 1477 | : $error_string; | ||||||||||||||||||||||||||||||||||||||||||
| 1478 | 6 | Marpa::R2::exception("$problem_description: $rule_description"); | |||||||||||||||||||||||||||||||||||||||||
| 1479 | } ## end if ( not defined $base_rule_id or $base_rule_id < 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 1480 | |||||||||||||||||||||||||||||||||||||||||||
| 1481 | 35595 | my $base_rule = shadow_rule( $grammar, $base_rule_id ); | |||||||||||||||||||||||||||||||||||||||||
| 1482 | |||||||||||||||||||||||||||||||||||||||||||
| 1483 | 35595 | ▶ | if ($is_ordinary_rule) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||||||||||||||||
| 1485 | # Only internal grammars can set a custom mask | ||||||||||||||||||||||||||||||||||||||||||
| 1486 | 33620 | ▶ | if ( not defined $mask or not $grammar_is_internal ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $mask and $grammar_is_internal
MC/DC50%1/2
defined $mask and $grammar_is_internal
defined $mask
$grammar_is_internal
Truth table66%2/3
A and B
A= defined $maskB= $grammar_is_internal
| |||||||||||||||||||||||||||||||||||||||||||
| 1487 | 11550 | $mask = [ (1) x scalar @rhs_ids ]; | |||||||||||||||||||||||||||||||||||||||||
| 1488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1489 | 33620 | $base_rule->[Marpa::R2::Internal::Rule::MASK] = $mask; | |||||||||||||||||||||||||||||||||||||||||
| 1490 | } ## end if ($is_ordinary_rule) | ||||||||||||||||||||||||||||||||||||||||||
| 1491 | |||||||||||||||||||||||||||||||||||||||||||
| 1492 | 35595 | ▶ | $base_rule->[Marpa::R2::Internal::Rule::DISCARD_SEPARATION] = | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$separator_id >= 0 && !$keep_separation
MC/DC100%2/2
$separator_id >= 0 && !$keep_separation
$separator_id >= 0
!$keep_separation
Truth table100%3/3
A && not(B)
A= $separator_id >= 0B= !$keep_separation
| |||||||||||||||||||||||||||||||||||||||||||
| 1493 | $separator_id >= 0 && !$keep_separation; | ||||||||||||||||||||||||||||||||||||||||||
| 1494 | |||||||||||||||||||||||||||||||||||||||||||
| 1495 | 35595 | $base_rule->[Marpa::R2::Internal::Rule::ACTION_NAME] = $action; | |||||||||||||||||||||||||||||||||||||||||
| 1496 | 35595 | ▶ | $grammar_c->rule_null_high_set( $base_rule_id, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1497 | ( $null_ranking eq 'high' ? 1 : 0 ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 1498 | 35595 | $grammar_c->rule_rank_set( $base_rule_id, $rank ); | |||||||||||||||||||||||||||||||||||||||||
| 1499 | |||||||||||||||||||||||||||||||||||||||||||
| 1500 | 35595 | ▶ | if ( defined $rule_name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1501 | 11191 | $base_rule->[Marpa::R2::Internal::Rule::NAME] = $rule_name; | |||||||||||||||||||||||||||||||||||||||||
| 1502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1503 | 35595 | ▶ | if ( defined $slif_tag ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1504 | 13973 | $base_rule->[Marpa::R2::Internal::Rule::SLIF_TAG] = $slif_tag; | |||||||||||||||||||||||||||||||||||||||||
| 1505 | 13973 | my $rule_id_by_tag = | |||||||||||||||||||||||||||||||||||||||||
| 1506 | $grammar->[Marpa::R2::Internal::Grammar::RULE_ID_BY_TAG]; | ||||||||||||||||||||||||||||||||||||||||||
| 1507 | 13973 | ▶ | if ( $rule_id_by_tag->{$slif_tag} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1508 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 1509 | qq{Duplicate tag in SLIF rule, tag was "$slif_tag"}); | ||||||||||||||||||||||||||||||||||||||||||
| 1510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1511 | 13973 | $rule_id_by_tag->{$slif_tag} = $base_rule_id; | |||||||||||||||||||||||||||||||||||||||||
| 1512 | } ## end if ( defined $slif_tag ) | ||||||||||||||||||||||||||||||||||||||||||
| 1513 | 35595 | ▶ | if ( defined $blessing ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1514 | 9365 | $base_rule->[Marpa::R2::Internal::Rule::BLESSING] = $blessing; | |||||||||||||||||||||||||||||||||||||||||
| 1515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1516 | 35595 | ▶ | if ( defined $description ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1517 | 16868 | $base_rule->[Marpa::R2::Internal::Rule::DESCRIPTION] = $description; | |||||||||||||||||||||||||||||||||||||||||
| 1518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||||||||||||||||
| 1520 | 35595 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||||||||||||||||
| 1522 | } ## end sub add_user_rule | ||||||||||||||||||||||||||||||||||||||||||
| 1523 | |||||||||||||||||||||||||||||||||||||||||||
| 1524 | sub rule_describe { | ||||||||||||||||||||||||||||||||||||||||||
| 1525 | 6 | ▶ | my ( $lhs_name, $rhs_names ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rule_describe: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1526 | # wrap symbol names with whitespaces allowed by SLIF | ||||||||||||||||||||||||||||||||||||||||||
| 1527 | 6 | ▶ | $lhs_name = "<$lhs_name>" if $lhs_name =~ / /; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1528 | 6 | ▶ | return "$lhs_name -> " . ( join q{ }, map { / / ? "<$_>" : $_ } @{$rhs_names} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1529 | } ## end sub rule_describe | ||||||||||||||||||||||||||||||||||||||||||
| 1530 | |||||||||||||||||||||||||||||||||||||||||||
| 1531 | sub set_start_symbol { | ||||||||||||||||||||||||||||||||||||||||||
| 1532 | 662 | ▶ | my $grammar = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_start_symbol: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||
| 1533 | |||||||||||||||||||||||||||||||||||||||||||
| 1534 | 662 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1535 | 662 | state $default_start_name = '[:start]'; | |||||||||||||||||||||||||||||||||||||||||
| 1536 | 662 | my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER]; | |||||||||||||||||||||||||||||||||||||||||
| 1537 | 662 | my $default_start_id = $tracer->symbol_by_name($default_start_name); | |||||||||||||||||||||||||||||||||||||||||
| 1538 | 662 | my $start_id; | |||||||||||||||||||||||||||||||||||||||||
| 1539 | VALIDATE_START_NAME: { | ||||||||||||||||||||||||||||||||||||||||||
| 1540 | 662 | my $named_arg_start_name = | |||||||||||||||||||||||||||||||||||||||||
| 1541 | $grammar->[Marpa::R2::Internal::Grammar::START_NAME]; | ||||||||||||||||||||||||||||||||||||||||||
| 1542 | 662 | ▶ | if ( defined $named_arg_start_name and defined $start_id ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $named_arg_start_name and defined $start_id
MC/DC0%0/2
defined $named_arg_start_name and defined $start_id
defined $named_arg_start_name
defined $start_id
Truth table66%2/3
A and B
A= defined $named_arg_start_nameB= defined $start_id
| |||||||||||||||||||||||||||||||||||||||||||
| 1543 | 0 | Marpa::R2::exception( | |||||||||||||||||||||||||||||||||||||||||
| 1544 | qq{Start symbol specified as '[:start]', but also with named argument\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 1545 | qq{ You must use one or the other\n} | ||||||||||||||||||||||||||||||||||||||||||
| 1546 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1547 | } ## end if ( defined $named_arg_start_name and defined $start_id) | ||||||||||||||||||||||||||||||||||||||||||
| 1548 | 662 | ▶ | if ( defined $named_arg_start_name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1549 | 659 | $start_id = $tracer->symbol_by_name($named_arg_start_name); | |||||||||||||||||||||||||||||||||||||||||
| 1550 | 659 | ▶ | Marpa::R2::exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1551 | qq{Start symbol "$named_arg_start_name" not in grammar}) | ||||||||||||||||||||||||||||||||||||||||||
| 1552 | if not defined $start_id; | ||||||||||||||||||||||||||||||||||||||||||
| 1553 | 659 | last VALIDATE_START_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 1554 | } ## end if ( defined $named_arg_start_name ) | ||||||||||||||||||||||||||||||||||||||||||
| 1555 | 3 | ▶ | if ( defined $default_start_id ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1556 | 2 | $start_id = $default_start_id; | |||||||||||||||||||||||||||||||||||||||||
| 1557 | 2 | $grammar->[Marpa::R2::Internal::Grammar::START_NAME] = | |||||||||||||||||||||||||||||||||||||||||
| 1558 | $named_arg_start_name; | ||||||||||||||||||||||||||||||||||||||||||
| 1559 | 2 | last VALIDATE_START_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 1560 | } ## end if ( defined $default_start_id ) | ||||||||||||||||||||||||||||||||||||||||||
| 1561 | 1 | Marpa::R2::exception(qq{No start symbol specified in grammar\n}); | |||||||||||||||||||||||||||||||||||||||||
| 1562 | } ## end VALIDATE_START_NAME: | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | |||||||||||||||||||||||||||||||||||||||||||
| 1564 | 661 | ▶ | if ( not defined $grammar_c->start_symbol_set($start_id) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1565 | 0 | Marpa::R2::uncaught_error( $grammar_c->error() ); | |||||||||||||||||||||||||||||||||||||||||
| 1566 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1567 | 661 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1568 | } ## end sub set_start_symbol | ||||||||||||||||||||||||||||||||||||||||||
| 1569 | |||||||||||||||||||||||||||||||||||||||||||
| 1570 | sub Marpa::R2::Grammar::error { | ||||||||||||||||||||||||||||||||||||||||||
| 1571 | 0 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1572 | 0 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1573 | 0 | return $grammar_c->error(); | |||||||||||||||||||||||||||||||||||||||||
| 1574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1575 | |||||||||||||||||||||||||||||||||||||||||||
| 1576 | # INTERNAL OK AFTER HERE _marpa_ | ||||||||||||||||||||||||||||||||||||||||||
| 1577 | |||||||||||||||||||||||||||||||||||||||||||
| 1578 | sub Marpa::R2::Grammar::show_isy { | ||||||||||||||||||||||||||||||||||||||||||
| 1579 | 37 | ▶ | my ( $grammar, $isy_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_isy: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1580 | 37 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1581 | 37 | my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER]; | |||||||||||||||||||||||||||||||||||||||||
| 1582 | 37 | my $text = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 1583 | |||||||||||||||||||||||||||||||||||||||||||
| 1584 | 37 | my $name = $tracer->isy_name($isy_id); | |||||||||||||||||||||||||||||||||||||||||
| 1585 | 37 | $text .= "$isy_id: $name"; | |||||||||||||||||||||||||||||||||||||||||
| 1586 | |||||||||||||||||||||||||||||||||||||||||||
| 1587 | 37 | my @tag_list = (); | |||||||||||||||||||||||||||||||||||||||||
| 1588 | 37 | ▶ | $grammar_c->_marpa_g_nsy_is_nulling($isy_id) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1589 | and push @tag_list, 'nulling'; | ||||||||||||||||||||||||||||||||||||||||||
| 1590 | |||||||||||||||||||||||||||||||||||||||||||
| 1591 | 37 | ▶ | $text .= join q{ }, q{,}, @tag_list if scalar @tag_list; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1592 | 37 | $text .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1593 | |||||||||||||||||||||||||||||||||||||||||||
| 1594 | 37 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 1595 | |||||||||||||||||||||||||||||||||||||||||||
| 1596 | } ## end sub Marpa::R2::Grammar::show_isy | ||||||||||||||||||||||||||||||||||||||||||
| 1597 | |||||||||||||||||||||||||||||||||||||||||||
| 1598 | sub Marpa::R2::Grammar::show_isys { | ||||||||||||||||||||||||||||||||||||||||||
| 1599 | 3 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_isys: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1600 | 3 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1601 | 3 | my $text = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 1602 | 3 | for my $isy_id ( 0 .. $grammar_c->_marpa_g_nsy_count() - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 1603 | 37 | $text .= $grammar->show_isy($isy_id); | |||||||||||||||||||||||||||||||||||||||||
| 1604 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1605 | 3 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 1606 | } ## end sub Marpa::R2::Grammar::show_isys | ||||||||||||||||||||||||||||||||||||||||||
| 1607 | |||||||||||||||||||||||||||||||||||||||||||
| 1608 | sub Marpa::R2::Grammar::brief_irl { | ||||||||||||||||||||||||||||||||||||||||||
| 1609 | 58 | ▶ | my ( $grammar, $irl_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
brief_irl: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1610 | 58 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1611 | 58 | my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER]; | |||||||||||||||||||||||||||||||||||||||||
| 1612 | 58 | my $lhs_id = $grammar_c->_marpa_g_irl_lhs($irl_id); | |||||||||||||||||||||||||||||||||||||||||
| 1613 | 58 | my $text = $irl_id . ': ' . $tracer->isy_name($lhs_id) . ' ->'; | |||||||||||||||||||||||||||||||||||||||||
| 1614 | 58 | ▶ | if ( my $rh_length = $grammar_c->_marpa_g_irl_length($irl_id) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1615 | 58 | my @rhs_ids = (); | |||||||||||||||||||||||||||||||||||||||||
| 1616 | 58 | for my $ix ( 0 .. $rh_length - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 1617 | 139 | push @rhs_ids, $grammar_c->_marpa_g_irl_rhs( $irl_id, $ix ); | |||||||||||||||||||||||||||||||||||||||||
| 1618 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1619 | 58 | $text .= q{ } . ( join q{ }, map { $tracer->isy_name($_) } @rhs_ids ); | |||||||||||||||||||||||||||||||||||||||||
| 1620 | } ## end if ( my $rh_length = $grammar_c->_marpa_g_irl_length...) | ||||||||||||||||||||||||||||||||||||||||||
| 1621 | 58 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 1622 | } ## end sub Marpa::R2::Grammar::brief_irl | ||||||||||||||||||||||||||||||||||||||||||
| 1623 | |||||||||||||||||||||||||||||||||||||||||||
| 1624 | sub Marpa::R2::Grammar::show_irls { | ||||||||||||||||||||||||||||||||||||||||||
| 1625 | 3 | ▶ | my ($grammar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_irls: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1626 | 3 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1627 | 3 | my $text = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 1628 | 3 | for my $irl_id ( 0 .. $grammar_c->_marpa_g_irl_count() - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 1629 | 56 | $text .= $grammar->brief_irl($irl_id) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1630 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1631 | 3 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 1632 | } ## end sub Marpa::R2::Grammar::show_irls | ||||||||||||||||||||||||||||||||||||||||||
| 1633 | |||||||||||||||||||||||||||||||||||||||||||
| 1634 | sub Marpa::R2::Grammar::rule_is_used { | ||||||||||||||||||||||||||||||||||||||||||
| 1635 | 135 | ▶ | my ( $grammar, $rule_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rule_is_used: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1636 | 135 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||||||||||||||||||||||||
| 1637 | 135 | return $grammar_c->_marpa_g_rule_is_used($rule_id); | |||||||||||||||||||||||||||||||||||||||||
| 1638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1639 | |||||||||||||||||||||||||||||||||||||||||||
| 1640 | sub Marpa::R2::Grammar::show_ahms { | ||||||||||||||||||||||||||||||||||||||||||
| 1641 | 14 | ▶ | my ( $grammar, $verbose ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_ahms: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1642 | 14 | return $grammar->[Marpa::R2::Internal::Grammar::TRACER] | |||||||||||||||||||||||||||||||||||||||||
| 1643 | ->show_ahms($verbose); | ||||||||||||||||||||||||||||||||||||||||||
| 1644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1645 | |||||||||||||||||||||||||||||||||||||||||||
| 1646 | 150 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1647 | |||||||||||||||||||||||||||||||||||||||||||
| 1648 | # vim: expandtab shiftwidth=4: | ||||||||||||||||||||||||||||||||||||||||||