/home/cpancover/.cpan/build/Inline-0.54_02-0/blib/lib/Inline/C/ParseRecDescent.pm

filter: Statementstmt 76.1% 16 / 21 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 3 totaltotal 64.7% 22 / 34 CC 3 SCAR 7.0
CC
3
Cov
72%
get_parser
3.1
register
2.0
__ANON__
2.0
CRAP 2.0
« blib/lib/Inline/Foo.pm ↑ Summary Makefile.PL »
1 package Inline::C::ParseRecDescent;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 sub register {
6 {
7 0 ▶ extends => [qw(C)],
Subroutine register: not called CC=1 SCAR=6.9
Pod undocumented
8 overrides => [qw(get_parser)],
9 }
10 }
11  
12 sub get_parser {
13 4 ▶ my $o = shift;
Subroutine get_parser: called CC=3 SCAR=11.2
Pod undocumented
14 4 ▶ Inline::C::_parser_test("Inline::C::ParseRecDescent::get_parser called\n") if $o->{CONFIG}{_TESTING};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"_TESTING"} 0 4 4
15 4 eval { require Parse::RecDescent };
16 4 ▶ croak <<END if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
17 This innvocation of Inline requires the Parse::RecDescent module.
18 $@
19 END
20 4 $main::RD_HINT++;
21 4 Parse::RecDescent->new(grammar())
22 }
23  
24 sub grammar {
25 4 ▶ <<'END';
Subroutine grammar: called CC=1 SCAR=0.0
Pod undocumented
26  
27 code: part(s)
28 {
29 return 1;
30 }
31  
32 part: comment
33 | function_definition
34 {
35 my $function = $item[1][0];
36 $return = 1, last if $thisparser->{data}{done}{$function}++;
37 push @{$thisparser->{data}{functions}}, $function;
38 $thisparser->{data}{function}{$function}{return_type} =
39 $item[1][1];
40 $thisparser->{data}{function}{$function}{arg_types} =
41 [map {ref $_ ? $_->[0] : '...'} @{$item[1][2]}];
42 $thisparser->{data}{function}{$function}{arg_names} =
43 [map {ref $_ ? $_->[1] : '...'} @{$item[1][2]}];
44 }
45 | function_declaration
46 {
47 $return = 1, last unless $thisparser->{data}{AUTOWRAP};
48 my $function = $item[1][0];
49 $return = 1, last if $thisparser->{data}{done}{$function}++;
50 my $dummy = 'arg1';
51 push @{$thisparser->{data}{functions}}, $function;
52 $thisparser->{data}{function}{$function}{return_type} =
53 $item[1][1];
54 $thisparser->{data}{function}{$function}{arg_types} =
55 [map {ref $_ ? $_->[0] : '...'} @{$item[1][2]}];
56 $thisparser->{data}{function}{$function}{arg_names} =
57 [map {ref $_ ? ($_->[1] || $dummy++) : '...'} @{$item[1][2]}];
58 }
59 | anything_else
60  
61 comment:
62 m{\s* // [^\n]* \n }x
63 | m{\s* /\* (?:[^*]+|\*(?!/))* \*/ ([ \t]*)? }x
64  
65 function_definition:
66 rtype IDENTIFIER '(' <leftop: arg ',' arg>(s?) ')' '{'
67 {
68 [@item[2,1], $item[4]]
69 }
70  
71 function_declaration:
72 rtype IDENTIFIER '(' <leftop: arg_decl ',' arg_decl>(s?) ')' ';'
73 {
74 [@item[2,1], $item[4]]
75 }
76  
77 rtype: rtype1 | rtype2
78  
79 rtype1: modifier(s?) TYPE star(s?)
80 {
81 $return = $item[2];
82 $return = join ' ',@{$item[1]},$return
83 if @{$item[1]} and $item[1][0] ne 'extern';
84 $return .= join '',' ',@{$item[3]} if @{$item[3]};
85 return undef unless (defined $thisparser->{data}{typeconv}
86 {valid_rtypes}{$return});
87 }
88  
89 rtype2: modifier(s) star(s?)
90 {
91 $return = join ' ',@{$item[1]};
92 $return .= join '',' ',@{$item[2]} if @{$item[2]};
93 return undef unless (defined $thisparser->{data}{typeconv}
94 {valid_rtypes}{$return});
95 }
96  
97 arg: type IDENTIFIER {[@item[1,2]]}
98 | '...'
99  
100 arg_decl:
101 type IDENTIFIER(s?) {[$item[1], $item[2][0] || '']}
102 | '...'
103  
104 type: type1 | type2
105  
106 type1: modifier(s?) TYPE star(s?)
107 {
108 $return = $item[2];
109 $return = join ' ',@{$item[1]},$return if @{$item[1]};
110 $return .= join '',' ',@{$item[3]} if @{$item[3]};
111 return undef unless (defined $thisparser->{data}{typeconv}
112 {valid_types}{$return});
113 }
114  
115 type2: modifier(s) star(s?)
116 {
117 $return = join ' ',@{$item[1]};
118 $return .= join '',' ',@{$item[2]} if @{$item[2]};
119 return undef unless (defined $thisparser->{data}{typeconv}
120 {valid_types}{$return});
121 }
122  
123 modifier:
124 'unsigned' | 'long' | 'extern' | 'const'
125  
126 star: '*'
127  
128 IDENTIFIER:
129 /\w+/
130  
131 TYPE: /\w+/
132  
133 anything_else:
134 /.*/
135  
136 END
137 }
138  
139 my $hack = sub { # Appease -w using Inline::Files
140 0 ▶ print Parse::RecDescent::IN '';
Subroutine __ANON__: not called CC=1 SCAR=6.9
141 0 print Parse::RecDescent::IN '';
142 0 print Parse::RecDescent::TRACE_FILE '';
143 0 print Parse::RecDescent::TRACE_FILE '';
144 1 };
145  
146 1 1;
147  
148 __DATA__
« blib/lib/Inline/Foo.pm ↑ Summary Makefile.PL »