chiark / gitweb /
i18n: dgit: mark some messages (2)
[dgit.git] / i18n-diff-auditor
index 5630d7e8dc192b7082ba6a66fcdf6d71c2845daf..d0b6e07074a96e620b8b491506b03861d2c27c15 100755 (executable)
@@ -122,6 +122,7 @@ sub qp ($) {
 sub semiparse ($) {
     ($_) = @_;
     my @o;
+    #my $in = $_;
     # entries contain
     #   T     type
     #   E     exact input text (does not contain here doc contents)
@@ -137,12 +138,18 @@ sub semiparse ($) {
            $q ||= '"';
            push @o, { T => 'heredoc', Q => $q, Delim => $d,
                       E => $&, P => "<<$q$d$q" };
-           s{^
-                (             .* \n    )
-                ( (?: (?! $d) .* \n )* )
-                          $d     \n
-              }{ $1 }xe or die "missing end of here doc $d\n";
-           $o[$#o]{V} = $2;
+           if (s{^
+                   (                 .* \n     )
+                   ( (?: (?! $d \n ) .* \n )*? )
+                             $d         \n
+                }{ $1 }xe) {
+               $o[$#o]{V} = $2;
+            } else {
+               m{^.*\n} or confess;
+               $_ = $&;
+               $o[$#o]{V} = $';
+               $o[$#o]{Invented} = 1;
+           }
        } elsif (s{^ (["'])( (?: [^\\'"]
                                | \\ [^"']
                                | (?! \1 ) [^"]
@@ -176,6 +183,7 @@ sub semiparse ($) {
        next if grep { !is_string($_) } @inputs;
        my $q = $inputs[0]{Q};
        next if grep { $_->{Q} ne $q } @inputs;
+       next if grep { $_->{Invented} } @inputs;
        my $new = { T => 'joinedstrings',
                    E => (join '.', map { $_->{E} } @inputs),
                    P => (join '.', map { $_->{P} } @inputs),
@@ -222,6 +230,7 @@ sub analyse_chunk_core () {
        next if $x->{E} eq $y->{E};
        next if $x->{E} eq 'sprintf' and $y->{E} eq 'f_';
        next if $x->{E} eq 'die'     and $y->{E} eq 'confess';
+       next if $x->{E} eq 'die'     and $y->{E} eq 'fail';
        if ($y->{E} eq '+'
            and @ys >= 3
            and $ys[0]{E} eq '('
@@ -266,7 +275,7 @@ sub analyse_chunk_core () {
        }
        if ($ye eq 'f_') {
            my $fmt = $y->{V};
-           die "no percent in _f string\n" unless $fmt =~ m{\%};
+           die "no percent in f_ string\n" unless $fmt =~ m{\%};
            next unless $string_changed;
            die "f_ old string '-quoted\n" if $x->{Q} ne '"';
            my $xs = $x->{V};
@@ -282,10 +291,12 @@ sub analyse_chunk_core () {
                $xs = substr($xs, length($lit));
            };
            for (;;) {
+               #print STDERR Dumper($fmt, $xs, \@xs, @ys);
                if ($fmt !~ m{\%[^\%]}) {
                    $exactly->($fmt, '(tail)');
                    $fmt = '';
-                   die "text deleted from end of string\n" if length $xs;
+                   die "text deleted from end of string: ".qp($xs)."\n"
+                       if length $xs;
                    last;
                }
                $exactly->($`, '(literal)');
@@ -354,6 +365,8 @@ sub analyse_chunk () {
        return unless length $@;
        if ($@ =~ m{^missing end of here doc (\S+)\n}) {
            # fudge this
+           # (this never happens now, but in the future we might
+           # want this code again eg to try adding to the chunk)
            $before .= "\n$1\n";
            $after .= "\n$1\n";
            next;