Welcome back, R7RS!

This commit is contained in:
Daniel Ziltener 2020-03-04 00:17:41 +01:00
parent f1d0002757
commit 1040154f91
4 changed files with 33 additions and 25 deletions

View file

@ -202,9 +202,9 @@ Example for a tag \"#keywordify\": add the entry `(cons keywordify: keywordify-p
(else (car result))) (else (car result)))
(cdr result))))) (cdr result)))))
(define (read-edn) (define (read-edn port)
@("Reads EDN data from the `current-input-port`, converts it to Chicken data and returns it. Precision suffixes for numbers get ignored, maps get converted to SRFI-69 hashtables, vectors to SRFI-4 vectors.") @("Reads EDN data from given port, converts it to Chicken data and returns it. Precision suffixes for numbers get ignored, maps get converted to SRFI-69 hashtables, vectors to SRFI-4 vectors.")
(second ((parse-edn '()) (current-input-port)))) (second ((parse-edn '()) port)))
;; EDN writing ;; EDN writing
;; =========== ;; ===========
@ -232,7 +232,7 @@ Example for a tag \"#keywordify\": add the entry `(cons keywordify: keywordify-p
(define (sequential->edn subparser ld rd in) (define (sequential->edn subparser ld rd in)
(string-append ld (string-append ld
(foldr (lambda (elem init) (fold-right (lambda (elem init)
(string-append (subparser elem) (string-append (subparser elem)
(if (equal? "" init) "" " ") (if (equal? "" init) "" " ")
init)) init))
@ -247,7 +247,7 @@ Example for a tag \"#keywordify\": add the entry `(cons keywordify: keywordify-p
(define (map->edn subparser in) (define (map->edn subparser in)
(string-append "{" (string-append "{"
(foldr (lambda (elem init) (fold-right (lambda (elem init)
(string-append (subparser (car elem)) (string-append (subparser (car elem))
" " " "
(subparser (cdr elem)) (subparser (cdr elem))
@ -310,8 +310,7 @@ Example for a tag \"#keywordify\": add the entry `(cons keywordify: keywordify-p
@(heading "Writing EDN") @(heading "Writing EDN")
(define (write-edn struct) (define (write-edn port struct)
@("Converts Chicken data structures to EDN and writes it to the `current-output-port`." @("Converts Chicken data structures to EDN and writes it to the given port."
(struct "A Chicken data structure consisting of atoms, lists, vectors and hashtables.")) (struct "A Chicken data structure consisting of atoms, lists, vectors and hashtables."))
(lambda () (display (parse-entry struct) port))
(display (parse-entry struct) (current-output-port))))

View file

@ -5,8 +5,9 @@
(category parsing) (category parsing)
(license "BSD") (license "BSD")
(version "0.5.2") (version "0.5.2")
(dependencies hahn srfi-69 srfi-1) (dependencies r7rs srfi-69 srfi-1 hahn)
(test-dependencies srfi-64) (test-dependencies r7rs srfi-64 hahn)
(components (extension edn (components (extension edn
(modules edn) (modules edn)
(csc-options "-X" "hahn")))) (csc-options "-X" "r7rs" "-R" "r7rs" "-X" "hahn")
)))

15
edn.scm
View file

@ -5,12 +5,15 @@
@(heading "Documentation") @(heading "Documentation")
@(noop) @(noop)
(module edn (parse-entry tag-handlers write-edn read-edn) (import r7rs)
(define-library (edn)
(import srfi-1 (import srfi-1
srfi-69 srfi-69
srfi-88 srfi-88
scheme (scheme base)
(chicken base) (scheme case-lambda)
(chicken keyword) (scheme char)
(chicken port)) (scheme cxr)
(include "edn-impl.scm")) (scheme write))
(export parse-entry tag-handlers write-edn read-edn)
(begin (include "edn-impl.scm")))

View file

@ -1,5 +1,6 @@
(require-extension r7rs srfi-69 srfi-64 srfi-88 srfi-1 hahn) (import r7rs)
(import (chicken port)) (require-extension srfi-69 srfi-64 srfi-88 srfi-1)
;;(import (chicken port))
(include "../edn-impl.scm") (include "../edn-impl.scm")
;; (run-hahn -o edn.wiki edn.scm edn-impl.scm) ;; (run-hahn -o edn.wiki edn.scm edn-impl.scm)
@ -15,16 +16,20 @@
(test-equal (parse-entry "String") "\"String\"") (test-equal (parse-entry "String") "\"String\"")
(test-equal (parse-entry (cons edn/reader-tag: neat:)) "#neat") (test-equal (parse-entry (cons edn/reader-tag: neat:)) "#neat")
(test-equal (list->edn parse-entry '(1 2 3 4)) "(1 2 3 4)") (test-equal (list->edn parse-entry '(1 2 3 4)) "(1 2 3 4)")
(test-equal (vector->edn parse-entry #(a: b: c: d:)) "[:a :b :c :d]") (test-equal (vector->edn parse-entry #(a: b: c: d:)) "[:a :b :c :d]")
(test-equal (parse-entry '((a: . "Hi") (test-equal
(let ((port (open-output-string)))
(write-edn port '((a: . "Hi")
(b: . i-am:) (b: . i-am:)
(c: . (a list)))) "{:a \"Hi\" :b :i-am :c (a list)}") (c: . (a list))))
(get-output-string port))
"{:a \"Hi\" :b :i-am :c (a list)}")
(test-end "EDN writing") (test-end "EDN writing")
(test-begin "EDN reading") (test-begin "EDN reading")
(define wifs with-input-from-string) (define (wifs str proc)
(call-with-port (open-input-string str) proc))
(test-equal (wifs "(:keyword)" read-edn) '(keyword:)) (test-equal (wifs "(:keyword)" read-edn) '(keyword:))
(test-equal (wifs "(123)" read-edn) '(123)) (test-equal (wifs "(123)" read-edn) '(123))