]> gitweb.factorcode.org Git - factor.git/commitdiff
toml: fix bug with `a=[]` by moving parser around. add tests and path>toml
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 4 Oct 2023 17:31:04 +0000 (12:31 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 4 Oct 2023 17:31:04 +0000 (12:31 -0500)
basis/toml/toml-tests.factor
basis/toml/toml.factor

index 1fdaf101b1a433ffdb3d140a533042f0115b6d5f..0b9c483f5616ec0112ae4d3cc7bc68885c950595 100644 (file)
@@ -509,6 +509,10 @@ animal = { type.name = "pug" }]=] toml>
            { x = 2, y = 4, z = 8 } ] ]=] toml>
 ] unit-test
 
+{ H{ { "a" { } } } } [ "a=[]" toml> ] unit-test
+{ H{ { "a" { 1 } } } } [ "a=[1]" toml> ] unit-test
+{ H{ { "a" { 1 2 3 } } } } [ "a=[1,2,3]" toml> ] unit-test
+
 ! unreleased
 
 ! Clarify Unicode and UTF-8 references.
index fe93abba20f4648ccf9a50aa656d3aa2c951c81e..eec51118d917f5be12c248ab04f808a50e3e178b 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2019 John Benediktsson
 ! See https://factorcode.org/license.txt for BSD license
 
-USING: accessors ascii assocs hashtables kernel make math.parser
-peg peg.parsers regexp sequences splitting strings.parser ;
+USING: accessors ascii assocs hashtables io.encodings.utf8
+io.files kernel make math.parser peg peg.parsers regexp
+sequences splitting strings.parser ;
 
 ! https://github.com/toml-lang/toml/blob/main/toml.abnf
 
@@ -243,6 +244,7 @@ DEFER: key-value-parser
 : value-parser ( -- parser )
     [
         [
+            array-parser ,
             boolean-parser ,
             datetime-parser ,
             date-parser ,
@@ -250,7 +252,6 @@ DEFER: key-value-parser
             float-parser ,
             integer-parser ,
             string-parser ,
-            array-parser ,
             inline-table-parser ,
         ] choice*
     ] delay ;
@@ -322,3 +323,6 @@ PRIVATE>
 
 : toml> ( string -- assoc )
     [ H{ } clone dup ] dip parse-toml [ update-toml ] each drop ;
+
+: path>toml ( path -- assoc )
+    utf8 file-contents toml> ;