From 0d25e5e12224ed2df8236d242df8f1fb118d3572 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 21 Jul 2020 22:35:47 -0400 Subject: [PATCH] Clean up error messages, provide filename if able --- cyclone.scm | 1 + scheme/base.sld | 12 +++++------- scheme/read.sld | 20 +++++++++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cyclone.scm b/cyclone.scm index 7f436f68..045df06b 100644 --- a/cyclone.scm +++ b/cyclone.scm @@ -957,6 +957,7 @@ Debug options: (parameterize ((current-output-port (current-error-port))) (display "Error: ") (display (car err)) + (display ": ") (newline) (for-each (lambda (obj) diff --git a/scheme/base.sld b/scheme/base.sld index 0a7963a9..c60b6222 100644 --- a/scheme/base.sld +++ b/scheme/base.sld @@ -243,19 +243,17 @@ (if loc-vec (error (string-append - "invalid syntax " - reason - " in " + "(" (vector-ref loc-vec 0) " line " (number->string (vector-ref loc-vec 1)) ", column " - (number->string (vector-ref loc-vec 2))) + (number->string (vector-ref loc-vec 2)) + ") " + reason) expr) (error - (string-append - "invalid syntax " - reason) + reason expr)))) ;; Features implemented by this Scheme diff --git a/scheme/read.sld b/scheme/read.sld index 51611571..32a58722 100644 --- a/scheme/read.sld +++ b/scheme/read.sld @@ -73,7 +73,7 @@ #f))) (let ((result (parse fp ssi! fname))) (if (Cyc-opaque? result) - (read-error fp "unexpected closing parenthesis") + (read-error fp fname "unexpected closing parenthesis") result))))) ;; Read given file, collecting source location information so we @@ -115,14 +115,20 @@ " Cyc_io_read_token(data, k, port);") (define-c read-error - "(void *data, int argc, closure _, object k, object port, object msg)" + "(void *data, int argc, closure _, object k, object port, object filename, object msg)" " char buf[1024]; port_type *p; Cyc_check_port(data, port); Cyc_check_str(data, msg); p = ((port_type *)port); - snprintf(buf, 1023, \"(line %d, column %d): %s\", - p->line_num, p->col_num, string_str(msg)); + if (Cyc_is_string(filename) == boolean_t) { + snprintf(buf, 1023, \"(%s line %d, column %d): %s\", + string_str(filename), p->line_num, p->col_num, + string_str(msg)); + } else { + snprintf(buf, 1023, \"(line %d, column %d): %s\", + p->line_num, p->col_num, string_str(msg)); + } Cyc_rt_raise_msg(data, buf);") (define-c Cyc-opaque-eq? @@ -203,7 +209,7 @@ (t (parse fp ssi! fname))) (cond ((eof-object? t) - (read-error fp "missing closing parenthesis")) + (read-error fp fname "missing closing parenthesis")) ((Cyc-opaque-eq? t #\)) (if (and (> (length lis) 2) (equal? (cadr lis) *sym-dot*)) @@ -265,7 +271,7 @@ (t (parse fp ssi! fname))) (cond ((eof-object? t) - (read-error fp "missing closing parenthesis")) + (read-error fp fname "missing closing parenthesis")) ((Cyc-opaque-eq? t #\)) (list->vector (reverse lis))) (else @@ -275,7 +281,7 @@ (t (parse fp ssi! fname))) (cond ((eof-object? t) - (read-error fp "missing closing parenthesis")) + (read-error fp fname "missing closing parenthesis")) ((Cyc-opaque-eq? t #\)) (apply bytevector (reverse lis))) (else