Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changing null value logic: several tests fail

  • Loading branch information...
commit 379d2f9e049a34f43f1ee2e556e8773e8dbbe22b 1 parent 11d22a5
Jeffrey Kegler authored
View
43 r2/lib/Marpa/R2/Grammar.pm
@@ -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
54 r2/lib/Marpa/R2/Value.pm
@@ -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,
View
1  r2/pperl/Marpa/R2/Perl.pm
@@ -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
3  r2/t/ah2.t
@@ -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
4 r2/t/ah_numeric.t
@@ -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
3  r2/t/bocage.t
@@ -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
3  r2/t/chaf.t
@@ -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
6 r2/t/code_diag.t
@@ -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
2  r2/t/duplicate_parse.t
@@ -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
2  r2/t/final_nonnullable.t
@@ -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
6 r2/t/infinite.t
@@ -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
2  r2/t/initial_nulls.t
@@ -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
2  r2/t/jirotka.t
@@ -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
2  r2/t/leo.t
@@ -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
3  r2/t/limits.t
@@ -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',
};
View
30 r2/t/null_example.t
@@ -63,30 +63,32 @@ sub S {
return 'S(' . ( join q{;}, map { $_ // '[ERROR!]' } @_ ) . ')';
}
+sub X { return $_[1]; }
+sub Y { return $_[1]; }
+
+our $null_A = 'null A';
+our $null_B = 'null B';
+our $null_L = 'null L';
+our $null_R = 'null R';
+our $null_X = 'null X';
+our $null_Y = 'null Y';
+
my $grammar = Marpa::R2::Grammar->new(
{ start => 'S',
actions => 'main',
rules => [
[ 'S', [qw/L R/] ],
[ 'L', [qw/A B X/] ],
- [ 'L', [] ],
+ [ 'L', [], 'null_L' ],
[ 'R', [qw/A B Y/] ],
- [ 'R', [] ],
- [ 'A', [] ],
- [ 'B', [] ],
- [ 'X', [] ],
+ [ 'R', [], 'null_R' ],
+ [ 'A', [], 'null_A' ],
+ [ 'B', [], 'null_B' ],
+ [ 'X', [], 'null_X' ],
[ 'X', [qw/x/] ],
- [ 'Y', [] ],
+ [ 'Y', [], 'null_Y' ],
[ 'Y', [qw/y/] ],
],
- symbols => {
- L => { null_value => 'null L' },
- R => { null_value => 'null R' },
- A => { null_value => 'null A' },
- B => { null_value => 'null B' },
- X => { null_value => 'null X' },
- Y => { null_value => 'null Y' },
- },
}
);
View
2  r2/t/null_infinite1.t
@@ -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 '(' . join( q{;}, @vals ) . ')';
} ## end sub default_action
View
13 r2/t/null_infinite4.t
@@ -27,13 +27,7 @@ use Marpa::R2;
## no critic (Subroutines::RequireArgUnpacking)
-sub default_action {
- shift;
- my $v_count = scalar @_;
- return q{} if $v_count <= 0;
- my @vals = map { $_ // q{-} } @_;
- return '(' . join( q{;}, @vals ) . ')';
-} ## end sub default_action
+our $dash = q{-};
sub rule_n {
shift;
@@ -61,13 +55,12 @@ my $grammar = Marpa::R2::Grammar->new(
action => 'main::start_rule'
},
{ lhs => 'n', rhs => ['a'], action => 'main::rule_n' },
- { lhs => 'n', rhs => [] },
+ { lhs => 'n', rhs => [], action => 'main::dash' },
{ lhs => 'f', rhs => ['a'], action => 'main::rule_f' },
- { lhs => 'f', rhs => [] },
+ { lhs => 'f', rhs => [], action => 'main::dash' },
{ lhs => 'f', rhs => ['S'], action => 'main::rule_f' },
],
symbols => { a => { terminal => 1 }, },
- default_action => 'main::default_action',
}
);
View
24 r2/t/null_value.t
@@ -50,20 +50,21 @@ $Test_Grammar::MARPA_OPTIONS = [
'lhs' => 's',
'rhs' => [ 'a', 'y' ]
},
- { 'lhs' => 'a',
- 'rhs' => [],
- action => '::undef',
+ { 'lhs' => 'a',
+ 'rhs' => [],
+ action => 'rule1',
},
{ 'action' => 'rule2',
'lhs' => 'a',
'rhs' => [ 'b', 'c' ]
},
- { 'lhs' => 'b',
- 'rhs' => []
+ { 'lhs' => 'b',
+ 'rhs' => [],
+ action => 'rule3'
},
- { 'lhs' => 'c',
- 'rhs' => [],
- action => '::undef',
+ { 'lhs' => 'c',
+ 'rhs' => [],
+ action => 'rule4'
},
{ 'action' => 'rule5',
'lhs' => 'c',
@@ -74,12 +75,7 @@ $Test_Grammar::MARPA_OPTIONS = [
'rhs' => ['Z']
}
],
- 'start' => 's',
- symbols => {
- a => { null_value => 'A is missing' },
- b => { null_value => 'B is missing' },
- c => { null_value => 'C is missing' },
- },
+ 'start' => 's',
'terminals' => ['Z'],
'action_object' => 'Test'
}
View
5 r2/t/perl.t
@@ -430,9 +430,12 @@ sub gen_closure {
my $closure = $unwrapped{$action};
die "lhs=$lhs: $closure is not a closure"
if defined $closure and ref $closure ne 'CODE';
+ if (not defined $closure and scalar @{$rhs} <= 0) {
+ $closure = sub { undef; }
+ }
return sub {
if ( not defined $closure ) {
- die 'No action defined for ',
+ die qq{No action ("$action") defined for },
"$lhs ::= " . ( join q{ }, map { $_ // q{-} } @{$rhs} );
}
my $v = $closure->(@_);
View
8 r2/t/randal.t
@@ -36,7 +36,6 @@ package Test_Grammar;
$Test_Grammar::MARPA_OPTIONS = [
{
- default_null_action => '::undef',
default_empty_action => '::undef',
'rules' => [
{
@@ -184,8 +183,7 @@ $g->precompute();
TEST: for my $test_data (@test_data) {
my ( $test_name, $test_input, $test_results ) = @{$test_data};
- my $recce =
- Marpa::R2::Recognizer->new( { grammar => $g } );
+ my $recce = Marpa::R2::Recognizer->new( { grammar => $g } );
my $input_length = length $test_input;
pos $test_input = 0;
@@ -205,8 +203,8 @@ TEST: for my $test_data (@test_data) {
if not $test_input =~ m{ \G \s* (?<match>$regex) }xgms;
## no critic (Variables::ProhibitPunctuationVars)
- $recce->alternative(
- $token, $+{match}, ( ( pos $test_input ) - $pos ) );
+ $recce->alternative( $token, $+{match},
+ ( ( pos $test_input ) - $pos ) );
} ## end while ( my ( $token, $regex ) = each %regexes )
$recce->earleme_complete();
View
4 r2/t/use.t
@@ -77,7 +77,7 @@ my %closure_by_lhs = (
ary => \&concat,
lineseq => sub {
shift @_;
- join "\n", grep {defined} @_;
+ join "\n", grep { defined and length } @_;
},
);
@@ -86,6 +86,8 @@ sub gen_closure {
my $closure = $closure_by_action{$action} // $closure_by_lhs{$lhs};
return $closure if defined $closure and ref $closure eq 'CODE';
die "lhs=$lhs: $closure is not a closure" if defined $closure;
+ return sub {undef}
+ if scalar @{$rhs} == 0;
return sub { $_[1] }
if scalar @{$rhs} == 1;
return sub {
Please sign in to comment.
Something went wrong with that request. Please try again.