diff options
author | David Phillips <david@sighup.nz> | 2018-08-01 02:04:47 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-08-01 02:04:47 +1200 |
commit | 957d77141f56714e9f4551c8d49e6658ff778ce7 (patch) | |
tree | b4d0207a06f12de12c1172312b6ee5de54c79a6f /parser.c | |
parent | a2e204aea97e7f844a5303f956c893579a89623e (diff) | |
download | hence-957d77141f56714e9f4551c8d49e6658ff778ce7.tar.xz |
Add line area/span indication to error messages
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 42 |
1 files changed, 39 insertions, 3 deletions
@@ -10,6 +10,7 @@ #include "gate.h" +static FILE* fd; static struct token *cursor; #ifdef emit_error @@ -18,7 +19,8 @@ static struct token *cursor; #endif /* ifdef emit_error */ #define emit_error(...) fprintf(stderr, "Error (%zd,%zd): ", cursor->loc.line, cursor->loc.column);\ - fprintf(stderr, __VA_ARGS__) + fprintf(stderr, __VA_ARGS__);\ + indicate_file_area(fd, cursor->loc.line, cursor->loc.column, cursor->span) //static struct op_lookup uop_handlers[] = { @@ -54,10 +56,44 @@ expect(enum TOKEN_TYPE e) { return 0; } +static void +kerchunk() { + cursor = cursor->next; +} int -parse(struct token *t) { +parse(FILE *f, struct token *t) { + char *token_desc = "(internal error)"; + fd = f; cursor = t; - expect(TOK_MODULE); + + if (expect(TOK_MODULE)) { + return 1; + } + kerchunk(); + + if (expect(TOK_IDENT)) { + return 1; + } + emit_error("Debug: module is named %s\n", cursor->value); + kerchunk(); + + if (expect(TOK_EOL)) { + return 1; + } + kerchunk(); + + while (cursor) { + switch(cursor->type) { + case TOK_EOL: + kerchunk(); + break; + /* FIXME implement everything */ + default: + token_desc = get_token_description(cursor->type); + emit_error("Unexpected %s\n", token_desc); + return 1; + } + } return 0; } |