aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-08-10 19:31:52 +0900
committernsfisis <nsfisis@gmail.com>2025-08-15 10:06:21 +0900
commit3e7147bb740afb5c78944d2ef721af9bf5ddbb95 (patch)
treee819b8563adb77b22c083a3b8014ca4beaf238fe
parent1a806d92c569a5013c6369c6b5bcc3f74c38bab0 (diff)
downloadducc-3e7147bb740afb5c78944d2ef721af9bf5ddbb95.tar.gz
ducc-3e7147bb740afb5c78944d2ef721af9bf5ddbb95.tar.zst
ducc-3e7147bb740afb5c78944d2ef721af9bf5ddbb95.zip
feat: show filename and line number in parsing phase
-rw-r--r--parse.c3
-rw-r--r--tests/059.sh4
-rw-r--r--tokenize.c1
3 files changed, 5 insertions, 3 deletions
diff --git a/parse.c b/parse.c
index f8ad4f1..d55d599 100644
--- a/parse.c
+++ b/parse.c
@@ -79,7 +79,8 @@ Token* expect(Parser* p, TokenKind expected) {
if (t->kind == expected) {
return t;
}
- fatal_error("expected '%s', but got '%s'", token_kind_stringify(expected), token_stringify(t));
+ fatal_error("%s:%d: expected '%s', but got '%s'", t->loc.filename, t->loc.line, token_kind_stringify(expected),
+ token_stringify(t));
}
int find_lvar(Parser* p, const String* name) {
diff --git a/tests/059.sh b/tests/059.sh
index 18e9bd7..80a6e10 100644
--- a/tests/059.sh
+++ b/tests/059.sh
@@ -1,7 +1,7 @@
set -e
cat <<'EOF' > expected
-expected '{', but got '}'
+main.c:1: expected '{', but got '}'
EOF
bash ../../test_compile_error.sh <<'EOF'
@@ -9,7 +9,7 @@ int main() }
EOF
cat <<'EOF' > expected
-expected '{', but got '123 (<integer>)'
+main.c:1: expected '{', but got '123 (<integer>)'
EOF
bash ../../test_compile_error.sh <<'EOF'
diff --git a/tokenize.c b/tokenize.c
index ff66525..e6c61c0 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -19,6 +19,7 @@ void tokenize_all(Lexer* l) {
while (l->src[l->pos].kind != TokenKind_eof) {
Token* pp_tok = l->src + l->pos;
Token* tok = l->tokens + l->n_tokens;
+ tok->loc = pp_tok->loc;
TokenKind k = pp_tok->kind;
++l->pos;
if (k == TokenKind_character_constant) {