| 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::Scanless::G; | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 150 | ▶ | use 5.010001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 150 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 150 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 150 | ▶ | use vars qw($VERSION $STRING_VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 150 | $VERSION = '13.003_000'; | |||||||||||||||||||
| 24 | 150 | $STRING_VERSION = $VERSION; | |||||||||||||||||||
| 25 | ## no critic(BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||
| 26 | 150 | $VERSION = eval $VERSION; | |||||||||||||||||||
| 27 | ## use critic | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | package Marpa::R2::Internal::Scanless::G; | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 150 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 150 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | # names of packages for strings | ||||||||||||||||||||
| 35 | 150 | our $PACKAGE = 'Marpa::R2::Scanless::G'; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | sub Marpa::R2::Internal::Scanless::meta_grammar { | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 85 | ▶ | my $meta_slg = bless [], 'Marpa::R2::Scanless::G'; | ||||||||||||||||||
|
Subroutine
meta_grammar: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 40 | 85 | state $hashed_metag = Marpa::R2::Internal::MetaG::hashed_grammar(); | |||||||||||||||||||
| 41 | 85 | $meta_slg->[Marpa::R2::Internal::Scanless::G::TRACE_TERMINALS] = 0; | |||||||||||||||||||
| 42 | 85 | Marpa::R2::Internal::Scanless::G::hash_to_runtime( $meta_slg, | |||||||||||||||||||
| 43 | $hashed_metag, | ||||||||||||||||||||
| 44 | { bless_package => 'Marpa::R2::Internal::MetaAST_Nodes' } ); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 85 | my $thick_g1_grammar = | |||||||||||||||||||
| 47 | $meta_slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR]; | ||||||||||||||||||||
| 48 | 85 | my @mask_by_rule_id; | |||||||||||||||||||
| 49 | $mask_by_rule_id[$_] = $thick_g1_grammar->_rule_mask($_) | ||||||||||||||||||||
| 50 | 85 | for $thick_g1_grammar->rule_ids(); | |||||||||||||||||||
| 51 | 85 | $meta_slg->[Marpa::R2::Internal::Scanless::G::MASK_BY_RULE_ID] = | |||||||||||||||||||
| 52 | \@mask_by_rule_id; | ||||||||||||||||||||
| 53 | 85 | $meta_slg->[Marpa::R2::Internal::Scanless::G::TRACE_TERMINALS] = 0; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 85 | return $meta_slg; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | } ## end sub Marpa::R2::Internal::Scanless::meta_grammar | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub Marpa::R2::Scanless::G::new { | ||||||||||||||||||||
| 60 | 203 | ▶ | my ( $class, @hash_ref_args ) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 203 | my $slg = []; | |||||||||||||||||||
| 63 | 203 | bless $slg, $class; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 203 | my ($dsl, $g1_args) = Marpa::R2::Internal::Scanless::G::set ( $slg, 'new', @hash_ref_args ); | |||||||||||||||||||
| 66 | 203 | my $ast = Marpa::R2::Internal::MetaAST->new( $dsl ); | |||||||||||||||||||
| 67 | 200 | my $hashed_ast = $ast->ast_to_hash(); | |||||||||||||||||||
| 68 | 200 | Marpa::R2::Internal::Scanless::G::hash_to_runtime($slg, $hashed_ast, $g1_args); | |||||||||||||||||||
| 69 | 184 | return $slg; | |||||||||||||||||||
| 70 | } ## end sub Marpa::R2::Scanless::G::new | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | sub Marpa::R2::Scanless::G::set { | ||||||||||||||||||||
| 73 | 1 | ▶ | my ( $slg, @hash_ref_args ) = @_; | ||||||||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 74 | 1 | Marpa::R2::Internal::Scanless::G::set ( $slg, 'set', @hash_ref_args ); | |||||||||||||||||||
| 75 | 1 | return $slg; | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | # The context flag indicates whether this ::set() is called directly by the user; | ||||||||||||||||||||
| 79 | # is for the external constructor; or is for the internal ("meta") constructor. | ||||||||||||||||||||
| 80 | # "Context" flags of this kind | ||||||||||||||||||||
| 81 | # are much decried practice, and for good reason, but in this case | ||||||||||||||||||||
| 82 | # I think it is justified. | ||||||||||||||||||||
| 83 | # This logic really needs to be all in one place, and so a flag | ||||||||||||||||||||
| 84 | # to trigger the minor differences needed by the various calling | ||||||||||||||||||||
| 85 | # contexts is a small price to pay. | ||||||||||||||||||||
| 86 | sub Marpa::R2::Internal::Scanless::G::set { | ||||||||||||||||||||
| 87 | 204 | ▶ | my ( $slg, $method, @hash_ref_args ) = @_; | ||||||||||||||||||
|
Subroutine
set: called CC=23 SCAR=32.7
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | # Other possible grammar options: | ||||||||||||||||||||
| 90 | # default_rank | ||||||||||||||||||||
| 91 | # inaccessible_ok | ||||||||||||||||||||
| 92 | # unproductive_ok | ||||||||||||||||||||
| 93 | # warnings | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | state $copy_to_g1_args = | ||||||||||||||||||||
| 96 | 204 | { map { ( $_, 1 ); } | |||||||||||||||||||
| 97 | qw(trace_file_handle action_object default_action bless_package) }; | ||||||||||||||||||||
| 98 | state $set_method_args = | ||||||||||||||||||||
| 99 | 204 | { map { ( $_, 1 ); } qw(trace_file_handle trace_terminals) }; | |||||||||||||||||||
| 100 | state $new_method_args = { | ||||||||||||||||||||
| 101 | 204 | map { ( $_, 1 ); } qw(source trace_terminals), keys %{$copy_to_g1_args} | |||||||||||||||||||
| 102 | }; | ||||||||||||||||||||
| 103 | 204 | for my $args (@hash_ref_args) { | |||||||||||||||||||
| 104 | 204 | my $ref_type = ref $args; | |||||||||||||||||||
| 105 | 204 | ▶ | if ( not $ref_type ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 0 | Marpa::R2::exception( q{$slg->} | |||||||||||||||||||
| 107 | . $method | ||||||||||||||||||||
| 108 | . qq{() expects args as ref to HASH; got non-reference instead} | ||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||
| 110 | } ## end if ( not $ref_type ) | ||||||||||||||||||||
| 111 | 204 | ▶ | if ( $ref_type ne 'HASH' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | 0 | Marpa::R2::exception( q{$slg->} | |||||||||||||||||||
| 113 | . $method | ||||||||||||||||||||
| 114 | . qq{() expects args as ref to HASH, got ref to $ref_type instead} | ||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||
| 116 | } ## end if ( $ref_type ne 'HASH' ) | ||||||||||||||||||||
| 117 | } ## end for my $args (@hash_ref_args) | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 204 | my %flat_args = (); | |||||||||||||||||||
| 120 | 204 | for my $hash_ref (@hash_ref_args) { | |||||||||||||||||||
| 121 | 204 | ARG: for my $arg_name ( keys %{$hash_ref} ) { | |||||||||||||||||||
| 122 | 243 | $flat_args{$arg_name} = $hash_ref->{$arg_name}; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 204 | my $ok_args = $set_method_args; | |||||||||||||||||||
| 127 | 204 | ▶ | $ok_args = $new_method_args if $method eq 'new'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 128 | 204 | my @bad_args = grep { not $ok_args->{$_} } keys %flat_args; | |||||||||||||||||||
| 129 | 204 | ▶ | if ( scalar @bad_args ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 131 | q{Bad named argument(s) to $slg->} | ||||||||||||||||||||
| 132 | . $method | ||||||||||||||||||||
| 133 | . q{() method: } | ||||||||||||||||||||
| 134 | . join q{ }, | ||||||||||||||||||||
| 135 | @bad_args | ||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||
| 137 | } ## end if ( scalar @bad_args ) | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 204 | my $dsl; | |||||||||||||||||||
| 140 | 204 | ▶ | if ( $method eq 'new' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 141 | 203 | state $arg_name = 'source'; | |||||||||||||||||||
| 142 | 203 | $dsl = $flat_args{$arg_name}; | |||||||||||||||||||
| 143 | 203 | ▶ | Marpa::R2::exception( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 144 | qq{Marpa::R2::Scanless::G::new() called without a "$arg_name" argument} | ||||||||||||||||||||
| 145 | ) if not defined $dsl; | ||||||||||||||||||||
| 146 | 203 | my $ref_type = ref $dsl; | |||||||||||||||||||
| 147 | 203 | ▶ | if ( $ref_type ne 'SCALAR' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 148 | 0 | ▶ | my $desc = $ref_type ? "a ref to $ref_type" : 'not a ref'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 149 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 150 | qq{'$arg_name' name argument to Marpa::R2::Scanless::G->new() is $desc\n}, | ||||||||||||||||||||
| 151 | " It should be a ref to a string\n" | ||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||
| 153 | } ## end if ( $ref_type ne 'SCALAR' ) | ||||||||||||||||||||
| 154 | 203 | ▶ | if ( not defined ${$dsl} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 155 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 156 | qq{'$arg_name' name argument to Marpa::R2::Scanless::G->new() is a ref to a an undef\n}, | ||||||||||||||||||||
| 157 | " It should be a ref to a string\n" | ||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||
| 159 | } ## end if ( $ref_type ne 'SCALAR' ) | ||||||||||||||||||||
| 160 | } ## end if ( $method eq 'new' ) | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | # A bit hack-ish, but some named args will be copies straight to a member of | ||||||||||||||||||||
| 163 | # the Scanless::G class, so this maps named args to the index of the array | ||||||||||||||||||||
| 164 | # that holds the members. | ||||||||||||||||||||
| 165 | 204 | state $copy_arg_to_index = { | |||||||||||||||||||
| 166 | trace_file_handle => Marpa::R2::Internal::Scanless::G::TRACE_FILE_HANDLE, | ||||||||||||||||||||
| 167 | trace_terminals => Marpa::R2::Internal::Scanless::G::TRACE_TERMINALS | ||||||||||||||||||||
| 168 | }; | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 204 | ARG: for my $arg_name ( keys %flat_args ) { | |||||||||||||||||||
| 171 | 243 | my $index = $copy_arg_to_index->{$arg_name}; | |||||||||||||||||||
| 172 | 243 | ▶ | next ARG if not defined $index; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 173 | 1 | my $value = $flat_args{$arg_name}; | |||||||||||||||||||
| 174 | 1 | $slg->[$index] = $value; | |||||||||||||||||||
| 175 | } ## end ARG: for my $arg_name ( keys %flat_args ) | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | # Normalize trace_terminals | ||||||||||||||||||||
| 178 | 204 | ▶ | $slg->[Marpa::R2::Internal::Scanless::G::TRACE_TERMINALS] = 0 | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 179 | if not Scalar::Util::looks_like_number( | ||||||||||||||||||||
| 180 | $slg->[Marpa::R2::Internal::Scanless::G::TRACE_TERMINALS] ); | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | # Trace file handle needs to be populated downwards | ||||||||||||||||||||
| 183 | 204 | ▶ | if ( defined( my $trace_file_handle = $flat_args{trace_file_handle} ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 184 | GRAMMAR: | ||||||||||||||||||||
| 185 | 1 | for my $naif_grammar ( | |||||||||||||||||||
| 186 | $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR], | ||||||||||||||||||||
| 187 | 1 | @{ $slg->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS] } | |||||||||||||||||||
| 188 | ) | ||||||||||||||||||||
| 189 | { | ||||||||||||||||||||
| 190 | 2 | ▶ | next GRAMMAR if not defined $naif_grammar; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 191 | 2 | $naif_grammar->set( { trace_file_handle => $trace_file_handle } ); | |||||||||||||||||||
| 192 | } ## end GRAMMAR: for my $naif_grammar ( $slg->[...]) | ||||||||||||||||||||
| 193 | } ## end if ( defined( my $trace_file_handle = $flat_args{...})) | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | 204 | ▶ | if ( $method eq 'new' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | # Prune flat args of all those named args which are NOT to be copied | ||||||||||||||||||||
| 198 | # into the NAIF recce args | ||||||||||||||||||||
| 199 | 203 | for my $arg_name ( keys %flat_args ) { | |||||||||||||||||||
| 200 | delete $flat_args{$arg_name} | ||||||||||||||||||||
| 201 | 242 | ▶ | if not $copy_to_g1_args->{$arg_name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 202 | } | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | # trace file handle must always be defined | ||||||||||||||||||||
| 205 | 203 | ▶ | $slg->[Marpa::R2::Internal::Scanless::G::TRACE_FILE_HANDLE] //= \*STDERR; | ||||||||||||||||||
|
Condition50%1/2
$slg->[13] //= \*STDERR
MC/DC0%0/1
$slg->[13] //= \*STDERR
$slg->[13]
Truth table50%1/2
A
A= $slg->[13]
| |||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | 203 | return ($dsl, \%flat_args); | |||||||||||||||||||
| 208 | } ## end if ( $method eq 'new' ) | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 1 | return; | |||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | } ## end sub Marpa::R2::Internal::Scanless::G::set | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | sub Marpa::R2::Internal::Scanless::G::hash_to_runtime { | ||||||||||||||||||||
| 215 | 285 | ▶ | my ( $slg, $hashed_source, $g1_args ) = @_; | ||||||||||||||||||
|
Subroutine
hash_to_runtime: called CC=90 SCAR=46.5
| |||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | 285 | my $trace_terminals = | |||||||||||||||||||
| 218 | $slg->[Marpa::R2::Internal::Scanless::G::TRACE_TERMINALS]; | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | # Pre-lexer G1 processing | ||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | my $start_lhs = $hashed_source->{'start_lhs'} | ||||||||||||||||||||
| 223 | 285 | ▶ | // $hashed_source->{'first_lhs'}; | ||||||||||||||||||
|
Condition66%2/3
$hashed_source->{"start_lhs"} // $hashed_source->{"first_lhs"}
MC/DC0%0/2
$hashed_source->{"start_lhs"} // $hashed_source->{"first_lhs"}
$hashed_source->{"start_lhs"}
$hashed_source->{"first_lhs"}
Truth table66%2/3
A // B
A= $hashed_source->{"start_lhs"}B= $hashed_source->{"first_lhs"}
| |||||||||||||||||||||
| 224 | 285 | ▶ | Marpa::R2::exception('No rules in SLIF grammar') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 225 | if not defined $start_lhs; | ||||||||||||||||||||
| 226 | 285 | Marpa::R2::Internal::MetaAST::start_rule_create( $hashed_source, | |||||||||||||||||||
| 227 | $start_lhs ); | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | 285 | $slg->[Marpa::R2::Internal::Scanless::G::CACHE_RULEIDS_BY_LHS_NAME] = {}; | |||||||||||||||||||
| 230 | $slg->[Marpa::R2::Internal::Scanless::G::DEFAULT_G1_START_ACTION] = | ||||||||||||||||||||
| 231 | 285 | $hashed_source->{'default_g1_start_action'}; | |||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | my $trace_fh = | ||||||||||||||||||||
| 234 | $slg->[Marpa::R2::Internal::Scanless::G::TRACE_FILE_HANDLE] = | ||||||||||||||||||||
| 235 | 285 | ▶ | $g1_args->{trace_file_handle} // \*STDERR; | ||||||||||||||||||
|
Condition50%1/2
$g1_args->{"trace_file_handle"} // \*STDERR
MC/DC0%0/1
$g1_args->{"trace_file_handle"} // \*STDERR
$g1_args->{"trace_file_handle"}
Truth table50%1/2
A
A= $g1_args->{"trace_file_handle"}
| |||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | my $if_inaccessible_default = | ||||||||||||||||||||
| 238 | 285 | ▶ | $hashed_source->{defaults}->{if_inaccessible} // 'warn'; | ||||||||||||||||||
|
Condition100%2/2
$hashed_source->{"defaults"}{"if_inaccessible"} // "warn"
MC/DC100%1/1
$hashed_source->{"defaults"}{"if_inaccessible"} // "warn"
$hashed_source->{"defaults"}{"if_inaccessible"}
Truth table100%2/2
A
A= $hashed_source->{"defaults"}{"if_inaccessible"}
| |||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | # Prepare the arguments for the G1 grammar | ||||||||||||||||||||
| 241 | 285 | $g1_args->{rules} = $hashed_source->{rules}->{G1}; | |||||||||||||||||||
| 242 | 285 | $g1_args->{symbols} = $hashed_source->{symbols}->{G1}; | |||||||||||||||||||
| 243 | 285 | state $g1_target_symbol = '[:start]'; | |||||||||||||||||||
| 244 | 285 | $g1_args->{start} = $g1_target_symbol; | |||||||||||||||||||
| 245 | 285 | $g1_args->{'_internal_'} = | |||||||||||||||||||
| 246 | { 'if_inaccessible' => $if_inaccessible_default }; | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | 285 | my $thick_g1_grammar = Marpa::R2::Grammar->new($g1_args); | |||||||||||||||||||
| 249 | 281 | my $g1_tracer = $thick_g1_grammar->tracer(); | |||||||||||||||||||
| 250 | 281 | my $g1_thin = $g1_tracer->grammar(); | |||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | 281 | my $symbol_ids_by_event_name_and_type = {}; | |||||||||||||||||||
| 253 | 281 | $slg->[ | |||||||||||||||||||
| 254 | Marpa::R2::Internal::Scanless::G::SYMBOL_IDS_BY_EVENT_NAME_AND_TYPE] | ||||||||||||||||||||
| 255 | = $symbol_ids_by_event_name_and_type; | ||||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | 281 | my $completion_events_by_name = $hashed_source->{completion_events}; | |||||||||||||||||||
| 258 | 281 | my $completion_events_by_id = | |||||||||||||||||||
| 259 | $slg->[Marpa::R2::Internal::Scanless::G::COMPLETION_EVENT_BY_ID] = []; | ||||||||||||||||||||
| 260 | 281 | for my $symbol_name ( keys %{$completion_events_by_name} ) { | |||||||||||||||||||
| 261 | my ( $event_name, $is_active ) = | ||||||||||||||||||||
| 262 | 54 | @{ $completion_events_by_name->{$symbol_name} }; | |||||||||||||||||||
| 263 | 54 | my $symbol_id = $g1_tracer->symbol_by_name($symbol_name); | |||||||||||||||||||
| 264 | 54 | ▶ | if ( not defined $symbol_id ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 265 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 266 | "Completion event defined for non-existent symbol: $symbol_name\n" | ||||||||||||||||||||
| 267 | ); | ||||||||||||||||||||
| 268 | } | ||||||||||||||||||||
| 269 | |||||||||||||||||||||
| 270 | # Must be done before precomputation | ||||||||||||||||||||
| 271 | 54 | $g1_thin->symbol_is_completion_event_set( $symbol_id, 1 ); | |||||||||||||||||||
| 272 | 54 | ▶ | $g1_thin->completion_symbol_activate( $symbol_id, 0 ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 273 | if not $is_active; | ||||||||||||||||||||
| 274 | 54 | $slg->[Marpa::R2::Internal::Scanless::G::COMPLETION_EVENT_BY_ID] | |||||||||||||||||||
| 275 | ->[$symbol_id] = $event_name; | ||||||||||||||||||||
| 276 | push | ||||||||||||||||||||
| 277 | 54 | @{ $symbol_ids_by_event_name_and_type->{$event_name}->{completion} | |||||||||||||||||||
| 278 | 54 | }, $symbol_id; | |||||||||||||||||||
| 279 | } ## end for my $symbol_name ( keys %{$completion_events_by_name...}) | ||||||||||||||||||||
| 280 | |||||||||||||||||||||
| 281 | 281 | my $nulled_events_by_name = $hashed_source->{nulled_events}; | |||||||||||||||||||
| 282 | 281 | my $nulled_events_by_id = | |||||||||||||||||||
| 283 | $slg->[Marpa::R2::Internal::Scanless::G::NULLED_EVENT_BY_ID] = []; | ||||||||||||||||||||
| 284 | 281 | for my $symbol_name ( keys %{$nulled_events_by_name} ) { | |||||||||||||||||||
| 285 | my ( $event_name, $is_active ) = | ||||||||||||||||||||
| 286 | 46 | @{ $nulled_events_by_name->{$symbol_name} }; | |||||||||||||||||||
| 287 | 46 | my $symbol_id = $g1_tracer->symbol_by_name($symbol_name); | |||||||||||||||||||
| 288 | 46 | ▶ | if ( not defined $symbol_id ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 289 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 290 | "nulled event defined for non-existent symbol: $symbol_name\n" | ||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||
| 292 | } | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | # Must be done before precomputation | ||||||||||||||||||||
| 295 | 46 | $g1_thin->symbol_is_nulled_event_set( $symbol_id, 1 ); | |||||||||||||||||||
| 296 | 46 | ▶ | $g1_thin->nulled_symbol_activate( $symbol_id, 0 ) if not $is_active; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 297 | 46 | $slg->[Marpa::R2::Internal::Scanless::G::NULLED_EVENT_BY_ID] | |||||||||||||||||||
| 298 | ->[$symbol_id] = $event_name; | ||||||||||||||||||||
| 299 | 46 | push @{ $symbol_ids_by_event_name_and_type->{$event_name}->{nulled} }, | |||||||||||||||||||
| 300 | $symbol_id; | ||||||||||||||||||||
| 301 | } ## end for my $symbol_name ( keys %{$nulled_events_by_name} ) | ||||||||||||||||||||
| 302 | |||||||||||||||||||||
| 303 | 281 | my $prediction_events_by_name = $hashed_source->{prediction_events}; | |||||||||||||||||||
| 304 | 281 | my $prediction_events_by_id = | |||||||||||||||||||
| 305 | $slg->[Marpa::R2::Internal::Scanless::G::PREDICTION_EVENT_BY_ID] = []; | ||||||||||||||||||||
| 306 | 281 | for my $symbol_name ( keys %{$prediction_events_by_name} ) { | |||||||||||||||||||
| 307 | my ( $event_name, $is_active ) = | ||||||||||||||||||||
| 308 | 52 | @{ $prediction_events_by_name->{$symbol_name} }; | |||||||||||||||||||
| 309 | 52 | my $symbol_id = $g1_tracer->symbol_by_name($symbol_name); | |||||||||||||||||||
| 310 | 52 | ▶ | if ( not defined $symbol_id ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 311 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 312 | "prediction event defined for non-existent symbol: $symbol_name\n" | ||||||||||||||||||||
| 313 | ); | ||||||||||||||||||||
| 314 | } | ||||||||||||||||||||
| 315 | |||||||||||||||||||||
| 316 | # Must be done before precomputation | ||||||||||||||||||||
| 317 | 52 | $g1_thin->symbol_is_prediction_event_set( $symbol_id, 1 ); | |||||||||||||||||||
| 318 | 52 | ▶ | $g1_thin->prediction_symbol_activate( $symbol_id, 0 ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 319 | if not $is_active; | ||||||||||||||||||||
| 320 | 52 | $slg->[Marpa::R2::Internal::Scanless::G::PREDICTION_EVENT_BY_ID] | |||||||||||||||||||
| 321 | ->[$symbol_id] = $event_name; | ||||||||||||||||||||
| 322 | push | ||||||||||||||||||||
| 323 | 52 | @{ $symbol_ids_by_event_name_and_type->{$event_name}->{prediction} | |||||||||||||||||||
| 324 | 52 | }, $symbol_id; | |||||||||||||||||||
| 325 | } ## end for my $symbol_name ( keys %{$prediction_events_by_name...}) | ||||||||||||||||||||
| 326 | |||||||||||||||||||||
| 327 | 281 | my $lexeme_events_by_id = | |||||||||||||||||||
| 328 | $slg->[Marpa::R2::Internal::Scanless::G::LEXEME_EVENT_BY_ID] = []; | ||||||||||||||||||||
| 329 | |||||||||||||||||||||
| 330 | 281 | ▶ | if (defined( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 331 | my $precompute_error = | ||||||||||||||||||||
| 332 | Marpa::R2::Internal::Grammar::slif_precompute( | ||||||||||||||||||||
| 333 | $thick_g1_grammar) | ||||||||||||||||||||
| 334 | ) | ||||||||||||||||||||
| 335 | ) | ||||||||||||||||||||
| 336 | { | ||||||||||||||||||||
| 337 | 1 | ▶ | if ( $precompute_error == $Marpa::R2::Error::UNPRODUCTIVE_START ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 338 | |||||||||||||||||||||
| 339 | # Maybe someday improve this by finding the start rule and showing | ||||||||||||||||||||
| 340 | # its RHS -- for now it is clear enough | ||||||||||||||||||||
| 341 | 1 | Marpa::R2::exception(qq{Unproductive start symbol}); | |||||||||||||||||||
| 342 | } ## end if ( $precompute_error == ...) | ||||||||||||||||||||
| 343 | Marpa::R2::exception( | ||||||||||||||||||||
| 344 | 0 | 'Internal errror: unnkown precompute error code ', | |||||||||||||||||||
| 345 | $precompute_error ); | ||||||||||||||||||||
| 346 | } ## end if ( defined( my $precompute_error = ...)) | ||||||||||||||||||||
| 347 | |||||||||||||||||||||
| 348 | # Find out the list of lexemes according to G1 | ||||||||||||||||||||
| 349 | 277 | my %g1_id_by_lexeme_name = (); | |||||||||||||||||||
| 350 | 277 | SYMBOL: for my $symbol_id ( 0 .. $g1_thin->highest_symbol_id() ) { | |||||||||||||||||||
| 351 | |||||||||||||||||||||
| 352 | # Not a lexeme, according to G1 | ||||||||||||||||||||
| 353 | 14861 | ▶ | next SYMBOL if not $g1_thin->symbol_is_terminal($symbol_id); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 354 | |||||||||||||||||||||
| 355 | 8979 | my $symbol_name = $g1_tracer->symbol_name($symbol_id); | |||||||||||||||||||
| 356 | 8979 | $g1_id_by_lexeme_name{$symbol_name} = $symbol_id; | |||||||||||||||||||
| 357 | |||||||||||||||||||||
| 358 | } ## end SYMBOL: for my $symbol_id ( 0 .. $g1_thin->highest_symbol_id(...)) | ||||||||||||||||||||
| 359 | |||||||||||||||||||||
| 360 | # A first phase of applying defaults | ||||||||||||||||||||
| 361 | 277 | my $discard_default_adverbs = $hashed_source->{discard_default_adverbs}; | |||||||||||||||||||
| 362 | 277 | my $lexeme_declarations = $hashed_source->{lexeme_declarations}; | |||||||||||||||||||
| 363 | 277 | my $lexeme_default_adverbs = $hashed_source->{lexeme_default_adverbs}; | |||||||||||||||||||
| 364 | 277 | ▶ | my $latm_default_value = $lexeme_default_adverbs->{latm} // 0; | ||||||||||||||||||
|
Condition100%2/2
$lexeme_default_adverbs->{"latm"} // 0
MC/DC100%1/1
$lexeme_default_adverbs->{"latm"} // 0
$lexeme_default_adverbs->{"latm"}
Truth table100%2/2
A
A= $lexeme_default_adverbs->{"latm"}
| |||||||||||||||||||||
| 365 | |||||||||||||||||||||
| 366 | # Current lexeme data is spread out in many places. | ||||||||||||||||||||
| 367 | # Change so that it all resides in this hash, indexed by | ||||||||||||||||||||
| 368 | # name | ||||||||||||||||||||
| 369 | 277 | my %lexeme_data = (); | |||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | # Determine "latm" status | ||||||||||||||||||||
| 372 | 277 | LEXEME: for my $lexeme_name ( keys %g1_id_by_lexeme_name ) { | |||||||||||||||||||
| 373 | 8979 | my $declarations = $lexeme_declarations->{$lexeme_name}; | |||||||||||||||||||
| 374 | 8979 | ▶ | my $latm_value = $declarations->{latm} // $latm_default_value; | ||||||||||||||||||
|
Condition100%3/3
$declarations->{"latm"} // $latm_default_value
MC/DC100%2/2
$declarations->{"latm"} // $latm_default_value
$declarations->{"latm"}
$latm_default_value
Truth table100%3/3
A // B
A= $declarations->{"latm"}B= $latm_default_value
| |||||||||||||||||||||
| 375 | 8979 | $lexeme_data{$lexeme_name}{latm} = $latm_value; | |||||||||||||||||||
| 376 | } | ||||||||||||||||||||
| 377 | |||||||||||||||||||||
| 378 | # Lexers | ||||||||||||||||||||
| 379 | |||||||||||||||||||||
| 380 | 277 | my $lexer_id = 0; | |||||||||||||||||||
| 381 | 277 | my $lexer_name = 'L0'; | |||||||||||||||||||
| 382 | |||||||||||||||||||||
| 383 | 277 | my %lexer_id_by_name = (); | |||||||||||||||||||
| 384 | 277 | my %thick_grammar_by_lexer_name = (); | |||||||||||||||||||
| 385 | 277 | my @discard_event_by_lexer_rule_id = (); | |||||||||||||||||||
| 386 | 277 | my %lexer_and_rule_to_g1_lexeme = (); | |||||||||||||||||||
| 387 | 277 | my %character_class_table_by_lexer_name = (); | |||||||||||||||||||
| 388 | 277 | state $lex_start_symbol_name = '[:start_lex]'; | |||||||||||||||||||
| 389 | 277 | state $discard_symbol_name = '[:discard]'; | |||||||||||||||||||
| 390 | |||||||||||||||||||||
| 391 | 277 | my $lexer_rules = $hashed_source->{rules}->{$lexer_name}; | |||||||||||||||||||
| 392 | 277 | my $character_class_hash = $hashed_source->{character_classes}; | |||||||||||||||||||
| 393 | 277 | my $lexer_symbols = $hashed_source->{symbols}->{'L'}; | |||||||||||||||||||
| 394 | |||||||||||||||||||||
| 395 | # If no lexer rules, fake a lexer | ||||||||||||||||||||
| 396 | # Fake a lexer -- it discards symbols in character classes which | ||||||||||||||||||||
| 397 | # never matches | ||||||||||||||||||||
| 398 | 277 | ▶ | if ( not $lexer_rules ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 399 | 2 | $character_class_hash = { '[[^\\d\\D]]' => [ '[^\\d\\D]', '' ] }; | |||||||||||||||||||
| 400 | 2 | $lexer_rules = [ | |||||||||||||||||||
| 401 | { 'rhs' => [ '[[^\\d\\D]]' ], | ||||||||||||||||||||
| 402 | 'lhs' => '[:discard]', | ||||||||||||||||||||
| 403 | 'symbol_as_event' => '[^\\d\\D]', | ||||||||||||||||||||
| 404 | 'description' => 'Discard rule for <[[^\\d\\D]]>' | ||||||||||||||||||||
| 405 | }, | ||||||||||||||||||||
| 406 | ]; | ||||||||||||||||||||
| 407 | 2 | $lexer_symbols = { | |||||||||||||||||||
| 408 | '[:discard]' => { | ||||||||||||||||||||
| 409 | 'display_form' => ':discard', | ||||||||||||||||||||
| 410 | 'description' => 'Internal LHS for lexer "L0" discard' | ||||||||||||||||||||
| 411 | }, | ||||||||||||||||||||
| 412 | '[[^\\d\\D]]' => { | ||||||||||||||||||||
| 413 | 'dsl_form' => '[^\\d\\D]', | ||||||||||||||||||||
| 414 | 'display_form' => '[^\\d\\D]', | ||||||||||||||||||||
| 415 | 'description' => 'Character class: [^\\d\\D]' | ||||||||||||||||||||
| 416 | } | ||||||||||||||||||||
| 417 | }; | ||||||||||||||||||||
| 418 | } ## end if ( not $lexer_rules ) | ||||||||||||||||||||
| 419 | |||||||||||||||||||||
| 420 | 277 | my %lex_lhs = (); | |||||||||||||||||||
| 421 | 277 | my %lex_rhs = (); | |||||||||||||||||||
| 422 | 277 | my %lex_separator = (); | |||||||||||||||||||
| 423 | 277 | my %lexer_rule_by_tag = (); | |||||||||||||||||||
| 424 | |||||||||||||||||||||
| 425 | 277 | my $rule_tag = 'rule0'; | |||||||||||||||||||
| 426 | 277 | for my $lex_rule ( @{$lexer_rules} ) { | |||||||||||||||||||
| 427 | 13973 | $lex_rule->{tag} = ++$rule_tag; | |||||||||||||||||||
| 428 | 13973 | my %lex_rule_copy = %{$lex_rule}; | |||||||||||||||||||
| 429 | 13973 | $lexer_rule_by_tag{$rule_tag} = \%lex_rule_copy; | |||||||||||||||||||
| 430 | 13973 | delete $lex_rule->{event}; | |||||||||||||||||||
| 431 | 13973 | delete $lex_rule->{symbol_as_event}; | |||||||||||||||||||
| 432 | 13973 | $lex_lhs{ $lex_rule->{lhs} } = 1; | |||||||||||||||||||
| 433 | 13973 | $lex_rhs{$_} = 1 for @{ $lex_rule->{rhs} }; | |||||||||||||||||||
| 434 | 13973 | ▶ | if ( defined( my $separator = $lex_rule->{separator} ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 435 | 170 | $lex_separator{$separator} = 1; | |||||||||||||||||||
| 436 | } | ||||||||||||||||||||
| 437 | } ## end for my $lex_rule ( @{$lexer_rules} ) | ||||||||||||||||||||
| 438 | |||||||||||||||||||||
| 439 | 277 | my %this_lexer_symbols = (); | |||||||||||||||||||
| 440 | SYMBOL: | ||||||||||||||||||||
| 441 | 277 | for my $symbol_name ( ( keys %lex_lhs ), ( keys %lex_rhs ), | |||||||||||||||||||
| 442 | ( keys %lex_separator ) ) | ||||||||||||||||||||
| 443 | { | ||||||||||||||||||||
| 444 | 20754 | my $symbol_data = $lexer_symbols->{$symbol_name}; | |||||||||||||||||||
| 445 | 20754 | ▶ | $this_lexer_symbols{$symbol_name} = $symbol_data | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 446 | if defined $symbol_data; | ||||||||||||||||||||
| 447 | } ## end SYMBOL: for my $symbol_name ( ( keys %lex_lhs ), ( keys %lex_rhs...)) | ||||||||||||||||||||
| 448 | |||||||||||||||||||||
| 449 | 9176 | my %is_lexeme_in_this_lexer = map { $_ => 1 } | |||||||||||||||||||
| 450 | 277 | ▶ | grep { not $lex_rhs{$_} and not $lex_separator{$_} } | ||||||||||||||||||
|
Condition100%3/3
$lex_rhs{$_} || $lex_separator{$_}
MC/DC100%2/2
$lex_rhs{$_} || $lex_separator{$_}
$lex_rhs{$_}
$lex_separator{$_}
Truth table100%3/3
A || B
A= $lex_rhs{$_}B= $lex_separator{$_}
| |||||||||||||||||||||
| 451 | keys %lex_lhs; | ||||||||||||||||||||
| 452 | |||||||||||||||||||||
| 453 | 277 | my @lex_lexeme_names = keys %is_lexeme_in_this_lexer; | |||||||||||||||||||
| 454 | |||||||||||||||||||||
| 455 | 277 | ▶ | Marpa::R2::exception( "No lexemes in lexer: $lexer_name\n", | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 456 | " An SLIF grammar must have at least one lexeme\n" ) | ||||||||||||||||||||
| 457 | if not scalar @lex_lexeme_names; | ||||||||||||||||||||
| 458 | |||||||||||||||||||||
| 459 | # Do I need this? | ||||||||||||||||||||
| 460 | my @unproductive = | ||||||||||||||||||||
| 461 | 0 | map {"<$_>"} | |||||||||||||||||||
| 462 | 277 | ▶ | grep { not $lex_lhs{$_} and not $_ =~ /\A \[\[ /xms } | ||||||||||||||||||
|
Condition66%2/3
$lex_lhs{$_} || $_ =~ /\A \[\[ /msx
MC/DC0%0/2
$lex_lhs{$_} || $_ =~ /\A \[\[ /msx
$lex_lhs{$_}
$_ =~ /\A \[\[ /msx
Truth table66%2/3
A || B
A= $lex_lhs{$_}B= $_ =~ /\A \[\[ /msx
| |||||||||||||||||||||
| 463 | ( keys %lex_rhs, keys %lex_separator ); | ||||||||||||||||||||
| 464 | 277 | ▶ | if (@unproductive) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 465 | 0 | Marpa::R2::exception( 'Unproductive lexical symbols: ', | |||||||||||||||||||
| 466 | join q{ }, @unproductive ); | ||||||||||||||||||||
| 467 | } | ||||||||||||||||||||
| 468 | |||||||||||||||||||||
| 469 | $this_lexer_symbols{$lex_start_symbol_name}->{display_form} = | ||||||||||||||||||||
| 470 | 277 | ':start_lex'; | |||||||||||||||||||
| 471 | $this_lexer_symbols{$lex_start_symbol_name}->{description} = | ||||||||||||||||||||
| 472 | 277 | 'Internal L0 (lexical) start symbol'; | |||||||||||||||||||
| 473 | 277 | push @{$lexer_rules}, map { | |||||||||||||||||||
| 474 | 277 | ; | |||||||||||||||||||
| 475 | 9176 | { description => "Internal lexical start rule for <$_>", | |||||||||||||||||||
| 476 | lhs => $lex_start_symbol_name, | ||||||||||||||||||||
| 477 | rhs => [$_] | ||||||||||||||||||||
| 478 | } | ||||||||||||||||||||
| 479 | } sort keys %is_lexeme_in_this_lexer; | ||||||||||||||||||||
| 480 | |||||||||||||||||||||
| 481 | # Prepare the arguments for the lex grammar | ||||||||||||||||||||
| 482 | 277 | my %lex_args = (); | |||||||||||||||||||
| 483 | 277 | $lex_args{trace_file_handle} = $trace_fh; | |||||||||||||||||||
| 484 | 277 | $lex_args{start} = $lex_start_symbol_name; | |||||||||||||||||||
| 485 | 277 | $lex_args{'_internal_'} = | |||||||||||||||||||
| 486 | { 'if_inaccessible' => $if_inaccessible_default }; | ||||||||||||||||||||
| 487 | 277 | $lex_args{rules} = $lexer_rules; | |||||||||||||||||||
| 488 | 277 | $lex_args{symbols} = \%this_lexer_symbols; | |||||||||||||||||||
| 489 | |||||||||||||||||||||
| 490 | # Create the thick lex grammar | ||||||||||||||||||||
| 491 | 277 | my $lex_grammar = Marpa::R2::Grammar->new( \%lex_args ); | |||||||||||||||||||
| 492 | 277 | $thick_grammar_by_lexer_name{$lexer_name} = $lex_grammar; | |||||||||||||||||||
| 493 | 277 | my $lex_tracer = $lex_grammar->tracer(); | |||||||||||||||||||
| 494 | 277 | my $lex_thin = $lex_tracer->grammar(); | |||||||||||||||||||
| 495 | |||||||||||||||||||||
| 496 | 277 | ▶ | my $lex_discard_symbol_id = | ||||||||||||||||||
|
Condition100%2/2
$lex_tracer->symbol_by_name($discard_symbol_name) // -1
MC/DC100%1/1
$lex_tracer->symbol_by_name($discard_symbol_name) // -1
$lex_tracer->symbol_by_name($discard_symbol_name)
Truth table100%2/2
A
A= $lex_tracer->symbol_by_name($discard_symbol_name)
| |||||||||||||||||||||
| 497 | $lex_tracer->symbol_by_name($discard_symbol_name) // -1; | ||||||||||||||||||||
| 498 | 277 | my @lex_lexeme_to_g1_symbol; | |||||||||||||||||||
| 499 | 277 | $lex_lexeme_to_g1_symbol[$_] = -1 for 0 .. $g1_thin->highest_symbol_id(); | |||||||||||||||||||
| 500 | |||||||||||||||||||||
| 501 | 277 | LEXEME_NAME: for my $lexeme_name (@lex_lexeme_names) { | |||||||||||||||||||
| 502 | 9175 | ▶ | next LEXEME_NAME if $lexeme_name eq $discard_symbol_name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 503 | 8978 | ▶ | next LEXEME_NAME if $lexeme_name eq $lex_start_symbol_name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 504 | 8978 | my $g1_symbol_id = $g1_id_by_lexeme_name{$lexeme_name}; | |||||||||||||||||||
| 505 | 8978 | ▶ | if ( not defined $g1_symbol_id ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 506 | 4 | Marpa::R2::exception( | |||||||||||||||||||
| 507 | qq{<$lexeme_name> is a lexeme but it is not a legal lexeme in G1:\n}, | ||||||||||||||||||||
| 508 | qq{ Lexemes must be G1 symbols that do not appear on a G1 LHS.\n} | ||||||||||||||||||||
| 509 | ); | ||||||||||||||||||||
| 510 | } | ||||||||||||||||||||
| 511 | 8974 | ▶ | if ( not $g1_thin->symbol_is_accessible($g1_symbol_id) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 512 | 2 | my $message = | |||||||||||||||||||
| 513 | "A lexeme in lexer $lexer_name is not accessible from the G1 start symbol: $lexeme_name"; | ||||||||||||||||||||
| 514 | 2 | ▶ | say {$trace_fh} $message | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 515 | if $if_inaccessible_default eq 'warn'; | ||||||||||||||||||||
| 516 | 2 | ▶ | Marpa::R2::exception($message) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 517 | if $if_inaccessible_default eq 'fatal'; | ||||||||||||||||||||
| 518 | } ## end if ( not $g1_thin->symbol_is_accessible($g1_symbol_id...)) | ||||||||||||||||||||
| 519 | 8974 | my $lex_symbol_id = $lex_tracer->symbol_by_name($lexeme_name); | |||||||||||||||||||
| 520 | 8974 | $lexeme_data{$lexeme_name}{lexers}{$lexer_name}{'id'} = | |||||||||||||||||||
| 521 | $lex_symbol_id; | ||||||||||||||||||||
| 522 | 8974 | $lex_lexeme_to_g1_symbol[$lex_symbol_id] = $g1_symbol_id; | |||||||||||||||||||
| 523 | } ## end LEXEME_NAME: for my $lexeme_name (@lex_lexeme_names) | ||||||||||||||||||||
| 524 | |||||||||||||||||||||
| 525 | 273 | my @lex_rule_to_g1_lexeme; | |||||||||||||||||||
| 526 | 273 | my $lex_start_symbol_id = | |||||||||||||||||||
| 527 | $lex_tracer->symbol_by_name($lex_start_symbol_name); | ||||||||||||||||||||
| 528 | 273 | RULE_ID: for my $rule_id ( 0 .. $lex_thin->highest_rule_id() ) { | |||||||||||||||||||
| 529 | 23137 | my $lhs_id = $lex_thin->rule_lhs($rule_id); | |||||||||||||||||||
| 530 | 23137 | ▶ | if ( $lhs_id == $lex_discard_symbol_id ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 531 | 321 | $lex_rule_to_g1_lexeme[$rule_id] = -2; | |||||||||||||||||||
| 532 | 321 | next RULE_ID; | |||||||||||||||||||
| 533 | } | ||||||||||||||||||||
| 534 | 22816 | ▶ | if ( $lhs_id != $lex_start_symbol_id ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 535 | 13646 | $lex_rule_to_g1_lexeme[$rule_id] = -1; | |||||||||||||||||||
| 536 | 13646 | next RULE_ID; | |||||||||||||||||||
| 537 | } | ||||||||||||||||||||
| 538 | 9170 | my $lexer_lexeme_id = $lex_thin->rule_rhs( $rule_id, 0 ); | |||||||||||||||||||
| 539 | 9170 | ▶ | if ( $lexer_lexeme_id == $lex_discard_symbol_id ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 540 | 197 | $lex_rule_to_g1_lexeme[$rule_id] = -1; | |||||||||||||||||||
| 541 | 197 | next RULE_ID; | |||||||||||||||||||
| 542 | } | ||||||||||||||||||||
| 543 | 8973 | ▶ | my $lexeme_id = $lex_lexeme_to_g1_symbol[$lexer_lexeme_id] // -1; | ||||||||||||||||||
|
Condition50%1/2
$lex_lexeme_to_g1_symbol[$lexer_lexeme_id] // -1
MC/DC0%0/1
$lex_lexeme_to_g1_symbol[$lexer_lexeme_id] // -1
$lex_lexeme_to_g1_symbol[$lexer_lexeme_id]
Truth table50%1/2
A
A= $lex_lexeme_to_g1_symbol[$lexer_lexeme_id]
| |||||||||||||||||||||
| 544 | 8973 | $lex_rule_to_g1_lexeme[$rule_id] = $lexeme_id; | |||||||||||||||||||
| 545 | 8973 | ▶ | next RULE_ID if $lexeme_id < 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 546 | 8973 | my $lexeme_name = $g1_tracer->symbol_name($lexeme_id); | |||||||||||||||||||
| 547 | |||||||||||||||||||||
| 548 | # If 1 is the default, we don't need an assertion | ||||||||||||||||||||
| 549 | 8973 | ▶ | next RULE_ID if not $lexeme_data{$lexeme_name}{latm}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 550 | |||||||||||||||||||||
| 551 | my $assertion_id = | ||||||||||||||||||||
| 552 | 8540 | $lexeme_data{$lexeme_name}{lexers}{$lexer_name}{'assertion'}; | |||||||||||||||||||
| 553 | 8540 | ▶ | if ( not defined $assertion_id ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 554 | 8540 | $assertion_id = $lex_thin->zwa_new(0); | |||||||||||||||||||
| 555 | |||||||||||||||||||||
| 556 | 8540 | ▶ | if ( $trace_terminals >= 2 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 557 | 0 | say {$trace_fh} "Assertion $assertion_id defaults to 0"; | |||||||||||||||||||
| 558 | } | ||||||||||||||||||||
| 559 | |||||||||||||||||||||
| 560 | 8540 | $lexeme_data{$lexeme_name}{lexers}{$lexer_name}{'assertion'} = | |||||||||||||||||||
| 561 | $assertion_id; | ||||||||||||||||||||
| 562 | } ## end if ( not defined $assertion_id ) | ||||||||||||||||||||
| 563 | 8540 | $lex_thin->zwa_place( $assertion_id, $rule_id, 0 ); | |||||||||||||||||||
| 564 | 8540 | ▶ | if ( $trace_terminals >= 2 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 565 | 0 | say {$trace_fh} | |||||||||||||||||||
| 566 | "Assertion $assertion_id applied to $lexer_name rule ", | ||||||||||||||||||||
| 567 | slg_rule_show( $slg, $rule_id, $lex_grammar ); | ||||||||||||||||||||
| 568 | } | ||||||||||||||||||||
| 569 | } ## end RULE_ID: for my $rule_id ( 0 .. $lex_thin->highest_rule_id() ) | ||||||||||||||||||||
| 570 | |||||||||||||||||||||
| 571 | 273 | Marpa::R2::Internal::Grammar::slif_precompute($lex_grammar); | |||||||||||||||||||
| 572 | |||||||||||||||||||||
| 573 | 273 | my @class_table = (); | |||||||||||||||||||
| 574 | |||||||||||||||||||||
| 575 | CLASS_SYMBOL: | ||||||||||||||||||||
| 576 | 273 | for my $class_symbol ( sort keys %{$character_class_hash} ) { | |||||||||||||||||||
| 577 | 5862 | my $symbol_id = $lex_tracer->symbol_by_name($class_symbol); | |||||||||||||||||||
| 578 | 5862 | ▶ | next CLASS_SYMBOL if not defined $symbol_id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 579 | 5862 | my $cc_components = $character_class_hash->{$class_symbol}; | |||||||||||||||||||
| 580 | 5862 | my ( $compiled_re, $error ) = | |||||||||||||||||||
| 581 | Marpa::R2::Internal::MetaAST::char_class_to_re($cc_components); | ||||||||||||||||||||
| 582 | 5862 | ▶ | if ( not $compiled_re ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 583 | 0 | $error =~ s/^/ /gxms; #indent all lines | |||||||||||||||||||
| 584 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 585 | "Failed belatedly to evaluate character class\n", $error ); | ||||||||||||||||||||
| 586 | } | ||||||||||||||||||||
| 587 | 5862 | push @class_table, [ $symbol_id, $compiled_re ]; | |||||||||||||||||||
| 588 | } ## end CLASS_SYMBOL: for my $class_symbol ( sort keys %{...}) | ||||||||||||||||||||
| 589 | 273 | $character_class_table_by_lexer_name{$lexer_name} = \@class_table; | |||||||||||||||||||
| 590 | |||||||||||||||||||||
| 591 | 273 | $lexer_and_rule_to_g1_lexeme{$lexer_name} = \@lex_rule_to_g1_lexeme; | |||||||||||||||||||
| 592 | |||||||||||||||||||||
| 593 | # Apply defaults to determine the discard event for every | ||||||||||||||||||||
| 594 | # rule id of the lexer. | ||||||||||||||||||||
| 595 | |||||||||||||||||||||
| 596 | 273 | my $default_discard_event = $discard_default_adverbs->{event}; | |||||||||||||||||||
| 597 | 273 | RULE_ID: for my $rule_id ( 0 .. $lex_thin->highest_rule_id() ) { | |||||||||||||||||||
| 598 | 23137 | my $tag = $lex_grammar->tag($rule_id); | |||||||||||||||||||
| 599 | 23137 | ▶ | next RULE_ID if not defined $tag; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 600 | 13967 | my $event; | |||||||||||||||||||
| 601 | FIND_EVENT: { | ||||||||||||||||||||
| 602 | 13967 | $event = $lexer_rule_by_tag{$tag}->{event}; | |||||||||||||||||||
| 603 | 13967 | ▶ | last FIND_EVENT if defined $event; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 604 | 13916 | my $lhs_id = $lex_thin->rule_lhs($rule_id); | |||||||||||||||||||
| 605 | 13916 | ▶ | last FIND_EVENT if $lhs_id != $lex_discard_symbol_id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 606 | 270 | $event = $default_discard_event; | |||||||||||||||||||
| 607 | } ## end FIND_EVENT: | ||||||||||||||||||||
| 608 | 13967 | ▶ | next RULE_ID if not defined $event; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 609 | |||||||||||||||||||||
| 610 | 60 | my ( $event_name, $event_starts_active ) = @{$event}; | |||||||||||||||||||
| 611 | 60 | ▶ | if ( $event_name eq q{'symbol} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 612 | my @event = ( | ||||||||||||||||||||
| 613 | $lexer_rule_by_tag{$tag}->{symbol_as_event}, | ||||||||||||||||||||
| 614 | 15 | $event_starts_active | |||||||||||||||||||
| 615 | ); | ||||||||||||||||||||
| 616 | 15 | $discard_event_by_lexer_rule_id[$rule_id] = \@event; | |||||||||||||||||||
| 617 | 15 | next RULE_ID; | |||||||||||||||||||
| 618 | } ## end if ( $event_name eq q{'symbol} ) | ||||||||||||||||||||
| 619 | 45 | ▶ | if ( ( substr $event_name, 0, 1 ) ne q{'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 620 | 45 | $discard_event_by_lexer_rule_id[$rule_id] = $event; | |||||||||||||||||||
| 621 | 45 | next RULE_ID; | |||||||||||||||||||
| 622 | } | ||||||||||||||||||||
| 623 | Marpa::R2::exception( | ||||||||||||||||||||
| 624 | 0 | qq{Discard event has unknown name: "$event_name"} | |||||||||||||||||||
| 625 | ); | ||||||||||||||||||||
| 626 | |||||||||||||||||||||
| 627 | } ## end RULE_ID: for my $rule_id ( 0 .. $lex_thin->highest_rule_id() ) | ||||||||||||||||||||
| 628 | |||||||||||||||||||||
| 629 | # Post-lexer G1 processing | ||||||||||||||||||||
| 630 | |||||||||||||||||||||
| 631 | 273 | my $thick_L0 = $thick_grammar_by_lexer_name{'L0'}; | |||||||||||||||||||
| 632 | 273 | my $thin_L0 = $thick_L0->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||
| 633 | 273 | my $thin_slg = $slg->[Marpa::R2::Internal::Scanless::G::C] = | |||||||||||||||||||
| 634 | Marpa::R2::Thin::SLG->new( $thin_L0, $g1_tracer->grammar() ); | ||||||||||||||||||||
| 635 | |||||||||||||||||||||
| 636 | # Relies on default lexer being given number zero | ||||||||||||||||||||
| 637 | 273 | $lexer_id_by_name{'L0'} = 0; | |||||||||||||||||||
| 638 | |||||||||||||||||||||
| 639 | 273 | LEXEME: for my $lexeme_name ( keys %g1_id_by_lexeme_name ) { | |||||||||||||||||||
| 640 | Marpa::R2::exception( | ||||||||||||||||||||
| 641 | "A lexeme in G1 is not a lexeme in any of the lexers: $lexeme_name" | ||||||||||||||||||||
| 642 | 8974 | ▶ | ) if not defined $lexeme_data{$lexeme_name}{'lexers'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 643 | } | ||||||||||||||||||||
| 644 | |||||||||||||||||||||
| 645 | # At this point we know which symbols are lexemes. | ||||||||||||||||||||
| 646 | # So now let's check for inconsistencies | ||||||||||||||||||||
| 647 | |||||||||||||||||||||
| 648 | # Check for lexeme declarations for things which are not lexemes | ||||||||||||||||||||
| 649 | 269 | for my $lexeme_name ( keys %{$lexeme_declarations} ) { | |||||||||||||||||||
| 650 | Marpa::R2::exception( | ||||||||||||||||||||
| 651 | "Symbol <$lexeme_name> is declared as a lexeme, but it is not used as one.\n" | ||||||||||||||||||||
| 652 | 59 | ▶ | ) if not defined $g1_id_by_lexeme_name{$lexeme_name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 653 | } | ||||||||||||||||||||
| 654 | |||||||||||||||||||||
| 655 | # Now that we know the lexemes, check attempts to defined a | ||||||||||||||||||||
| 656 | # completion or a nulled event for one | ||||||||||||||||||||
| 657 | 269 | for my $symbol_name ( keys %{$completion_events_by_name} ) { | |||||||||||||||||||
| 658 | Marpa::R2::exception( | ||||||||||||||||||||
| 659 | "A completion event is declared for <$symbol_name>, but it is a lexeme.\n", | ||||||||||||||||||||
| 660 | " Completion events are only valid for symbols on the LHS of G1 rules.\n" | ||||||||||||||||||||
| 661 | 54 | ▶ | ) if defined $g1_id_by_lexeme_name{$symbol_name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 662 | } ## end for my $symbol_name ( keys %{$completion_events_by_name...}) | ||||||||||||||||||||
| 663 | |||||||||||||||||||||
| 664 | 269 | for my $symbol_name ( keys %{$nulled_events_by_name} ) { | |||||||||||||||||||
| 665 | Marpa::R2::exception( | ||||||||||||||||||||
| 666 | "A nulled event is declared for <$symbol_name>, but it is a G1 lexeme.\n", | ||||||||||||||||||||
| 667 | " nulled events are only valid for symbols on the LHS of G1 rules.\n" | ||||||||||||||||||||
| 668 | 46 | ▶ | ) if defined $g1_id_by_lexeme_name{$symbol_name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 669 | } ## end for my $symbol_name ( keys %{$nulled_events_by_name} ) | ||||||||||||||||||||
| 670 | |||||||||||||||||||||
| 671 | # Mark the lexemes, and set their data | ||||||||||||||||||||
| 672 | # Now that we have created the SLG, we can set the latm value, | ||||||||||||||||||||
| 673 | # already determined above. | ||||||||||||||||||||
| 674 | 269 | LEXEME: for my $lexeme_name ( keys %g1_id_by_lexeme_name ) { | |||||||||||||||||||
| 675 | 8969 | my $g1_lexeme_id = $g1_id_by_lexeme_name{$lexeme_name}; | |||||||||||||||||||
| 676 | 8969 | my $declarations = $lexeme_declarations->{$lexeme_name}; | |||||||||||||||||||
| 677 | 8969 | ▶ | my $priority = $declarations->{priority} // 0; | ||||||||||||||||||
|
Condition100%2/2
$declarations->{"priority"} // 0
MC/DC100%1/1
$declarations->{"priority"} // 0
$declarations->{"priority"}
Truth table100%2/2
A
A= $declarations->{"priority"}
| |||||||||||||||||||||
| 678 | 8969 | $thin_slg->g1_lexeme_set( $g1_lexeme_id, $priority ); | |||||||||||||||||||
| 679 | 8969 | ▶ | my $latm_value = $lexeme_data{$lexeme_name}{latm} // 0; | ||||||||||||||||||
|
Condition50%1/2
$lexeme_data{$lexeme_name}{"latm"} // 0
MC/DC0%0/1
$lexeme_data{$lexeme_name}{"latm"} // 0
$lexeme_data{$lexeme_name}{"latm"}
Truth table50%1/2
A
A= $lexeme_data{$lexeme_name}{"latm"}
| |||||||||||||||||||||
| 680 | 8969 | $thin_slg->g1_lexeme_latm_set( $g1_lexeme_id, $latm_value ); | |||||||||||||||||||
| 681 | 8969 | my $pause_value = $declarations->{pause}; | |||||||||||||||||||
| 682 | 8969 | ▶ | if ( defined $pause_value ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 683 | 54 | $thin_slg->g1_lexeme_pause_set( $g1_lexeme_id, $pause_value ); | |||||||||||||||||||
| 684 | 54 | my $is_active = 1; | |||||||||||||||||||
| 685 | |||||||||||||||||||||
| 686 | 54 | ▶ | if ( defined( my $event_data = $declarations->{'event'} ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 687 | 49 | my $event_name; | |||||||||||||||||||
| 688 | 49 | ( $event_name, $is_active ) = @{$event_data}; | |||||||||||||||||||
| 689 | 49 | $lexeme_events_by_id->[$g1_lexeme_id] = $event_name; | |||||||||||||||||||
| 690 | 49 | push @{ $symbol_ids_by_event_name_and_type->{$event_name} | |||||||||||||||||||
| 691 | 49 | ->{lexeme} }, $g1_lexeme_id; | |||||||||||||||||||
| 692 | } ## end if ( defined( my $event_data = $declarations->{'event'...})) | ||||||||||||||||||||
| 693 | |||||||||||||||||||||
| 694 | 54 | $thin_slg->g1_lexeme_pause_activate( $g1_lexeme_id, $is_active ); | |||||||||||||||||||
| 695 | } ## end if ( defined $pause_value ) | ||||||||||||||||||||
| 696 | |||||||||||||||||||||
| 697 | } ## end LEXEME: for my $lexeme_name ( keys %g1_id_by_lexeme_name ) | ||||||||||||||||||||
| 698 | |||||||||||||||||||||
| 699 | # Second phase of lexer processing | ||||||||||||||||||||
| 700 | 269 | my $lexer_rule_to_g1_lexeme = $lexer_and_rule_to_g1_lexeme{$lexer_name}; | |||||||||||||||||||
| 701 | |||||||||||||||||||||
| 702 | 269 | RULE_ID: for my $lexer_rule_id ( 0 .. $#{$lexer_rule_to_g1_lexeme} ) { | |||||||||||||||||||
| 703 | 23127 | my $g1_lexeme_id = $lexer_rule_to_g1_lexeme->[$lexer_rule_id]; | |||||||||||||||||||
| 704 | 23127 | my $lexeme_name = $g1_tracer->symbol_name($g1_lexeme_id); | |||||||||||||||||||
| 705 | my $assertion_id = | ||||||||||||||||||||
| 706 | 23127 | ▶ | $lexeme_data{$lexeme_name}{lexers}{$lexer_name}{'assertion'} | ||||||||||||||||||
|
Condition100%2/2
$lexeme_data{$lexeme_name}{"lexers"}{$lexer_name}{"assertion"} // -1
MC/DC100%1/1
$lexeme_data{$lexeme_name}{"lexers"}{$lexer_name}{"assertion"} // -1
$lexeme_data{$lexeme_name}{"lexers"}{$lexer_name}{"assertion"}
Truth table100%2/2
A
A= $lexeme_data{$lexeme_name}{"lexers"}{$lexer_name}{"assertion"}
| |||||||||||||||||||||
| 707 | // -1; | ||||||||||||||||||||
| 708 | 23127 | $thin_slg->lexer_rule_to_g1_lexeme_set( $lexer_rule_id, | |||||||||||||||||||
| 709 | $g1_lexeme_id, $assertion_id ); | ||||||||||||||||||||
| 710 | 23127 | my $discard_event = $discard_event_by_lexer_rule_id[$lexer_rule_id]; | |||||||||||||||||||
| 711 | 23127 | ▶ | if ( defined $discard_event ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 712 | 60 | my ( $event_name, $is_active ) = @{$discard_event}; | |||||||||||||||||||
| 713 | 60 | $slg->[ | |||||||||||||||||||
| 714 | Marpa::R2::Internal::Scanless::G::DISCARD_EVENT_BY_LEXER_RULE | ||||||||||||||||||||
| 715 | ]->[$lexer_rule_id] = $event_name; | ||||||||||||||||||||
| 716 | 60 | push @{ $symbol_ids_by_event_name_and_type->{$event_name} | |||||||||||||||||||
| 717 | 60 | ->{discard} }, $lexer_rule_id; | |||||||||||||||||||
| 718 | 60 | $thin_slg->discard_event_set( $lexer_rule_id, 1 ); | |||||||||||||||||||
| 719 | 60 | ▶ | $thin_slg->discard_event_activate( $lexer_rule_id, 1 ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 720 | if $is_active; | ||||||||||||||||||||
| 721 | } ## end if ( defined $discard_event ) | ||||||||||||||||||||
| 722 | } ## end RULE_ID: for my $lexer_rule_id ( 0 .. $#{$lexer_rule_to_g1_lexeme...}) | ||||||||||||||||||||
| 723 | |||||||||||||||||||||
| 724 | # Second phase of G1 processing | ||||||||||||||||||||
| 725 | |||||||||||||||||||||
| 726 | 269 | $thin_slg->precompute(); | |||||||||||||||||||
| 727 | 269 | $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR] = | |||||||||||||||||||
| 728 | $thick_g1_grammar; | ||||||||||||||||||||
| 729 | |||||||||||||||||||||
| 730 | # More lexer processing | ||||||||||||||||||||
| 731 | # Determine events by lexer rule, applying the defaults | ||||||||||||||||||||
| 732 | |||||||||||||||||||||
| 733 | { | ||||||||||||||||||||
| 734 | 269 | my $character_class_table = | |||||||||||||||||||
| 735 | 269 | $character_class_table_by_lexer_name{$lexer_name}; | |||||||||||||||||||
| 736 | 269 | $slg->[Marpa::R2::Internal::Scanless::G::CHARACTER_CLASS_TABLES] | |||||||||||||||||||
| 737 | ->[$lexer_id] = $character_class_table; | ||||||||||||||||||||
| 738 | $slg->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS] | ||||||||||||||||||||
| 739 | 269 | ->[$lexer_id] = $thick_grammar_by_lexer_name{$lexer_name}; | |||||||||||||||||||
| 740 | } | ||||||||||||||||||||
| 741 | |||||||||||||||||||||
| 742 | # This section violates the NAIF interface, directly changing some | ||||||||||||||||||||
| 743 | # of its internal structures. | ||||||||||||||||||||
| 744 | # | ||||||||||||||||||||
| 745 | # Some lexeme default adverbs are applied in earlier phases. | ||||||||||||||||||||
| 746 | # | ||||||||||||||||||||
| 747 | APPLY_DEFAULT_LEXEME_ADVERBS: { | ||||||||||||||||||||
| 748 | 269 | ▶ | last APPLY_DEFAULT_LEXEME_ADVERBS if not $lexeme_default_adverbs; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 749 | |||||||||||||||||||||
| 750 | 269 | my $action = $lexeme_default_adverbs->{action}; | |||||||||||||||||||
| 751 | 269 | my $g1_symbols = | |||||||||||||||||||
| 752 | $thick_g1_grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | ||||||||||||||||||||
| 753 | LEXEME: | ||||||||||||||||||||
| 754 | 269 | for my $lexeme_name ( keys %g1_id_by_lexeme_name ) { | |||||||||||||||||||
| 755 | 8969 | my $g1_lexeme_id = $g1_id_by_lexeme_name{$lexeme_name}; | |||||||||||||||||||
| 756 | 8969 | my $g1_symbol = $g1_symbols->[$g1_lexeme_id]; | |||||||||||||||||||
| 757 | 8969 | ▶ | next LEXEME if $lexeme_name =~ m/ \] \z/xms; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 758 | 1809 | ▶ | $g1_symbol->[Marpa::R2::Internal::Symbol::LEXEME_SEMANTICS] //= | ||||||||||||||||||
|
Condition66%2/3
$g1_symbol->[2] //= $action
MC/DC50%1/2
$g1_symbol->[2] //= $action
$g1_symbol->[2]
$action
Truth table66%2/3
A //= B
A= $g1_symbol->[2]B= $action
| |||||||||||||||||||||
| 759 | $action; | ||||||||||||||||||||
| 760 | } ## end LEXEME: for my $lexeme_name ( keys %g1_id_by_lexeme_name ) | ||||||||||||||||||||
| 761 | |||||||||||||||||||||
| 762 | 269 | my $blessing = $lexeme_default_adverbs->{bless}; | |||||||||||||||||||
| 763 | 269 | ▶ | last APPLY_DEFAULT_LEXEME_ADVERBS if not $blessing; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 764 | 89 | ▶ | last APPLY_DEFAULT_LEXEME_ADVERBS if $blessing eq '::undef'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 765 | |||||||||||||||||||||
| 766 | LEXEME: | ||||||||||||||||||||
| 767 | 89 | for my $lexeme_name ( keys %g1_id_by_lexeme_name ) { | |||||||||||||||||||
| 768 | 8445 | my $g1_lexeme_id = $g1_id_by_lexeme_name{$lexeme_name}; | |||||||||||||||||||
| 769 | 8445 | my $g1_symbol = $g1_symbols->[$g1_lexeme_id]; | |||||||||||||||||||
| 770 | 8445 | ▶ | next LEXEME if $lexeme_name =~ m/ \] \z/xms; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 771 | 1546 | ▶ | if ( $blessing eq '::name' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 772 | 1546 | ▶ | if ( $lexeme_name =~ / [^ [:alnum:]] /xms ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 773 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 774 | qq{Lexeme blessing by '::name' only allowed if lexeme name is whitespace and alphanumerics\n}, | ||||||||||||||||||||
| 775 | qq{ Problematic lexeme was <$lexeme_name>\n} | ||||||||||||||||||||
| 776 | ); | ||||||||||||||||||||
| 777 | } ## end if ( $lexeme_name =~ / [^ [:alnum:]] /xms ) | ||||||||||||||||||||
| 778 | 1546 | my $blessing_by_name = $lexeme_name; | |||||||||||||||||||
| 779 | 1546 | $blessing_by_name =~ s/[ ]/_/gxms; | |||||||||||||||||||
| 780 | 1546 | ▶ | $g1_symbol->[Marpa::R2::Internal::Symbol::BLESSING] //= | ||||||||||||||||||
|
Condition33%1/3
$g1_symbol->[1] //= $blessing_by_name
MC/DC0%0/2
$g1_symbol->[1] //= $blessing_by_name
$g1_symbol->[1]
$blessing_by_name
Truth table33%1/3
A //= B
A= $g1_symbol->[1]B= $blessing_by_name
| |||||||||||||||||||||
| 781 | $blessing_by_name; | ||||||||||||||||||||
| 782 | 1546 | next LEXEME; | |||||||||||||||||||
| 783 | } ## end if ( $blessing eq '::name' ) | ||||||||||||||||||||
| 784 | 0 | ▶ | if ( $blessing =~ / [\W] /xms ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 785 | 0 | Marpa::R2::exception( | |||||||||||||||||||
| 786 | qq{Blessing lexeme as '$blessing' is not allowed\n}, | ||||||||||||||||||||
| 787 | qq{ Problematic lexeme was <$lexeme_name>\n} | ||||||||||||||||||||
| 788 | ); | ||||||||||||||||||||
| 789 | } ## end if ( $blessing =~ / [\W] /xms ) | ||||||||||||||||||||
| 790 | 0 | ▶ | $g1_symbol->[Marpa::R2::Internal::Symbol::BLESSING] //= $blessing; | ||||||||||||||||||
|
Condition0%0/3
$g1_symbol->[1] //= $blessing
MC/DC0%0/2
$g1_symbol->[1] //= $blessing
$g1_symbol->[1]
$blessing
Truth table0%0/3
A //= B
A= $g1_symbol->[1]B= $blessing
| |||||||||||||||||||||
| 791 | } ## end LEXEME: for my $lexeme_name ( keys %g1_id_by_lexeme_name ) | ||||||||||||||||||||
| 792 | |||||||||||||||||||||
| 793 | } ## end APPLY_DEFAULT_LEXEME_ADVERBS: | ||||||||||||||||||||
| 794 | |||||||||||||||||||||
| 795 | 269 | return $slg; | |||||||||||||||||||
| 796 | |||||||||||||||||||||
| 797 | } ## end sub Marpa::R2::Internal::Scanless::G::hash_to_runtime | ||||||||||||||||||||
| 798 | |||||||||||||||||||||
| 799 | sub thick_subgrammar_by_name { | ||||||||||||||||||||
| 800 | 665 | ▶ | my ( $slg, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
thick_subgrammar_by_name: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 801 | |||||||||||||||||||||
| 802 | # Allow G0 as legacy synonym for L0 | ||||||||||||||||||||
| 803 | 665 | state $grammar_names = { 'G0' => 1, 'G1' => 1, 'L0' => 1 }; | |||||||||||||||||||
| 804 | 665 | ▶ | $subgrammar //= 'G1'; | ||||||||||||||||||
|
Condition100%2/2
$subgrammar //= "G1"
MC/DC100%1/1
$subgrammar //= "G1"
$subgrammar
Truth table100%2/2
A
A= $subgrammar
| |||||||||||||||||||||
| 805 | |||||||||||||||||||||
| 806 | Marpa::R2::exception(qq{No lexer named "$subgrammar"}) | ||||||||||||||||||||
| 807 | 665 | ▶ | if not defined $grammar_names->{$subgrammar}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 808 | |||||||||||||||||||||
| 809 | 665 | ▶ | return $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR] | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 810 | if $subgrammar eq 'G1'; | ||||||||||||||||||||
| 811 | |||||||||||||||||||||
| 812 | 203 | return $slg->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS] | |||||||||||||||||||
| 813 | ->[0]; | ||||||||||||||||||||
| 814 | } ## end sub thick_subgrammar_by_name | ||||||||||||||||||||
| 815 | |||||||||||||||||||||
| 816 | sub Marpa::R2::Scanless::G::start_symbol_id { | ||||||||||||||||||||
| 817 | 1 | ▶ | my ( $slg, $rule_id, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
start_symbol_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 818 | 1 | return thick_subgrammar_by_name( $slg, $subgrammar )->start_symbol(); | |||||||||||||||||||
| 819 | } | ||||||||||||||||||||
| 820 | |||||||||||||||||||||
| 821 | sub Marpa::R2::Scanless::G::rule_name { | ||||||||||||||||||||
| 822 | 5 | ▶ | my ( $slg, $rule_id, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
rule_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 823 | 5 | return thick_subgrammar_by_name( $slg, $subgrammar )->rule_name($rule_id); | |||||||||||||||||||
| 824 | } | ||||||||||||||||||||
| 825 | |||||||||||||||||||||
| 826 | sub Marpa::R2::Scanless::G::rule_expand { | ||||||||||||||||||||
| 827 | 60 | ▶ | my ( $slg, $rule_id, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
rule_expand: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 828 | 60 | return thick_subgrammar_by_name( $slg, $subgrammar )->tracer() | |||||||||||||||||||
| 829 | ->rule_expand($rule_id); | ||||||||||||||||||||
| 830 | } | ||||||||||||||||||||
| 831 | |||||||||||||||||||||
| 832 | sub Marpa::R2::Scanless::G::symbol_name { | ||||||||||||||||||||
| 833 | 171 | ▶ | my ( $slg, $symbol_id, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
symbol_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 834 | 171 | return thick_subgrammar_by_name($slg, $subgrammar)->tracer() | |||||||||||||||||||
| 835 | ->symbol_name($symbol_id); | ||||||||||||||||||||
| 836 | } | ||||||||||||||||||||
| 837 | |||||||||||||||||||||
| 838 | sub Marpa::R2::Scanless::G::symbol_display_form { | ||||||||||||||||||||
| 839 | 139 | ▶ | my ( $slg, $symbol_id, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
symbol_display_form: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 840 | 139 | return thick_subgrammar_by_name( $slg, $subgrammar ) | |||||||||||||||||||
| 841 | ->symbol_in_display_form($symbol_id); | ||||||||||||||||||||
| 842 | } | ||||||||||||||||||||
| 843 | |||||||||||||||||||||
| 844 | sub Marpa::R2::Scanless::G::symbol_dsl_form { | ||||||||||||||||||||
| 845 | 59 | ▶ | my ( $slg, $symbol_id, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
symbol_dsl_form: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 846 | 59 | return thick_subgrammar_by_name( $slg, $subgrammar ) | |||||||||||||||||||
| 847 | ->symbol_dsl_form($symbol_id); | ||||||||||||||||||||
| 848 | } | ||||||||||||||||||||
| 849 | |||||||||||||||||||||
| 850 | sub Marpa::R2::Scanless::G::symbol_description { | ||||||||||||||||||||
| 851 | 59 | ▶ | my ( $slg, $symbol_id, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
symbol_description: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 852 | 59 | return thick_subgrammar_by_name($slg, $subgrammar) | |||||||||||||||||||
| 853 | ->symbol_description($symbol_id); | ||||||||||||||||||||
| 854 | } | ||||||||||||||||||||
| 855 | |||||||||||||||||||||
| 856 | sub Marpa::R2::Scanless::G::rule_show | ||||||||||||||||||||
| 857 | { | ||||||||||||||||||||
| 858 | 136 | ▶ | my ( $slg, $rule_id, $subgrammar) = @_; | ||||||||||||||||||
|
Subroutine
rule_show: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 859 | 136 | return slg_rule_show($slg, $rule_id, thick_subgrammar_by_name($slg, $subgrammar)); | |||||||||||||||||||
| 860 | } | ||||||||||||||||||||
| 861 | |||||||||||||||||||||
| 862 | sub slg_rule_show { | ||||||||||||||||||||
| 863 | 136 | ▶ | my ( $slg, $rule_id, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
slg_rule_show: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 864 | 136 | my $tracer = $subgrammar->tracer(); | |||||||||||||||||||
| 865 | 136 | my $subgrammar_c = $subgrammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||
| 866 | 136 | my @symbol_ids = $tracer->rule_expand($rule_id); | |||||||||||||||||||
| 867 | 136 | ▶ | return if not scalar @symbol_ids; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 868 | my ( $lhs, @rhs ) = | ||||||||||||||||||||
| 869 | 136 | map { $subgrammar->symbol_in_display_form($_) } @symbol_ids; | |||||||||||||||||||
| 870 | 136 | my $minimum = $subgrammar_c->sequence_min($rule_id); | |||||||||||||||||||
| 871 | 136 | my @quantifier = (); | |||||||||||||||||||
| 872 | |||||||||||||||||||||
| 873 | 136 | ▶ | if ( defined $minimum ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 874 | 8 | ▶ | @quantifier = ( $minimum <= 0 ? q{*} : q{+} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 875 | } | ||||||||||||||||||||
| 876 | 136 | return join q{ }, $lhs, q{::=}, @rhs, @quantifier; | |||||||||||||||||||
| 877 | } ## end sub slg_rule_show | ||||||||||||||||||||
| 878 | |||||||||||||||||||||
| 879 | sub Marpa::R2::Scanless::G::show_rules { | ||||||||||||||||||||
| 880 | 10 | ▶ | my ( $slg, $verbose, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
show_rules: called CC=15 SCAR=27.3
| |||||||||||||||||||||
| 881 | 10 | my $text = q{}; | |||||||||||||||||||
| 882 | 10 | ▶ | $verbose //= 0; | ||||||||||||||||||
|
Condition100%2/2
$verbose //= 0
MC/DC100%1/1
$verbose //= 0
$verbose
Truth table100%2/2
A
A= $verbose
| |||||||||||||||||||||
| 883 | 10 | ▶ | $subgrammar //= 'G1'; | ||||||||||||||||||
|
Condition100%2/2
$subgrammar //= "G1"
MC/DC100%1/1
$subgrammar //= "G1"
$subgrammar
Truth table100%2/2
A
A= $subgrammar
| |||||||||||||||||||||
| 884 | |||||||||||||||||||||
| 885 | 10 | my $thick_grammar = thick_subgrammar_by_name($slg, $subgrammar); | |||||||||||||||||||
| 886 | |||||||||||||||||||||
| 887 | 10 | my $rules = $thick_grammar->[Marpa::R2::Internal::Grammar::RULES]; | |||||||||||||||||||
| 888 | 10 | my $grammar_c = $thick_grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||
| 889 | |||||||||||||||||||||
| 890 | 10 | for my $rule ( @{$rules} ) { | |||||||||||||||||||
| 891 | 183 | my $rule_id = $rule->[Marpa::R2::Internal::Rule::ID]; | |||||||||||||||||||
| 892 | |||||||||||||||||||||
| 893 | 183 | my $minimum = $grammar_c->sequence_min($rule_id); | |||||||||||||||||||
| 894 | 183 | ▶ | my @quantifier = | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 895 | defined $minimum ? $minimum <= 0 ? (q{*}) : (q{+}) : (); | ||||||||||||||||||||
| 896 | 183 | my $lhs_id = $grammar_c->rule_lhs($rule_id); | |||||||||||||||||||
| 897 | 183 | my $rule_length = $grammar_c->rule_length($rule_id); | |||||||||||||||||||
| 898 | my @rhs_ids = | ||||||||||||||||||||
| 899 | 183 | map { $grammar_c->rule_rhs( $rule_id, $_ ) } | |||||||||||||||||||
| 900 | ( 0 .. $rule_length - 1 ); | ||||||||||||||||||||
| 901 | $text .= join q{ }, $subgrammar, "R$rule_id", | ||||||||||||||||||||
| 902 | $thick_grammar->symbol_in_display_form($lhs_id), | ||||||||||||||||||||
| 903 | '::=', | ||||||||||||||||||||
| 904 | 183 | ( map { $thick_grammar->symbol_in_display_form($_) } @rhs_ids ), | |||||||||||||||||||
| 905 | @quantifier; | ||||||||||||||||||||
| 906 | 183 | $text .= "\n"; | |||||||||||||||||||
| 907 | |||||||||||||||||||||
| 908 | 183 | ▶ | if ( $verbose >= 2 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 909 | |||||||||||||||||||||
| 910 | 48 | my $description = $rule->[Marpa::R2::Internal::Rule::DESCRIPTION]; | |||||||||||||||||||
| 911 | 48 | ▶ | $text .= " $description\n" if $description; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 912 | 48 | my @comment = (); | |||||||||||||||||||
| 913 | 48 | ▶ | $grammar_c->rule_length($rule_id) == 0 | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 914 | and push @comment, 'empty'; | ||||||||||||||||||||
| 915 | 48 | ▶ | $thick_grammar->rule_is_used($rule_id) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 916 | or push @comment, '!used'; | ||||||||||||||||||||
| 917 | 48 | ▶ | $grammar_c->rule_is_productive($rule_id) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 918 | or push @comment, 'unproductive'; | ||||||||||||||||||||
| 919 | 48 | ▶ | $grammar_c->rule_is_accessible($rule_id) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 920 | or push @comment, 'inaccessible'; | ||||||||||||||||||||
| 921 | 48 | ▶ | $rule->[Marpa::R2::Internal::Rule::DISCARD_SEPARATION] | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 922 | and push @comment, 'discard_sep'; | ||||||||||||||||||||
| 923 | |||||||||||||||||||||
| 924 | 48 | ▶ | if (@comment) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 925 | 0 | $text .= q{ } . ( join q{ }, q{/*}, @comment, q{*/} ) . "\n"; | |||||||||||||||||||
| 926 | } | ||||||||||||||||||||
| 927 | |||||||||||||||||||||
| 928 | $text .= " Symbol IDs: <$lhs_id> ::= " | ||||||||||||||||||||
| 929 | 48 | . ( join q{ }, map {"<$_>"} @rhs_ids ) . "\n"; | |||||||||||||||||||
| 930 | |||||||||||||||||||||
| 931 | } ## end if ( $verbose >= 2 ) | ||||||||||||||||||||
| 932 | |||||||||||||||||||||
| 933 | 183 | ▶ | if ( $verbose >= 3 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 934 | |||||||||||||||||||||
| 935 | 48 | my $tracer = $thick_grammar->tracer(); | |||||||||||||||||||
| 936 | |||||||||||||||||||||
| 937 | $text | ||||||||||||||||||||
| 938 | .= " Internal symbols: <" | ||||||||||||||||||||
| 939 | . $tracer->symbol_name($lhs_id) | ||||||||||||||||||||
| 940 | . q{> ::= } | ||||||||||||||||||||
| 941 | . ( | ||||||||||||||||||||
| 942 | join q{ }, | ||||||||||||||||||||
| 943 | 48 | map { '<' . $tracer->symbol_name($_) . '>' } @rhs_ids | |||||||||||||||||||
| 944 | ) . "\n"; | ||||||||||||||||||||
| 945 | |||||||||||||||||||||
| 946 | } ## end if ( $verbose >= 3 ) | ||||||||||||||||||||
| 947 | |||||||||||||||||||||
| 948 | } ## end for my $rule ( @{$rules} ) | ||||||||||||||||||||
| 949 | |||||||||||||||||||||
| 950 | 10 | return $text; | |||||||||||||||||||
| 951 | } ## end sub Marpa::R2::Scanless::G::show_rules | ||||||||||||||||||||
| 952 | |||||||||||||||||||||
| 953 | sub Marpa::R2::Scanless::G::show_symbols { | ||||||||||||||||||||
| 954 | 4 | ▶ | my ( $slg, $verbose, $subgrammar ) = @_; | ||||||||||||||||||
|
Subroutine
show_symbols: called CC=13 SCAR=25.7
| |||||||||||||||||||||
| 955 | 4 | my $text = q{}; | |||||||||||||||||||
| 956 | 4 | ▶ | $verbose //= 0; | ||||||||||||||||||
|
Condition100%2/2
$verbose //= 0
MC/DC100%1/1
$verbose //= 0
$verbose
Truth table100%2/2
A
A= $verbose
| |||||||||||||||||||||
| 957 | 4 | ▶ | $subgrammar //= 'G1'; | ||||||||||||||||||
|
Condition100%2/2
$subgrammar //= "G1"
MC/DC100%1/1
$subgrammar //= "G1"
$subgrammar
Truth table100%2/2
A
A= $subgrammar
| |||||||||||||||||||||
| 958 | |||||||||||||||||||||
| 959 | 4 | my $thick_grammar = thick_subgrammar_by_name($slg, $subgrammar); | |||||||||||||||||||
| 960 | |||||||||||||||||||||
| 961 | 4 | my $symbols = $thick_grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; | |||||||||||||||||||
| 962 | 4 | my $grammar_c = $thick_grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||
| 963 | |||||||||||||||||||||
| 964 | 4 | for my $symbol ( @{$symbols} ) { | |||||||||||||||||||
| 965 | 68 | my $symbol_id = $symbol->[Marpa::R2::Internal::Symbol::ID]; | |||||||||||||||||||
| 966 | |||||||||||||||||||||
| 967 | 68 | $text .= join q{ }, $subgrammar, "S$symbol_id", | |||||||||||||||||||
| 968 | $thick_grammar->symbol_in_display_form($symbol_id); | ||||||||||||||||||||
| 969 | |||||||||||||||||||||
| 970 | 68 | my $description = $symbol->[Marpa::R2::Internal::Symbol::DESCRIPTION]; | |||||||||||||||||||
| 971 | 68 | ▶ | if ($description) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 972 | 49 | $text .= " -- $description"; | |||||||||||||||||||
| 973 | } | ||||||||||||||||||||
| 974 | 68 | $text .= "\n"; | |||||||||||||||||||
| 975 | |||||||||||||||||||||
| 976 | 68 | ▶ | if ( $verbose >= 2 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 977 | |||||||||||||||||||||
| 978 | 59 | my @tag_list = (); | |||||||||||||||||||
| 979 | 59 | ▶ | $grammar_c->symbol_is_productive($symbol_id) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 980 | or push @tag_list, 'unproductive'; | ||||||||||||||||||||
| 981 | 59 | ▶ | $grammar_c->symbol_is_accessible($symbol_id) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 982 | or push @tag_list, 'inaccessible'; | ||||||||||||||||||||
| 983 | 59 | ▶ | $grammar_c->symbol_is_nulling($symbol_id) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 984 | and push @tag_list, 'nulling'; | ||||||||||||||||||||
| 985 | 59 | ▶ | $grammar_c->symbol_is_terminal($symbol_id) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 986 | and push @tag_list, 'terminal'; | ||||||||||||||||||||
| 987 | |||||||||||||||||||||
| 988 | 59 | ▶ | if (@tag_list) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 989 | 30 | $text | |||||||||||||||||||
| 990 | .= q{ } . ( join q{ }, q{/*}, @tag_list, q{*/} ) . "\n"; | ||||||||||||||||||||
| 991 | } | ||||||||||||||||||||
| 992 | |||||||||||||||||||||
| 993 | 59 | my $tracer = $thick_grammar->tracer(); | |||||||||||||||||||
| 994 | 59 | $text .= " Internal name: <" | |||||||||||||||||||
| 995 | . $tracer->symbol_name($symbol_id) . qq{>\n}; | ||||||||||||||||||||
| 996 | |||||||||||||||||||||
| 997 | } ## end if ( $verbose >= 2 ) | ||||||||||||||||||||
| 998 | |||||||||||||||||||||
| 999 | 68 | ▶ | if ( $verbose >= 3 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1000 | |||||||||||||||||||||
| 1001 | 59 | my $dsl_form = $symbol->[Marpa::R2::Internal::Symbol::DSL_FORM]; | |||||||||||||||||||
| 1002 | 59 | ▶ | if ($dsl_form) { $text .= qq{ SLIF name: $dsl_form\n}; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1003 | |||||||||||||||||||||
| 1004 | } ## end if ( $verbose >= 3 ) | ||||||||||||||||||||
| 1005 | |||||||||||||||||||||
| 1006 | } ## end for my $symbol ( @{$symbols} ) | ||||||||||||||||||||
| 1007 | |||||||||||||||||||||
| 1008 | 4 | return $text; | |||||||||||||||||||
| 1009 | } ## end sub Marpa::R2::Scanless::G::show_symbols | ||||||||||||||||||||
| 1010 | |||||||||||||||||||||
| 1011 | sub Marpa::R2::Scanless::G::show_dotted_rule { | ||||||||||||||||||||
| 1012 | 428 | ▶ | my ( $slg, $rule_id, $dot_position ) = @_; | ||||||||||||||||||
|
Subroutine
show_dotted_rule: called CC=6 SCAR=17.9
| |||||||||||||||||||||
| 1013 | 428 | my $grammar = $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR]; | |||||||||||||||||||
| 1014 | 428 | my $tracer = $grammar->tracer(); | |||||||||||||||||||
| 1015 | 428 | my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; | |||||||||||||||||||
| 1016 | my ( $lhs, @rhs ) = | ||||||||||||||||||||
| 1017 | 428 | map { $grammar->symbol_in_display_form($_) } $tracer->rule_expand($rule_id); | |||||||||||||||||||
| 1018 | 428 | my $rhs_length = scalar @rhs; | |||||||||||||||||||
| 1019 | |||||||||||||||||||||
| 1020 | 428 | my $minimum = $grammar_c->sequence_min($rule_id); | |||||||||||||||||||
| 1021 | 428 | my @quantifier = (); | |||||||||||||||||||
| 1022 | 428 | ▶ | if (defined $minimum) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1023 | 4 | ▶ | @quantifier = ($minimum <= 0 ? q{*} : q{+} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||
| 1025 | 428 | ▶ | $dot_position += ($rhs_length + 1) if $dot_position < 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1026 | 428 | ▶ | $dot_position = 0 if $dot_position < 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1027 | 428 | ▶ | if ($dot_position < $rhs_length) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1028 | 324 | splice @rhs, $dot_position, 0, q{.}; | |||||||||||||||||||
| 1029 | 324 | return join q{ }, $lhs, q{->}, @rhs, @quantifier; | |||||||||||||||||||
| 1030 | } else { | ||||||||||||||||||||
| 1031 | 104 | return join q{ }, $lhs, q{->}, @rhs, @quantifier, q{.}; | |||||||||||||||||||
| 1032 | } | ||||||||||||||||||||
| 1033 | } ## end sub Marpa::R2::Grammar::show_dotted_rule | ||||||||||||||||||||
| 1034 | |||||||||||||||||||||
| 1035 | sub Marpa::R2::Scanless::G::rule { | ||||||||||||||||||||
| 1036 | 6 | ▶ | my ( $slg, @args ) = @_; | ||||||||||||||||||
|
Subroutine
rule: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 1037 | 6 | return $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR] | |||||||||||||||||||
| 1038 | ->rule(@args); | ||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||
| 1040 | |||||||||||||||||||||
| 1041 | sub Marpa::R2::Scanless::G::rule_ids { | ||||||||||||||||||||
| 1042 | 11 | ▶ | my ($slg, $subgrammar) = @_; | ||||||||||||||||||
|
Subroutine
rule_ids: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 1043 | 11 | return thick_subgrammar_by_name($slg, $subgrammar)->rule_ids(); | |||||||||||||||||||
| 1044 | } | ||||||||||||||||||||
| 1045 | |||||||||||||||||||||
| 1046 | sub Marpa::R2::Scanless::G::symbol_ids { | ||||||||||||||||||||
| 1047 | 6 | ▶ | my ($slg, $subgrammar) = @_; | ||||||||||||||||||
|
Subroutine
symbol_ids: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 1048 | 6 | return thick_subgrammar_by_name($slg, $subgrammar)->symbol_ids(); | |||||||||||||||||||
| 1049 | } | ||||||||||||||||||||
| 1050 | |||||||||||||||||||||
| 1051 | sub Marpa::R2::Scanless::G::g1_rule_ids { | ||||||||||||||||||||
| 1052 | 1 | ▶ | my ($slg) = @_; | ||||||||||||||||||
|
Subroutine
g1_rule_ids: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 1053 | 1 | return $slg->rule_ids(); | |||||||||||||||||||
| 1054 | } | ||||||||||||||||||||
| 1055 | |||||||||||||||||||||
| 1056 | sub Marpa::R2::Scanless::G::g0_rule_ids { | ||||||||||||||||||||
| 1057 | 1 | ▶ | my ($slg) = @_; | ||||||||||||||||||
|
Subroutine
g0_rule_ids: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 1058 | 1 | return $slg->rule_ids('L0'); | |||||||||||||||||||
| 1059 | } | ||||||||||||||||||||
| 1060 | |||||||||||||||||||||
| 1061 | sub Marpa::R2::Scanless::G::g0_rule { | ||||||||||||||||||||
| 1062 | 17 | ▶ | my ( $slg, @args ) = @_; | ||||||||||||||||||
|
Subroutine
g0_rule: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 1063 | 17 | return $slg->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS]->[0] | |||||||||||||||||||
| 1064 | ->rule(@args); | ||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||
| 1066 | |||||||||||||||||||||
| 1067 | # Internal methods, not to be documented | ||||||||||||||||||||
| 1068 | |||||||||||||||||||||
| 1069 | sub Marpa::R2::Scanless::G::thick_g1_grammar { | ||||||||||||||||||||
| 1070 | 0 | ▶ | my ($slg) = @_; | ||||||||||||||||||
|
Subroutine
thick_g1_grammar: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 1071 | 0 | return $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR]; | |||||||||||||||||||
| 1072 | } | ||||||||||||||||||||
| 1073 | |||||||||||||||||||||
| 1074 | sub Marpa::R2::Scanless::G::show_irls { | ||||||||||||||||||||
| 1075 | 2 | ▶ | my ($slg, $subgrammar) = @_; | ||||||||||||||||||
|
Subroutine
show_irls: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 1076 | 2 | return thick_subgrammar_by_name($slg, $subgrammar)->show_irls(); | |||||||||||||||||||
| 1077 | } | ||||||||||||||||||||
| 1078 | |||||||||||||||||||||
| 1079 | sub Marpa::R2::Scanless::G::show_isys { | ||||||||||||||||||||
| 1080 | 2 | ▶ | my ($slg, $subgrammar) = @_; | ||||||||||||||||||
|
Subroutine
show_isys: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 1081 | 2 | return thick_subgrammar_by_name($slg, $subgrammar)->show_isys(); | |||||||||||||||||||
| 1082 | } | ||||||||||||||||||||
| 1083 | |||||||||||||||||||||
| 1084 | 150 | 1; | |||||||||||||||||||
| 1085 | |||||||||||||||||||||
| 1086 | # vim: expandtab shiftwidth=4: | ||||||||||||||||||||