Skip to content

Commit

Permalink
feat: Implement everything planned in the initial spec
Browse files Browse the repository at this point in the history
Fix converting of array of TOML tables represented by S-exp vectors.
  • Loading branch information
kaushalmodi committed Apr 30, 2022
1 parent 10a1994 commit e2b313c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
9 changes: 4 additions & 5 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#+property: header-args :eval never-export

*NOTE*: This library is in a severe beta stage. It is not ready for any use!! :poop:

[[https://github.com/kaushalmodi/tomelr/actions][https://github.com/kaushalmodi/tomelr/actions/workflows/test.yml/badge.svg]] [[https://www.gnu.org/licenses/gpl-3.0][https://img.shields.io/badge/License-GPL%20v3-blue.svg]]

* Installation
Expand All @@ -18,7 +16,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 [7/7]
- [X] Scalar
- [X] Boolean
- [X] Integer
Expand All @@ -35,7 +33,7 @@ specification defined below.
- [X] Array of Tables
- [X] Basic Array of Tables
- [X] Nested Array of Tables
- [ ] Property Lists
- [X] Property Lists
* Specification and Conversion Examples
[[https://scripter.co/defining-tomelr/][Companion blog post]]

Expand Down Expand Up @@ -954,7 +952,8 @@ contributors = [
]
}
#+end_example
** TODO P-lists
** DONE P-lists
CLOSED: [2022-04-30 Sat 01:55]
**** S-expression
#+begin_src emacs-lisp :eval no :noweb-ref p-list
'(:int 123
Expand Down
3 changes: 3 additions & 0 deletions test/tinternal.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
;; TTA with 1 table nesting another TTA
(((a . (((b . 2))))))
((:a ((:b 2))))
;; TTA with vector notation
[(:a 100 :b "foo")
(:a 200 :b "bar")]
)))
(dolist (el inp)
(should (equal t (tomelr--toml-table-array-p el))))))
Expand Down
22 changes: 11 additions & 11 deletions test/tplist.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
: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\"
Expand All @@ -55,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))
Expand Down
22 changes: 13 additions & 9 deletions tomelr.el
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ Definition of a TOML Table Array (TTA):
TOML Table (TT)."
(let (ttap)
(when (and (not (tomelr--toml-table-p object))
(listp object))
(or (listp object)
(vectorp object)))
;; (message "[tomelr--toml-table-array-p DBG] object = %S, type = %S, len = %d"
;; object (type-of object) (safe-length object))
(setq ttap (cond
Expand All @@ -404,18 +405,21 @@ Definition of a TOML Table Array (TTA):
;; (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))
(or
(tomelr--toml-table-p elem)
;; Handling the case of a nested TTA.
;; Example: (((a . (((b . 2))))))
(and (listp elem) ; ((a . (((b . 2)))))
(listp (car elem)) ; (a . (((b . 2))))
(symbolp (car (car elem))) ; a <- symbol
;; --(((b . 2)))- <-- This will be a TTA.
(tomelr--toml-table-array-p (cdr (car 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))))
;; (message "[tomelr--toml-table-array-p DBG] ttap = %S" ttap)
;; (message "=====")
ttap))

(defun tomelr--print-tta-key ()
Expand Down

0 comments on commit e2b313c

Please sign in to comment.