Change the way choices work again

This commit is contained in:
Dane Johnson 2021-12-17 15:42:47 -06:00
parent c23d2db949
commit a8155e885f

View File

@ -73,7 +73,7 @@ page_node_t *pages;
choice_t *make_choice();
void add_page(page_t*);
void add_choice(page_t*, choice_t*);
void add_choice(choicelist*, choice_t*);
page_t *emit_ending();
page_t *emit_goto(char*);
@ -85,6 +85,8 @@ union value {
page_t *page;
char *string;
choice_t *choice;
choicelist *choices;
int num;
};
#define YYSTYPE union value
@ -108,7 +110,7 @@ TextLine = < (!Newline .)* Newline > { $$.string = strndup(yytext, yyleng);
Footer = Ending { $$.page = emit_ending(); }
| g:Goto { $$.page = emit_goto(g.string); }
| Choice+ { $$.page = emit_ending(); }
| c:ChoiceList { $$.page = emit_choices(c.choices); }
;
Goto = 'GOTO' Spacing < i:Identifier > Newline
@ -117,7 +119,19 @@ Goto = 'GOTO' Spacing < i:Identifier > Newline
Ending = 'THE END' Newline;
Choice = { $$.choice = make_choice(); } [0-9]+ ')' Spacing < (!Redirect .)+ > Redirect;
ChoiceList = c:Choice l:ChoiceList { $$ = l; add_choice($$.choices, c.choice); }
| c:Choice { $$.choices = NULL; add_choice($$.choices, c.choice); }
Choice = b:Bullet f:Freetext r:Redirect
{
$$ = r;
$$.choice->option = b.num;
$$.choice->flavor = f.string;
};
Bullet = < [0-9]+ > ')' Spacing { $$.num = atoi(yytext); };
Freetext = < (!Redirect .)+ > { $$.string = strndup(yytext, yyleng); };
Redirect = StatCheck? Spacing '[' Identifier ']' Spacing StatChange? Newline;
@ -153,20 +167,19 @@ void add_page(page_t *page) {
}
}
void add_choice(page_t *page, choice_t* choice) {
assert(page != choice);
void add_choice(choicelist *choices, choice_t* choice) {
choicelist *mychoices = (choicelist *) malloc(sizeof(choicelist));
mychoices->choice = choice;
mychoices->next = NULL;
choicelist *curr = page->footer.choices;
choicelist *curr = choices;
choicelist *prev = NULL;
if (curr) {
for(; curr; prev = curr, curr = curr->next);
prev->next = mychoices;
} else {
page->footer.choices = mychoices;
choices = mychoices;
}
}