Permalink
Browse files

Changing null value logic: html tests fail

  • Loading branch information...
Jeffrey Kegler Jeffrey Kegler
Jeffrey Kegler authored and Jeffrey Kegler committed May 22, 2012
1 parent df4157d commit 92c88c4f88ee8c00b18ac8d259e17497260f7afc
Showing with 78 additions and 38 deletions.
  1. +33 −6 r2/lib/Marpa/R2/Value.pm
  2. +34 −17 r2/libmarpa/dev/marpa.w
  3. +9 −10 r2/t/rewrite.t
  4. +2 −5 r2/t/sequence.t
View
@@ -252,22 +252,41 @@ sub Marpa::R2::Internal::Recognizer::set_actions {
for ( my $lhs_id = 0; $lhs_id <= $#nullable_ruleids_by_lhs; $lhs_id++ )
{
my $ruleids = $nullable_ruleids_by_lhs[$lhs_id];
+ my $resolution_rule;
next LHS if not defined $ruleids;
my $rule_count = scalar @{$ruleids};
next LHS if $rule_count <= 0;
if ( $rule_count == 1 ) {
- my ( undef, $closure ) = @{ $rule_resolutions->[ $ruleids->[0] ] };
+ $resolution_rule = $ruleids->[0];
+ my ( $resolution_name, $closure ) =
+ @{ $rule_resolutions->[ $resolution_rule ] };
+ if ($trace_actions) {
+ my $lhs_name = $grammar->symbol_name($lhs_id);
+ say {$Marpa::R2::Internal::TRACE_FH}
+ qq{Nulled symbol "$lhs_name" },
+ qq{ resolved to "$resolution_name" from rule },
+ $grammar->brief_rule($resolution_rule);
+ }
$null_symbol_closures[$lhs_id] = $closure;
next LHS;
- }
+ } ## end if ( $rule_count == 1 )
my @empty_rules = grep { $grammar_c->rule_length($_) <= 0 } @{$ruleids};
if ( scalar @empty_rules ) {
- my ( undef, $closure ) =
- @{ $rule_resolutions->[ $empty_rules[0] ] };
+ $resolution_rule = $empty_rules[0];
+ my ( $resolution_name, $closure ) =
+ @{ $rule_resolutions->[ $resolution_rule ] };
+ if ($trace_actions) {
+ my $lhs_name = $grammar->symbol_name($lhs_id);
+ say {$Marpa::R2::Internal::TRACE_FH}
+ qq{Nulled symbol "$lhs_name" },
+ qq{ resolved to "$resolution_name" from rule },
+ $grammar->brief_rule($resolution_rule);
+ } ## end if ($trace_actions)
$null_symbol_closures[$lhs_id] = $closure;
next LHS;
} ## end if ( scalar @empty_rules )
- my ($first_resolution_name, @other_resolution_names) = map { $rule_resolutions->[$_]->[0] } @{$ruleids};
+ my ( $first_resolution_name, @other_resolution_names ) =
+ map { $rule_resolutions->[$_]->[0] } @{$ruleids};
if ( grep { $_ ne $first_resolution_name } @other_resolution_names ) {
my %seen = map { ( $_, 1 ); } $first_resolution_name,
@other_resolution_names;
@@ -279,7 +298,15 @@ sub Marpa::R2::Internal::Recognizer::set_actions {
qq{ Marpa needs there to be only one\n}
);
} ## end if ( grep { $_ ne $first_resolution_name } ...)
- my ( undef, $closure ) = @{ $rule_resolutions->[ $empty_rules[0] ] };
+ $resolution_rule = $empty_rules[0];
+ my ( $resolution_name, $closure ) = @{ $rule_resolutions->[ $resolution_rule ] };
+ if ($trace_actions) {
+ my $lhs_name = $grammar->symbol_name($lhs_id);
+ say {$Marpa::R2::Internal::TRACE_FH}
+ qq{Nulled symbol "$lhs_name" },
+ qq{ resolved to "$resolution_name" from rule },
+ $grammar->brief_rule($resolution_rule) ;
+ } ## end if ($trace_actions)
$null_symbol_closures[$lhs_id] = $closure;
} ## end for ( my $lhs_id = 0; $lhs_id <= $#nullable_ruleids_by_lhs...)
View
@@ -3012,24 +3012,36 @@ and productive.
for (xrl_id = 0; xrl_id < xrl_count; xrl_id++)
{
const XRL xrl = XRL_by_ID (xrl_id);
- int rh_ix;
- int is_nulling = 1;
- int is_nullable = 1;
- int is_productive = 1;
const XSYID lhs_id = LHS_ID_of_XRL (xrl);
const XSY lhs = XSY_by_ID (lhs_id);
XRL_is_Accessible (xrl) = XSY_is_Accessible (lhs);
- for (rh_ix = 0; rh_ix < Length_of_XRL (xrl); rh_ix++)
+ if (XRL_is_Sequence (xrl) && Minimum_of_XRL (xrl) <= 0)
{
- const XSYID rhs_id = RHS_ID_of_XRL (xrl, rh_ix);
- const XSY rh_xsy = XSY_by_ID(rhs_id);
- if (LIKELY(!XSY_is_Nulling (rh_xsy))) is_nulling = 0;
- if (LIKELY(!XSY_is_Nullable (rh_xsy))) is_nullable = 0;
- if (UNLIKELY(!XSY_is_Productive (rh_xsy))) is_productive = 0;
+ XRL_is_Nulling (xrl) = 0;
+ XRL_is_Nullable (xrl) = 1;
+ XRL_is_Productive (xrl) = 1;
+ continue;
}
- XRL_is_Nulling (xrl) = is_nulling;
- XRL_is_Nullable (xrl) = is_nullable;
- XRL_is_Productive (xrl) = is_productive;
+ {
+ int rh_ix;
+ int is_nulling = 1;
+ int is_nullable = 1;
+ int is_productive = 1;
+ for (rh_ix = 0; rh_ix < Length_of_XRL (xrl); rh_ix++)
+ {
+ const XSYID rhs_id = RHS_ID_of_XRL (xrl, rh_ix);
+ const XSY rh_xsy = XSY_by_ID (rhs_id);
+ if (LIKELY (!XSY_is_Nulling (rh_xsy)))
+ is_nulling = 0;
+ if (LIKELY (!XSY_is_Nullable (rh_xsy)))
+ is_nullable = 0;
+ if (UNLIKELY (!XSY_is_Productive (rh_xsy)))
+ is_productive = 0;
+ }
+ XRL_is_Nulling (xrl) = is_nulling;
+ XRL_is_Nullable (xrl) = is_nullable;
+ XRL_is_Productive (xrl) = is_productive;
+ }
}
}
@@ -11974,7 +11986,12 @@ struct marpa_value {
#define marpa_v_arg_n(v) \
((v)->t_arg_n)
#define marpa_v_result(v) marpa_v_arg_0(v)
-@ @d XSYID_of_V(val) ((val)->public.t_token_id)
+@
+{\bf To Do}: @^To Do@>
+|TOS_of_V| is misnamed. |Arg_N_of_V| is actually
+the top of stack.
+I need to straighten this out sometime.
+@d XSYID_of_V(val) ((val)->public.t_token_id)
@d RULEID_of_V(val) ((val)->public.t_rule_id)
@d Token_Value_of_V(val) ((val)->public.t_token_value)
@d Token_Type_of_V(val) ((val)->t_token_type)
@@ -12328,14 +12345,14 @@ Marpa_Step_Type marpa_v_step(Marpa_Value public_v)
@ @<Perform evaluation steps@> =
{
AND and_nodes;
- @<Unpack value objects@>@;
- @<Fail if fatal error@>@;
- and_nodes = ANDs_of_B(B_of_O(o));
/* flag to indicate whether the arguments of
a rule should be popped off the stack. Coming
into this loop that is always the case -- if
no rule was executed, this is a no-op. */
int pop_arguments = 1;
+ @<Unpack value objects@>@;
+ @<Fail if fatal error@>@;
+ and_nodes = ANDs_of_B(B_of_O(o));
if (NOOK_of_V(v) < 0) {
NOOK_of_V(v) = Size_of_TREE(t);
View
@@ -44,19 +44,18 @@ my $separated_sequence_rule = {
min => 1
};
-my $sequence_rule =
- { lhs => 'block', rhs => [qw/statements/], min => 0 },
- ; # semicolon to terminate rule
+our $null_parse = 'Null parse';
+
+my $sequence_rule = {
+ lhs => 'block',
+ rhs => [qw/statements/],
+ min => 0,
+ action => 'main::null_parse'
+};
my $grammar = Marpa::R2::Grammar->new(
{ start => 'block',
- symbols => {
- 'block' => {
- terminal => 1,
- null_value => 'Null parse'
- }
- },
- terminals => [qw(whitespace modifier expression comma)],
+ terminals => [qw(block whitespace modifier expression comma)],
rules => [
$chaf_rule,
$separated_sequence_rule,
View
@@ -30,12 +30,10 @@ use Marpa::R2;
## no critic (Subroutines::RequireArgUnpacking)
-our $null_string = q{};
-
sub default_action {
shift;
my $v_count = scalar @_;
- return q{} if $v_count <= 0;
+ return q{} if $v_count <= 0;
return $_[0] if $v_count == 1;
return '(' . join( q{;}, @_ ) . ')';
} ## end sub default_action
@@ -65,8 +63,7 @@ sub run_sequence_test {
@separation_args
},
],
- default_action => 'main::default_action',
- default_null_action => 'main::null_string',
+ default_action => 'main::default_action',
}
);

0 comments on commit 92c88c4

Please sign in to comment.