Skip to content

Commit

Permalink
Changing null value logic: many tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Kegler authored and Jeffrey Kegler committed May 21, 2012
1 parent e5d20a8 commit 173e974
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
12 changes: 5 additions & 7 deletions r2/lib/Marpa/R2/Grammar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ BEGIN {
{ === Evaluator Fields === }
SYMBOL_HASH { hash to symbol ID by name of symbol }
DEFAULT_NULL_VALUE { default value for nulled symbols }
DEFAULT_NULL_ACTION { default value for nulled symbols }
ACTION_OBJECT
INFINITE_ACTION
Expand Down Expand Up @@ -260,7 +260,7 @@ use constant GRAMMAR_OPTIONS => [
actions
infinite_action
default_action
default_null_value
default_null_action
default_rank
inaccessible_ok
rule_name_required
Expand Down Expand Up @@ -362,11 +362,9 @@ sub Marpa::R2::Grammar::set {
add_user_rules( $grammar, $value );
} ## end if ( defined( my $value = $args->{'rules'} ) )

if ( exists $args->{'default_null_value'} ) {
my $value = $args->{'default_null_value'};
Marpa::R2::exception('default_null_value must be undefined or a reference')
if defined $value and not ref $value;
$grammar->[Marpa::R2::Internal::Grammar::DEFAULT_NULL_VALUE] =
if ( exists $args->{'default_null_action'} ) {
my $value = $args->{'default_null_action'};
$grammar->[Marpa::R2::Internal::Grammar::DEFAULT_NULL_ACTION] =
$value;
}

Expand Down
36 changes: 25 additions & 11 deletions r2/lib/Marpa/R2/Value.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ sub Marpa::R2::Internal::Recognizer::set_null_values {

my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES];
my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS];
my $default_null_value =
$grammar->[Marpa::R2::Internal::Grammar::DEFAULT_NULL_VALUE];
my $default_null_action =
$grammar->[Marpa::R2::Internal::Grammar::DEFAULT_NULL_ACTION];
my $default_null_value_ref;
if ( defined $default_null_action ) {
$default_null_value_ref =
Marpa::R2::Internal::Recognizer::resolve_semantics( $recce,
$default_null_action );
}

my $null_values;
$#{$null_values} = $#{$symbols};
Expand All @@ -69,7 +75,7 @@ sub Marpa::R2::Internal::Recognizer::set_null_values {
$symbol->[Marpa::R2::Internal::Symbol::NULL_VALUE];
}
else {
$null_value = $default_null_value;
$null_value = $default_null_value_ref;
}
next SYMBOL if not defined $null_value;

Expand Down Expand Up @@ -140,16 +146,27 @@ sub Marpa::R2::Internal::Recognizer::resolve_semantics {

return if not defined $fully_qualified_name;

no strict 'refs';
my $closure = *{$fully_qualified_name}{'CODE'};
use strict 'refs';
my $closure;
my $resolved_type;
TYPE: for my $type (qw(CODE REF SCALAR)) {
no strict 'refs';
$resolved_type = $type;
$closure = *{$fully_qualified_name}{$resolved_type};
last TYPE if defined $closure;
}

if ($trace_actions) {
if (defined $resolved_type) {
print {$Marpa::R2::Internal::TRACE_FH}
( $closure ? 'Successful' : 'Failed' )
. qq{ resolution of "$closure_name" },
qq{Successful resolution of "$closure_name" as $resolved_type },
'to ', $fully_qualified_name, "\n"
or Marpa::R2::exception('Could not print to trace file');
} else {
print {$Marpa::R2::Internal::TRACE_FH}
qq{'Failed resolution of "$closure_name" },
'to ', $fully_qualified_name, "\n"
or Marpa::R2::exception('Could not print to trace file');
}
} ## end if ($trace_actions)

return $closure;
Expand Down Expand Up @@ -491,9 +508,6 @@ sub Marpa::R2::Recognizer::value {
} ## end if ($tree)
else {

# Perhaps this call should be moved.
# The null values are currently a function of the grammar,
# and should be constant for the life of a recognizer.
$recce->[Marpa::R2::Internal::Recognizer::NULL_VALUES] //=
Marpa::R2::Internal::Recognizer::set_null_values($recce);
Marpa::R2::Internal::Recognizer::set_actions($recce);
Expand Down
5 changes: 4 additions & 1 deletion r2/t/ah2.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ sub default_action {

## use critic

our $nullstring;
$main::nullstring = q{};

my $grammar = Marpa::R2::Grammar->new(
{ start => 'S',
rules => [
Expand All @@ -47,7 +50,7 @@ my $grammar = Marpa::R2::Grammar->new(
[ 'A', [qw/E/] ],
['E'],
],
default_null_value => \q{},
default_null_action => 'main::nullstring',
default_action => 'main::default_action',
}
);
Expand Down

0 comments on commit 173e974

Please sign in to comment.