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};
79 foreach my $op (split /\s+/) {
80 next unless length $op;
81 next if $op =~ m{^\w+$};
86 $perlop_re = '(?: '.(join ' | ', @ops).' )';
87 $perlop_re = qr{$perlop_re}x;
88 #print STDERR "$perlop_re\n";
93 our ($ifilehead, $ihunkhead, $ichunkstart, $ichunkend);
94 our ($before, $after);
101 if (s{^[\$\@\%]?[_0-9a-zA-Z]+}{}) {
102 push @o, { T => 'ident', L => $& };
103 } elsif (s{^\<\<('?)([A-Z_]+)\1}{}) {
104 my ($q,$d) = ($1,$2);
105 push @o, { T => 'heredoc', Q => $q, Delim => $d };
108 ( (?: (?! $d) .* \n )* )
109 }{ $1 } or die "missing end of here doc $d\n";
111 } elsif (s{^ (["'])( (?: [^\\] | \\ \1 )* )}{}x) {
112 my ($q,$v) = ($1,$2);
113 push @o, { T => 'string', Q => $q, V => $v };
114 } elsif (s{^$perlop_re}{}) {
115 push @o, { T => 'op', L => $& };
116 } elsif (s/[[{(]//) {
117 push @o, { T => 'bra', L => $& };
118 } elsif (s/[]})]//) {
119 push @o, { T => 'ket', L => $& };
124 die "cannot tokenise \`$&'";
130 sub analyse_chunk () {
131 die "plain deletion\n" unless defined $after;
132 die "plain insertion\n" unless defined $before;
133 my @before = semiparse $before;
134 my @after = semiparse $after;
135 print Dumper($ichunkstart, $ichunkend, \@before, \@after);
139 for ($ifilehead = 0; l_ok $ifilehead; $ifilehead++) {
141 while (l_ok $ifilehead and m{^diff|^index|^---|^\Q+++\E}) { $ifilehead++ }
142 $ihunkhead = $ifilehead;
143 while (l_ok $ihunkhead) {
144 m{^\@\@} or confess "$ihunkhead $_ ?";
145 my $i = $ihunkhead + 1;
147 if (!l_ok $i or m{^ } or m{^\@\@}) {
148 if (defined $ichunkstart) {
150 eval { analyse_chunk(); 1; };
152 print Dumper($ichunkstart, $ichunkend,
156 $ichunkstart = $ichunkend = $before = $after = undef;
161 my $which = $& eq '-' ? \$before : \$after;