[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj e7686c49ed 052/185: Greater parity with edn.el
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj e7686c49ed 052/185: Greater parity with edn.el |
Date: |
Tue, 28 Dec 2021 14:05:16 -0500 (EST) |
branch: elpa/parseclj
commit e7686c49ed8e5670034489617c11a285c67179d1
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Greater parity with edn.el
- parse sets as (edn-set (...))
- parse maps as hash tables
- add a clj-parse-edn-read-str that acts like edn-read
---
clj-parse-test.el | 15 ++++++++++++---
clj-parse.el | 16 ++++++++++++----
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/clj-parse-test.el b/clj-parse-test.el
index a9888933ce..1a193def46 100644
--- a/clj-parse-test.el
+++ b/clj-parse-test.el
@@ -26,6 +26,15 @@
(require 'ert)
(require 'clj-parse)
+(defun clj-parse--equal (a b)
+ (cond
+ ((and (hash-table-p a) (hash-table-p b))
+ (a-equal a b))
+ ((and (consp a) (consp b))
+ (and (clj-parse--equal (car a) (car b))
+ (clj-parse--equal (cdr a) (cdr b))))
+ (t (equal a b))))
+
(defun clj-parse--deftest-mode (mode test-name test-string expected)
(let* ((parse-fn (intern (concat "clj-parse-" mode)))
(test-name (intern (concat (symbol-name parse-fn) "-" (symbol-name
test-name)))))
@@ -33,7 +42,7 @@
(with-temp-buffer
(insert ,test-string)
(goto-char 1)
- (should (equal (,parse-fn) ,expected))))))
+ (should (clj-parse--equal (,parse-fn) ,expected))))))
(defmacro clj-parse-deftest (test-name test-string mode-vs-expected-alist)
(declare (indent defun))
@@ -214,7 +223,7 @@
(:value . 123)))))))))))
(clj-parse-deftest map "{:count 123}"
- (("edn" '(((:count . 123))))
+ (("edn" (list (a-hash-table :count 123)))
("ast" '((:node-type . :root)
(:position . 0)
(:children . (((:node-type . :map)
@@ -229,7 +238,7 @@
(:value . 123)))))))))))
(clj-parse-deftest set "#{:x}"
- (("edn" '((:x)))
+ (("edn" '((edn-set (:x))))
("ast" '((:node-type . :root)
(:position . 0)
(:children . (((:node-type . :set)
diff --git a/clj-parse.el b/clj-parse.el
index a447ca8a43..163c7441e6 100644
--- a/clj-parse.el
+++ b/clj-parse.el
@@ -210,15 +210,23 @@
(cl-case type
(:lparen children)
(:lbracket (apply #'vector children))
- (:set children)
- (:lbrace (mapcar (lambda (pair)
- (cons (car pair) (cadr pair)))
- (-partition 2 children))))
+ (:set (list 'edn-set children))
+ (:lbrace (let* ((kvs (seq-partition children 2))
+ (hash-map (make-hash-table :test 'equal :size (length
kvs))))
+ (seq-do (lambda (pair)
+ (puthash (car pair) (cadr pair) hash-map))
+ kvs)
+ hash-map)))
stack))))
(defun clj-parse-edn ()
(clj-parse-reduce #'clj-parse--edn-reduce-leaf #'clj-parse--edn-reduce-node))
+(defun clj-parse-edn-str (s)
+ (with-temp-buffer
+ (insert s)
+ (goto-char 1)
+ (car (clj-parse-reduce #'clj-parse--edn-reduce-leaf
#'clj-parse--edn-reduce-node))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Printer implementations
- [nongnu] elpa/parseclj 343052c01a 014/185: Add linting to the build, (continued)
- [nongnu] elpa/parseclj 343052c01a 014/185: Add linting to the build, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 07739abe2c 030/185: support keywords, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ced0b91c08 029/185: "Support" namespaces symbols, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1eef0b62c8 034/185: Support #_discard forms, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 0974b56833 035/185: Stick to non CL functions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj f8822bb43c 040/185: Add support for tags in lexer, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 43f59dcb91 043/185: Avoid dropping whitespaces, handling them while reducing, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 7733985037 047/185: DESIGN.md-related adjustments, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj c906de33a1 048/185: Rewrite all tests, and add new tests for the AST "printer", ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 697618dbb1 049/185: Merge pull request #1 from volrath/master, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj e7686c49ed 052/185: Greater parity with edn.el,
ELPA Syncer <=
- [nongnu] elpa/parseclj 2da47798d9 057/185: Enable more edn.el tests, document how time/uuid are stored, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj f6de87fbe6 067/185: Split EDN and AST handling in separate files, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj d410a1530e 096/185: Add code-checking defaults to `dir-locals.el`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 3a92eafce9 079/185: Rename reduce-node to reduce-branch, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 7beff77b15 083/185: Introduce parseclj-parse-clojure, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 3d261f5d3c 072/185: Bump version of a, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 47cf208a91 091/185: Fix parsing of tags/discard with :lexical-preservation, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj da4bacb5f5 078/185: Rename parseclj-reduce to parseclj-parse, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 2a42dcb6fa 066/185: Update License info in README, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ba9f4d723f 076/185: Document proposal for alternative package organization, ELPA Syncer, 2021/12/28