Skip to content

Parsing "Arrays of Tables" #9

@mjemmeson

Description

@mjemmeson

It seems the TOML module can't parse arrays of tables (see https://github.com/mojombo/toml#array-of-tables ).

For example, the sample TOML file here fails: https://raw.github.com/mojombo/toml/master/tests/example.toml

Something like the following will do it, for top level tables anyway (needs ultimately to support nested tables):
(will send pull request with test once I have a moment, didn't realise it was on github so did a patch for rt.cpan.org)

--- TOML.pm.old 2013-11-29 14:36:21.905118496 +0000
+++ TOML.pm 2013-11-29 14:43:57.735378830 +0000
@@ -218,6 +218,16 @@
             }
         }

+        # Array of Tables
+        elsif ($string =~ s/^\s*\[\[([^]]+)\]\]\s*//) {
+            my $key = "$1";
+            die "'$key' already defined"
+                if $toml{$key} && ref $toml{$key} != 'ARRAY';
+            $toml{$key} ||= [];
+            $cur = {};
+            push @{$toml{$key}}, $cur;
+        }
+
         # New section
         elsif ($string =~ s/^\[([^]]+)\]\s*//) {
             my $section = "$1";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions