line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FLAT::Regex; |
2
|
6
|
|
|
6
|
|
2764
|
use parent 'FLAT'; |
|
6
|
|
|
|
|
1871
|
|
|
6
|
|
|
|
|
32
|
|
3
|
6
|
|
|
6
|
|
314
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
100
|
|
4
|
6
|
|
|
6
|
|
25
|
use Carp; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
372
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
2386
|
use FLAT::Regex::Parser; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
191
|
|
7
|
6
|
|
|
6
|
|
37
|
use FLAT::Regex::Op; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
897
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $PARSER = FLAT::Regex::Parser->new(qw[ alt concat star ]); |
10
|
|
|
|
|
|
|
#### TODO: error checking in the parse |
11
|
|
|
|
|
|
|
|
12
|
43
|
|
|
43
|
|
486
|
sub _parser { $PARSER } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
3079
|
|
|
3079
|
1
|
28579
|
my ( $pkg, $string ) = @_; |
16
|
3079
|
100
|
|
|
|
11184
|
my $result = $pkg->_parser->parse($string) |
17
|
|
|
|
|
|
|
or croak qq[``$string'' is not a valid regular expression]; |
18
|
|
|
|
|
|
|
|
19
|
3070
|
|
|
|
|
835566
|
$pkg->_from_op($result); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _from_op { |
23
|
3073
|
|
|
3073
|
|
8902
|
my ( $proto, $op ) = @_; |
24
|
3073
|
|
66
|
|
|
13388
|
$proto = ref $proto || $proto; ## I really do want this |
25
|
|
|
|
|
|
|
|
26
|
3073
|
|
|
|
|
41550
|
bless [$op], $proto; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub op { |
30
|
186
|
|
|
186
|
0
|
1129
|
$_[0][0]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
6
|
|
39
|
use overload '""' => 'as_string'; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
49
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub as_string { |
36
|
9
|
|
|
9
|
1
|
41
|
$_[0]->op->as_string(0); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub as_perl_regex { |
40
|
14
|
|
|
14
|
1
|
38
|
my ( $self, %opts ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
14
|
50
|
|
|
|
68
|
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
|
7710
|
my ( $self, $string ) = @_; |
48
|
13
|
|
|
|
|
30
|
$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
|
1020
|
$_[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
|
5
|
$_[0]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub union { |
67
|
1
|
|
|
1
|
1
|
6
|
my $self = $_[0]; |
68
|
1
|
|
|
|
|
2
|
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
|
5
|
my $self = shift; |
97
|
2
|
|
|
|
|
6
|
my $op = $self->op->reverse; |
98
|
2
|
|
|
|
|
5
|
$self->_from_op($op); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub is_empty { |
102
|
11
|
|
|
11
|
1
|
57
|
$_[0]->op->is_empty; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub is_finite { |
106
|
11
|
|
|
11
|
1
|
66
|
$_[0]->op->is_finite; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |