@@ -9,65 +9,61 @@ my @files = Test-Files.documents;
9
9
10
10
enum Syntax (
11
11
CodeDoc => 0 ,
12
- ForDoc => 1 ,
13
- Doc => 2
12
+ TextDoc => 1
14
13
);
15
14
16
15
sub check-line ($ line , $ state ) {
17
16
given $ line {
18
- when /^ \=begin\s code / { CodeDoc }
19
- when /^ \=for\s code / { ForDoc }
20
- when /^ \=end\s code / { Doc }
21
- when /^ \=\w + / { Doc }
22
- when /^ \s ** 4 / { CodeDoc }
23
- when /^.+ $ / { $ state ! ~~ Doc ?? $ state !! Doc }
24
- default { $ state }
17
+ when /^ \=begin\s code / { CodeDoc }
18
+ when /^ \=for\s code / { CodeDoc }
19
+ when /^ \=end\s code / { TextDoc }
20
+ when /^ \=\w + / { TextDoc }
21
+ when /^ \s ** 4 / { CodeDoc }
22
+ default { $ state }
25
23
}
26
24
}
27
25
28
26
my @ promises = @ files . map (-> $ file {
29
27
Promise . start({
30
- my Str @ contents ;
31
- my Str @ lines = $ file . IO . lines ;
32
- my IO ::Handle $ fh = $ file . IO . open (: rw);
33
- my Syntax $ state = Doc;
34
- my Str $ buf ;
35
- my Bool $ logged ;
36
- for @ lines -> $ line {
37
- next if $ line === Nil ;
28
+ my Str @ in = $ file . IO . lines ;
29
+ my Str @ out = [];
30
+ my Syntax $ state = TextDoc;
31
+ my Bool $ modified = False ;
32
+ for @ in -> $ in-line {
33
+ unless $ in-line {
34
+ @ out . push ($ in-line );
35
+ next ;
36
+ }
38
37
39
- $ state = check-line($ line , $ state );
40
- if $ state ! ~~ Doc {
41
- # Perl 5 or Perl 6 should keep regular spaces in code.
42
- @ contents . push ($ line );
38
+ $ state = check-line($ in- line , $ state );
39
+ if $ state ~~ CodeDoc {
40
+ # Perl 5 and Perl 6 should keep regular spaces in code.
41
+ @ out . push ($ in- line );
43
42
next ;
44
43
}
45
44
46
- my $ new-line = $ line ;
47
- if $ new-line . chars < 6 {
45
+ if $ in-line . chars < 6 {
48
46
# Too short to contain Perl 5 or Perl 6.
49
- @ contents . push ($ line );
47
+ @ out . push ($ in- line );
50
48
next ;
51
49
}
52
50
53
- $ new-line ~~ s :g /Perl\x [ 0020] (5|| 6) /Perl\x [00 A0]$0 / ;
54
- if $ new-line ne $ line and ~ $/ {
55
- $ logged = True ;
56
- @ contents . push ($ new-line );
51
+ my $ out-line = $ in-line ;
52
+ $ out-line ~~ s :g /Perl\x [ 0020] (5|| 6) /Perl\x [00 A0]$0 / ;
53
+ if $ out-line ne $ in-line and ~ $/ {
54
+ $ modified = True ;
55
+ @ out . push ($ out-line );
57
56
} else {
58
- @ contents . push ($ line );
57
+ @ out . push ($ in- line );
59
58
}
60
59
}
61
60
62
- if $ logged {
61
+ if $ modified {
63
62
say " Corrected mentions of Perl 6 to use NBSP in '$ file '." ;
64
- $ logged = False ;
63
+ $ file . IO . spurt (@ out . join (" \n " ), : close);
64
+ $ modified = False ;
65
65
}
66
-
67
- $ fh . spurt (@ contents . join (" \n " ));
68
- $ fh . close ;
69
66
})
70
67
});
71
68
72
69
@ promises . race (: $ degree ). map (-> $ p { await $ p });
73
-
0 commit comments