[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseedn 92bf875962 17/32: Merge pull request #5 from cloj
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseedn 92bf875962 17/32: Merge pull request #5 from clojure-emacs/support-dotted-pairs |
Date: |
Tue, 28 Dec 2021 14:04:42 -0500 (EST) |
branch: elpa/parseedn
commit 92bf875962e62f8c6370b56991d546f122536c6b
Merge: f42ff98833 876dfead6b
Author: Arne Brasseur <arne.brasseur@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #5 from clojure-emacs/support-dotted-pairs
Support dotted pairs
---
parseedn.el | 51 +++++++++++++++++++++++++++++++++++++++++++++------
test/parseedn-test.el | 4 ++++
2 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/parseedn.el b/parseedn.el
index e969d23d42..986b13790b 100644
--- a/parseedn.el
+++ b/parseedn.el
@@ -141,8 +141,8 @@ TAG-READERS is an optional association list. For more
information, see
(insert " ")
(parseedn-print-seq next))))
-(defun parseedn-print-kvs (map &optional ks)
- "Insert hash table MAP as an EDN map into the current buffer."
+(defun parseedn-print-hash-or-alist (map &optional ks)
+ "Insert hash table MAP or elisp a-list as an EDN map into the current
buffer."
(let ((keys (or ks (a-keys map))))
(parseedn-print (car keys))
(insert " ")
@@ -150,7 +150,35 @@ TAG-READERS is an optional association list. For more
information, see
(let ((next (cdr keys)))
(when (not (seq-empty-p next))
(insert ", ")
- (parseedn-print-kvs map next)))))
+ (parseedn-print-hash-or-alist map next)))))
+
+(defun parseedn-print-plist (plist)
+ "Insert an elisp property list as an EDN map into the current buffer."
+ (parseedn-print (car plist))
+ (insert " ")
+ (parseedn-print (cadr plist))
+ (let ((next (cddr plist)))
+ (when (not (seq-empty-p next))
+ (insert ", ")
+ (parseedn-print-plist next))))
+
+(defun parseedn-alist-p (list)
+ "Non-null if and only if LIST is an alist with simple keys."
+ (while (consp list)
+ (setq list (if (and (consp (car list))
+ (atom (caar list)))
+ (cdr list)
+ 'not-alist)))
+ (null list))
+
+(defun parseedn-plist-p (list)
+ "Non-null if and only if LIST is a plist with keyword keys."
+ (while (consp list)
+ (setq list (if (and (keywordp (car list))
+ (consp (cdr list)))
+ (cddr list)
+ 'not-plist)))
+ (null list))
(defun parseedn-print (datum)
"Insert DATUM as EDN into the current buffer.
@@ -175,19 +203,30 @@ DATUM can be any Emacs Lisp value."
((eq t datum)
(insert "true"))
- ((symbolp datum)
+ ((or (keywordp datum) (symbolp datum))
(insert (symbol-name datum)))
((vectorp datum) (insert "[") (parseedn-print-seq datum) (insert "]"))
+ ((or (hash-table-p datum) (parseedn-alist-p datum))
+ (insert "{")
+ (parseedn-print-hash-or-alist datum)
+ (insert "}"))
+
+ ((parseedn-plist-p datum)
+ (insert "{")
+ (parseedn-print-plist datum)
+ (insert "}"))
+
((consp datum)
(cond
+ ((not (listp (cdr datum))) ; dotted pair
+ (error "Don't know how to print: %s" datum))
((eq 'edn-set (car datum))
(insert "#{") (parseedn-print-seq (cadr datum)) (insert "}"))
(t (insert "(") (parseedn-print-seq datum) (insert ")"))))
- ((hash-table-p datum)
- (insert "{") (parseedn-print-kvs datum) (insert "}"))))
+ (t (error "Don't know how to print: %s" datum))))
(defun parseedn-print-str (datum)
"Return a string containing DATUM as EDN.
diff --git a/test/parseedn-test.el b/test/parseedn-test.el
index 9ddbdb4409..8815543fd0 100644
--- a/test/parseedn-test.el
+++ b/test/parseedn-test.el
@@ -38,6 +38,10 @@
(should (equal (parseedn-print-str 1.2) "1.2"))
(should (equal (parseedn-print-str [1 2 3]) "[1 2 3]"))
(should (equal (parseedn-print-str t) "true"))
+ (should (equal (parseedn-print-str '((a . 1) (b . 2))) "{a 1, b 2}"))
+ (should (equal (parseedn-print-str '((a . 1) (b . ((c . 3))))) "{a 1, b {c
3}}"))
+ (should (equal (parseedn-print-str '(:a 1 :b 2)) "{:a 1, :b 2}"))
+ (should (equal (parseedn-print-str '(:a 1 :b (:c 3))) "{:a 1, :b {:c 3}}"))
(should (listp (member (parseedn-print-str
(let ((ht (make-hash-table)))
(puthash :a 1 ht)
- [nongnu] elpa/parseedn acbea6bb1e 03/32: Fix a typo, (continued)
- [nongnu] elpa/parseedn acbea6bb1e 03/32: Fix a typo, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn ddf824bc1d 08/32: Update the installation instructions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 4efa23a851 15/32: oops! fix test., ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 1a3640d298 29/32: Replace `cl-case` with `cond`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn b00eb42a1c 28/32: Update the required Emacs version, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn adf57f36f4 11/32: Fix printing of hash-maps with multiple entries, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 17c4b2f658 05/32: Fix a couple of typos, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 342359abd1 10/32: Merge pull request #2 from clojure-emacs/fix-build-question-mark, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 7b9ca20b39 22/32: Merge pull request #7 from clojure-emacs/print-uuid-inst, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn ef0f8772bf 01/32: Initial commit, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 92bf875962 17/32: Merge pull request #5 from clojure-emacs/support-dotted-pairs,
ELPA Syncer <=
- [nongnu] elpa/parseedn e5ba280d1f 32/32: Correctly bump versions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn f42ff98833 13/32: Merge pull request #1 from ak-coram/fix-hash-map-printing, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 8f0582da3f 06/32: Improve the commentary front matter, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 0ffab01927 12/32: Add test to cover the printing of hash-maps, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn 3b1bea1425 27/32: Drop use of map-merge alist, for Emacs 25/26, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseedn fe8e30a770 31/32: Update CHANGELOG, ELPA Syncer, 2021/12/28