Turned a-list into parameter

This commit is contained in:
Daniel Ziltener 2022-10-30 22:37:47 +01:00
parent 23ad941e04
commit 9611de7aa9
6 changed files with 12 additions and 8 deletions

2
.dir-locals.el Normal file
View File

@ -0,0 +1,2 @@
((scheme-mode . ((flymake-chicken-command-args . ("-X" "r7rs" "-R" "r7rs" "-X" "chalk"))
(geiser-scheme . 'chicken))))

View File

@ -30,11 +30,12 @@ API
* Transforming EDN into Scheme: `(read-edn <port>)`
* Transforming Scheme into EDN: `(write-edn <port> <datastructure>)`
* Using reader tags: the library contains a public a-list `tag-handlers`. To register a handler, add an a-list entry where the key is the tag without `\#` and as a keyword, and the value a one-argument procedure.
* Using reader tags: the library contains a parameter `tag-handlers` containing an a-list. To register a handler, add an a-list entry where the key is the tag without `\#` and as a keyword, and the value a one-argument procedure.
Releases
--------
* **1.0**: Made the custom parsers a parameter.
* **0.5.2**: Update for Chicken 5
* **0.5.1**: Small compatibility improvements: "/" now starts a symbol as well, and "," is treated as whitespace.
* **0.5**: Reader tag support.

View File

@ -159,7 +159,7 @@
@("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)`.")
(list (cons _: (lambda (input) edn/omit:))))
(make-parameter (list (cons _: (lambda (input) edn/omit:)))))
(define reader-handlers
(list (cons (is-char? #\() edn->list)
@ -182,10 +182,10 @@ Example for a tag \"#keywordify\": add the entry `(cons keywordify: keywordify-p
(contains-tag-handler? (car in))))
(define (contains-tag-handler? tag)
(assoc (cdr tag) tag-handlers))
(assoc (cdr tag) (tag-handlers)))
(define (call-tag tag data)
((cdr (assoc (cdr tag) tag-handlers)) data))
((cdr (assoc (cdr tag) (tag-handlers))) data))
(define (parse-edn state)
(lambda (in-port)

View File

@ -4,7 +4,7 @@
(synopsis "EDN data reader/writer.")
(category parsing)
(license "BSD")
(version "0.5.2")
(version "1.0")
(dependencies r7rs srfi-69 srfi-1 chalk)
(test-dependencies r7rs srfi-64 chalk)
(components (extension edn

View File

@ -1,4 +1,5 @@
(repo git "https:///gitea.lyrion.ch/zilti/edn.git")
(uri targz "https://gitea.lyrion.ch/zilti/edn/archive/{egg-release}.tar.gz")
(release "1.0") ;; Made the custom parsers a parameter
(release "0.5.3") ;; Replaced Hahn with Chalk
(release "0.5.2") ;; Update for Chicken 5

View File

@ -1,4 +1,4 @@
(import r7rs)
(import r7rs chalk)
(require-extension srfi-69 srfi-64 srfi-88 srfi-1)
;;(import (chicken port))
(include "../edn-impl.scm")
@ -50,9 +50,9 @@
(test-begin "Tag handling")
(test-equal (wifs "(1 2 #_ 3 4)" read-edn) '(1 2 4))
(set! tag-handlers (cons (cons keywordify:
(tag-handlers (cons (cons keywordify:
(lambda (input)
(string->keyword (symbol->string input))))
tag-handlers))
(tag-handlers)))
(test-equal (wifs "(asdf #keywordify qwertz)" read-edn) '(asdf qwertz:))
(test-end "Tag handling")