Permalink
Browse files

Changing null value logic: several tests fail

  • Loading branch information...
1 parent 11d22a5 commit 379d2f9e049a34f43f1ee2e556e8773e8dbbe22b Jeffrey Kegler committed May 22, 2012
View
@@ -57,8 +57,6 @@ BEGIN {
LHS_RANK
TERMINAL_RANK
NULL_VALUE { null value }
- WARN_IF_NO_NULL_VALUE { should have a null value -- warn
- if not }
END_OF_STRUCTURE
Marpa::R2::offset($structure);
} ## end BEGIN
@@ -99,7 +97,6 @@ BEGIN {
{ === Evaluator Fields === }
SYMBOL_HASH { hash to symbol ID by name of symbol }
- DEFAULT_NULL_ACTION { default value for nulled symbols }
DEFAULT_EMPTY_ACTION { default value for empty rules }
ACTION_OBJECT
INFINITE_ACTION
@@ -261,7 +258,6 @@ use constant GRAMMAR_OPTIONS => [
actions
infinite_action
default_action
- default_null_action
default_empty_action
default_rank
inaccessible_ok
@@ -370,12 +366,6 @@ sub Marpa::R2::Grammar::set {
$value;
}
- if ( exists $args->{'default_null_action'} ) {
- my $value = $args->{'default_null_action'};
- $grammar->[Marpa::R2::Internal::Grammar::DEFAULT_NULL_ACTION] =
- $value;
- }
-
if ( defined( my $value = $args->{'actions'} ) ) {
$grammar->[Marpa::R2::Internal::Grammar::ACTIONS] = $value;
}
@@ -659,27 +649,6 @@ sub Marpa::R2::Grammar::precompute {
} ## end for my $symbol ( @{ Marpa::R2::Grammar::unproductive_symbols...})
} ## end if ( $grammar->[Marpa::R2::Internal::Grammar::WARNINGS...])
- if ( $grammar->[Marpa::R2::Internal::Grammar::WARNINGS] ) {
- SYMBOL:
- for my $symbol (
- @{ $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS] } )
- {
-
- next SYMBOL
- if not $symbol
- ->[Marpa::R2::Internal::Symbol::WARN_IF_NO_NULL_VALUE];
-
- next SYMBOL
- if defined $symbol->[Marpa::R2::Internal::Symbol::NULL_VALUE];
-
- my $symbol_id = $symbol->[Marpa::R2::Internal::Symbol::ID];
- my $symbol_name = $grammar->symbol_name($symbol_id);
- say {$trace_fh}
- qq{Zero length sequence for symbol without null value: "$symbol_name"}
- or Marpa::R2::exception("Could not print: $ERRNO");
- } ## end for my $symbol ( @{ $grammar->[...]})
- } ## end if ( $grammar->[Marpa::R2::Internal::Grammar::WARNINGS...])
-
RULE: for my $rule_id ( 0 .. $grammar_c->rule_count() - 1 ) {
my $rule = $rules->[$rule_id];
$rule->[Marpa::R2::Internal::Rule::RANK] //= $default_rank;
@@ -978,16 +947,13 @@ sub assign_user_symbol {
PROPERTY: while ( my ( $property, $value ) = each %{$options} ) {
if (not $property ~~
- [qw(terminal rank lhs_rank terminal_rank null_value)] )
+ [qw(terminal rank lhs_rank terminal_rank )] )
{
Marpa::R2::exception(qq{Unknown symbol property "$property"});
}
if ( $property eq 'terminal' ) {
$grammar_c->symbol_is_terminal_set( $symbol_id, $value );
}
- if ( $property eq 'null_value' ) {
- $symbol->[Marpa::R2::Internal::Symbol::NULL_VALUE] = \$value;
- }
if ( $property eq 'terminal_rank' ) {
Marpa::R2::exception(
qq{Symbol "$name": terminal_rank must be an integer})
@@ -1227,13 +1193,6 @@ sub add_user_rule {
Marpa::R2::exception('Only one rhs symbol allowed for counted rule')
if scalar @{$rhs_names} != 1;
- # For a zero-length sequence
- # with an action
- # warn if we don't also have a null value.
- if ( $min == 0 and $action ) {
- $lhs->[Marpa::R2::Internal::Symbol::WARN_IF_NO_NULL_VALUE] = 1;
- }
-
# create the separator symbol, if we're using one
my $separator;
my $separator_id = -1;
View
@@ -42,56 +42,6 @@ sub Marpa::R2::show_rank_ref {
package Marpa::R2::Internal::Value;
-sub Marpa::R2::Internal::Recognizer::set_null_values {
- my ($recce) = @_;
- my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR];
- my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C];
- my $trace_values =
- $recce->[Marpa::R2::Internal::Recognizer::TRACE_VALUES];
-
- my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES];
- my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS];
- my $default_null_action =
- $grammar->[Marpa::R2::Internal::Grammar::DEFAULT_NULL_ACTION];
- (undef, my $default_null_value_ref ) =
- @{Marpa::R2::Internal::Recognizer::resolve_semantics(
- $recce, $default_null_action )};
-
- my $null_values;
- $#{$null_values} = $#{$symbols};
-
- SYMBOL: for my $symbol ( @{$symbols} ) {
-
- my $symbol_id = $symbol->[Marpa::R2::Internal::Symbol::ID];
-
- next SYMBOL if not $grammar_c->symbol_is_nullable($symbol_id);
-
- my $null_value = undef;
- if ( $symbol->[Marpa::R2::Internal::Symbol::NULL_VALUE] ) {
- $null_value =
- $symbol->[Marpa::R2::Internal::Symbol::NULL_VALUE];
- }
- else {
- $null_value = $default_null_value_ref;
- }
- next SYMBOL if not defined $null_value;
-
- $null_values->[$symbol_id] = $null_value;
-
- if ($trace_values) {
- print {$Marpa::R2::Internal::TRACE_FH}
- 'Setting null value for symbol ',
- $grammar->symbol_name($symbol_id),
- ' to ', Data::Dumper->new( [ \$null_value ] )->Terse(1)->Dump
- or Marpa::R2::exception('Could not print to trace file');
- } ## end if ($trace_values)
-
- } ## end for my $symbol ( @{$symbols} )
-
- return $null_values;
-
-} # set_null_values
-
# Given the grammar and an action name, resolve it to a closure,
# or return undef
sub Marpa::R2::Internal::Recognizer::resolve_semantics {
@@ -333,6 +283,8 @@ sub Marpa::R2::Internal::Recognizer::set_actions {
$null_symbol_closures[$lhs_id] = $closure;
} ## end for ( my $lhs_id = 0; $lhs_id <= $#nullable_ruleids_by_lhs...)
+ $recce->[Marpa::R2::Internal::Recognizer::NULL_VALUES] = \@null_symbol_closures;
+
return 1;
} # set_actions
@@ -609,8 +561,6 @@ sub Marpa::R2::Recognizer::value {
else {
Marpa::R2::Internal::Recognizer::set_actions($recce);
- $recce->[Marpa::R2::Internal::Recognizer::NULL_VALUES] =
- Marpa::R2::Internal::Recognizer::set_null_values($recce);
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C] =
Marpa::R2::Internal::B_C->new( $recce_c,
@@ -926,7 +926,6 @@ sub Marpa::R2::Perl::new {
my $grammar = Marpa::R2::Grammar->new(
{ start => 'prog',
rules => \@rules,
- symbols => { listexpr => { null_value => undef } },
}
);
View
@@ -39,8 +39,6 @@ sub default_action {
## use critic
-our $nullstring = q{};
-
my $grammar = Marpa::R2::Grammar->new(
{ start => 'S',
rules => [
@@ -49,7 +47,6 @@ my $grammar = Marpa::R2::Grammar->new(
[ 'A', [qw/E/] ],
['E'],
],
- default_null_action => 'main::nullstring',
default_action => 'main::default_action',
}
);
View
@@ -39,8 +39,6 @@ sub default_action {
## use critic
-our $null_string = q{};
-
sub gen_grammar {
my ($null_ranking) = @_;
my $grammar = Marpa::R2::Grammar->new(
@@ -53,9 +51,7 @@ sub gen_grammar {
[ 'A', [qw/a/] ],
['A'],
],
- default_null_action => 'main::null_string',
default_action => 'main::default_action',
- symbols => { S => { null_value => '' }},
}
);
$grammar->set( { terminals => ['a'], } );
View
@@ -41,8 +41,6 @@ sub default_action {
## use critic
-our $null_string = q{};
-
my $grammar = Marpa::R2::Grammar->new(
{ start => 'S',
rules => [
@@ -51,7 +49,6 @@ my $grammar = Marpa::R2::Grammar->new(
[ 'A', [qw/E/] ],
['E'],
],
- default_null_action => 'main::null_string',
default_action => 'main::default_action',
}
);
View
@@ -37,8 +37,6 @@ sub default_action {
## use critic
-our $null_string = q{};
-
my $grammar = Marpa::R2::Grammar->new(
{ start => 'S',
rules => [
@@ -48,7 +46,6 @@ my $grammar = Marpa::R2::Grammar->new(
[ 'B', [] ],
[ 'C', [] ],
],
- default_null_action => 'main::null_string',
default_action => 'main::default_action',
}
);
View
@@ -27,6 +27,7 @@ use English qw( -no_match_vars );
use Marpa::R2;
our $default_null_desc = '[default null]',
+our $null_desc = '[null]',
my @features = qw(
e_op_action default_action
@@ -174,12 +175,11 @@ sub run_test {
[ 'F', [qw/Number/], $e_number_action, ],
[ 'optional_trailer1', [qw/trailer/], ],
[ 'optional_trailer1', [], ],
- [ 'optional_trailer2', [], ],
+ [ 'optional_trailer2', [], 'main::null_desc' ],
[ 'trailer', [qw/Text/], ],
],
default_action => $default_action,
- default_null_action => 'main::default_null_desc',
- symbols => { optional_trailer2 => { null_value => '[null]' } },
+ default_empty_action => 'main::default_null_desc',
terminals => [qw(Number AddOp MultOp Text)],
}
);
View
@@ -31,7 +31,7 @@ use Marpa::R2;
sub default_action {
shift;
my $v_count = scalar @_;
- return q{} if $v_count <= 0;
+ return q{-} if $v_count <= 0;
my @vals = map { $_ // q{-} } @_;
return $vals[0] if $v_count == 1;
return '(' . join( q{;}, @vals ) . ')';
View
@@ -32,7 +32,7 @@ use Marpa::R2;
sub default_action {
shift;
my $v_count = scalar @_;
- return q{} if $v_count <= 0;
+ return q{-} if $v_count <= 0;
my @vals = map { $_ // q{-} } @_;
return $vals[0] if $v_count == 1;
return '(' . join( q{;}, @vals ) . ')';
View
@@ -30,6 +30,7 @@ use Marpa::R2;
## no critic (Subroutines::RequireArgUnpacking)
sub default_action {
shift;
+ return undef if not scalar @_;
return join q{ }, grep { defined $_ } @_;
}
## use critic
@@ -44,11 +45,11 @@ $Test_Grammar::MARPA_OPTIONS_1 = [
{ 'default_action' => 'main::default_action',
'rules' => [
{ 'lhs' => 's',
- 'rhs' => [ 's' ]
+ 'rhs' => ['s']
}
],
'start' => 's',
- 'terminals' => [ 's' ],
+ 'terminals' => ['s'],
}
];
@@ -69,7 +70,6 @@ $Test_Grammar::MARPA_OPTIONS_2 = [
$Test_Grammar::MARPA_OPTIONS_8 = [
{ default_action => 'main::default_action',
- default_null_action => '::undef',
rules => [
{ 'lhs' => 'S',
'rhs' => [ 'A' ]
View
@@ -30,7 +30,7 @@ use Marpa::R2;
sub default_action {
shift;
my $v_count = scalar @_;
- return q{} if $v_count <= 0;
+ return q{-} if $v_count <= 0;
my @vals = map { $_ // q{-} } @_;
return $_[0] if scalar @vals == 1;
return '(' . join( q{;}, @vals ) . ')';
View
@@ -50,7 +50,7 @@ my $grammar = Marpa::R2::Grammar->new(
{ start => 'Input',
action_object => 'Maql_Actions',
default_action => 'tisk',
- default_null_action => '::undef',
+ default_empty_action => '::undef',
terminals => \@terminals,
rules => [
{ lhs => 'Input',
View
@@ -35,7 +35,7 @@ sub generate_action {
return sub {
shift;
my $v_count = scalar @_;
- return q{} if $v_count <= 0;
+ return q{-} if $v_count <= 0;
my @vals = map { $_ // q{-} } @_;
return $lhs . '(' . ( join q{;}, @vals ) . ')';
}
View
@@ -27,8 +27,6 @@ use Marpa::R2;
## no critic (Subroutines::RequireArgUnpacking)
-our $null_string = q{};
-
sub default_action {
shift;
my $v_count = scalar @_;
@@ -95,7 +93,6 @@ my $placebo = {
[ 'A', [qw/a/] ]
#>>>
],
- default_null_action => 'main::null_string',
default_action => 'main::default_action',
};
Oops, something went wrong.

0 comments on commit 379d2f9

Please sign in to comment.