From a697219713b24ca6efe7e934d16564395692297c Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sun, 5 Apr 2020 14:30:55 -0400 Subject: no #force with unnamed include --- main.c | 1 - parse.c | 10 +++++++++- test.toc | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index caf8d61..a644ae4 100644 --- a/main.c +++ b/main.c @@ -16,7 +16,6 @@ use for accessing struct members (and other things, potentially) with struct["member"], just replace e with a BINARY_DOT local structs should not be named in C -for some reason forgetting a ; after #include causes a misleading unrecognized expression simplify eval macros with val_to_u/i64 &&, || start making a standard library... (printf; stringbuilder would be nice to have) diff --git a/parse.c b/parse.c index bd25189..f5699bf 100644 --- a/parse.c +++ b/parse.c @@ -2422,8 +2422,10 @@ static Status parse_stmt(Parser *p, Statement *s, bool *was_a_statement) { i->flags |= INC_FORCED; ++t->token; } - if (!parse_expr(p, &i->filename, expr_find_end(p, EXPR_CAN_END_WITH_COMMA))) + if (!parse_expr(p, &i->filename, expr_find_end(p, EXPR_CAN_END_WITH_COMMA))) { + tokr_skip_semicolon(t); return false; + } if (token_is_kw(t->token, KW_COMMA)) { Expression filename = i->filename; ++t->token; @@ -2466,6 +2468,12 @@ static Status parse_stmt(Parser *p, Statement *s, bool *was_a_statement) { inc_stmt->where = s->where; inc_stmt->inc = parser_calloc(p, 1, sizeof *inc_stmt->inc); inc_stmt->inc->filename = filename; + } else if (i->flags & INC_FORCED) { + /* go back to #forced */ + while (!token_is_direct(t->token, DIRECT_FORCE)) --t->token; + err_print(token_location(p->file, t->token), "You don't need to specify #force if you're not including into a namespace (this is the default behaviour)."); + tokr_skip_semicolon(t); + return false; } if (!token_is_kw(t->token, KW_SEMICOLON)) { tokr_err(t, "Expected ; after #include directive"); diff --git a/test.toc b/test.toc index a233fed..f08f2d6 100644 --- a/test.toc +++ b/test.toc @@ -1,3 +1,4 @@ + #include "std/io.toc"; Point ::= struct { -- cgit v1.2.3