]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/toml/toml.factor
toml: parse more datetime formats into timestamps
[factor.git] / basis / toml / toml.factor
index 4697b81cf42b2bf6a38fa812f2c422fc2f13a6d9..ac0f6d7771c5db972c7aed615f4d36c0b2f4a07c 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2019 John Benediktsson
 ! See https://factorcode.org/license.txt for BSD license
 
-USING: accessors ascii assocs hashtables io.encodings.utf8
-io.files kernel make math.parser peg peg.parsers regexp
-sequences splitting strings.parser ;
+USING: accessors ascii assocs calendar.parser 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
 
@@ -186,12 +186,12 @@ M: table update-toml
         decdigit 2 exactly-n ,
         ":" token ,
         decdigit 2 exactly-n ,
-        "." token decdigit repeat1 2seq optional ,
+        "." token decdigit repeat1 2seq optional [ concat ] action ,
     ] seq* [ "" concat-as ] action ;
 
 : timezone-parser ( -- parser )
     "Z" token
-    "-" token
+    "+" token "-" token 2choice
     decdigit 2 exactly-n ":" token
     decdigit 2 exactly-n 4seq [ "" concat-as ] action
     2choice ;
@@ -199,10 +199,10 @@ M: table update-toml
 : datetime-parser ( -- parser )
     [
         date-parser ,
-        "T" token " " token 2choice ,
+        "T" token "t" token " " token 3choice ,
         time-parser ,
         timezone-parser optional ,
-    ] seq* [ "" concat-as ] action ;
+    ] seq* [ "" concat-as rfc3339>timestamp ] action ;
 
 : separator ( -- parser )
     "," token comment optional 2seq ;