diff --git a/encoding-reader.scm b/encoding-reader.scm index d02e572..9edf3e4 100644 --- a/encoding-reader.scm +++ b/encoding-reader.scm @@ -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)) diff --git a/test.scm b/test.scm index 09f94d3..8a70394 100644 --- a/test.scm +++ b/test.scm @@ -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)