Skip to content
Browse files

Changing null value logic: several tests fail

  • Loading branch information...
1 parent e501cb3 commit 76ec9a40507b0302bfacf907b814f5711876947d Jeffrey Kegler committed May 21, 2012
Showing with 24 additions and 3 deletions.
  1. +8 −0 r2/lib/Marpa/R2/Grammar.pm
  2. +16 −3 r2/lib/Marpa/R2/Value.pm
View
8 r2/lib/Marpa/R2/Grammar.pm
@@ -100,6 +100,7 @@ BEGIN {
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,6 +262,7 @@ use constant GRAMMAR_OPTIONS => [
infinite_action
default_action
default_null_action
+ default_empty_action
default_rank
inaccessible_ok
rule_name_required
@@ -362,6 +364,12 @@ sub Marpa::R2::Grammar::set {
add_user_rules( $grammar, $value );
} ## end if ( defined( my $value = $args->{'rules'} ) )
+ if ( exists $args->{'default_empty_action'} ) {
+ my $value = $args->{'default_empty_action'};
+ $grammar->[Marpa::R2::Internal::Grammar::DEFAULT_EMPTY_ACTION] =
+ $value;
+ }
+
if ( exists $args->{'default_null_action'} ) {
my $value = $args->{'default_null_action'};
$grammar->[Marpa::R2::Internal::Grammar::DEFAULT_NULL_ACTION] =
View
19 r2/lib/Marpa/R2/Value.pm
@@ -191,18 +191,27 @@ sub Marpa::R2::Internal::Recognizer::set_actions {
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C];
my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES];
my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS];
+
my $default_action =
$grammar->[Marpa::R2::Internal::Grammar::DEFAULT_ACTION];
-
- my $rule_resolutions = [];
-
my $default_action_resolution =
Marpa::R2::Internal::Recognizer::resolve_semantics( $recce,
$default_action );
Marpa::R2::exception(
"Could not resolve default action named '$default_action'")
if not $default_action_resolution;
+ my $default_empty_action =
+ $grammar->[Marpa::R2::Internal::Grammar::DEFAULT_EMPTY_ACTION];
+ my $default_empty_action_resolution =
+ Marpa::R2::Internal::Recognizer::resolve_semantics( $recce,
+ $default_empty_action );
+ Marpa::R2::exception(
+ "Could not resolve default empty rule action named '$default_empty_action'")
+ if not $default_empty_action_resolution;
+
+ my $rule_resolutions = [];
+
RULE: for my $rule ( @{$rules} ) {
my $rule_id = $rule->[Marpa::R2::Internal::Rule::ID];
@@ -235,6 +244,10 @@ sub Marpa::R2::Internal::Recognizer::set_actions {
next RULE;
} ## end FIND_CLOSURE_BY_LHS:
+ if ($default_empty_action_resolution and $grammar_c->rule_length($rule_id) == 0) {
+ $rule_resolutions->[$rule_id] = $default_empty_action_resolution;
+ }
+
$rule_resolutions->[$rule_id] = $default_action_resolution;
} ## end for my $rule ( @{$rules} )

0 comments on commit 76ec9a4

Please sign in to comment.
Something went wrong with that request. Please try again.