aboutsummaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/parse.c b/src/parse.c
index a047424..2fa3ee4 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -5,8 +5,10 @@
#include "util.h"
static noreturn void
-error(const char *fmt, ...)
+error(struct location loc, const char *fmt, ...)
{
+ fprintf(stderr, "%s:%d:%d ", loc.file, loc.line, loc.column);
+
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
@@ -34,7 +36,7 @@ parse_path(struct lexer *lexer, struct ast_path *out)
struct token name;
if (lex(lexer, &name) != T_NAME) {
- error("syntax error: expected path");
+ error(name.loc, "syntax error: expected path");
}
out->segments = must_calloc(1, sizeof(const char *));
@@ -44,7 +46,7 @@ parse_path(struct lexer *lexer, struct ast_path *out)
while (match(lexer, T_MODDELIM)) {
if (lex(lexer, &name) != T_NAME) {
- error("syntax error: expected name");
+ error(name.loc, "syntax error: expected name");
}
append(out, name.info.str);
}
@@ -60,7 +62,7 @@ parse_import(struct lexer *lexer, struct ast_import *out)
}
if (!parse_path(lexer, &out->path)) {
- error("syntax error: expected import path");
+ error(lex_loc(lexer), "syntax error: expected import path");
}
struct token token;
@@ -72,7 +74,7 @@ parse_import(struct lexer *lexer, struct ast_import *out)
}
if (!match(lexer, T_SEMICOLON)) {
- error("syntax error: expected semicolon");
+ error(lex_loc(lexer), "syntax error: expected semicolon");
}
return true;