You are looking at historical revision 32745 of this page. It may differ significantly from its current revision.

edn.egg

EDN data reader/writer

EDN

This egg provides a parser and a writer for the Extensible Data Notation.

Documentation

edn->atom

[procedure] (edn->atom skip-fn end-fn finalizer) → unspecified
[procedure] (edn->atom subparser skip-fn end-fn finalizer result pile input) → unspecified

Reading EDN

(define edn->atom
  (case-lambda
    ((skip-fn end-fn finalizer)
     (lambda (subparser input)
       (edn->atom subparser skip-fn end-fn finalizer '() '() input)))
    ((subparser skip-fn end-fn finalizer result pile input)
     (cond ((or (eq? #!eof (peek-char input)) (end-fn result pile input))
            (cons (finalizer (reverse result))
                  (if (or (not (char-ready? input))
                          (char=? #\# (peek-char input))
                          (char=? #\) (peek-char input))
                          (char=? #\] (peek-char input))
                          (char=? #\} (peek-char input)))
                    input
                    (begin (read-char input) input))))
           ((skip-fn result pile input)
            (edn->atom
              subparser
              skip-fn
              end-fn
              finalizer
              result
              (cons (read-char input) pile)
              input))
           (else
            (edn->atom
              subparser
              skip-fn
              end-fn
              finalizer
              (cons (peek-char input) result)
              (cons (peek-char input) pile)
              (if (null? input) input (begin (read-char input) input))))))))

tag-handlers

[constant] tag-handlers → (list (cons _: (lambda (input) edn/omit:)))

An a-list containing the handlers for reader tags. You can register your own reader tags by simply adding a new a-list entry.

Example for a tag "#keywordify": add the entry `(cons keywordify: keywordify-procedure)`.

(define tag-handlers (list (cons _: (lambda (input) edn/omit:))))

read-edn

[procedure] (read-edn) → unspecified

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.

(define (read-edn) (second ((parse-edn '()) (current-input-port))))

pair->reader-tag

[procedure] (pair->reader-tag subparser in) → unspecified

Writing EDN

(define (pair->reader-tag subparser in)
  (string-append "#" (keyword->string (cdr in))))

write-edn

[procedure] (write-edn struct) → unspecified

Converts Chicken data structures to EDN and writes it to the `current-output-port`.

struct
A Chicken data structure consisting of atoms, lists, vectors and hashtables.
(define (write-edn struct)
  (lambda () (display (parse-entry struct) (current-output-port))))

About this egg

Author

Daniel Ziltener

License

BSD

Dependencies

Colophon

Documented by hahn.