[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr ad8366d904 36/84: feat: Support basic TOML Table
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr ad8366d904 36/84: feat: Support basic TOML Table Arrays |
Date: |
Tue, 3 May 2022 09:58:10 -0400 (EDT) |
branch: externals/tomelr
commit ad8366d904dea6fc3f4af5bf57bcd92c6b37f57e
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
feat: Support basic TOML Table Arrays
---
README.org | 35 +++++++++++++++++++++++++---
test/all-tests.el | 1 +
test/ttable-array.el | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tomelr.el | 50 ++++++++++++++++++++++++++++++++-------
4 files changed, 141 insertions(+), 11 deletions(-)
diff --git a/README.org b/README.org
index 6e45a61a8f..18d1b37754 100644
--- a/README.org
+++ b/README.org
@@ -32,8 +32,8 @@ specification defined below.
- [X] Tables
- [X] Basic Tables
- [X] Nested Tables
-- [ ] Array of Tables
- - [ ] Basic Array of Tables
+- [-] Array of Tables
+ - [X] Basic Array of Tables
- [ ] Nested Array of Tables
- [ ] Property Lists
* Specification and Conversion Examples
@@ -483,7 +483,8 @@ CLOSED: [2022-04-29 Fri 14:30]
}
#+end_example
** TOML Array of Tables: Lists of Maps
-*** Basic Array of Tables
+*** DONE Basic Array of Tables
+CLOSED: [2022-04-29 Fri 18:14]
**** S-expression
#+begin_src emacs-lisp :eval no :noweb-ref table-arrays
'((products . (((name . "Hammer")
@@ -500,6 +501,34 @@ CLOSED: [2022-04-29 Fri 14:30]
(note . "A note `mono`.")))))
#+end_src
**** TOML
+#+begin_src emacs-lisp :noweb yes :exports results :wrap src toml
+(tomelr-encode
+ <<table-arrays>>)
+#+end_src
+
+#+RESULTS:
+#+begin_src toml
+[[products]]
+ name = "Hammer"
+ sku = 738594937
+[[products]]
+[[products]]
+ name = "Nail"
+ sku = 284758393
+ color = "gray"
+[[org_logbook]]
+ timestamp = 2022-04-08T14:53:00-04:00
+ note = """
+This note addition prompt shows up on typing the `C-c C-z` binding.
+See
[org#Drawers](https://www.gnu.org/software/emacs/manual/html_mono/org.html#Drawers)."""
+[[org_logbook]]
+ timestamp = 2018-09-06T11:45:00-04:00
+ note = "Another note **bold** _italics_."
+[[org_logbook]]
+ timestamp = 2018-09-06T11:37:00-04:00
+ note = "A note `mono`."
+#+end_src
+
#+begin_src toml
[[products]]
name = "Hammer"
diff --git a/test/all-tests.el b/test/all-tests.el
index 8a19f4a81a..b031e739ec 100644
--- a/test/all-tests.el
+++ b/test/all-tests.el
@@ -25,4 +25,5 @@
(require 'tnil)
(require 'tarray)
(require 'ttable)
+(require 'ttable-array)
(require 'tplist)
diff --git a/test/ttable-array.el b/test/ttable-array.el
new file mode 100644
index 0000000000..37392ba28d
--- /dev/null
+++ b/test/ttable-array.el
@@ -0,0 +1,66 @@
+;; -*- lexical-binding: t; -*-
+
+;; Authors: Kaushal Modi <kaushal.modi@gmail.com>
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Test conversion to TOML tables.
+
+;;; Code:
+(require 'tomelr)
+
+;;;; Basic array of tables
+(ert-deftest test-array-of-tables ()
+ (let ((inp '(((products . (((name . "Hammer")
+ (sku . 738594937))
+ ()
+ ((name . "Nail")
+ (sku . 284758393)
+ (color . "gray"))))
+ (org_logbook . (((timestamp . 2022-04-08T14:53:00-04:00)
+ (note . "This note addition prompt shows up
on typing the `C-c C-z` binding.\nSee
[org#Drawers](https://www.gnu.org/software/emacs/manual/html_mono/org.html#Drawers)."))
+ ((timestamp . 2018-09-06T11:45:00-04:00)
+ (note . "Another note **bold** _italics_."))
+ ((timestamp . 2018-09-06T11:37:00-04:00)
+ (note . "A note `mono`.")))))))
+ (ref '("[[products]]
+ name = \"Hammer\"
+ sku = 738594937
+[[products]]
+[[products]]
+ name = \"Nail\"
+ sku = 284758393
+ color = \"gray\"
+[[org_logbook]]
+ timestamp = 2022-04-08T14:53:00-04:00
+ note = \"\"\"
+This note addition prompt shows up on typing the `C-c C-z` binding.
+See
[org#Drawers](https://www.gnu.org/software/emacs/manual/html_mono/org.html#Drawers).\"\"\"
+[[org_logbook]]
+ timestamp = 2018-09-06T11:45:00-04:00
+ note = \"Another note **bold** _italics_.\"
+[[org_logbook]]
+ timestamp = 2018-09-06T11:37:00-04:00
+ note = \"A note `mono`.\""))
+ out)
+ (dolist (el inp)
+ (push (tomelr-encode el) out))
+ (should (equal ref (nreverse out)))))
+
+
+(provide 'ttable-array)
diff --git a/tomelr.el b/tomelr.el
index fc504b5a29..5561d5604e 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -53,7 +53,10 @@ ordered alphabetically.")
Dictates repetitions of `tomelr-encoding-default-indentation'.")
(defvar tomelr--print-table-hierarchy ()
- "Internal variable used to save the TOML table hierarchy.")
+ "Internal variable used to save the TOML Table hierarchy.")
+
+(defvar tomelr--print-table-array-key ""
+ "Internal variable used to save the TOML Table Array name.")
(defvar tomelr--print-keyval-separator " = "
"String used to separate key-value pairs during encoding.")
@@ -236,6 +239,10 @@ Return nil if OBJECT cannot be encoded as a TOML string."
;; (message "[tomelr--print-stringlike DBG] table hier: %S"
;; tomelr--print-table-hierarchy)
(princ (format "[%s]" (string-join tomelr--print-table-hierarchy
"."))))
+ ((equal type 'table-array)
+ (let ((tta-name (format "[[%s]]" sym-name)))
+ (setq tomelr--print-table-array-key tta-name)
+ (princ tta-name)))
(t
(princ sym-name)))))))
@@ -290,6 +297,7 @@ Definition of a TOML Table (TT):
"Insert TOML representation of KEY - VAL pair at point."
(let ((type (cond
((tomelr--toml-table-p val) 'table)
+ ((tomelr--toml-table-array-p val) 'table-array)
(t nil))))
;; (message "[tomelr--print-pair DBG] key = %S, val = %S, type = %S"
;; key val type)
@@ -356,21 +364,47 @@ See `tomelr-encode-alist' that returns the same as a
string."
((signal 'tomelr-error (list list)))))
;;;; Arrays
+(defun tomelr--toml-table-array-p (object)
+ "Return non-nil if OBJECT can represent a TOML Table Array.
+
+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 (listp object)
+ (seq-every-p
+ (lambda (elem)
+ (tomelr--toml-table-p elem))
+ object)))
+
(defun tomelr--print-array (array)
"Insert a TOML representation of ARRAY at point.
See `tomelr-encode-array' that returns the same as a string."
- (insert "[ ")
- (unless (= 0 (length array))
- (tomelr--with-indentation
+ ;; (message "[tomelr--print-array DBG] array = %S, TTA = %S"
+ ;; array (tomelr--toml-table-array-p array))
+ (cond
+ ((tomelr--toml-table-array-p array)
+ (unless (= 0 (length array))
(let ((first t))
(mapc (lambda (elt)
(if first
(setq first nil)
- (insert ", "))
+ (insert (format "\n%s" tomelr--print-table-array-key)))
(tomelr--print elt))
- array)))
- (insert " "))
- (insert "]"))
+ array))))
+ (t
+ (insert "[ ")
+ (unless (= 0 (length array))
+ (tomelr--with-indentation
+ (let ((first t))
+ (mapc (lambda (elt)
+ (if first
+ (setq first nil)
+ (insert ", "))
+ (tomelr--print elt))
+ array)))
+ (insert " "))
+ (insert "]"))))
(defun tomelr-encode-array (array)
"Return a TOML representation of ARRAY.
- [elpa] externals/tomelr af40c0b40f 11/84: fix: Require subr-x for older Emacs versions, (continued)
- [elpa] externals/tomelr af40c0b40f 11/84: fix: Require subr-x for older Emacs versions, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 060c38b934 16/84: chore(readme): Limit up to 3 levels of headings for Org exports, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 20bf9e6c54 12/84: chore(doc): Add GHA and license badges, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr f37841cc78 25/84: test: Add test for TOML Array of Arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr cedb75df72 29/84: feat: Support basic TOML tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 91800b26b8 21/84: feat: Recognize RFC 3339 formatted date-time + offset, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 83e924559e 13/84: chore(doc): Fix typo, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 98c9b8c1fc 26/84: fix: Use `=` and `length` separately instead of `length=`, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr c0962ba15f 33/84: fix: Don't run plist to TOML conversion test on emacs 26.3 and older, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 3c068fb9d9 34/84: refactor: Move TOML Table detection logic to a separate fn, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr ad8366d904 36/84: feat: Support basic TOML Table Arrays,
ELPA Syncer <=
- [elpa] externals/tomelr 55fefb0fa8 40/84: doc: Add few links, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 38160ef271 41/84: fix: Stricter condition before starting TOML table array check, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a7b3a57037 48/84: feat: Make a very basic nested array of TTA work, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 3aa4dc1dbd 54/84: chore: Add Package-Requires and other info in the header comment, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr f3b6951cfe 53/84: doc: Add note that the scalars need to be earlier in the order, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 192cb06a23 57/84: chore(style): Whitespace change only, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 6d2be83669 69/84: chore: package-lint fixes, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 41ccea4ebe 64/84: refactor: Remove unnecessary tomelr-encode-keyword, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 406f4922a8 58/84: test: Add tests for json.el functions used in tomelr, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr b3b6a28d15 68/84: doc: Add more examples, ELPA Syncer, 2022/05/03