| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (c) 2011 - Olof Johansson |
|
2
|
|
|
|
|
|
|
# All rights reserved. |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
|
5
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
6
|
|
|
|
|
|
|
package Regexp::Common::Chess; |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
113581
|
use warnings; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
93
|
|
|
9
|
3
|
|
|
3
|
|
15
|
use strict; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
106
|
|
|
10
|
3
|
|
|
3
|
|
15
|
use Regexp::Common qw/pattern no_defaults/; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
37
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
194
|
use vars qw/$VERSION/; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
828
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.1'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $check = '[+#]'; |
|
16
|
|
|
|
|
|
|
my $rank = '[1-8]'; |
|
17
|
|
|
|
|
|
|
my $file = '[a-h]'; |
|
18
|
|
|
|
|
|
|
my $piece = '[KNBQR]'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $promotion = "x?${file}[18]=(?!K)$piece"; |
|
21
|
|
|
|
|
|
|
my $pawnmove = "(?:$file?x)?$file(?![18])$rank"; |
|
22
|
|
|
|
|
|
|
my $stdmove = "$piece$file?$rank?x?$file$rank"; |
|
23
|
|
|
|
|
|
|
my $castling = "O-O(?:-O)?"; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
pattern name => ['Chess' => 'SAN'], |
|
26
|
|
|
|
|
|
|
create => "(?-i:(?:$promotion|$castling|$pawnmove|$stdmove)$check?)" |
|
27
|
|
|
|
|
|
|
; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Regexp::Common::Chess - regexp for algebraic notation in chess |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Regexp::Common qw/Chess/; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $move = 'Rxh7+'; |
|
38
|
|
|
|
|
|
|
if($move =~ /^$RE{Chess}{SAN}$/) { |
|
39
|
|
|
|
|
|
|
say "Yay! A valid chess move!"; |
|
40
|
|
|
|
|
|
|
} else { |
|
41
|
|
|
|
|
|
|
say "Sad to say, that doesn't look valid..."; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This module defines a regular expression for use when parsing |
|
47
|
|
|
|
|
|
|
standard algebaric notation (SAN) as specified in the Portable |
|
48
|
|
|
|
|
|
|
Game Notation (PGN) standard (export format). It is not a |
|
49
|
|
|
|
|
|
|
complete PGN regexp. It is limited to only match one specific |
|
50
|
|
|
|
|
|
|
move at a time. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
The PGN format, including its SAN specification, is documented |
|
55
|
|
|
|
|
|
|
in the "Portable Game Notation Specification and Implementation |
|
56
|
|
|
|
|
|
|
Guide", available here: |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item * L |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=back |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The L manual documents the use of the |
|
65
|
|
|
|
|
|
|
Regexp::Common framework and interface, used by |
|
66
|
|
|
|
|
|
|
Regexp::Common::Chess. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 AVAILABILITY |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The latest released code of this module is available from CPAN. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The latest development, useful for contributing and for those |
|
73
|
|
|
|
|
|
|
living on the edge etc. is available from Github: |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * L |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Copyright (c) 2011 - Olof Johansson |
|
84
|
|
|
|
|
|
|
All rights reserved. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
|
87
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |