Skip to content

Commit

Permalink
toml: fix issue with sub-tables being defined first
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Jan 7, 2024
1 parent 7df25bc commit ba8d61e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 11 additions & 0 deletions basis/toml/toml-tests.factor
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions basis/toml/toml.factor
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand All @@ -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 ;
Expand Down

0 comments on commit ba8d61e

Please sign in to comment.