diff options
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 45 |
1 files changed, 37 insertions, 8 deletions
@@ -1,24 +1,53 @@ #include "parse.h" #include <stdio.h> +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; +} |