Browse Source

Welcome back, R7RS!

master
Daniel Ziltener 2 years ago
parent
commit
1040154f91
4 changed files with 33 additions and 25 deletions
  1. +8
    -9
      edn-impl.scm
  2. +4
    -3
      edn.egg
  3. +9
    -6
      edn.scm
  4. +12
    -7
      tests/run.scm

+ 8
- 9
edn-impl.scm View File

@ -202,9 +202,9 @@ Example for a tag \"#keywordify\": add the entry `(cons keywordify: keywordify-p
(else (car result)))
(cdr result)))))
(define (read-edn)
@("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.")
(second ((parse-edn '()) (current-input-port))))
(define (read-edn port)
@("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 '()) port)))
;; 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)
(string-append ld
(foldr (lambda (elem init)
(fold-right (lambda (elem init)
(string-append (subparser elem)
(if (equal? "" init) "" " ")
init))
@ -247,7 +247,7 @@ Example for a tag \"#keywordify\": add the entry `(cons keywordify: keywordify-p
(define (map->edn subparser in)
(string-append "{"
(foldr (lambda (elem init)
(fold-right (lambda (elem init)
(string-append (subparser (car elem))
" "
(subparser (cdr elem))
@ -310,8 +310,7 @@ Example for a tag \"#keywordify\": add the entry `(cons keywordify: keywordify-p
@(heading "Writing EDN")
(define (write-edn struct)
@("Converts Chicken data structures to EDN and writes it to the `current-output-port`."
(define (write-edn port struct)
@("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."))
(lambda ()
(display (parse-entry struct) (current-output-port))))
(display (parse-entry struct) port))

+ 4
- 3
edn.egg View File

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

+ 9
- 6
edn.scm View File

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

+ 12
- 7
tests/run.scm View File

@ -1,5 +1,6 @@
(require-extension r7rs srfi-69 srfi-64 srfi-88 srfi-1 hahn)
(import (chicken port))
(import r7rs)
(require-extension srfi-69 srfi-64 srfi-88 srfi-1)
;;(import (chicken port))
(include "../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 (cons edn/reader-tag: neat:)) "#neat")
(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 (parse-entry '((a: . "Hi")
(b: . i-am:)
(c: . (a list)))) "{:a \"Hi\" :b :i-am :c (a list)}")
(test-equal
(let ((port (open-output-string)))
(write-edn port '((a: . "Hi")
(b: . i-am:)
(c: . (a list))))
(get-output-string port))
"{:a \"Hi\" :b :i-am :c (a list)}")
(test-end "EDN writing")
(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 "(123)" read-edn) '(123))


Loading…
Cancel
Save