mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
WIP
This commit is contained in:
parent
d69acb1148
commit
d699e1e846
2 changed files with 16 additions and 3 deletions
14
read.scm
14
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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue