line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FLAT::Regex::Parser; |
2
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
166
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#### Is this one level of abstraction too far? Parser generator generators.. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#### TODO: try YAPP, since recursive descent is SLOOOW |
7
|
6
|
|
|
6
|
|
6280
|
use Parse::RecDescent; |
|
6
|
|
|
|
|
232518
|
|
|
6
|
|
|
|
|
40
|
|
8
|
6
|
|
|
6
|
|
2871
|
use FLAT::Regex::Op; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
1586
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $CHAR = qr{ [A-Za-z0-9_\$\#\%\@\;\:\-\^] | \[[^\]]*\] }x; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
12
|
|
|
12
|
0
|
34
|
my $pkg = shift; |
14
|
60
|
|
|
|
|
118
|
my @ops = sort {$a->{prec} <=> $b->{prec}} |
15
|
|
|
|
|
|
|
map { |
16
|
12
|
|
|
|
|
31
|
{ |
17
|
48
|
|
|
|
|
214
|
pkg => "FLAT::Regex::Op::$_", |
18
|
|
|
|
|
|
|
prec => "FLAT::Regex::Op::$_"->precedence, |
19
|
|
|
|
|
|
|
spec => "FLAT::Regex::Op::$_"->parse_spec, |
20
|
|
|
|
|
|
|
short => $_ |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} @_; |
23
|
|
|
|
|
|
|
|
24
|
12
|
|
|
|
|
27
|
my $lowest = shift @ops; |
25
|
12
|
|
|
|
|
32
|
my $grammar = qq! |
26
|
|
|
|
|
|
|
parse: |
27
|
|
|
|
|
|
|
$lowest->{short} /^\\Z/ { \$item[1] } |
28
|
|
|
|
|
|
|
!; |
29
|
|
|
|
|
|
|
|
30
|
12
|
|
|
|
|
72
|
my $prev = $lowest; |
31
|
12
|
|
|
|
|
26
|
for (@ops) { |
32
|
36
|
|
|
|
|
97
|
my $spec = sprintf $prev->{spec}, $_->{short}; |
33
|
|
|
|
|
|
|
|
34
|
36
|
|
|
|
|
105
|
$grammar .= qq! |
35
|
|
|
|
|
|
|
$prev->{short}: |
36
|
|
|
|
|
|
|
$spec { $prev->{pkg}\->from_parse(\@item) } |
37
|
|
|
|
|
|
|
| $_->{short} { \$item[1] } |
38
|
|
|
|
|
|
|
!; |
39
|
|
|
|
|
|
|
|
40
|
36
|
|
|
|
|
49
|
$prev = $_; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
12
|
|
|
|
|
30
|
my $spec = sprintf $prev->{spec}, "atomic"; |
44
|
12
|
|
|
|
|
44
|
$grammar .= qq! |
45
|
|
|
|
|
|
|
$prev->{short}: |
46
|
|
|
|
|
|
|
$spec { $prev->{pkg}\->from_parse(\@item) } |
47
|
|
|
|
|
|
|
| atomic { \$item[1] } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
atomic: |
50
|
|
|
|
|
|
|
"(" $lowest->{short} ")" { \$item[2] } |
51
|
|
|
|
|
|
|
| /\$FLAT::Regex::Parser::CHAR/ |
52
|
|
|
|
|
|
|
{ FLAT::Regex::Op::atomic->from_parse(\@item) } |
53
|
|
|
|
|
|
|
!; |
54
|
|
|
|
|
|
|
|
55
|
12
|
|
|
|
|
62
|
Parse::RecDescent->new($grammar); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |