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 #\() (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) (define (skip-char* k)
(when (read-char? k) (skip-char* k))) (when (read-char? k) (skip-char* k)))
(define (read-rest-of-line) (define (read-rest-of-line)
@ -60,6 +67,14 @@
#f #f
(list->string chars)) (list->string chars))
(loop (append chars (list c))))))) (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) (define (read-list)
(let loop ((xs '())) (let loop ((xs '()))
(skip-whitespace-and-comments) (skip-whitespace-and-comments)
@ -71,12 +86,15 @@
(loop (append xs (list x)))))))) (loop (append xs (list x))))))))
(define (read-form) (define (read-form)
(skip-whitespace-and-comments) (skip-whitespace-and-comments)
(if (read-char? #\() (cond ((read-char? #\()
(read-list) (read-list))
(let ((symbol-name (read-char* not-special-char?))) ((read-char? #\")
(if symbol-name (read-string))
(string->symbol symbol-name) (else
(eof-object))))) (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? #\!)) (let* ((shebang (if (and (read-char? #\#) (read-char? #\!))
(read-rest-of-line) (read-rest-of-line)
#f)) #f))

View File

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