Skip to content

Commit

Permalink
fix: Detect nested TTA correctly when not present in first TT key
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Apr 30, 2022
1 parent b64eb07 commit a33dbd1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions test/tinternal.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
((a . 1)
(b . ((c . 3)
(d . 4))))
;; Nested TTA
((a . 1)
(b . (((c . 3))
((c . 300)))))
)))
(dolist (el inp)
(should (equal t (tomelr--toml-table-p el))))))
Expand Down
12 changes: 11 additions & 1 deletion test/ttable-array.el
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ See [org#Drawers](https://www.gnu.org/software/emacs/manual/html_mono/org.html#D
(let ((inp '(
((fruits . (((varieties . (((name . "red delicious"))
((name . "granny smith"))))))))
((fruits . (((name . "apple")
(varieties . (((name . "red delicious"))
((name . "granny smith"))))))))
;; ((fruits . (((name . "apple")
;; (physical . ((color . "red")
;; (shape . "round")))
Expand All @@ -91,7 +94,14 @@ See [org#Drawers](https://www.gnu.org/software/emacs/manual/html_mono/org.html#D
;; ((name . "banana")
;; (varieties . (((name . "plantain"))))))))
))
(ref '("[[fruits]]
(ref '(
"[[fruits]]
[[fruits.varieties]]
name = \"red delicious\"
[[fruits.varieties]]
name = \"granny smith\""
"[[fruits]]
name = \"apple\"
[[fruits.varieties]]
name = \"red delicious\"
[[fruits.varieties]]
Expand Down
24 changes: 18 additions & 6 deletions tomelr.el
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,24 @@ Definition of a TOML Table (TT):
;; (when (listp elem)
;; (message " [tomelr--toml-table-p DBG] sub-elem 0 = %S, type = %S, len = %d"
;; (car elem) (type-of (car elem)) (safe-length (car elem))))
(or (and (consp elem)
(= 1 (safe-length elem))
(not (consp (car elem))))
(and (listp elem)
(symbolp (car elem))
(tomelr--toml-table-p (cdr elem)))))
(or
;; Basic TT case
;; ((a . 1)
;; (b . 2))
(and (consp elem)
(= 1 (safe-length elem))
(not (consp (car elem))))
(and (listp elem)
(symbolp (car elem))
(or
;; Nested TT case
;; ((b . ((c . 3)
;; (d . 4))))
(tomelr--toml-table-p (cdr elem))
;; Nested TTA case
;; ((b . (((c . 3))
;; ((c . 300)))))
(tomelr--toml-table-array-p (cdr elem))))))
object)
t)
(t
Expand Down

0 comments on commit a33dbd1

Please sign in to comment.