line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FLAT::Regex::Parser; |
2
|
6
|
|
|
6
|
|
37
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
181
|
|
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
|
|
6846
|
use Parse::RecDescent; |
|
6
|
|
|
|
|
251366
|
|
|
6
|
|
|
|
|
45
|
|
8
|
6
|
|
|
6
|
|
3121
|
use FLAT::Regex::Op; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
176
|
|
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
44
|
use vars '$CHAR'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
1823
|
|
11
|
|
|
|
|
|
|
$CHAR = qr{ [A-Za-z0-9_\$\#] | \[[^\]]*\] }x; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
12
|
|
|
12
|
0
|
38
|
my $pkg = shift; |
15
|
60
|
|
|
|
|
212
|
my @ops = sort {$a->{prec} <=> $b->{prec}} |
16
|
|
|
|
|
|
|
map { |
17
|
12
|
|
|
|
|
45
|
{ |
18
|
48
|
|
|
|
|
273
|
pkg => "FLAT::Regex::Op::$_", |
19
|
|
|
|
|
|
|
prec => "FLAT::Regex::Op::$_"->precedence, |
20
|
|
|
|
|
|
|
spec => "FLAT::Regex::Op::$_"->parse_spec, |
21
|
|
|
|
|
|
|
short => $_ |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} @_; |
24
|
|
|
|
|
|
|
|
25
|
12
|
|
|
|
|
25
|
my $lowest = shift @ops; |
26
|
12
|
|
|
|
|
37
|
my $grammar = qq! |
27
|
|
|
|
|
|
|
parse: |
28
|
|
|
|
|
|
|
$lowest->{short} /^\\Z/ { \$item[1] } |
29
|
|
|
|
|
|
|
!; |
30
|
|
|
|
|
|
|
|
31
|
12
|
|
|
|
|
24
|
my $prev = $lowest; |
32
|
12
|
|
|
|
|
33
|
for (@ops) { |
33
|
36
|
|
|
|
|
115
|
my $spec = sprintf $prev->{spec}, $_->{short}; |
34
|
|
|
|
|
|
|
|
35
|
36
|
|
|
|
|
107
|
$grammar .= qq! |
36
|
|
|
|
|
|
|
$prev->{short}: |
37
|
|
|
|
|
|
|
$spec { $prev->{pkg}\->from_parse(\@item) } |
38
|
|
|
|
|
|
|
| $_->{short} { \$item[1] } |
39
|
|
|
|
|
|
|
!; |
40
|
|
|
|
|
|
|
|
41
|
36
|
|
|
|
|
59
|
$prev = $_; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
12
|
|
|
|
|
42
|
my $spec = sprintf $prev->{spec}, "atomic"; |
45
|
12
|
|
|
|
|
66
|
$grammar .= qq! |
46
|
|
|
|
|
|
|
$prev->{short}: |
47
|
|
|
|
|
|
|
$spec { $prev->{pkg}\->from_parse(\@item) } |
48
|
|
|
|
|
|
|
| atomic { \$item[1] } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
atomic: |
51
|
|
|
|
|
|
|
"(" $lowest->{short} ")" { \$item[2] } |
52
|
|
|
|
|
|
|
| /\$FLAT::Regex::Parser::CHAR/ |
53
|
|
|
|
|
|
|
{ FLAT::Regex::Op::atomic->from_parse(\@item) } |
54
|
|
|
|
|
|
|
!; |
55
|
|
|
|
|
|
|
|
56
|
12
|
|
|
|
|
76
|
Parse::RecDescent->new($grammar); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |