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