emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/tomelr 0f4e7b4f2c 47/84: fix: Better detection of neste


From: ELPA Syncer
Subject: [elpa] externals/tomelr 0f4e7b4f2c 47/84: fix: Better detection of nested TTA, but still wip
Date: Tue, 3 May 2022 09:58:11 -0400 (EDT)

branch: externals/tomelr
commit 0f4e7b4f2c40a2cdce735d614eba9b7ac4640d06
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>

    fix: Better detection of nested TTA, but still wip
    
    This fix also breaks the plist support for TTA
---
 README.org        |  7 +++----
 test/tinternal.el | 10 ++++++++++
 test/tplist.el    | 23 ++++++++++++-----------
 tomelr.el         | 33 ++++++++++++++++++++++++++-------
 4 files changed, 51 insertions(+), 22 deletions(-)

diff --git a/README.org b/README.org
index 4944ec5fcb..e44d71aea8 100644
--- a/README.org
+++ b/README.org
@@ -18,7 +18,7 @@ the Emacs core library 
[[https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/j
 
 It will then be gradually refactored so that it meets the
 specification defined below.
-* Library Completion Status [6/7]
+* Library Completion Status [5/7]
 - [X] Scalar
   - [X] Boolean
   - [X] Integer
@@ -35,7 +35,7 @@ specification defined below.
 - [-] Array of Tables
   - [X] Basic Array of Tables
   - [ ] Nested Array of Tables
-- [X] Property Lists
+- [ ] Property Lists
 * Specification and Conversion Examples
 [[https://scripter.co/defining-tomelr/][Companion blog post]]
 
@@ -952,8 +952,7 @@ contributors = [
   ]
 }
 #+end_example
-** DONE P-lists
-CLOSED: [2022-04-29 Fri 18:42]
+** TODO P-lists
 **** S-expression
 #+begin_src emacs-lisp :eval no :noweb-ref p-list
 '(:int 123
diff --git a/test/tinternal.el b/test/tinternal.el
index 5b4e1bb5d8..0e46b57ebb 100644
--- a/test/tinternal.el
+++ b/test/tinternal.el
@@ -47,7 +47,17 @@
 ;;;; tomelr--toml-table-array-p
 (ert-deftest test-internal-valid-tta ()
   (let ((inp '(
+               ;; ;; TTA with 1 table of 1 key-val pair
                (((a . 1)))
+               ((:a  1))
+               ;; ;; TTA with 2 tables of 2 key-val pairs
+               (((a . 1) (b . 2))
+                ((a . 100) (b . 200)))
+               ((:a 1 :b 2)
+                (:a 100 :b 200))
+               ;; TTA with 1 table nesting another TTA
+               (((a . (((b . 2))))))
+               ((:a ((:b 2))))
                )))
     (dolist (el inp)
       (should (equal t (tomelr--toml-table-array-p el))))))
diff --git a/test/tplist.el b/test/tplist.el
index 6798e137cf..2191d305f9 100644
--- a/test/tplist.el
+++ b/test/tplist.el
@@ -40,10 +40,11 @@
                   :list_of_lists [(1 2) (3 4 5)]
                   :map (:key1 123
                         :key2 "xyz")
-                  :list_of_maps [(:key1 123
-                                  :key2 "xyz")
-                                 (:key1 567
-                                  :key2 "klm")])))
+                  ;; :list_of_maps [(:key1 123
+                  ;;                 :key2 "xyz")
+                  ;;                (:key1 567
+                  ;;                 :key2 "klm")]
+                  )))
           (ref '("int = 123
 str = \"abc\"
 bool_false = false
@@ -54,13 +55,13 @@ bool_list = [ true, false, true, false ]
 list_of_lists = [ [ 1, 2 ], [ 3, 4, 5 ] ]
 [map]
   key1 = 123
-  key2 = \"xyz\"
-[[list_of_maps]]
-  key1 = 123
-  key2 = \"xyz\"
-[[list_of_maps]]
-  key1 = 567
-  key2 = \"klm\""))
+  key2 = \"xyz\""))
+          ;; [[list_of_maps]]
+          ;;   key1 = 123
+          ;;   key2 = \"xyz\"
+          ;; [[list_of_maps]]
+          ;;   key1 = 567
+          ;;   key2 = \"klm\""))
           out)
       (dolist (el inp)
         (push (tomelr-encode el) out))
diff --git a/tomelr.el b/tomelr.el
index 2c3ed32b74..f61c10db9d 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -378,13 +378,32 @@ Definition of a TOML Table Array (TTA):
 
 - OBJECT is TTA if it is of type ((TT1) (TT2) ..) where each element is a
   TOML Table (TT)."
-  (when (and (not (tomelr--toml-table-p object))
-             (not (stringp object))
-             (mapp object)) ;Because `mapp' is non-nil for strings too
-    (seq-every-p
-     (lambda (elem)
-       (tomelr--toml-table-p elem))
-     object)))
+  (let (ttap)
+    (when (and (not (tomelr--toml-table-p object))
+               (listp object))
+      ;; (message "[tomelr--toml-table-array-p DBG] object = %S, type = %S, 
len = %d"
+      ;;          object (type-of object) (safe-length object))
+      (setq ttap (cond
+                  ((seq-every-p
+                    (lambda (elem)
+                      ;; (message "  [tomelr--toml-table-array-p DBG] elem = 
%S, type = %S, len = %d"
+                      ;;          elem (type-of elem) (safe-length elem))
+                      ;; (when (listp elem)
+                      ;;   (message "  [tomelr--toml-table-array-p DBG] 
sub-elem 0 = %S, type = %S, len = %d"
+                      ;;            (car elem) (type-of (car elem)) 
(safe-length (car elem))))
+                      (tomelr--toml-table-p elem))
+                    object)
+                   t)
+                  ;; Handling the case of a nested TTA.
+                  ;; Example:                                 (((a . (((b . 
2))))))
+                  ((and (listp (car object))                 ; ((a . (((b . 
2)))))
+                        (listp (car (car object)))           ;  (a . (((b . 
2))))
+                        (symbolp (car (car (car object)))))  ;   a  <- symbol
+                   ;;                           ------(((b . 2)))-----  <-- 
This will be a TTA.
+                   (tomelr--toml-table-array-p (cdr (car (car object)))))
+                  (t
+                   nil))))
+    ttap))
 
 (defun tomelr--print-array (array)
   "Insert a TOML representation of ARRAY at point.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]