diff options
| author | Mel <mel@rnrd.eu> | 2025-06-14 00:15:41 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-06-14 00:15:41 +0200 |
| commit | 5f4f2c7c87053eeda22a32b0f944f39f27c1e522 (patch) | |
| tree | ce8496654e81c12f2bc6de553d24abd83c47c555 /boot | |
| parent | 4a49045f77b5be5d82e84c6e3e57721686ec5a0a (diff) | |
| download | catskill-5f4f2c7c87053eeda22a32b0f944f39f27c1e522.tar.zst catskill-5f4f2c7c87053eeda22a32b0f944f39f27c1e522.zip | |
Don't choke on \n followed by EOF
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot')
| -rw-r--r-- | boot/parse.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/boot/parse.c b/boot/parse.c index 6129950..54461fa 100644 --- a/boot/parse.c +++ b/boot/parse.c @@ -80,6 +80,12 @@ parser_new(struct Parser* p, struct Lexer* lexer) } bool +parser_reached_end(struct Parser* p) +{ + return p->lexer->eof; +} + +bool parser_lookahead_pop(struct Parser* p, struct Token* token) { struct Token head = p->lookahead[0]; @@ -994,6 +1000,7 @@ parser_statement(struct Parser* p, struct Parser_Error* error) // skip empty statements. while (token_ends_statement(&token)) { + if (parser_reached_end(p)) return nil; parser_next(p); token = parser_peek(p); } @@ -1037,8 +1044,10 @@ parser_do_your_thing(struct Parser* p, struct Parser_Error* error) struct Statement* head = nil; struct Statement* current = nil; - while (!p->lexer->eof) { + while (!parser_reached_end(p)) { struct Statement* next = CHECK_RETURN(parser_statement(p, error), struct Tree); + if (!next) break; // on eof + CHECK_RETURN(parser_end_statement(p, error), struct Tree); if (current) { |
