-USING: assocs multiline present toml tools.test ;
+USING: assocs calendar multiline present toml tools.test ;
! Example document
"bio"
"GitHub Cofounder & CEO\nLikes tater tots and beer."
}
- { "dob" "1979-05-27T07:32:00Z" }
+ { "dob"
+ T{ timestamp
+ { year 1979 }
+ { month 5 }
+ { day 27 }
+ { hour 7 }
+ { minute 32 }
+ }
+ }
}
}
{
! Offset Date-Time
-! XXX:
+{
+ H{
+ {
+ "odt4"
+ T{ timestamp
+ { year 1979 }
+ { month 5 }
+ { day 27 }
+ { hour 7 }
+ { minute 32 }
+ }
+ }
+ {
+ "odt1"
+ T{ timestamp
+ { year 1979 }
+ { month 5 }
+ { day 27 }
+ { hour 7 }
+ { minute 32 }
+ }
+ }
+ {
+ "odt2"
+ T{ timestamp
+ { year 1979 }
+ { month 5 }
+ { day 27 }
+ { minute 32 }
+ { gmt-offset T{ duration { hour -7 } } }
+ }
+ }
+ {
+ "odt3"
+ T{ timestamp
+ { year 1979 }
+ { month 5 }
+ { day 27 }
+ { minute 32 }
+ { second 999999/1000000 }
+ { gmt-offset T{ duration { hour -7 } } }
+ }
+ }
+ }
+} [
+ [=[
+odt1 = 1979-05-27T07:32:00Z
+odt2 = 1979-05-27T00:32:00-07:00
+odt3 = 1979-05-27T00:32:00.999999-07:00
+odt4 = 1979-05-27 07:32:00Z
+]=] toml>
+] unit-test
! Local Date-Time
-! XXX:
+{
+ H{
+ {
+ "ldt1"
+ T{ timestamp
+ { year 1979 }
+ { month 5 }
+ { day 27 }
+ { hour 7 }
+ { minute 32 }
+ }
+ }
+ {
+ "ldt2"
+ T{ timestamp
+ { year 1979 }
+ { month 5 }
+ { day 27 }
+ { minute 32 }
+ { second 999999/1000000 }
+ }
+ }
+ }
+} [
+ [=[
+ldt1 = 1979-05-27T07:32:00
+ldt2 = 1979-05-27T00:32:00.999999
+]=] toml>
+] unit-test
! Local Date
-! XXX:
+{ H{ { "ld1" "1979-05-27" } } } [
+ [=[
+ld1 = 1979-05-27
+]=] toml>
+] unit-test
! Local Time
-! XXX:
+{ H{ { "lt2" "00:32:00.999999" } { "lt1" "07:32:00" } } } [
+ [=[
+lt1 = 07:32:00
+lt2 = 00:32:00.999999
+]=] toml>
+] unit-test
! Array
! 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
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 ;
: 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 ;