-
Notifications
You must be signed in to change notification settings - Fork 0
/
spell-stream.pl
executable file
·71 lines (64 loc) · 1.14 KB
/
spell-stream.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env perl
# -*- mode: cperl; indent-tabs-mode: nil; tab-width: 3; cperl-indent-level: 3; -*-
use strict;
use warnings;
use utf8;
BEGIN {
$| = 1;
binmode(STDIN, ':encoding(UTF-8)');
binmode(STDOUT, ':encoding(UTF-8)');
}
use open qw( :encoding(UTF-8) :std );
use feature 'unicode_strings';
my $wf = '';
my $type = '';
my @suggs = ();
my $noncg = '';
my $print_cohort = sub {
if (!$wf) {
return;
}
print "$wf";
if ($type) {
print "\t$type";
if (@suggs) {
for my $sug (@suggs) {
print " <R:$sug>";
}
}
}
print "\n";
print "$noncg";
$wf = '';
$type = '';
@suggs = ();
$noncg = '';
};
while (<STDIN>) {
if (m@^<s@ || m@^</s@) {
$print_cohort->();
print;
}
elsif (m@^"<(.*)>"@) {
$print_cohort->();
$wf = $1;
}
elsif (m@^\s+"@) {
if (m@ \?$@) {
$type = '@unknown';
}
elsif (m@^\s+".*".+<spelled>@ && m@ "(.*?)"S@) {
$type = '@spell';
push(@suggs, $1);
}
}
else {
if ($wf) {
$noncg .= $_;
}
else {
print;
}
}
}
$print_cohort->();