From a560cc2aef70616ec16259acbaa6c02f03bc8874 Mon Sep 17 00:00:00 2001 From: kdx Date: Fri, 20 Jan 2023 05:18:22 +0100 Subject: organize --- parse.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/parse.c b/parse.c index 609e8a6..ba1644f 100644 --- a/parse.c +++ b/parse.c @@ -1,24 +1,53 @@ #include "parse.h" #include +static void unexpected(const Token *tok); +static const Token *keyword_fn(const Token *tok); +static const Token *keyword_var(const Token *tok); +static const Token *keyword_const(const Token *tok); + int parse(const Token *tok) { - while (tok->type != TOK_NONE) { + while (tok != NULL && tok->type != TOK_NONE) { switch (tok->type) { case TOK_KW_FN: + tok = keyword_fn(tok + 1); + break; case TOK_KW_VAR: + tok = keyword_var(tok + 1); + break; case TOK_KW_CONST: + tok = keyword_const(tok + 1); break; default: - fprintf(stderr, "unexpected %s %s%s%sat %u:%u\n", - token_type_str(tok->type), - (tok->s != NULL) ? "(" : "", - (tok->s != NULL) ? tok->s : "", - (tok->s != NULL) ? ") " : "", - tok->line, tok->column); + unexpected(tok); return 1; } - tok += 1; } return 0; } + +static void unexpected(const Token *tok) +{ + fprintf(stderr, "unexpected %s %s%s%sat %u:%u\n", + token_type_str(tok->type), + (tok->s != NULL) ? "(" : "", + (tok->s != NULL) ? tok->s : "", + (tok->s != NULL) ? ") " : "", + tok->line, tok->column); +} + +static const Token *keyword_fn(const Token *tok) +{ + return tok; +} + +static const Token *keyword_var(const Token *tok) +{ + return tok; +} + +static const Token *keyword_const(const Token *tok) +{ + return tok; +} -- cgit v1.2.3