| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | pairtable2yaml - Create YAML version of pairing table | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use YAML qw/LoadFile DumpFile/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use IO::All; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Parse::RecDescent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | our $RD_HINT=1; | |||||||||||||||||||||||||||
| 17 | 1 | ▶ | use List::MoreUtils qw/firstval/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | my $io = io $ARGV[0]; | |||||||||||||||||||||||||||
| 20 | 1 | my @lines = $io->slurp; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # shift @lines; shift @lines; shift @lines; shift @lines; | ||||||||||||||||||||||||||||
| 23 | 1 | my $table; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | for my $line ( @lines ) | |||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 7 | our ($player, $opponents, $roles, $b5float, $b6float, $score, $result); | |||||||||||||||||||||||||||
| 28 | 7 | my $format = q{ | |||||||||||||||||||||||||||
| 29 | line: data end | longform end | comment end | <error> | ||||||||||||||||||||||||||||
| 30 | data: player opponents roles floats score | ||||||||||||||||||||||||||||
| 31 | longform: place player opponents roles floats score | ||||||||||||||||||||||||||||
| 32 | place: wholenumber(s /-/) | ||||||||||||||||||||||||||||
| 33 | player: id { $::player = $item[1] } | ||||||||||||||||||||||||||||
| 34 | id: wholenumber | ||||||||||||||||||||||||||||
| 35 | wholenumber: m/^\d+/ | ||||||||||||||||||||||||||||
| 36 | Bye: '-' | ||||||||||||||||||||||||||||
| 37 | opponents: opponent(s /,/) { $::opponents = $item[1] } | ||||||||||||||||||||||||||||
| 38 | opponent: id | Bye | ||||||||||||||||||||||||||||
| 39 | roles: role(s) { $::roles = $item[1] } | ||||||||||||||||||||||||||||
| 40 | role: White | Black | Bye | ||||||||||||||||||||||||||||
| 41 | White: 'W' | ||||||||||||||||||||||||||||
| 42 | Black: 'B' | ||||||||||||||||||||||||||||
| 43 | floats: B6andB5 | B5andB6 | B5float | B6float | NotFloat | ||||||||||||||||||||||||||||
| 44 | B6andB5: B6float B5float | ||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | $::b5float ||= $item{'B5float'}; | ||||||||||||||||||||||||||||
| 47 | $::b6float ||= $item{'B6float'}; | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | B5andB6: B5float B6float | ||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | $::b5float ||= $item{'B5float'}; | ||||||||||||||||||||||||||||
| 52 | $::b6float ||= $item{'B6float'}; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | B6float: lowercasefloat | ||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||
| 56 | $::b6float ||= $item{'lowercasefloat'}; | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | lowercasefloat: 'u' | 'd' | ||||||||||||||||||||||||||||
| 59 | B5float: uppercasefloat | ||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | $::b5float ||= $item{'uppercasefloat'}; | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | uppercasefloat: 'U' | 'D' | ||||||||||||||||||||||||||||
| 64 | NotFloat: '' | ||||||||||||||||||||||||||||
| 65 | score: scorenumber { $::score = $item[1] } | ||||||||||||||||||||||||||||
| 66 | scorenumber: m/^\d+(?:\.5)?/ | ||||||||||||||||||||||||||||
| 67 | comment: token(s?) {$::result = 'comment'} | ||||||||||||||||||||||||||||
| 68 | token: m/\S+/ | ||||||||||||||||||||||||||||
| 69 | end: m/^\Z/ | ||||||||||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 7 | my $parser = Parse::RecDescent->new($format); | |||||||||||||||||||||||||||
| 73 | 7 | ▶ | defined $parser->line($line) or die "parser died: $?\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 7 | ▶ | unless ( $result and $result eq 'comment' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$main::result and $main::result eq "comment"
MC/DC50%1/2
$main::result and $main::result eq "comment"
$main::result
$main::result eq "comment"
Truth table66%2/3
A and B
A= $main::resultB= $main::result eq "comment"
| |||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||
| 76 | 4 | for ( @$opponents ) | |||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||
| 78 | 16 | ▶ | $_ = 'Bye' if $_ and $_ eq '-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_ and $_ eq "-"
MC/DC0%0/2
$_ and $_ eq "-"
$_
$_ eq "-"
Truth table33%1/3
A and B
A= $_B= $_ eq "-"
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 4 | $table->{opponents}->{$player} = $opponents; | |||||||||||||||||||||||||||
| 81 | 4 | for ( @$roles ) | |||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | 16 | ▶ | $_ = 'White' if $_ and $_ eq 'W'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ and $_ eq "W"
MC/DC50%1/2
$_ and $_ eq "W"
$_
$_ eq "W"
Truth table66%2/3
A and B
A= $_B= $_ eq "W"
| |||||||||||||||||||||||||||||
| 84 | 16 | ▶ | $_ = 'Black' if $_ and $_ eq 'B'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ and $_ eq "B"
MC/DC50%1/2
$_ and $_ eq "B"
$_
$_ eq "B"
Truth table66%2/3
A and B
A= $_B= $_ eq "B"
| |||||||||||||||||||||||||||||
| 85 | 16 | ▶ | $_ = 'Bye' if $_ and $_ eq '-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_ and $_ eq "-"
MC/DC0%0/2
$_ and $_ eq "-"
$_
$_ eq "-"
Truth table33%1/3
A and B
A= $_B= $_ eq "-"
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 4 | $table->{roles}->{$player} = $roles; | |||||||||||||||||||||||||||
| 88 | 4 | for ( $b5float, $b6float ) | |||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | 8 | ▶ | $_ = 'Up' if $_ and $_ =~ m/^U$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_ and $_ =~ /^U$/i
MC/DC100%2/2
$_ and $_ =~ /^U$/i
$_
$_ =~ /^U$/i
Truth table100%3/3
A and B
A= $_B= $_ =~ /^U$/i
| |||||||||||||||||||||||||||||
| 91 | 8 | ▶ | $_ = 'Down' if $_ and $_ =~ m/^D$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_ and $_ =~ /^D$/i
MC/DC100%2/2
$_ and $_ =~ /^D$/i
$_
$_ =~ /^D$/i
Truth table100%3/3
A and B
A= $_B= $_ =~ /^D$/i
| |||||||||||||||||||||||||||||
| 92 | 8 | ▶ | $_ = undef unless $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 4 | $table->{floats}->{$player} = [ $b6float, $b5float ]; | |||||||||||||||||||||||||||
| 95 | 4 | $table->{score}->{$player} = $score; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 7 | ($::player, $::opponents, $::roles, $::b5float, $::b6float, $::score, $::result) = undef; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | DumpFile 'pairtable.yaml', $table; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||