From 957d77141f56714e9f4551c8d49e6658ff778ce7 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Wed, 1 Aug 2018 02:04:47 +1200 Subject: Add line area/span indication to error messages --- parser.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'parser.c') diff --git a/parser.c b/parser.c index c577105..987f26d 100644 --- a/parser.c +++ b/parser.c @@ -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; } -- cgit v1.1