]> gitweb.factorcode.org Git - factor.git/commitdiff
toml: fix issue with sub-tables being defined first
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 7 Jan 2024 01:46:48 +0000 (17:46 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 7 Jan 2024 01:46:48 +0000 (17:46 -0800)
basis/toml/toml-tests.factor
basis/toml/toml.factor

index dca56efe6d2ba7650a467d718c7d3b7315c0563e..a9075d28b988598f90fa4df2ef893c9431380881 100644 (file)
@@ -141,6 +141,17 @@ hosts = [
     temp_targets = { case = 72.0 }" toml>
 ] unit-test
 
+{
+    H{ { "foo" H{ { "qux" 456 } { "bar" H{ { "baz" 123 } } } } } }
+} [
+[=[
+[foo.bar]
+baz = 123
+[foo]
+qux = 456
+]=] toml>
+] unit-test
+
 ! TESTS FROM 1.0.0 SPEC
 
 ! Comments
index ac0f6d7771c5db972c7aed615f4d36c0b2f4a07c..37e04293d00580d9d3980d4e53a840f8f9fbc09b 100644 (file)
@@ -22,11 +22,15 @@ TUPLE: entry key value ;
 : check-no-key ( key assoc -- key assoc )
     2dup at* nip [ over duplicate-key ] when ;
 
+: check-no-value ( key assoc -- table )
+    over '[
+        [ dup hashtable? [ _ duplicate-key ] unless ]
+        [ H{ } clone ] if* dup
+    ] change-at ;
+
 : entries-at ( table keys -- key entries )
     unclip-last -rot [
-        over ?at [ nip ] [
-            H{ } clone [ spin check-no-key set-at ] keep
-        ] if
+        over ?at [ nip ] [ swap check-no-value ] if
     ] each ;
 
 GENERIC: update-toml ( root table entry -- root table' )
@@ -37,9 +41,7 @@ M: entry update-toml
 
 M: table update-toml
     nip dupd [ name>> entries-at ] [ array?>> ] bi
-    H{ } clone [
-        swap [ -rot push-at ] [ -rot check-no-key set-at ] if
-    ] keep ;
+    [ H{ } clone [ -rot push-at ] keep ] [ check-no-value ] if ;
 
 : ws ( -- parser )
     [ " \t" member? ] satisfy repeat0 ;