diff --git a/read.scm b/read.scm index f02f74de..2bbdf138 100644 --- a/read.scm +++ b/read.scm @@ -698,7 +698,8 @@ " Cyc_io_read_token(data, k, port);") (write - (read-token (open-input-file "test.scm"))) + (parse2 (open-input-file "test.scm"))) + ;(read-token (open-input-file "test.scm"))) ;; Notes on writing a fast parser: ; - Interface to the user is (read). This needs to be fast @@ -729,8 +730,19 @@ (define (parse2 fp) (let ((token (read-token fp))) ;; TODO: this will be a C call + ;(write `(token ,token)) (cond ;; Open paren, start read loop + ((eq? token #\() + (let loop ((lis '()) + (t (parse2 fp))) + (cond + ;; TODO: EOF + ((eq? t #\)) + (reverse lis)) + (else + (loop (cons t lis) (parse2 fp))))) + ) ;; Close parent, stop current read loop ;; Quote ;; , - could be unquote or unquote-splicing diff --git a/runtime.c b/runtime.c index f1c3b0e7..1e24caf7 100644 --- a/runtime.c +++ b/runtime.c @@ -5719,12 +5719,13 @@ void _read_whitespace(port_type *p) break; // Return if buf is empty } } - p->buf_idx++; 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; break; } else if (isspace(p->mem_buf[p->buf_idx])) { + p->buf_idx++; p->col_num++; } else { break; // Terminate on non-whitespace char @@ -5747,7 +5748,7 @@ void _read_return_atom(void *data, object cont, port_type *p) p->buf_idx--; p->col_num--; - p->tok_buf[p->tok_end + 1] = '\0'; // TODO: what if buffer is full? + p->tok_buf[p->tok_end] = '\0'; // TODO: what if buffer is full? p->tok_end = 0; // Reset for next atom printf("TODO: return atom from %s\n", p->tok_buf); return_closcall1(data, cont, boolean_f);