Skip to content

Commit

Permalink
Handle END or past-end cases for ?? in PARSE
Browse files Browse the repository at this point in the history
The ?? debugging command in PARSE shows the current rule and
the current position in the data.  Both of these could be at the end of
series, which are not currently legal to pass to the molding of values.
This adds very basic handling for the end conditions in custom print
messages for those cases.
  • Loading branch information
hostilefork committed Dec 16, 2015
1 parent 9a0bffe commit 6e5a9ec
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/core/u-parse.c
Expand Up @@ -64,12 +64,34 @@ enum parse_flags {

static REBCNT Parse_Rules_Loop(REBPARSE *parse, REBCNT index, const REBVAL *rules, REBCNT depth);

void Print_Parse_Index(enum Reb_Kind type, const REBVAL *rules, REBSER *series, REBCNT index)
{
REBVAL val;
Val_Init_Series(&val, type, series);
VAL_INDEX(&val) = index;
Debug_Fmt("%r: %r", rules, &val);
void Print_Parse_Index(
enum Reb_Kind type,
const REBVAL rule[], // positioned at the current rule
REBSER *series,
REBCNT index
) {
REBVAL item;
Val_Init_Series(&item, type, series);
VAL_INDEX(&item) = index;

// Either the rules or the data could be positioned at the end. The
// data might even be past the end.
//
// !!! Or does PARSE adjust to ensure it never is past the end, e.g.
// when seeking a position given in a variable or modifying?
//
if (IS_END(rule)) {
if (index >= SERIES_LEN(series))
Debug_Fmt("[]: ** END **");
else
Debug_Fmt("[]: %r", &item);
}
else {
if (index >= SERIES_LEN(series))
Debug_Fmt("%r: ** END **", rule);
else
Debug_Fmt("%r: %r", rule, &item);
}
}


Expand Down

0 comments on commit 6e5a9ec

Please sign in to comment.