line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FLAT::Regex; |
2
|
6
|
|
|
6
|
|
2552
|
use parent 'FLAT'; |
|
6
|
|
|
|
|
1711
|
|
|
6
|
|
|
|
|
26
|
|
3
|
6
|
|
|
6
|
|
280
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
92
|
|
4
|
6
|
|
|
6
|
|
24
|
use Carp; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
325
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
2432
|
use FLAT::Regex::Parser; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
171
|
|
7
|
6
|
|
|
6
|
|
35
|
use FLAT::Regex::Op; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
794
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $PARSER = FLAT::Regex::Parser->new(qw[ alt concat star ]); |
10
|
|
|
|
|
|
|
#### TODO: error checking in the parse |
11
|
|
|
|
|
|
|
|
12
|
43
|
|
|
43
|
|
307
|
sub _parser { $PARSER } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
3061
|
|
|
3061
|
1
|
25505
|
my ( $pkg, $string ) = @_; |
16
|
3061
|
100
|
|
|
|
10573
|
my $result = $pkg->_parser->parse($string) |
17
|
|
|
|
|
|
|
or croak qq[``$string'' is not a valid regular expression]; |
18
|
|
|
|
|
|
|
|
19
|
3052
|
|
|
|
|
827578
|
$pkg->_from_op($result); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _from_op { |
23
|
3055
|
|
|
3055
|
|
8693
|
my ( $proto, $op ) = @_; |
24
|
3055
|
|
66
|
|
|
13846
|
$proto = ref $proto || $proto; ## I really do want this |
25
|
|
|
|
|
|
|
|
26
|
3055
|
|
|
|
|
40224
|
bless [$op], $proto; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub op { |
30
|
186
|
|
|
186
|
0
|
981
|
$_[0][0]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
6
|
|
36
|
use overload '""' => 'as_string'; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
37
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub as_string { |
36
|
9
|
|
|
9
|
1
|
34
|
$_[0]->op->as_string(0); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub as_perl_regex { |
40
|
14
|
|
|
14
|
1
|
42
|
my ( $self, %opts ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
14
|
50
|
|
|
|
51
|
my $fmt = $opts{anchored} ? '(?:\A%s\z)' : '(?:%s)'; |
43
|
14
|
|
|
|
|
33
|
return sprintf $fmt, $self->op->as_perl_regex(0); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub contains { |
47
|
13
|
|
|
13
|
1
|
7505
|
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
|
1110
|
$_[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
|
3
|
$_[0]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub union { |
67
|
1
|
|
|
1
|
1
|
7
|
my $self = $_[0]; |
68
|
1
|
|
|
|
|
3
|
my $op = FLAT::Regex::Op::alt->new( map { $_->as_regex->op } @_ ); |
|
2
|
|
|
|
|
6
|
|
69
|
1
|
|
|
|
|
2
|
$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
|
3
|
my $self = shift; |
97
|
2
|
|
|
|
|
6
|
my $op = $self->op->reverse; |
98
|
2
|
|
|
|
|
6
|
$self->_from_op($op); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub is_empty { |
102
|
11
|
|
|
11
|
1
|
60
|
$_[0]->op->is_empty; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub is_finite { |
106
|
11
|
|
|
11
|
1
|
27
|
$_[0]->op->is_finite; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |