line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FLAT::Regex; |
2
|
6
|
|
|
6
|
|
8992
|
use parent 'FLAT'; |
|
6
|
|
|
|
|
1977
|
|
|
6
|
|
|
|
|
52
|
|
3
|
6
|
|
|
6
|
|
341
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
115
|
|
4
|
6
|
|
|
6
|
|
27
|
use Carp; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
403
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
2777
|
use FLAT::Regex::Parser; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
208
|
|
7
|
6
|
|
|
6
|
|
35
|
use FLAT::Regex::Op; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
901
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $PARSER = FLAT::Regex::Parser->new(qw[ alt concat star ]); |
10
|
|
|
|
|
|
|
#### TODO: error checking in the parse |
11
|
|
|
|
|
|
|
|
12
|
43
|
|
|
43
|
|
256
|
sub _parser { $PARSER } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
3071
|
|
|
3071
|
1
|
22843
|
my ( $pkg, $string ) = @_; |
16
|
3071
|
100
|
|
|
|
10877
|
my $result = $pkg->_parser->parse($string) |
17
|
|
|
|
|
|
|
or croak qq[``$string'' is not a valid regular expression]; |
18
|
|
|
|
|
|
|
|
19
|
3062
|
|
|
|
|
925158
|
$pkg->_from_op($result); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _from_op { |
23
|
3065
|
|
|
3065
|
|
8228
|
my ( $proto, $op ) = @_; |
24
|
3065
|
|
66
|
|
|
14132
|
$proto = ref $proto || $proto; ## I really do want this |
25
|
|
|
|
|
|
|
|
26
|
3065
|
|
|
|
|
41210
|
bless [$op], $proto; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub op { |
30
|
186
|
|
|
186
|
0
|
1042
|
$_[0][0]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
6
|
|
39
|
use overload '""' => 'as_string'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
49
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub as_string { |
36
|
9
|
|
|
9
|
1
|
25
|
$_[0]->op->as_string(0); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub as_perl_regex { |
40
|
14
|
|
|
14
|
1
|
32
|
my ( $self, %opts ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
14
|
50
|
|
|
|
27
|
my $fmt = $opts{anchored} ? '(?:\A%s\z)' : '(?:%s)'; |
43
|
14
|
|
|
|
|
26
|
return sprintf $fmt, $self->op->as_perl_regex(0); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub contains { |
47
|
13
|
|
|
13
|
1
|
6051
|
my ( $self, $string ) = @_; |
48
|
13
|
|
|
|
|
28
|
$string =~ $self->as_perl_regex( anchored => 1 ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub as_nfa { |
52
|
0
|
|
|
0
|
1
|
0
|
$_[0]->op->as_nfa; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub as_pfa { |
56
|
137
|
|
|
137
|
0
|
1193
|
$_[0]->op->as_pfa; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#### regular language standard interface implementation: |
60
|
|
|
|
|
|
|
#### TODO: parameter checking? |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub as_regex { |
63
|
2
|
|
|
2
|
1
|
24
|
$_[0]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub union { |
67
|
1
|
|
|
1
|
1
|
6
|
my $self = $_[0]; |
68
|
1
|
|
|
|
|
3
|
my $op = FLAT::Regex::Op::alt->new( map { $_->as_regex->op } @_ ); |
|
2
|
|
|
|
|
6
|
|
69
|
1
|
|
|
|
|
3
|
$self->_from_op($op); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub intersect { |
73
|
0
|
|
|
0
|
1
|
0
|
my @dfas = map { $_->as_dfa } @_; |
|
0
|
|
|
|
|
0
|
|
74
|
0
|
|
|
|
|
0
|
my $self = shift @dfas; |
75
|
0
|
|
|
|
|
0
|
$self->intersect(@dfas)->as_regex; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub complement { |
79
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
80
|
0
|
|
|
|
|
0
|
$self->as_dfa->complement->as_regex; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub concat { |
84
|
0
|
|
|
0
|
1
|
0
|
my $self = $_[0]; |
85
|
0
|
|
|
|
|
0
|
my $op = FLAT::Regex::Op::concat->new( map { $_->as_regex->op } @_ ); |
|
0
|
|
|
|
|
0
|
|
86
|
0
|
|
|
|
|
0
|
$self->_from_op($op); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub kleene { |
90
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
91
|
0
|
|
|
|
|
0
|
my $op = FLAT::Regex::Op::star->new( $self->op ); |
92
|
0
|
|
|
|
|
0
|
$self->_from_op($op); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub reverse { |
96
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
97
|
2
|
|
|
|
|
5
|
my $op = $self->op->reverse; |
98
|
2
|
|
|
|
|
5
|
$self->_from_op($op); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub is_empty { |
102
|
11
|
|
|
11
|
1
|
22
|
$_[0]->op->is_empty; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub is_finite { |
106
|
11
|
|
|
11
|
1
|
20
|
$_[0]->op->is_finite; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |