Got rid of non-determinism.

This commit is contained in:
Neil 2022-02-14 22:34:45 -08:00
parent 2c8475ff9c
commit 4fdb66076a
1 changed files with 9 additions and 5 deletions

View File

@ -79,9 +79,9 @@ static struct scan {
size_t line;
int is_ws_expected, is_source;
#define X(n) EXPECT_ ## n
/* "[something: expect; there; to; be; args]", in this case, `size = 5` and
expect would be 5 `EXPECT_KEYWORD`. */
struct { unsigned size; enum { EXPECT } expect[20]; } command;
/* "[something: expect; there; to; be; args]", in this case, expect would
be a stack of `size = 5` `EXPECT_KEYWORD`. */
struct { unsigned size; enum { EXPECT } expect[16]; } command;
#undef X
} scan; /* Terrible, gah. */
@ -118,9 +118,11 @@ id = [a-zA-Z_][a-zA-Z_\-0-9]{0,63};
date = "-"? natural "-" [0-1][0-9] "-" [0-1][0-9];
*/
/** I don't think `re2c` supports branching on variable conditions.
It does now? */
static void expect_pop(void) {
printf("<expect_pop>");
if(!scan.command.size) { printf("nostack\n"); scan.condition = yyccommand_end; return; }
if(!scan.command.size) { printf("allfinished\n"); scan.condition = yyccommand_end; return; }
switch(scan.command.expect[--scan.command.size]) {
case EXPECT_KEYWORD: printf("keyword\n");scan.condition = yyccommand_keyword; break;
case EXPECT_DATE: printf("date\n");scan.condition = yyccommand_date; break;
@ -209,7 +211,9 @@ scan:
<command_date> ws* @s0 date @s1 ws* ";"? / "]"?
{ x->s0 = s0, x->s1 = s1; expect_pop();
return x->symbol = ARG_DATE, 1; }
<command_freeform> ws* @s0 [^\t\n\r\v\f;[\]\x00]* @s1 ws* ";"? / "]"?
<command_freeform> ws* @s0
[^ \t\n\r\v\f;[\]\x00][^\t\n\r\v\f;[\]\x00]*[^ \t\n\r\v\f;[\]\x00]*
@s1 ws* ";"? / "]"?
{ x->s0 = s0, x->s1 = s1; expect_pop();
return x->symbol = ARG_FREEFORM, 1; }
<command, command_end> "]" => text