Parse strings and illustrate some more metadata
This commit is contained in:
parent
000a898778
commit
2ab02b063f
|
@ -40,6 +40,13 @@
|
|||
(eqv? c #\")
|
||||
(eqv? c #\()
|
||||
(eqv? c #\)))))
|
||||
(define (string-char? c)
|
||||
(not (or (eof-object? c)
|
||||
(eqv? c #\tab)
|
||||
(eqv? c #\newline)
|
||||
(eqv? c #\return)
|
||||
(eqv? c #\")
|
||||
(eqv? c #\\))))
|
||||
(define (skip-char* k)
|
||||
(when (read-char? k) (skip-char* k)))
|
||||
(define (read-rest-of-line)
|
||||
|
@ -60,6 +67,14 @@
|
|||
#f
|
||||
(list->string chars))
|
||||
(loop (append chars (list c)))))))
|
||||
(define (read-string)
|
||||
(let loop ((chars '()))
|
||||
(if (read-char? #\")
|
||||
(list->string chars)
|
||||
(let ((c (read-char? string-char?)))
|
||||
(if (not c)
|
||||
(eof-object)
|
||||
(loop (append chars (list c))))))))
|
||||
(define (read-list)
|
||||
(let loop ((xs '()))
|
||||
(skip-whitespace-and-comments)
|
||||
|
@ -71,12 +86,15 @@
|
|||
(loop (append xs (list x))))))))
|
||||
(define (read-form)
|
||||
(skip-whitespace-and-comments)
|
||||
(if (read-char? #\()
|
||||
(read-list)
|
||||
(let ((symbol-name (read-char* not-special-char?)))
|
||||
(if symbol-name
|
||||
(string->symbol symbol-name)
|
||||
(eof-object)))))
|
||||
(cond ((read-char? #\()
|
||||
(read-list))
|
||||
((read-char? #\")
|
||||
(read-string))
|
||||
(else
|
||||
(let ((symbol-name (read-char* not-special-char?)))
|
||||
(if symbol-name
|
||||
(string->symbol symbol-name)
|
||||
(eof-object))))))
|
||||
(let* ((shebang (if (and (read-char? #\#) (read-char? #\!))
|
||||
(read-rest-of-line)
|
||||
#f))
|
||||
|
|
Loading…
Reference in New Issue