Skip to content

Instantly share code, notes, and snippets.

@JRaspass
Created November 7, 2019 16:33
Show Gist options
  • Select an option

  • Save JRaspass/3ad55f144740237b4aaa04bbc4631de2 to your computer and use it in GitHub Desktop.

Select an option

Save JRaspass/3ad55f144740237b4aaa04bbc4631de2 to your computer and use it in GitHub Desktop.
--- a/lib/TOML/Tiny.pm6
+++ b/lib/TOML/Tiny.pm6
@@ -23,7 +23,8 @@ grammar Grammar {
proto token value {*}
+ rule value:sym<array> { '[' <value>* % ',' ']' }
token value:sym<datetime> { \d\d [\d\d] ** 3 % '-' T <value:time> Z }
token value:sym<date> { \d\d [\d\d] ** 3 % '-' }
token value:sym<false> { <sym> }
@@ -41,6 +42,7 @@ class Actions {
method key-value ($/) { make $<key>.made => $<value>.made }
method table ($/) { make $<key>.made => $<key-value>».made.Hash }
+ method value:sym<array> ($/) { make $<value>».made }
method value:sym<datetime> ($/) { make DateTime.new(~$/) }
method value:sym<date> ($/) { make Date.new(~$/) }
method value:sym<false> ($/) { make False }
diff --git a/t/values.t b/t/values.t
index 43f088d..a9e1324 100644
--- a/t/values.t
+++ b/t/values.t
@@ -49,6 +49,13 @@ is-deeply from-toml("[foo]\nbar = {.key}"), %(:foo(%(:bar(.value)))), .key for
# Local Time
'07:32:01' => TOML::Tiny::Time.new(7, 32, 1),
+
+# Array
+'[]' => [],
+'[ 123 ]' => [ 123 ],
+'[ 123, 456 ]' => [ 123, 456 ],
+'[ "foo" ]' => [<foo>],
+'[ "foo", "bar" ]' => [<foo bar>],
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment