Skip to content

Commit 8293246

Browse files
committed
Simplify util/perl-nbsp.p6
1 parent 9dc9ae4 commit 8293246

File tree

3 files changed

+34
-38
lines changed

3 files changed

+34
-38
lines changed

doc/Language/5to6-nutshell.pod6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,4 +1688,4 @@ be better than losing the information about a real need.
16881688
16891689
=end comments
16901690

1691-
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
1691+
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

doc/Language/5to6-perlfunc.pod6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ In Perl 6, this only reverses the elements of a list. C<reverse(@a)>
14531453
or C<@a.reverse>. To reverse the characters in a string, use the
14541454
C<.flip> method.
14551455
1456-
C<reverse> without parameters is not supported in Perl 6.
1456+
C<reverse> without parameters is not supported in Perl 6.
14571457
14581458
The Perl 6 ecosystem has a module L<C<P5reverse>|https://modules.perl6.org/dist/P5reverse>
14591459
which exports a C<reverse> function that mimics the original Perl 5 behaviour
@@ -2274,4 +2274,4 @@ C<tr///>.
22742274
22752275
=end pod
22762276

2277-
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
2277+
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

util/perl-nbsp.p6

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,65 +9,61 @@ my @files = Test-Files.documents;
99

1010
enum Syntax (
1111
CodeDoc => 0,
12-
ForDoc => 1,
13-
Doc => 2
12+
TextDoc => 1
1413
);
1514

1615
sub check-line($line, $state) {
1716
given $line {
18-
when /^\=begin\scode/ { CodeDoc }
19-
when /^\=for\scode/ { ForDoc }
20-
when /^\=end\scode/ { Doc }
21-
when /^\=\w+/ { Doc }
22-
when /^\s ** 4/ { CodeDoc }
23-
when /^.+$/ { $state !~~ Doc ?? $state !! Doc }
24-
default { $state }
17+
when /^\=begin\scode/ { CodeDoc }
18+
when /^\=for\scode/ { CodeDoc }
19+
when /^\=end\scode/ { TextDoc }
20+
when /^\=\w+/ { TextDoc }
21+
when /^\s ** 4/ { CodeDoc }
22+
default { $state }
2523
}
2624
}
2725

2826
my @promises = @files.map(-> $file {
2927
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+
}
3837

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);
4342
next;
4443
}
4544

46-
my $new-line = $line;
47-
if $new-line.chars < 6 {
45+
if $in-line.chars < 6 {
4846
# Too short to contain Perl 5 or Perl 6.
49-
@contents.push($line);
47+
@out.push($in-line);
5048
next;
5149
}
5250

53-
$new-line ~~ s:g/Perl\x[0020](5||6)/Perl\x[00A0]$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[00A0]$0/;
53+
if $out-line ne $in-line and ~$/ {
54+
$modified = True;
55+
@out.push($out-line);
5756
} else {
58-
@contents.push($line);
57+
@out.push($in-line);
5958
}
6059
}
6160

62-
if $logged {
61+
if $modified {
6362
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;
6565
}
66-
67-
$fh.spurt(@contents.join("\n"));
68-
$fh.close;
6966
})
7067
});
7168

7269
@promises.race(:$degree).map(-> $p { await $p });
73-

0 commit comments

Comments
 (0)