diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-14 23:38:43 +0200 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-15 02:16:29 +0200 |
commit | f2bc5274bb55bc2b180efae274ada107ea4716d1 (patch) | |
tree | ed4bc690e81e2aab5c2629987865524e289d2b6e /src/parser.c | |
parent | e927a4b22115e0461db6feeee891256b10650c0e (diff) |
parser: Show filepath row and col when parsing fails
In order to find out where a parsing error occurred, this patch
introduces the exactly location following the format 'file:row:col'.
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/parser.c b/src/parser.c index 5d2a734..4867201 100644 --- a/src/parser.c +++ b/src/parser.c @@ -38,12 +38,22 @@ expected_token(parser_t *parser, token_kind_t kind) lexer_next_token(parser->lexer, &token); if (token.kind == TOKEN_EOF) { - fprintf(stderr, "[ERROR]: expected '%s' but got end of file\n", token_kind_to_str(kind)); + fprintf( + stderr, + "%s:%d:%d: [ERROR]: expected '%s' but got end of file\n", + token.filepath, token.row + 1, token.col + 1, + token_kind_to_str(kind) + ); exit(EXIT_FAILURE); } if (token.kind != kind) { - fprintf(stderr, "[ERROR]: expected '%s' but got '%s'\n", token_kind_to_str(kind), token_kind_to_str(token.kind)); + fprintf( + stderr, + "%s:%d:%d: [ERROR]: expected '%s' but got '%s'\n", + token.filepath, token.row + 1, token.col + 1, + token_kind_to_str(kind), token_kind_to_str(token.kind) + ); exit(EXIT_FAILURE); } |