line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FLAT::Regex::Parser; |
2
|
6
|
|
|
6
|
|
39
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
174
|
|
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
|
|
6633
|
use Parse::RecDescent; |
|
6
|
|
|
|
|
249747
|
|
|
6
|
|
|
|
|
50
|
|
8
|
6
|
|
|
6
|
|
3385
|
use FLAT::Regex::Op; |
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
1785
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $CHAR = qr{ [A-Za-z0-9_\$\#\%\@\;\:\-\^] | \[[^\]]*\] }x; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
12
|
|
|
12
|
0
|
35
|
my $pkg = shift; |
14
|
60
|
|
|
|
|
138
|
my @ops = sort {$a->{prec} <=> $b->{prec}} |
15
|
|
|
|
|
|
|
map { |
16
|
12
|
|
|
|
|
40
|
{ |
17
|
48
|
|
|
|
|
546
|
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
|
|
|
|
|
38
|
my $grammar = qq! |
26
|
|
|
|
|
|
|
parse: |
27
|
|
|
|
|
|
|
$lowest->{short} /^\\Z/ { \$item[1] } |
28
|
|
|
|
|
|
|
!; |
29
|
|
|
|
|
|
|
|
30
|
12
|
|
|
|
|
91
|
my $prev = $lowest; |
31
|
12
|
|
|
|
|
32
|
for (@ops) { |
32
|
36
|
|
|
|
|
124
|
my $spec = sprintf $prev->{spec}, $_->{short}; |
33
|
|
|
|
|
|
|
|
34
|
36
|
|
|
|
|
107
|
$grammar .= qq! |
35
|
|
|
|
|
|
|
$prev->{short}: |
36
|
|
|
|
|
|
|
$spec { $prev->{pkg}\->from_parse(\@item) } |
37
|
|
|
|
|
|
|
| $_->{short} { \$item[1] } |
38
|
|
|
|
|
|
|
!; |
39
|
|
|
|
|
|
|
|
40
|
36
|
|
|
|
|
63
|
$prev = $_; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
12
|
|
|
|
|
30
|
my $spec = sprintf $prev->{spec}, "atomic"; |
44
|
12
|
|
|
|
|
56
|
$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
|
|
|
|
|
79
|
Parse::RecDescent->new($grammar); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |