diff options
author | kdx <kdx@42l.fr> | 2023-01-20 05:18:22 +0100 |
---|---|---|
committer | kdx <kdx@42l.fr> | 2023-01-20 05:19:26 +0100 |
commit | a560cc2aef70616ec16259acbaa6c02f03bc8874 (patch) | |
tree | 0906b82da4cee9a93787b94b644f0bd942f7cd4a | |
parent | cca86dc829074e51da2cebcf9e7bb75ef9d3e544 (diff) | |
download | golem-a560cc2aef70616ec16259acbaa6c02f03bc8874.tar.gz |
organize
-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; +} |