diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-10 19:31:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-15 10:06:21 +0900 |
| commit | 3e7147bb740afb5c78944d2ef721af9bf5ddbb95 (patch) | |
| tree | e819b8563adb77b22c083a3b8014ca4beaf238fe | |
| parent | 1a806d92c569a5013c6369c6b5bcc3f74c38bab0 (diff) | |
| download | ducc-3e7147bb740afb5c78944d2ef721af9bf5ddbb95.tar.gz ducc-3e7147bb740afb5c78944d2ef721af9bf5ddbb95.tar.zst ducc-3e7147bb740afb5c78944d2ef721af9bf5ddbb95.zip | |
feat: show filename and line number in parsing phase
| -rw-r--r-- | parse.c | 3 | ||||
| -rw-r--r-- | tests/059.sh | 4 | ||||
| -rw-r--r-- | tokenize.c | 1 |
3 files changed, 5 insertions, 3 deletions
@@ -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' @@ -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) { |
