Skip to content

Commit

Permalink
Fix error tokens and load-dump
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Jan 26, 2020
1 parent 78a0506 commit 34bc7da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 1 addition & 2 deletions bin/yamlpp5-load-dump
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ unless ($file) {
}

my $ypp = YAML::PP->new(boolean => 'JSON::PP');
my $yppd = YAML::PP::Dumper->new;
my @docs = $file ? $ypp->load_file($file) : $ypp->load_string($yaml);
my $out_yaml = $yppd->dump_string(@docs);
my $out_yaml = $ypp->dump_string(@docs);

print encode_utf8 $out_yaml;
4 changes: 2 additions & 2 deletions etc/test-suite-html.pl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Encode;

chomp(my $version = qx{git describe --dirty});
my $yaml_test_suite = 'yaml-test-suite';
my $yaml_test_suite = 'test-suite/yaml-test-suite-data/';
my @dirs = grep { m{/[0-9A-Z]{4}$} } map { "$_" } io->dir($yaml_test_suite)->all;
my @valid = grep { not -f "$_/error" } @dirs;
my @invalid = grep { -f "$_/error" } @dirs;
Expand Down Expand Up @@ -217,7 +217,7 @@ sub highlight_test {
"Doc " . ($_+1) . ': ' . $coder->encode( $docs[ $_ ] );
} 0 .. $#docs;

my $yppd = YAML::PP::Dumper->new( bool => 'JSON::PP' );
my $yppd = YAML::PP->new( boolean => 'JSON::PP' );
my $yaml_dump = $yppd->dump_string(@docs);

my @reload_docs = $ypp->load_string($yaml_dump);
Expand Down
20 changes: 19 additions & 1 deletion lib/YAML/PP/Lexer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ sub fetch_quoted {

unless ($start) {
$next_line = $self->fetch_next_line or do {
for (my $i = 0; $i < @tokens; $i+= 3) {
my $token = $tokens[ $i + 1 ];
if (ref $token) {
$tokens[ $i + 1 ] = $token->{orig};
}
}
$self->push_tokens(\@tokens);
$self->exception("Missing closing quote <$context> at EOF");
};
Expand All @@ -623,10 +629,22 @@ sub fetch_quoted {
next;
}
elsif (not $spaces and $$yaml =~ m/\A(---|\.\.\.)(?=$RE_WS|\z)/) {
for (my $i = 0; $i < @tokens; $i+= 3) {
my $token = $tokens[ $i + 1 ];
if (ref $token) {
$tokens[ $i + 1 ] = $token->{orig};
}
}
$self->push_tokens(\@tokens);
$self->exception("Missing closing quote <$context> or invalid document marker");
}
elsif ((length $spaces) < $indent) {
for (my $i = 0; $i < @tokens; $i+= 3) {
my $token = $tokens[ $i + 1 ];
if (ref $token) {
$tokens[ $i + 1 ] = $token->{orig};
}
}
$self->push_tokens(\@tokens);
$self->exception("Wrong indendation or missing closing quote <$context>");
}
Expand Down Expand Up @@ -709,7 +727,7 @@ sub _read_quoted_tokens {
return $value;
}
if (length $$yaml) {
push @$tokens, ( $token_name . 'D' => $value, $self->line );
push @$tokens, ( $token_name . 'D' => $value->{orig}, $self->line );
$self->push_tokens($tokens);
$self->exception("Invalid quoted <$first> string");
}
Expand Down

0 comments on commit 34bc7da

Please sign in to comment.