summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-01-20 05:18:22 +0100
committerkdx <kdx@42l.fr>2023-01-20 05:19:26 +0100
commita560cc2aef70616ec16259acbaa6c02f03bc8874 (patch)
tree0906b82da4cee9a93787b94b644f0bd942f7cd4a
parentcca86dc829074e51da2cebcf9e7bb75ef9d3e544 (diff)
downloadgolem-a560cc2aef70616ec16259acbaa6c02f03bc8874.tar.gz
organize
-rw-r--r--parse.c45
1 files 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 <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;
+}