From 8c729d52182ba1fe05c009be4e8b26db2b15bece Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Fri, 17 Dec 2021 17:01:51 -0600 Subject: [PATCH] Choices as vector pointer (getting close!...) --- cyoa.leg | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cyoa.leg b/cyoa.leg index e1623fc..4e47ca0 100644 --- a/cyoa.leg +++ b/cyoa.leg @@ -44,7 +44,7 @@ enum class FooterType { struct Footer { FooterType type; union { - std::vector choices; + std::vector *choices; char *link; }; @@ -65,7 +65,7 @@ std::vector pages; Page *emit_ending(); Page *emit_goto(char*); -Page *emit_choices(); +Page *emit_choices(std::vector*); void append_body(Page *page, char *str); @@ -100,7 +100,7 @@ TextLine = < (!Newline .)* Newline > { $$.string = strndup(yytext, yyleng); Footer = Ending { $$.page = emit_ending(); } | g:Goto { $$.page = emit_goto(g.string); } - | c:ChoiceList { $$.page = emit_choices(); } + | c:ChoiceList { $$.page = emit_choices(c.choices); } ; Goto = 'GOTO' Spacing < i:Identifier > Newline @@ -187,10 +187,10 @@ Page *emit_ending() { return mypage; } -Page *emit_choices() { +Page *emit_choices(std::vector *choices) { Page *mypage = new Page; mypage->footer.type = FooterType::Choices; - printf("page 0x%x\n", mypage); + mypage->footer.choices = choices; return mypage; } @@ -218,7 +218,9 @@ void print_page(Page *page) { break; case FooterType::Choices: printf("CHOICES:\n"); - break; + for (Choice *c : *page->footer.choices) { + printf("%d) %s\n", c->option, c->flavor); + } } }