diff options
Diffstat (limited to 'bootstrap')
| -rw-r--r-- | bootstrap/parsedecl.c | 8 | ||||
| -rw-r--r-- | bootstrap/parsestmt.c | 7 | ||||
| -rw-r--r-- | bootstrap/token.c | 1 | ||||
| -rw-r--r-- | bootstrap/token.h | 1 |
4 files changed, 11 insertions, 6 deletions
diff --git a/bootstrap/parsedecl.c b/bootstrap/parsedecl.c index 472c861..e2414e3 100644 --- a/bootstrap/parsedecl.c +++ b/bootstrap/parsedecl.c @@ -82,20 +82,16 @@ void parse_file(FILE *f, const char *basename) seen_defs = SEEN_FUNCS; parse_func(FK_FUNC); break; - case T_LowerIdent: + case T_KW_main: /* `main` can appear at the top level, and is a (mandatory) shorthand for the following: entry main code - */ - if (li.len != 4 || memcmp(li.string, "main", 4)) { - error_token("Unexpected word at top level", &li); - } seen_defs = SEEN_FUNCS; entryfunc_checks(); - func_start(li.string, li.len, FK_ENTRY); + func_start("main", 4, FK_ENTRY); current_func->is_modifying = true; current_funcparams = NULL; expect_next_line(); diff --git a/bootstrap/parsestmt.c b/bootstrap/parsestmt.c index dce754b..77e8a8c 100644 --- a/bootstrap/parsestmt.c +++ b/bootstrap/parsestmt.c @@ -318,6 +318,13 @@ static struct Stmt *parse_statement(enum Token t) s->u.expr = expr; } break; } + case T_KW_entry: + case T_KW_func: + case T_KW_main: + if (!tokenizer_line_is_indented()) { + error("Missing `end` before start of function"); + } + /* Fall through */ default: error("Unexpected token at start of statement"); } diff --git a/bootstrap/token.c b/bootstrap/token.c index 8557991..e1a46b4 100644 --- a/bootstrap/token.c +++ b/bootstrap/token.c @@ -245,6 +245,7 @@ static enum Token match_keyword(const char *ident, size_t len) CMP_KW(4, "from", T_KW_from) CMP_KW(4, "func", T_KW_func) CMP_KW(4, "long", T_KW_long) + CMP_KW(4, "main", T_KW_main) CMP_KW(4, "none", T_KW_none) CMP_KW(4, "sets", T_KW_sets) CMP_KW(4, "this", T_KW_this) diff --git a/bootstrap/token.h b/bootstrap/token.h index b18dfd5..4d43aa3 100644 --- a/bootstrap/token.h +++ b/bootstrap/token.h @@ -49,6 +49,7 @@ enum Token { T_KW_func, T_KW_constructor, T_KW_giveme, + T_KW_main, T_KW_ignore, T_KW_record, T_KW_templates, |
