[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr a1f434f03a 31/84: feat: Support nested TOML tabl
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr a1f434f03a 31/84: feat: Support nested TOML tables |
Date: |
Tue, 3 May 2022 09:58:10 -0400 (EDT) |
branch: externals/tomelr
commit a1f434f03a761c50cd9813e27d5441d6b2c2902d
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
feat: Support nested TOML tables
---
README.org | 15 +++++++++++----
test/ttable.el | 18 ++++++++++++++++++
tomelr.el | 30 ++++++++++++++++++++++++------
3 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/README.org b/README.org
index 2acd5d41be..6a43d4df76 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 [4/7]
+* Library Completion Status [5/7]
- [X] Scalar
- [X] Boolean
- [X] Integer
@@ -29,9 +29,9 @@ specification defined below.
- [X] Nil
- [X] Arrays
- [X] Array of Arrays
-- [-] Tables
+- [X] Tables
- [X] Basic Tables
- - [ ] Nested Tables
+ - [X] Nested Tables
- [ ] Array of Tables
- [ ] Basic Array of Tables
- [ ] Nested Array of Tables
@@ -436,7 +436,8 @@ CLOSED: [2022-04-29 Fri 13:41]
}
}
#+end_example
-*** Nested TOML Tables
+*** DONE Nested TOML Tables
+CLOSED: [2022-04-29 Fri 14:30]
**** S-expression
#+begin_src emacs-lisp :eval no :noweb-ref nested-tables
'((table-1 . ((table-1a . ((key1 . "some string")
@@ -445,6 +446,12 @@ CLOSED: [2022-04-29 Fri 13:41]
(key2 . 98765))))))
#+end_src
**** TOML
+#+begin_src emacs-lisp :noweb yes :exports results :wrap src toml
+(tomelr-encode
+ <<nested-tables>>)
+#+end_src
+
+#+RESULTS:
#+begin_src toml
[table-1]
[table-1.table-1a]
diff --git a/test/ttable.el b/test/ttable.el
index fdcafa87f4..3898b187cd 100644
--- a/test/ttable.el
+++ b/test/ttable.el
@@ -41,5 +41,23 @@
(push (tomelr-encode el) out))
(should (equal ref (nreverse out)))))
+;;;; Nested tables
+(ert-deftest test-nested-table ()
+ (let ((inp '(((table-1 . ((table-1a . ((key1 . "some string")
+ (key2 . 123)))
+ (table-1b . ((key1 . "foo")
+ (key2 . 98765))))))))
+ (ref '("[table-1]
+ [table-1.table-1a]
+ key1 = \"some string\"
+ key2 = 123
+ [table-1.table-1b]
+ key1 = \"foo\"
+ key2 = 98765"))
+ out)
+ (dolist (el inp)
+ (push (tomelr-encode el) out))
+ (should (equal ref (nreverse out)))))
+
(provide 'ttable)
diff --git a/tomelr.el b/tomelr.el
index 4cbfbe45dc..55b3b07d73 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -52,6 +52,9 @@ ordered alphabetically.")
"Current indentation level during encoding.
Dictates repetitions of `tomelr-encoding-default-indentation'.")
+(defvar tomelr--print-table-hierarchy ()
+ "Internal variable used to save the TOML table hierarchy.")
+
(defvar tomelr--print-keyval-separator " = "
"String used to separate key-value pairs during encoding.")
@@ -211,12 +214,27 @@ Return nil if OBJECT cannot be encoded as a TOML string."
;; (message "[tomelr--print-stringlike DBG] %S is keyword" object)
(tomelr--print-string (symbol-name object) 1))
((symbolp object)
- ;; (message "[tomelr--print-stringlike DBG] %S is symbol" object)
- (cond
- ((equal type 'table)
- (princ (format "[%s]" (symbol-name object))))
- (t
- (princ (symbol-name object)))))))
+ (let ((sym-name (symbol-name object)))
+ ;; (message "[tomelr--print-stringlike DBG] %S is symbol, type =
%S, depth = %d"
+ ;; object type tomelr--print-indentation-depth)
+ (cond
+ ((equal type 'table)
+ (if (null (nth tomelr--print-indentation-depth
tomelr--print-table-hierarchy))
+ (progn
+ (push sym-name tomelr--print-table-hierarchy)
+ (setq tomelr--print-table-hierarchy (nreverse
tomelr--print-table-hierarchy)))
+ ;; Throw away table keys collected at higher depths, if
+ ;; any, from earlier runs of this function.
+ (setq tomelr--print-table-hierarchy
+ (seq-take tomelr--print-table-hierarchy
+ (1+ tomelr--print-indentation-depth)))
+ (setf (nth tomelr--print-indentation-depth
tomelr--print-table-hierarchy)
+ sym-name))
+ ;; (message "[tomelr--print-stringlike DBG] table hier: %S"
+ ;; tomelr--print-table-hierarchy)
+ (princ (format "[%s]" (string-join tomelr--print-table-hierarchy
"."))))
+ (t
+ (princ sym-name)))))))
(defun tomelr--print-key (key &optional type)
"Insert a TOML key representation of KEY at point.
- [elpa] branch externals/tomelr created (now a1fa47379e), ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 732140041e 07/84: doc: Discover `json-encoding-pretty-print` variable!, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr d96a3b235b 04/84: doc: Add LOGBOOK drawer example, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 05d2cafcd9 09/84: test: Add test for boolean scalar key-value pairs, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 2ea3b5e032 03/84: fix!: Set boolean false using :false value, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 28642f2e78 05/84: fix: dates will be strings in Lisp, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 52dc93201d 08/84: feat: First cut -- Port json-encode from json.el to tomelr-encode, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 7cd15e79b8 10/84: tool(ci): Add GHA setup, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr c872e9efc1 17/84: test: Add test for integer scalar key-value pairs, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a1f434f03a 31/84: feat: Support nested TOML tables,
ELPA Syncer <=
- [elpa] externals/tomelr 6bbe740e52 28/84: test: Test that 'false is also considered as boolean false in TOML, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 9c91e0dc07 18/84: test: Add test for float scalar key-value pairs, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 96c890a68b 23/84: feat: Convert Lisp lists to TOML arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr bb85106ee9 27/84: doc: Add spec for nested tables and arrays of tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 1d65064ffa 20/84: feat: Recognize local date format YYYY-MM-DD, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 2810504e84 32/84: feat: Add basic support for S-exp plists -> TOML conversion, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 0f4e7b4f2c 47/84: fix: Better detection of nested TTA, but still wip, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr cff1f8aa89 38/84: fix: Support TOML tables arrays specified as plist vector, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4c419bcee2 37/84: fix: Support TOML tables specified as plists, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr baf81228bc 45/84: fix: Correct the spec for nested array of tables, ELPA Syncer, 2022/05/03