mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-06 20:56:36 +02:00
WIP, not quite right with differentiating chars
This commit is contained in:
parent
61d242521b
commit
62a54a50d5
2 changed files with 30 additions and 19 deletions
41
read.scm
41
read.scm
|
@ -701,6 +701,9 @@
|
||||||
(parse2 (open-input-file "test.scm")))
|
(parse2 (open-input-file "test.scm")))
|
||||||
;(read-token (open-input-file "test.scm")))
|
;(read-token (open-input-file "test.scm")))
|
||||||
|
|
||||||
|
TODO: getting there, but still not parsed correctly:
|
||||||
|
(eq? c #\))
|
||||||
|
|
||||||
;; Notes on writing a fast parser:
|
;; Notes on writing a fast parser:
|
||||||
; - Interface to the user is (read). This needs to be fast
|
; - Interface to the user is (read). This needs to be fast
|
||||||
; - Could read input a line at a time, but then need to buffer in the port_type object
|
; - Could read input a line at a time, but then need to buffer in the port_type object
|
||||||
|
@ -732,17 +735,6 @@
|
||||||
(let ((token (read-token fp))) ;; TODO: this will be a C call
|
(let ((token (read-token fp))) ;; TODO: this will be a C call
|
||||||
;(write `(token ,token))
|
;(write `(token ,token))
|
||||||
(cond
|
(cond
|
||||||
;; Open paren, start read loop
|
|
||||||
((eq? token #\()
|
|
||||||
(let loop ((lis '())
|
|
||||||
(t (parse2 fp)))
|
|
||||||
(cond
|
|
||||||
((eof-object? t)
|
|
||||||
(error "missing closing parenthesis"))
|
|
||||||
((eq? t #\))
|
|
||||||
(reverse lis))
|
|
||||||
(else
|
|
||||||
(loop (cons t lis) (parse2 fp))))))
|
|
||||||
((vector? token)
|
((vector? token)
|
||||||
(cond
|
(cond
|
||||||
((= (vector-length token) 2) ;; Special case: number
|
((= (vector-length token) 2) ;; Special case: number
|
||||||
|
@ -752,7 +744,26 @@
|
||||||
(exact (string->number (vector-ref token 0) (vector-ref token 1)))
|
(exact (string->number (vector-ref token 0) (vector-ref token 1)))
|
||||||
(inexact (string->number (vector-ref token 0) (vector-ref token 1)))))
|
(inexact (string->number (vector-ref token 0) (vector-ref token 1)))))
|
||||||
((= (vector-length token) 1) ;; Special case: error
|
((= (vector-length token) 1) ;; Special case: error
|
||||||
(error (vector-ref token 0)))
|
(cond
|
||||||
|
;; Open paren, start read loop
|
||||||
|
((eq? (vector-ref token 0) #\()
|
||||||
|
(let loop ((lis '())
|
||||||
|
(t (parse2 fp)))
|
||||||
|
(cond
|
||||||
|
((eof-object? t)
|
||||||
|
(error "missing closing parenthesis"))
|
||||||
|
((eq? t #\)) TODO: here and below, need to wait for the vectorized close?
|
||||||
|
(reverse lis))
|
||||||
|
(else
|
||||||
|
(loop (cons t lis) (parse2 fp))))))
|
||||||
|
((eq? (vector-ref token 0) #\')
|
||||||
|
(list 'quote (parse2 fp)))
|
||||||
|
((eq? (vector-ref token 0) #\`)
|
||||||
|
(list 'quasiquote (parse2 fp)))
|
||||||
|
((eq? (vector-ref token 0) #\,)
|
||||||
|
(list 'unquote (parse2 fp)))
|
||||||
|
(else
|
||||||
|
(error (vector-ref token 0)))))
|
||||||
(else
|
(else
|
||||||
(let loop ((lis '())
|
(let loop ((lis '())
|
||||||
(t (parse2 fp)))
|
(t (parse2 fp)))
|
||||||
|
@ -773,12 +784,6 @@
|
||||||
(apply bytevector (reverse lis)))
|
(apply bytevector (reverse lis)))
|
||||||
(else
|
(else
|
||||||
(loop (cons t lis) (parse2 fp))))))
|
(loop (cons t lis) (parse2 fp))))))
|
||||||
((eq? token #\')
|
|
||||||
(list 'quote (parse2 fp)))
|
|
||||||
((eq? token #\`)
|
|
||||||
(list 'quasiquote (parse2 fp)))
|
|
||||||
((eq? token #\,)
|
|
||||||
(list 'unquote (parse2 fp)))
|
|
||||||
((eq? token (string->symbol ",@"))
|
((eq? token (string->symbol ",@"))
|
||||||
(list 'unquote-splicing (parse2 fp)))
|
(list 'unquote-splicing (parse2 fp)))
|
||||||
((eq? token (string->symbol "#;"))
|
((eq? token (string->symbol "#;"))
|
||||||
|
|
|
@ -6106,7 +6106,13 @@ void Cyc_io_read_token(void *data, object cont, object port)
|
||||||
_read_whitespace(p);
|
_read_whitespace(p);
|
||||||
} else if (c == '(' || c == ')' || c == '\'' || c == '`') {
|
} else if (c == '(' || c == ')' || c == '\'' || c == '`') {
|
||||||
if (p->tok_end) _read_return_atom(data, cont, p);
|
if (p->tok_end) _read_return_atom(data, cont, p);
|
||||||
return_thread_runnable(data, obj_char2obj(c));
|
//return_thread_runnable(data, obj_char2obj(c));
|
||||||
|
// Encode within a vector so we can distinguish between these and chars such as #\(
|
||||||
|
make_empty_vector(vec);
|
||||||
|
vec.num_elements = 1;
|
||||||
|
vec.elements = (object *) alloca(sizeof(object) * vec.num_elements);
|
||||||
|
vec.elements[0] = obj_char2obj(c);
|
||||||
|
return_thread_runnable(data, &vec);
|
||||||
} else if (c == ',') {
|
} else if (c == ',') {
|
||||||
if (p->tok_end) _read_return_atom(data, cont, p);
|
if (p->tok_end) _read_return_atom(data, cont, p);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue