Created
September 10, 2015 19:34
-
-
Save anonymous/059bd2164593536fc7f6 to your computer and use it in GitHub Desktop.
Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl6 | |
use v6; | |
my $IPC_file = slurp 'IPC_SROS.txt'; | |
my $PNs_file = slurp 'PNATA_A320_A321.csv'; | |
grammar ITEM { ... }; | |
my $result; | |
my $ATA; | |
my %table; | |
my int $counter = 0; | |
for $IPC_file.lines { | |
FIRST {$*ERR.nl = "\c[ZERO WIDTH SPACE]"; note "Gathering IPC data"} | |
note '.' if $counter++ % 100_000 == 0; | |
LAST {$*ERR.nl = "\n"; note " done!"}; | |
$result = ITEM.parse($_); | |
if $result<ITEM_LINE> { | |
$ATA = ($result<ITEM_LINE><CHAPNBR>, $result<ITEM_LINE><SECTNBR>, $result<ITEM_LINE><UNITNBR>).join('-'); | |
} else { | |
%table{$result<PNR_LINE><PN>}.push: ($ATA); | |
} | |
} | |
$counter = 0; | |
for $PNs_file.lines { | |
FIRST {$*ERR.nl = "\c[ZERO WIDTH SPACE]"; note "Matching PNs and ATA chapters"} | |
note '.' if ++$counter % 100 == 0; | |
LAST {$*ERR.nl = "\n"; note " done!"}; | |
say $_ ~', ' ~(%table{$_} // 'NF').unique.join(', '); | |
} | |
grammar ITEM { | |
rule TOP { | |
<ITEM_LINE>||<PNR_LINE> | |
} | |
rule ITEM_LINE { | |
^^'<'ITEM CHG'="'<CHG>'"' REVDATE'="'<REVDATE>'"' [ATTACH'="'<ATTACH>'"']? CHAPNBR'="'<CHAPNBR>'"' FIGNBR'="'<FIGNBR>'"' [ILLUSIND'="'<ILLUSIND>'"']? INDENT'="'<INDENT>'"' ITEMNBR'="'<ITEMNBR>'"' KEY'="'<KEY>'"' SECTNBR'="'<SECTNBR>'"' UNITNBR'="'<UNITNBR>'">'$$ | |
} | |
rule PNR_LINE { | |
^^'<'PNR PID'="'<PID>'">'<PN>$$ | |
} | |
token PN { | |
\N+ | |
} | |
token PID { | |
<-[\"]>+ | |
} | |
token CHG { | |
U|R|N|D | |
} | |
token REVDATE { | |
\d ** 8 | |
} | |
token ATTACH { | |
<-[\"]>+ | |
} | |
token CHAPNBR { | |
\d\d | |
} | |
token FIGNBR { | |
<-[\"]>+ | |
} | |
token ILLUSIND { | |
<-[\"]>+ | |
} | |
token INDENT { | |
<-[\"]>+ | |
} | |
token ITEMNBR { | |
<-[\"]>+ | |
} | |
token KEY { | |
<-[\"]>+ | |
} | |
token SECTNBR { | |
\d\d | |
} | |
token UNITNBR { | |
\d\d | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment