[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr 4c419bcee2 37/84: fix: Support TOML tables speci
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr 4c419bcee2 37/84: fix: Support TOML tables specified as plists |
Date: |
Tue, 3 May 2022 09:58:11 -0400 (EDT) |
branch: externals/tomelr
commit 4c419bcee218a95d6669a5b198d1b71f6a8e7691
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
fix: Support TOML tables specified as plists
---
test/tplist.el | 16 +++++++++----
tomelr.el | 76 +++++++++++++++++++++++++++++++---------------------------
2 files changed, 53 insertions(+), 39 deletions(-)
diff --git a/test/tplist.el b/test/tplist.el
index 844ec11101..a8ebf8086f 100644
--- a/test/tplist.el
+++ b/test/tplist.el
@@ -38,9 +38,14 @@
:str_list ("a" "b" "c")
:bool_list (t :false t :false)
:list_of_lists [(1 2) (3 4 5)]
- ;; TODO plist specification of TOML tables is not yet
supported.
- ;; :map (:key1 123
- ;; :key2 "xyz")
+ :map (:key1 123
+ :key2 "xyz")
+ ;; TODO plist specification of TOML tables arrays is
+ ;; not yet supported.
+ ;; :list_of_maps [(:key1 123
+ ;; :key2 "xyz")
+ ;; (:key1 567
+ ;; :key2 "klm")]
)))
(ref '("int = 123
str = \"abc\"
@@ -49,7 +54,10 @@ bool_true = true
int_list = [ 1, 2, 3 ]
str_list = [ \"a\", \"b\", \"c\" ]
bool_list = [ true, false, true, false ]
-list_of_lists = [ [ 1, 2 ], [ 3, 4, 5 ] ]"))
+list_of_lists = [ [ 1, 2 ], [ 3, 4, 5 ] ]
+[map]
+ key1 = 123
+ key2 = \"xyz\""))
out)
(dolist (el inp)
(push (tomelr-encode el) out))
diff --git a/tomelr.el b/tomelr.el
index 5561d5604e..2ba7549787 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -24,6 +24,7 @@
;;; Code:
+(require 'json)
(require 'map)
(require 'subr-x) ;For `string-trim' on Emacs versions 27.2 and older
@@ -208,43 +209,46 @@ returns the TOML representation as a string."
(defun tomelr--print-stringlike (object &optional type)
"Insert OBJECT encoded as a TOML string at point.
-TYPE is set to `table' if OBJECT is a TOML Table key.
+Possible value of TYPE are `table', `table-array' or nil.
Return nil if OBJECT cannot be encoded as a TOML string."
- (cond ((stringp object)
- ;; (message "[tomelr--print-stringlike DBG] %S is string" object)
- (tomelr--print-string object))
- ((keywordp object) ;Symbol beginning with `:', like `:some_key'
- ;; (message "[tomelr--print-stringlike DBG] %S is keyword" object)
- (tomelr--print-string
- (string-trim-left (symbol-name object) ":")
- 'keyword))
- ((symbolp 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
"."))))
- ((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)))))))
+ (let ((sym-name (cond ((stringp object)
+ object)
+ ;; Symbol beginning with `:', like `:some_key'
+ ((keywordp object)
+ (string-trim-left (symbol-name object) ":"))
+ ((symbolp object)
+ (symbol-name object)))))
+ (cond
+ ((equal type 'table)
+ ;; (message "[tomelr--print-stringlike DBG] %S is symbol, type = %S,
depth = %d"
+ ;; object type tomelr--print-indentation-depth)
+ (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 "."))))
+ ((equal type 'table-array)
+ (let ((tta-name (format "[[%s]]" sym-name)))
+ (setq tomelr--print-table-array-key tta-name)
+ (princ tta-name)))
+ ((stringp object)
+ ;; (message "[tomelr--print-stringlike DBG] %S is string" object)
+ (tomelr--print-string sym-name))
+ ((keywordp object)
+ ;; (message "[tomelr--print-stringlike DBG] %S is keyword" object)
+ (tomelr--print-string sym-name 'keyword))
+ (sym-name
+ (princ sym-name)))))
(defun tomelr--print-key (key &optional type)
"Insert a TOML key representation of KEY at point.
@@ -273,6 +277,8 @@ Definition of a TOML Table (TT):
;; (car object) (type-of (car object)))
(setq tablep
(cond
+ ((json-plist-p object)
+ t)
((seq-every-p
;; Ensure that every element in the `object' is a (KEY
;; . VAL) kind of cons.
- [elpa] externals/tomelr c872e9efc1 17/84: test: Add test for integer scalar key-value pairs, (continued)
- [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, 2022/05/03
- [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 <=
- [elpa] externals/tomelr baf81228bc 45/84: fix: Correct the spec for nested array of tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4dda8e6be3 46/84: chore: Style edits in a test, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 5959b90ffa 44/84: fix: Don't let TOML tables be recognized as TOML tables arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr b64eb07e99 49/84: fix: Detect TT with sub-tables correctly, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4386d99a85 65/84: refactor(minor): Use `tomelr--toml-table-p`, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 26f1fc2f3c 55/84: doc: Update the medley example, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr e2b313ca3b 52/84: feat: Implement everything planned in the initial spec, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4434ccc64b 70/84: chore: Bump version, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 10a1994aed 51/84: feat: Support (lightly tested) nested TOML Table Arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr df0e73334f 59/84: Revert "doc: Update the medley example", ELPA Syncer, 2022/05/03