Parser.yp

filter: Statementstmt 84.6% 55 / 65 Branchbran 70.0% 14 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 86.1% 31 / 36 Podpod 0.0% 0 / 2 totaltotal 81.3% 100 / 123 CC 12 SCAR 12.0
CC
12
Cov
81%
_Lexer
10.3
_Error
6.0
new
2.0
CRAP 3.3
« blib/lib/Chemistry/File/SLN.pm ↑ Summary blib/lib/Chemistry/File/SLN/Parser.pm »
1 # Parse::Yapp grammar for SLN
2  
3 2 ▶%{ no warnings 'uninitialized'; %}
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶# expected one shift/reduce conflict for H
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
6 2 %expect 1
7 2 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 2 2
8 %%
9  
10 0 ▶ctab: ctab_bracket { +{ chain => [], attr => $_[1] } }
Subroutine __ANON__: not called CC=1 SCAR=6.9
11 72 ▶ | atom chain ctab_bracket { +{ chain => [ $_[1], @{$_[2]} ],
Subroutine __ANON__: called CC=1 SCAR=0.0
12 attr => $_[3] } } ;
13  
14 153 ▶chain: /* empty */ { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
15 322 ▶ | bondatom chain { [ @{$_[1]}, @{$_[2]}, ] }
Subroutine __ANON__: called CC=1 SCAR=0.0
16 79 ▶ | '(' bondatom chain ')' chain {
Subroutine __ANON__: called CC=1 SCAR=0.0
17 79 [ $_[1], @{$_[2]}, @{$_[3]}, $_[4], @{$_[5]} ] }
18 ;
19  
20 378 ▶bondatom: bond atom { [@_[1,2]]}
Subroutine __ANON__: called CC=1 SCAR=0.0
21 23 ▶ | bond closure { [@_[1,2]]}
Subroutine __ANON__: called CC=1 SCAR=0.0
22 ;
23  
24 296 ▶bond: /* empty */ { +{type => '-'} }
Subroutine __ANON__: called CC=1 SCAR=0.0
25 105 ▶ | bond_symbol bond_bracket { +{
Subroutine __ANON__: called CC=1 SCAR=0.0
26 105 type => $_[1],
27 attr => $_[2]
28 }
29 }
30 ;
31  
32 23 ▶closure: '@' NUM { +{closure => $_[2]} }
Subroutine __ANON__: called CC=1 SCAR=0.0
33 ;
34  
35 bond_symbol: '-' | '=' | '#' | '.' | ':';
36  
37 450 ▶atom: symbol atom_bracket hcount { +{
Subroutine __ANON__: called CC=1 SCAR=0.0
38 450 symbol => $_[1],
39 id => $_[2][0],
40 hcount => $_[3],
41 attr => $_[2][1],
42 }
43 }
44 ;
45  
46 450 ▶symbol: UC lc_str { $_[1] . $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
47 ;
48  
49 lc_str: #empty
50 47 ▶ | lc_str LC { $_[1] . $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
51 ;
52  
53 UC: UC_NON_H | H;
54 ALPHA: UC | LC ;
55 ALNUM: ALPHA | NUM;
56 WORD: ALNUM | '_';
57  
58 atom_bracket: #empty
59 1 ▶ | '[' NUM ':' attr ']' { [@_[2,4]] }
Subroutine __ANON__: called CC=1 SCAR=0.0
60 2 ▶ | '[' attr ']' { [undef, $_[2]] }
Subroutine __ANON__: called CC=1 SCAR=0.0
61 22 ▶ | '[' NUM ']' { [$_[2], undef] }
Subroutine __ANON__: called CC=1 SCAR=0.0
62 ;
63  
64 bond_bracket: #empty
65 1 ▶ | '[' attr ']' { $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
66 ;
67  
68 ctab_bracket: #empty
69 66 ▶ | '<' attr '>' { $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
70 ;
71  
72 hcount: #empty
73 195 ▶ | H NUM { $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
74 90 ▶ | H { 1 }
Subroutine __ANON__: called CC=1 SCAR=0.0
75 ;
76  
77 attr: # empty
78 | attr_list;
79  
80 attr_list: key_val
81 4 ▶ | attr_list ';' key_val { +{%{$_[1]}, %{$_[3]}} }
Subroutine __ANON__: called CC=1 SCAR=0.0
82 ;
83  
84 70 ▶key_val: key '=' value { +{lc($_[1]) => $_[3]} }
Subroutine __ANON__: called CC=1 SCAR=0.0
85 2 ▶ | key { +{lc($_[1]) => 'TRUE' } }
Subroutine __ANON__: called CC=1 SCAR=0.0
86 2 ▶ | charge { +{charge => $_[1] } }
Subroutine __ANON__: called CC=1 SCAR=0.0
87 ;
88  
89 value: STRING | string;
90  
91 72 ▶key: ALPHA key_tail { $_[1] . $_[2] } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
92  
93 key_tail: #empty
94 219 ▶ | key_tail WORD { $_[1] . $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
95 ;
96  
97 2 ▶charge: '+' NUM { $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
98 0 ▶ | '-' NUM { -$_[2] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 ▶ | '+' { 1 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 0 ▶ | '-' { -1 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 ;
102  
103 string: #empty
104 24 ▶ | string string_char { $_[1] . $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
105 2 ;
106  
107 string_char: WORD | OTHER_CHAR | '+' | '-' | '.';
108  
109 #special chars: s/^([<>[\];=_()\@#.:+-])//s
110  
111  
112 %%
113  
114 0 ▶sub _Error {
Subroutine _Error: not called CC=2 SCAR=17.9
115 exists $_[0]->YYData->{ERRMSG}
116 0 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]->YYData->{"ERRMSG"} and do { warn $_[0]->YYData->{"ERRMSG"}; delete $_[0]->YYData->{"ERRMSG"}; return } 0 0 0
117 0 warn $_[0]->YYData->{ERRMSG};
118 0 delete $_[0]->YYData->{ERRMSG};
119 0 return;
120 };
121 0 warn "Syntax error.\n";
122 }
123 2  
124 2025 ▶sub _Lexer {
Subroutine _Lexer: called CC=10 SCAR=23.3
125 2025 my($parser)=shift;
126  
127 $parser->YYData->{INPUT}
128 #or $parser->YYData->{INPUT} = <STDIN>
129 2025 ▶ or return('',undef);
Branch: 1 branch
BranchTrueFalseTotal
$parser->YYData->{"INPUT"} or return "", undef 1953 72 2025
130  
131 1953 $parser->YYData->{INPUT}=~s/^[ \t]//;
132  
133 1953 for ($parser->YYData->{INPUT}) {
134 1953 ▶ s/^([0-9]+(?:\.[0-9]+)?)//
Branch: 1 branch
BranchTrueFalseTotal
s/^([0-9]+(?:\.[0-9]+)?)// and return "NUM", $1 243 1710 1953
135 and return('NUM',$1);
136 1710 ▶ s/^(H)//
Branch: 1 branch
BranchTrueFalseTotal
s/^(H)// and return "H", $1 285 1425 1710
137 and return('H',$1);
138 1425 ▶ s/^([A-Z])//
Branch: 1 branch
BranchTrueFalseTotal
s/^([A-Z])// and return "UC_NON_H", $1 450 975 1425
139 and return('UC_NON_H',$1);
140 975 ▶ s/^([a-z])//
Branch: 1 branch
BranchTrueFalseTotal
s/^([a-z])// and return "LC", $1 362 613 975
141 and return('LC',$1);
142 613 ▶ s/^"(.*?)"//s
Branch: 1 branch
BranchTrueFalseTotal
s/^"(.*?)"//s and return "STRING", $1 66 547 613
143 and return('STRING',$1);
144 547 ▶ s/^([<>[\];=_()\@#.:+-])//s
Branch: 1 branch
BranchTrueFalseTotal
s/^([<>[\];=_()\@#.:+-])//s and return $1, $1 547 0 547
145 and return($1,$1); # "special" character
146 0 ▶ s/^(.)//s
Branch: 1 branch
BranchTrueFalseTotal
s/^(.)//s and return "OTHER_CHAR", $1 0 0 0
147 and return('OTHER_CHAR',$1);
148 }
149 }
150  
151 72 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
152 72 my($self)=shift;
153 72 $self->YYData->{INPUT} = shift;
154 72 $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
155 }
156  
« blib/lib/Chemistry/File/SLN.pm ↑ Summary blib/lib/Chemistry/File/SLN/Parser.pm »