Permalink
Browse files

Finish _read_array

  • Loading branch information...
1 parent 18c7af9 commit ab3071b00af42417549ade1e313ebfaf8600bc96 @bacek bacek committed Jan 30, 2011
Showing with 39 additions and 36 deletions.
  1. +39 −36 lib/YAML/Tiny.pm
View
@@ -251,42 +251,45 @@ method _read_array(@array, @indent, @lines) {
@lines.shift;
@array.push(self._read_scalar( ~$m[1], [ @indent, undef ], @lines ));
}
-### } elsif ( $lines->[0] =~ /^\s*\-\s*\z/ ) {
-### shift @$lines;
-### unless ( @$lines ) {
-### push @$array, undef;
-### return 1;
-### }
-### if ( $lines->[0] =~ /^(\s*)\-/ ) {
-### my $indent2 = length("$1");
-### if ( $indent->[-1] == $indent2 ) {
-### # Null array entry
-### push @$array, undef;
-### } else {
-### # Naked indenter
-### push @$array, [ ];
-### $self->_read_array( $array->[-1], [ @$indent, $indent2 ], $lines );
-### }
-###
-### } elsif ( $lines->[0] =~ /^(\s*)\S/ ) {
-### push @$array, { };
-### $self->_read_hash( $array->[-1], [ @$indent, length("$1") ], $lines );
-###
-### } else {
-### pir::die \"YAML::Tiny failed to classify line '$lines->[0]'";
-### }
-###
-### }
-### elsif ( defined $indent->[-2] and $indent->[-1] == $indent->[-2] ) {
-### # This is probably a structure like the following...
-### # ---
-### # foo:
-### # - list
-### # bar: value
-### #
-### # ... so lets return and let the hash parser handle it
-### return 1;
-###
+ elsif $m := @lines[0] ~~ /^\s*\-\s*$/ {
+ @lines.shift;
+ unless @lines {
+ @array.push(undef);
+ return 1;
+ }
+
+ if $m := @lines[0] ~~ /^(\s*)\-/ {
+ my $indent2 := length($m[0]);
+ if @indent[-1] == $indent2 {
+ # Null array entry
+ @array.push(undef);
+ }
+ else {
+ # Naked indenter
+ @array.push([ ]);
+ self._read_array( @array[-1], [ @indent, $indent2 ], @lines );
+ }
+
+ }
+ elsif $m := @lines[0] ~~ /^(\s*)\S/ {
+ @array.push(hash());
+ self._read_hash( @array[-1], [ @indent, length($m[0]) ], @lines );
+
+ }
+ else {
+ pir::die("YAML::Tiny failed to classify line '{ @lines[0] }'");
+ }
+ }
+ elsif pir::defined(@indent[-2]) && @indent[-1] == @indent[-2] {
+ # This is probably a structure like the following...
+ # ---
+ # foo:
+ # - list
+ # bar: value
+ #
+ # ... so lets return and let the hash parser handle it
+ return 1;
+ }
else {
pir::die("YAML::Tiny failed to classify line '{ @lines[0] }'");
}

0 comments on commit ab3071b

Please sign in to comment.