Skip to content

Commit

Permalink
Working on AST: t+
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Kegler committed Mar 3, 2013
1 parent 506866e commit 8e5e005
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 59 deletions.
96 changes: 42 additions & 54 deletions r2/lib/Marpa/R2/Value.pm
Expand Up @@ -949,18 +949,16 @@ sub Marpa::R2::Internal::Recognizer::evaluate {

# After this point, any closure will be a ref to 'CODE'

if ( defined $lexeme_id and $semantics eq '::value') {
@ops = ( $op_result_is_token_value );
if ( defined $lexeme_id and $semantics eq '::value' ) {
@ops = ($op_result_is_token_value);
last SET_OPS;
}

PROCESS_SINGLETON_RESULT: {
last PROCESS_SINGLETON_RESULT if not defined $rule_id;

my $singleton;
if (
$semantics =~ m/\A [:][:] rhs (\d+) \z/xms )
{
if ( $semantics =~ m/\A [:][:] rhs (\d+) \z/xms ) {
$singleton = $1 + 0;
}

Expand Down Expand Up @@ -1013,62 +1011,52 @@ sub Marpa::R2::Internal::Recognizer::evaluate {
# if here, $array_fate is defined

my @bless_ops = ();
if ($blessing ne '::undef') {
if ( $blessing ne '::undef' ) {
my $constant_ix = $value->constant_register($blessing);
push @bless_ops, $op_bless, $constant_ix;
}

if ($is_sequence_rule) {
my $push_op =
$is_discard_sequence_rule
? $op_push_sequence
: $op_push_values;
@ops = ( $push_op, @bless_ops, $array_fate );
last SET_OPS;
} ## end if ($is_sequence_rule)

# temporary, while developing
# die "Semantics: $semantics" if ( substr $semantics, 0, 1 ) ne '[';
Marpa::R2::exception(qq{Unknown semantics: "$semantics"})
if ( substr $semantics, 0, 1 ) ne '[';

my @push_ops = ();
SET_PUSH_OPS: {
if ( ( substr $semantics, 0, 1 ) eq '[' ) {
my $array_descriptor = substr $semantics, 1, -1;
RESULT_DESCRIPTOR:
for my $result_descriptor ( split /[,]/xms,
$array_descriptor )
{
if ( $result_descriptor eq 'range' ) {
push @push_ops, $op_push_slr_range;
next RESULT_DESCRIPTOR;
}
if ( $result_descriptor eq 'values'
or $result_descriptor eq 'value' )
{
if ( defined $lexeme_id ) {
push @push_ops, $op_push_values;
next RESULT_DESCRIPTOR;
}
my $mask =
$rule->[Marpa::R2::Internal::Rule::MASK];
if ( $rule_length > 0 ) {
push @push_ops, map {
$mask->[$_]
? ( $op_push_one, $_ )
: ()
} 0 .. $rule_length - 1;
} ## end if ( $rule_length > 0 )
next RESULT_DESCRIPTOR;
} ## end if ( $result_descriptor eq 'values' or ...)
Marpa::R2::exception(
qq{Unknown result descriptor: "$result_descriptor"\n},
qq{ The full semantics were "$semantics"}
);
} ## end RESULT_DESCRIPTOR: for my $result_descriptor ( split /[,]/xms, ...)
} ## end if ( ( substr $semantics, 0, 1 ) eq '[' ) (])
} ## end SET_PUSH_OPS:

my $array_descriptor = substr $semantics, 1, -1;
RESULT_DESCRIPTOR:
for my $result_descriptor ( split /[,]/xms, $array_descriptor ) {
if ( $result_descriptor eq 'range' ) {
push @push_ops, $op_push_slr_range;
next RESULT_DESCRIPTOR;
}
if ( $result_descriptor eq 'values'
or $result_descriptor eq 'value' )
{
if ( defined $lexeme_id ) {
push @push_ops, $op_push_values;
next RESULT_DESCRIPTOR;
}
if ($is_sequence_rule) {
my $push_op =
$is_discard_sequence_rule
? $op_push_sequence
: $op_push_values;
push @push_ops, $push_op;
next RESULT_DESCRIPTOR;
} ## end if ($is_sequence_rule)
my $mask = $rule->[Marpa::R2::Internal::Rule::MASK];
if ( $rule_length > 0 ) {
push @push_ops,
map { $mask->[$_] ? ( $op_push_one, $_ ) : () }
0 .. $rule_length - 1;
}
next RESULT_DESCRIPTOR;
} ## end if ( $result_descriptor eq 'values' or ...)
Marpa::R2::exception(
qq{Unknown result descriptor: "$result_descriptor"\n},
qq{ The full semantics were "$semantics"}
);
} ## end RESULT_DESCRIPTOR: for my $result_descriptor ( split /[,]/xms, ...)
@ops = ( @push_ops, @bless_ops, $array_fate );

} ## end SET_OPS:

if ( defined $rule_id ) {
Expand Down
9 changes: 4 additions & 5 deletions r2/xs/R2.xs
Expand Up @@ -1555,8 +1555,7 @@ slr_locations (Scanless_R * slr, Marpa_Earley_Set_ID earley_set, int *p_start,
{
dTHX;
int result = 0;
/* We need to fake the values for Earley set 0,
* since we are using it to store the values for Earley set 1.
/* We fake the values for Earley set 0,
*/
if (earley_set <= 0)
{
Expand All @@ -1567,13 +1566,13 @@ slr_locations (Scanless_R * slr, Marpa_Earley_Set_ID earley_set, int *p_start,
{
void *end_pos;
result =
marpa_r_earley_set_values (slr->r1, earley_set, p_start,
&end_pos);
marpa_r_earley_set_values (slr->r1, earley_set, p_start, &end_pos);
*p_end = (int) PTR2IV (end_pos);
}
if (result < 0)
{
croak ("failure in slr->location(): %s", xs_g_error (slr->g1_wrapper));
croak ("failure in slr->location(%d): %s", earley_set,
xs_g_error (slr->g1_wrapper));
}
}

Expand Down

0 comments on commit 8e5e005

Please sign in to comment.