Parse strings and illustrate some more metadata

This commit is contained in:
Lassi Kortela 2019-05-12 16:38:03 +03:00
parent 000a898778
commit 2ab02b063f
2 changed files with 28 additions and 7 deletions

View File

@ -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)
(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)))))
(eof-object))))))
(let* ((shebang (if (and (read-char? #\#) (read-char? #\!))
(read-rest-of-line)
#f))

View File

@ -1,7 +1,10 @@
#! /usr/bin/env gosh
(declare-file
(coding shift_jis))
(coding shift_jis)
(language (scheme r7rs))
(author "Lassi Kortela")
(spdx-license-identifier "ISC"))
(display "こんにちは世界")
(newline)