7 unshift @d, "# dummy line to make line 1 index 1 in \@d\n";
10 our $count_i_last_l_ok;
15 if ($i == $i_last_l_ok) {
16 confess $i if $count_i_last_l_ok++ > 50;
18 $count_i_last_l_ok = 0;
22 return unless $i < @d;
24 #print STDERR "L $i\n";
30 confess $i unless l_ok $i;
33 our $perlop_text = <<'END'; # c&p from man perlop
34 left terms and list operators (leftward)
38 right ! ~ \ and unary + and -
43 nonassoc named unary operators
44 nonassoc < > <= >= lt gt le ge
45 nonassoc == != <=> eq ne cmp ~~
52 right = += -= *= etc. goto last next redo dump
54 nonassoc list operators (rightward)
59 **= += *= &= &.= <<= &&=
69 foreach (split /\n/, $perlop_text) {
73 s{^(?: left | right | nonassoc ) \s+}{}x;
74 next if m{^terms and list operators};
75 next if m{^named unary};
76 next if m{^list operators};
80 foreach my $op (split /\s+/) {
81 next unless length $op;
82 next if $op =~ m{^\w+$};
87 $perlop_re = '(?: '.(join ' | ', @ops).' )';
88 $perlop_re = qr{$perlop_re}x;
89 #print STDERR "$perlop_re\n";
94 our ($ifilehead, $ihunkhead, $ichunkstart, $ichunkend);
95 our ($before, $after);
102 # E exact input text (does not contain here doc contents)
103 # P something to print in messages
104 # V value, only for: heredoc string
105 # Q quote characcter, only for: heredoc string
108 if (s{^[\$\@\%]?[_0-9a-zA-Z]+}{}) {
109 push @o, { T => 'ident', E => $&, P => $& };
110 } elsif (s{^\<\<('?)([A-Z_]+)\1}{}) {
111 my ($q,$d) = ($1,$2);
112 push @o, { T => 'heredoc', Q => $q, Delim => $d,
113 E => $&, P => "<<$q$d..." };
116 ( (?: (?! $d) .* \n )* )
118 }{ $1 }x or die "missing end of here doc $d\n";
120 } elsif (s{^ (["'])( (?: [^\\'"]
125 my ($q,$v) = ($1,$2);
126 push @o, { T => 'string', Q => $q, V => $v,
127 I => $&, P => "$q-string" };
128 } elsif (s{^$perlop_re|\;}{}) {
129 push @o, { T => 'op', E => $&, I => $& };
130 } elsif (s/[[{(]//) {
131 push @o, { T => 'bra', E => $&, I => $& };
132 } elsif (s/[]})]//) {
133 push @o, { T => 'ket', E => $&, I => $& };
134 } elsif (s/^( [\$\@\%] )( \{ )//x) {
135 push @o, { T => 'deref', E => $1, I => $1 },
136 { T => 'bra', E => $2, I => $1 };
137 } elsif (s/^ [\$\@\%] [^[^{] //x) {
138 push @o, { T => 'specvar', E => $&, I => $& };
143 die "cannot tokenise \`$&'";
146 # coalesce concatenated strings
150 sub analyse_chunk_core () {
151 die "plain deletion\n" unless defined $after;
152 die "plain insertion\n" unless defined $before;
153 my @before = semiparse $before;
154 my @after = semiparse $after;
155 my $next_something = sub {
156 my ($ary,$var,$what) = @_;
157 die "ran out of $what\n" unless @$ary;
160 my $next_before = sub { $next_something->(\@before, \$x, 'before'); };
161 my $next_after = sub { $next_something->(\@after , \$y, 'after' ); };
162 sub $is_string = sub { $_[0]{T} =~ m/heredoc|string/; };
164 last unless @before or @after;
167 next if $x->{I} eq $y->{I};
169 if ($y->{I} eq '__' or $y->{I} eq '_f') {
171 die "__ on non-string\n" unless Sis_string($y);
172 die "__ on was non-string\n" unless $is_string($x);
173 if ($y->{Q} ne "'") {
174 die "var subst in new str\n" if $y->{V} =~ m{(?<!\\) [\$\@]};
177 die "__ string changed\n" unless $y->{V} eq $x->{V};
178 die "__ string quote changed\n" unless $y->{Q} eq $x->{Q};
180 $string_changed = $@;
182 if ($y->{I} eq '__') {
184 die "percent in __ ' string\n" if m{\%};
185 die $string_changed if length $not_unchanged;
188 if ($y->{I} eq 'f_') {
190 die "no percent in _f string\n" unless $fmt =~ m{\%};
191 next unless $string_changed;
192 die "f_ old string '-quoted\n" if length $x->{V};
196 my $xl = substr($xs, 0, length($lit));
197 die "exactly mismatch in $lit\n" unless $xl eq $lit;
198 $xs = substr($xs, length($lit));
201 if ($fmt !~ m{\%[^\%]}) {
208 if ($& eq '%%') { $exactly('%'); next; }
209 elsif ($& ne '%s') { die "unhandled %-subst $&\n"; }
211 die "expected comma, got $y->{T}\n" unless $y->{I} eq ',';
212 if ($old =~ m{^\@}) {
214 die "\@... => not string" unless $is_string($y);
220 if (!$bra and !@after) {
225 (grep { $y->{I} eq $_ } qw( or xor and not ; : )
233 if ($y->{T} eq 'bra' or $y->{L} eq '?') {
235 } elsif ($y->{T} eq 'ket' or $y->{L} eq ':') {
236 die "too many kets at $y->{L}\n" unless $bras;
250 if ($y->{Q} eq $x->{Q} && $y->
253 print Dumper($ichunkstart, $ichunkend, \@before, \@after);
257 sub analyse_chunk () {
259 eval { analyse_chunk_core(); };
260 return unless length $@;
261 if ($@ =~ m{^missing end of here doc (\S+)\n}) {
272 for ($ifilehead = 0; l_ok $ifilehead; $ifilehead++) {
274 while (l_ok $ifilehead and m{^diff|^index|^---|^\Q+++\E}) { $ifilehead++ }
275 $ihunkhead = $ifilehead;
276 while (l_ok $ihunkhead) {
277 m{^\@\@} or confess "$ihunkhead $_ ?";
278 my $i = $ihunkhead + 1;
280 if (!l_ok $i or m{^ } or m{^\@\@}) {
281 if (defined $ichunkstart) {
283 eval { analyse_chunk(); 1; };
285 print Dumper('REPORT',
286 $ichunkstart, $ichunkend,
290 $ichunkstart = $ichunkend = $before = $after = undef;
295 my $which = $& eq '-' ? \$before : \$after;