Finish up the cli driver

This commit is contained in:
Dane Johnson 2022-01-02 17:50:40 -06:00
parent 67aebee24d
commit ae1266ccc9
4 changed files with 31 additions and 21 deletions

View File

@ -96,3 +96,20 @@ I'm getting pretty frustrated with what I perceive to be bugs in the peg/leg par
I don't really feel like maintaining it. And GNU Bison is like right there. If I can write a cfg for my little language I don't really feel like maintaining it. And GNU Bison is like right there. If I can write a cfg for my little language
here I'll switch. I also can't shake the feeling that this is over-engineered, and I really don't need a parser for all this, but here I'll switch. I also can't shake the feeling that this is over-engineered, and I really don't need a parser for all this, but
oh well. I could probably do it all with just lex actually. Maybe I need to spend some time rethinking this. oh well. I could probably do it all with just lex actually. Maybe I need to spend some time rethinking this.
1/2/22
Okay I decided to just power through, and I finished the CLI version, which I'll be committing with this update. I did write a CFG
however I realized that since this isn't a programming language an LR parser isn't exactly right. I made the right choice with the
PEG, I just need better tooling. Anyway the immediate problem that I was having was that I assumed that semantic actions following
an optional term in leg would be run with a null pointer or not be run at all, but it turns out you need to wrap the semantic
action in the optional as well. Oh well lesson learned. Maybe some day I'll write my own.
Next up is definitely the Godot Native module. I've already read a bit about how to do it, but I know there will be a few hitches
here and there. Also I want to convert the base module to use entirely c++ semantics, with the exception of printf since I'm not
sure if there is a c++ parallel, which is a bit odd. C++ is weird, no wonder I've avoided using it until now. It seems like c++
developers spend a lot of time coming up with new ways to do things, then declaring them unidomatic and banning them. I guess
that's kind of a trend with higher level languages as they get older cough Java cough. Regardless, I need to learn it and this
is as good of a project as any.
Also I still haven't mentioned to Pam I was doing this. Hope that's not a problem...

View File

@ -153,22 +153,6 @@ void append_body(Page *page, char *str) {
} }
} }
void print_page(Page *page) {
printf("HEADER: %s\nBODY: %s\n", page->id, page->body);
switch (page->footer.type) {
case FooterType::End:
printf("THE END\n");
break;
case FooterType::Goto:
printf("GOTO %s\n", page->footer.link);
break;
case FooterType::Choices:
printf("CHOICES:\n");
// TODO
break;
}
}
std::vector<Page*> CyoaParse(FILE *file) { std::vector<Page*> CyoaParse(FILE *file) {
yyin = file; yyin = file;
yyparse(); yyparse();

View File

@ -56,10 +56,9 @@ void Storybook::Advance() {
} }
} }
void Storybook::Advance(int choice_option) { void Storybook::Advance(int choice_option) {
// TODO throw an exception if the ending type is not choices.
if (!IsChoiceAvailable(choice_option)) { if (!IsChoiceAvailable(choice_option)) {
// TODO throw exception? throw IllegalChoiceException();
} }
Choice* choice = (*current->footer.choices)[choice_option]; Choice* choice = (*current->footer.choices)[choice_option];
@ -122,9 +121,13 @@ void Storybook::Play() {
printf("Make a selection: "); printf("Make a selection: ");
int choice_option; int choice_option;
std::cin >> choice_option; std::cin >> choice_option;
Advance(choice_option); try {
Advance(choice_option);
} catch (IllegalChoiceException e) {
printf("You can't do that!\n\n");
}
break; break;
default: default:
IsEnded = true; // TODO IsEnded = true;
} }
} }

View File

@ -31,6 +31,12 @@ public:
// This will probably be moved to the cli driver // This will probably be moved to the cli driver
void Play(); void Play();
class IllegalChoiceException : std::exception {
virtual const char *what() const noexcept {
return "Illegal Choice.";
}
};
}; };
#endif /* STORYBOOK_H */ #endif /* STORYBOOK_H */