diff --git a/CHANGELOG.md b/CHANGELOG.md index 26d84f74..574cf702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Features Bug Fixes - Prevent `remainder` from crashing the runtime due to divide by zero. +- Avoid printing an unnecessary colon after certain error messages. ## 0.5.4 - August 3, 2017 diff --git a/runtime.c b/runtime.c index f3a81dda..730041b8 100644 --- a/runtime.c +++ b/runtime.c @@ -5745,7 +5745,7 @@ void _read_line_comment(port_type *p) } if (p->mem_buf[p->buf_idx++] == '\n') { p->line_num++; // Ignore col_num since we are just skipping over chars - p->col_num = 0; + p->col_num = 1; break; } } @@ -5780,7 +5780,7 @@ void _read_multiline_comment(port_type *p) if (p->mem_buf[p->buf_idx] == '\n') { p->line_num++; - p->col_num = 0; + p->col_num = 1; } else { p->col_num++; } @@ -5804,7 +5804,7 @@ void _read_whitespace(port_type *p) if (p->mem_buf[p->buf_idx] == '\n') { p->buf_idx++; p->line_num++; // Ignore col_num since we are just skipping over chars - p->col_num = 0; + p->col_num = 1; break; } else if (isspace(p->mem_buf[p->buf_idx])) { p->buf_idx++; @@ -5921,7 +5921,7 @@ void _read_string(void *data, object cont, port_type *p) escaped = 1; } else if (c == '\n') { p->line_num++; - p->col_num = 0; + p->col_num = 1; _read_add_to_tok_buf(p, c); } else { _read_add_to_tok_buf(p, c); @@ -5956,7 +5956,7 @@ void _read_literal_identifier(void *data, port_type *p) } } else if (c == '\n') { p->line_num++; - p->col_num = 0; + p->col_num = 1; _read_add_to_tok_buf(p, c); } else { _read_add_to_tok_buf(p, c); @@ -6194,7 +6194,7 @@ void Cyc_io_read_token(void *data, object cont, object port) } else if (c == '\n') { if (p->tok_end) _read_return_atom(data, cont, p); p->line_num++; - p->col_num = 0; + p->col_num = 1; } else if (isspace(c)) { if (p->tok_end) _read_return_atom(data, cont, p); _read_whitespace(p); diff --git a/scheme/read.sld b/scheme/read.sld index aed535f8..941264ec 100644 --- a/scheme/read.sld +++ b/scheme/read.sld @@ -54,7 +54,7 @@ (car args)))) (let ((result (parse fp))) (if (Cyc-opaque? result) - (error "unexpected closing parenthesis") + (read-error fp "unexpected closing parenthesis") result))))) ;; read-all -> port -> [objects] @@ -82,6 +82,17 @@ "(void *data, int argc, closure _, object k, object port)" " Cyc_io_read_token(data, k, port);") +(define-c read-error + "(void *data, int argc, closure _, object k, object port, 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)); + Cyc_rt_raise_msg(data, buf);") + (define-c Cyc-opaque-eq? "(void *data, int argc, closure _, object k, object opq, object obj)" " if (Cyc_is_opaque(opq) == boolean_f) @@ -104,7 +115,7 @@ (t (parse fp))) (cond ((eof-object? t) - (error "missing closing parenthesis")) + (read-error fp "missing closing parenthesis")) ((Cyc-opaque-eq? t #\)) (if (and (> (length lis) 2) (equal? (cadr lis) (string->symbol "."))) @@ -135,7 +146,7 @@ (t (parse fp))) (cond ((eof-object? t) - (error "missing closing parenthesis")) + (read-error fp "missing closing parenthesis")) ((Cyc-opaque-eq? t #\)) (list->vector (reverse lis))) (else @@ -145,7 +156,7 @@ (t (parse fp))) (cond ((eof-object? t) - (error "missing closing parenthesis")) + (read-error fp "missing closing parenthesis")) ((Cyc-opaque-eq? t #\)) (apply bytevector (reverse lis))) (else