blib/lib/Pugs/Grammar/Base.pm

filter: Statementstmt 46.3% 32 / 69 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 4 totaltotal 36.5% 38 / 104 CC 9 SCAR 20.7
CC
9
Cov
38%
AUTOLOAD
20.0
before
12.0
no_match
6.0
CRAP 8.0
« blib/lib/Pugs/Runtime/Match/HsBridge.pm ↑ Summary blib/lib/Pugs/Runtime/Tracer.pm »
1 package Pugs::Grammar::Base;
2 13 ▶use Pugs::Runtime::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use Pugs::Compiler::RegexPerl5;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use Pugs::Compiler::Regex;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use charnames ":full"; # support \c[DIGIT SIX]
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # This class defines <ws>, unicode character classes, etc
11  
12 # internal methods - not in spec
13  
14 0 ▶sub no_match {
Subroutine no_match: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my $grammar = shift;
16 0 ▶ my $pos = $_[1]{p} || 0;
Condition0%0/2
$_[1]{'p'} || 0
l!l
00
MC/DC0%0/1
$_[1]{'p'} || 0
$_[1]{'p'}
Truth table0%0/2
A
A= $_[1]{'p'}
Aresult
11
00
17 0 return Pugs::Runtime::Match->new( {
18 bool => \0,
19 str => \$_[0],
20 match => [],
21 from => \$pos,
22 to => \$pos,
23 capture => undef,
24 } );
25 }
26  
27 13 *fail = \&no_match;
28  
29 13 *any = Pugs::Compiler::RegexPerl5->compile(
30 '\X'
31 )->code;
32  
33 # <<word
34 13 *_wb_left = Pugs::Compiler::RegexPerl5->compile(
35 '\b(?=\w)'
36 )->code;
37  
38 # word>>
39 13 *_wb_right = Pugs::Compiler::RegexPerl5->compile(
40 '(?<=\w)\b'
41 )->code;
42  
43 =for later - unused
44 # \h
45 *_horizontal_ws = Pugs::Compiler::RegexPerl5->compile(
46 #'XXX - Infinite loop in pugs stdrules.t' .
47 '\x20|\t'
48
49 #'\x0a|\x0b|\x0c|\x0d|\x85'
50 # from regex_tests, plus \t and ' '
51 )->code;
52  
53 # \v
54 *_vertical_ws = Pugs::Compiler::RegexPerl5->compile(
55 #'XXX - Infinite loop in pugs stdrules.t' .
56 '[\n\r]'
57
58 #'\x{1680}|\x{180e}|\x{2000}|\x{2001}|\x{2002}|\x{2003}|\x{2004}|\x{2005}|\x{2006}|\x{2007}|\x{2008}|\x{2008}|\x{2009}|\x{200a}|\x{202f}|\x{205f}|\x{3000}'
59 # from regex_tests
60 )->code;
61 =cut
62  
63 # specced methods
64  
65 0 ▶sub before {
Subroutine before: not called CC=3 SCAR=24.8
Pod undocumented
66 #print "Base->before: ", Dumper(\@_);
67 0 my $grammar = shift;
68 0 ▶ my $pos = $_[1]{p} || 0;
Condition0%0/2
$_[1]{'p'} || 0
l!l
00
MC/DC0%0/1
$_[1]{'p'} || 0
$_[1]{'p'}
Truth table0%0/2
A
A= $_[1]{'p'}
Aresult
11
00
69 0 my $arg = $_[1]{positionals}[0];
70  
71 # XXX - token or regex?
72 0 my $rule = Pugs::Compiler::Regex->compile( $arg );
73 0 my $match = $rule->match( $_[0], { pos => $pos } );
74
75 0 ▶ return Pugs::Runtime::Match->new( {
Branch: 1 branch
BranchTrueFalseTotal
$match ? : 0 0 0
76 bool => \( $match ? 1 : 0 ),
77 str => \$_[0],
78 match => [],
79 from => \$pos,
80 to => \$pos,
81 capture => undef,
82 } );
83 }
84  
85 0 ▶sub at {
Subroutine at: not called CC=2 SCAR=17.9
Pod undocumented
86 #print "Base->at: ", Dumper(\@_);
87 0 my $grammar = shift;
88 0 ▶ my $pos = $_[1]{p} || 0;
Condition0%0/2
$_[1]{'p'} || 0
l!l
00
MC/DC0%0/1
$_[1]{'p'} || 0
$_[1]{'p'}
Truth table0%0/2
A
A= $_[1]{'p'}
Aresult
11
00
89 0 my $arg = $_[1]{positionals}[0];
90 # print "at: ",Dumper( @_ );
91 0 return Pugs::Runtime::Match->new( {
92 bool => \( $pos == $arg ),
93 str => \$_[0],
94 match => [],
95 from => \$pos,
96 to => \$pos,
97 capture => undef,
98 } );
99 }
100  
101 0 ▶sub prior {
Subroutine prior: not called CC=2 SCAR=17.9
Pod undocumented
102 0 ▶ die "Error: <prior> is undefined"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $main::_V6_PRIOR_ 0 0 0
103 unless defined $main::_V6_PRIOR_;
104  
105 0 my $prior = $main::_V6_PRIOR_;
106 ## local $main::_V6_PRIOR_;
107 0 $prior->(@_[0, 1, 2, 2]); # XXX fix parameter list
108 }
109  
110 13 *null = Pugs::Compiler::RegexPerl5->compile(
111 ''
112 )->code;
113  
114 13 *ws = Pugs::Compiler::RegexPerl5->compile(
115 '(?:(?<!\w)|(?!\w)|\s)\s*'
116 )->code;
117  
118 # <wb> = word boundary - from regex_tests
119 13 *wb = Pugs::Compiler::RegexPerl5->compile(
120 '\b'
121 )->code;
122  
123 13 *ident = Pugs::Compiler::RegexPerl5->compile(
124 '[[:alpha:]_][[:alnum:]_]*'
125 )->code;
126  
127 13 *name = Pugs::Compiler::RegexPerl5->compile(
128 # from pugs tests
129 '(?:[[:alpha:]_][[:alnum:]_]*::)*[[:alpha:]_][[:alnum:]_]*'
130 )->code;
131  
132 13 *sp = Pugs::Compiler::RegexPerl5->compile(
133 '\x20'
134 )->code;
135  
136 13 *dot = Pugs::Compiler::RegexPerl5->compile(
137 '\.'
138 )->code;
139  
140 13 *gt = Pugs::Compiler::RegexPerl5->compile(
141 '>'
142 )->code;
143  
144 13 *lt = Pugs::Compiler::RegexPerl5->compile(
145 '<'
146 )->code;
147  
148 #BEGIN {
149 # # this list was extracted from 'perlre'
150 # for ( qw(
151 # alpha alnum ascii blank
152 # cntrl digit graph lower
153 # print punct space upper
154 # word xdigit
155 # ) ) {
156 # *{$_} = Pugs::Compiler::RegexPerl5->compile(
157 # "[[:$_:]]"
158 # )->code;
159 # }
160 #}
161  
162 0 ▶sub DESTROY { } # avoid autoloading this
Subroutine DESTROY: not called CC=1 SCAR=0.0
163  
164 0 ▶ sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
165 #my $self = shift;
166 0 my $meth = $AUTOLOAD;
167 0 $meth =~ s/.*:://; # strip fully-qualified portion
168
169 # is it a Unicode property? "isL"
170 {
171 0 local $@;
172 0 my $p5;
173 0 ▶ if ( exists $Pugs::Emitter::Rule::Perl5::CharClass::extra_unicode{$meth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Pugs::Emitter::Rule::Perl5::CharClass::extra_unicode{$meth}) { } 0 0 0
174 0 $p5 = $Pugs::Emitter::Rule::Perl5::CharClass::extra_unicode{$meth};
175 }
176 else {
177 0 $p5 = '\p{' . $meth . '}';
178 0 eval ' my $s="a"; $s =~ /' . $p5 . '/ ';
179 }
180 0 ▶ unless ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
181 0 *{$meth} = Pugs::Compiler::RegexPerl5->compile($p5)->code;
182 0 return $meth->( @_ );
183 }
184 }
185
186 # is it a char class? "digit"
187 {
188 0 local $@;
189 0 eval ' my $s="a"; $s =~ /[[:' . $meth . ':]]/ ';
190 0 ▶ unless ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
191 0 *{$meth} = Pugs::Compiler::RegexPerl5->compile(
192 '[[:' . $meth . ':]]'
193 )->code;
194 0 return $meth->( @_ );
195 }
196 }
197
198 0 carp "unknown rule: <$meth>";
199 }
200  
201 13 1;
« blib/lib/Pugs/Runtime/Match/HsBridge.pm ↑ Summary blib/lib/Pugs/Runtime/Tracer.pm »