File Coverage

blib/lib/Chemistry/File/InChI/Parser.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             ####################################################################
2             #
3             # This file was generated using Parse::Yapp version 1.21.
4             #
5             # Don't edit this file, use source file instead.
6             #
7             # ANY CHANGE MADE HERE WILL BE LOST !
8             #
9             ####################################################################
10             package Chemistry::File::InChI::Parser;
11 3     3   96914 use vars qw ( @ISA );
  3         9  
  3         212  
12 3     3   16 use strict;
  3         9  
  3         130  
13              
14             @ISA= qw ( Parse::Yapp::Driver );
15 3     3   2299 use Parse::Yapp::Driver;
  3         7531  
  3         1012  
16              
17             #line 3 "lib/Chemistry/File/InChI/Parser.yp"
18              
19              
20             use strict;
21             use warnings;
22              
23             use Chemistry::Atom;
24             use Chemistry::Mol;
25              
26             use List::Util qw( first );
27              
28             my @LAYER_ORDER = qw( PREFIX FORMULA CONNECTIONS H_ATOMS CHARGE TETRAHEDRAL STEREOCHEMISTRY );
29              
30              
31              
32             sub new {
33             my($class)=shift;
34             ref($class)
35             and $class=ref($class);
36              
37             my($self)=$class->SUPER::new( yyversion => '1.21',
38             yystates =>
39             [
40             {#State 0
41             ACTIONS => {
42             'prefix' => 1
43             },
44             GOTOS => {
45             'string' => 2
46             }
47             },
48             {#State 1
49             DEFAULT => -1
50             },
51             {#State 2
52             ACTIONS => {
53             '' => 10,
54             "/" => 5,
55             'formula_first' => 7
56             },
57             GOTOS => {
58             'charge' => 6,
59             'tetrahedral' => 12,
60             'h_atoms' => 3,
61             'connections' => 9,
62             'layer' => 8,
63             'formula' => 11,
64             'stereochemistry' => 4
65             }
66             },
67             {#State 3
68             ACTIONS => {
69             ";" => 13
70             },
71             DEFAULT => -5
72             },
73             {#State 4
74             DEFAULT => -8
75             },
76             {#State 5
77             ACTIONS => {
78             "s" => 17,
79             "q" => 14,
80             "t" => 16,
81             "h" => 15,
82             "c" => 18
83             }
84             },
85             {#State 6
86             ACTIONS => {
87             ";" => 21,
88             "+" => 19,
89             "-" => 20
90             },
91             DEFAULT => -6
92             },
93             {#State 7
94             DEFAULT => -9
95             },
96             {#State 8
97             DEFAULT => -2
98             },
99             {#State 9
100             ACTIONS => {
101             ";" => 22
102             },
103             DEFAULT => -4
104             },
105             {#State 10
106             DEFAULT => 0
107             },
108             {#State 11
109             ACTIONS => {
110             'formula_continuation' => 23
111             },
112             DEFAULT => -3
113             },
114             {#State 12
115             ACTIONS => {
116             ";" => 24
117             },
118             DEFAULT => -7
119             },
120             {#State 13
121             ACTIONS => {
122             "6" => 36,
123             "7" => 35,
124             "(" => 37,
125             "3" => 38,
126             "2" => 39,
127             "5" => 41,
128             "4" => 25,
129             "9" => 27,
130             "1" => 32,
131             "8" => 33
132             },
133             DEFAULT => -17,
134             GOTOS => {
135             'count' => 34,
136             'mobile_hydrogens' => 42,
137             'index' => 43,
138             'virtual_hydrogen_receivers' => 40,
139             'mh_count' => 30,
140             'hydrogens' => 31,
141             'virtual_hydrogens' => 29,
142             'vh_count' => 28,
143             'twoplus' => 26
144             }
145             },
146             {#State 14
147             DEFAULT => -65
148             },
149             {#State 15
150             ACTIONS => {
151             "1" => 32,
152             "8" => 33,
153             "4" => 25,
154             "9" => 27,
155             "5" => 41,
156             "(" => 37,
157             "6" => 36,
158             "7" => 35,
159             "3" => 38,
160             "2" => 39
161             },
162             DEFAULT => -15,
163             GOTOS => {
164             'virtual_hydrogens' => 29,
165             'vh_count' => 28,
166             'twoplus' => 26,
167             'mobile_hydrogens' => 42,
168             'index' => 43,
169             'count' => 34,
170             'mh_count' => 30,
171             'virtual_hydrogen_receivers' => 40,
172             'hydrogens' => 44
173             }
174             },
175             {#State 16
176             ACTIONS => {
177             "1" => 32,
178             "8" => 33,
179             "4" => 25,
180             "9" => 27,
181             "5" => 41,
182             "7" => 35,
183             "6" => 36,
184             "2" => 39,
185             "3" => 38
186             },
187             DEFAULT => -19,
188             GOTOS => {
189             'tetrahedral_center' => 45,
190             'twoplus' => 26,
191             'count' => 46,
192             'tetrahedral_centers' => 47,
193             'index' => 48
194             }
195             },
196             {#State 17
197             ACTIONS => {
198             "2" => 49,
199             "1" => 50
200             }
201             },
202             {#State 18
203             ACTIONS => {
204             "7" => 35,
205             "6" => 36,
206             "3" => 38,
207             "2" => 39,
208             "5" => 41,
209             "4" => 25,
210             "9" => 27,
211             "1" => 32,
212             "8" => 33
213             },
214             DEFAULT => -11,
215             GOTOS => {
216             'graph' => 51,
217             'twoplus' => 26,
218             'count' => 53,
219             'chain' => 54,
220             'index' => 52
221             }
222             },
223             {#State 19
224             ACTIONS => {
225             "5" => 41,
226             "1" => 56,
227             "8" => 33,
228             "4" => 25,
229             "6" => 36,
230             "7" => 35,
231             "9" => 27,
232             "3" => 38,
233             "2" => 39
234             },
235             GOTOS => {
236             'twoplus' => 55,
237             'natural' => 57
238             }
239             },
240             {#State 20
241             ACTIONS => {
242             "9" => 27,
243             "3" => 38,
244             "2" => 39,
245             "4" => 25,
246             "7" => 35,
247             "6" => 36,
248             "8" => 33,
249             "5" => 41,
250             "1" => 56
251             },
252             GOTOS => {
253             'twoplus' => 55,
254             'natural' => 58
255             }
256             },
257             {#State 21
258             DEFAULT => -68
259             },
260             {#State 22
261             ACTIONS => {
262             "8" => 33,
263             "1" => 32,
264             "9" => 27,
265             "4" => 25,
266             "5" => 41,
267             "2" => 39,
268             "3" => 38,
269             "6" => 36,
270             "7" => 35
271             },
272             DEFAULT => -13,
273             GOTOS => {
274             'twoplus' => 26,
275             'graph' => 59,
276             'index' => 52,
277             'count' => 53,
278             'chain' => 54
279             }
280             },
281             {#State 23
282             DEFAULT => -10
283             },
284             {#State 24
285             ACTIONS => {
286             "1" => 32,
287             "8" => 33,
288             "4" => 25,
289             "9" => 27,
290             "5" => 41,
291             "7" => 35,
292             "6" => 36,
293             "3" => 38,
294             "2" => 39
295             },
296             DEFAULT => -21,
297             GOTOS => {
298             'tetrahedral_center' => 45,
299             'twoplus' => 26,
300             'count' => 46,
301             'tetrahedral_centers' => 60,
302             'index' => 48
303             }
304             },
305             {#State 25
306             DEFAULT => -82
307             },
308             {#State 26
309             DEFAULT => -73
310             },
311             {#State 27
312             DEFAULT => -87
313             },
314             {#State 28
315             ACTIONS => {
316             "," => 62
317             },
318             DEFAULT => -38,
319             GOTOS => {
320             'mh_counts' => 61
321             }
322             },
323             {#State 29
324             DEFAULT => -43
325             },
326             {#State 30
327             ACTIONS => {
328             "(" => 37
329             },
330             DEFAULT => -42,
331             GOTOS => {
332             'mobile_hydrogens' => 63
333             }
334             },
335             {#State 31
336             DEFAULT => -18
337             },
338             {#State 32
339             ACTIONS => {
340             "1" => 64,
341             "8" => 33,
342             "4" => 25,
343             "9" => 27,
344             "5" => 41,
345             "6" => 36,
346             "7" => 35,
347             "0" => 67,
348             "2" => 39,
349             "3" => 38
350             },
351             DEFAULT => -69,
352             GOTOS => {
353             'twoplus' => 65,
354             'digit' => 66
355             }
356             },
357             {#State 33
358             DEFAULT => -86
359             },
360             {#State 34
361             ACTIONS => {
362             "3" => 38,
363             "2" => 39,
364             "0" => 67,
365             "6" => 36,
366             "7" => 35,
367             "5" => 41,
368             "9" => 27,
369             "4" => 25,
370             "*" => 69,
371             "8" => 33,
372             "1" => 64
373             },
374             DEFAULT => -70,
375             GOTOS => {
376             'digit' => 68,
377             'twoplus' => 65
378             }
379             },
380             {#State 35
381             DEFAULT => -85
382             },
383             {#State 36
384             DEFAULT => -84
385             },
386             {#State 37
387             ACTIONS => {
388             "H" => 70
389             }
390             },
391             {#State 38
392             DEFAULT => -81
393             },
394             {#State 39
395             DEFAULT => -80
396             },
397             {#State 40
398             ACTIONS => {
399             "," => 71,
400             "-" => 73,
401             "H" => 72
402             }
403             },
404             {#State 41
405             DEFAULT => -83
406             },
407             {#State 42
408             DEFAULT => -45
409             },
410             {#State 43
411             DEFAULT => -51
412             },
413             {#State 44
414             DEFAULT => -16
415             },
416             {#State 45
417             DEFAULT => -63
418             },
419             {#State 46
420             ACTIONS => {
421             "1" => 64,
422             "8" => 33,
423             "4" => 25,
424             "9" => 27,
425             "5" => 41,
426             "7" => 35,
427             "6" => 36,
428             "0" => 67,
429             "2" => 39,
430             "3" => 38
431             },
432             DEFAULT => -70,
433             GOTOS => {
434             'digit' => 68,
435             'twoplus' => 65
436             }
437             },
438             {#State 47
439             ACTIONS => {
440             "," => 74
441             },
442             DEFAULT => -20
443             },
444             {#State 48
445             ACTIONS => {
446             "-" => 76,
447             "+" => 75,
448             "?" => 77
449             }
450             },
451             {#State 49
452             DEFAULT => -24
453             },
454             {#State 50
455             DEFAULT => -23
456             },
457             {#State 51
458             DEFAULT => -12
459             },
460             {#State 52
461             ACTIONS => {
462             "-" => 80,
463             "(" => 78
464             },
465             GOTOS => {
466             'branches' => 79,
467             'branch' => 81
468             }
469             },
470             {#State 53
471             ACTIONS => {
472             "0" => 67,
473             "6" => 36,
474             "7" => 35,
475             "3" => 38,
476             "2" => 39,
477             "5" => 41,
478             "4" => 25,
479             "9" => 27,
480             "1" => 64,
481             "*" => 82,
482             "8" => 33
483             },
484             DEFAULT => -70,
485             GOTOS => {
486             'twoplus' => 65,
487             'digit' => 68
488             }
489             },
490             {#State 54
491             ACTIONS => {
492             "(" => 78,
493             "-" => 83
494             },
495             DEFAULT => -25,
496             GOTOS => {
497             'branch' => 81,
498             'branches' => 84
499             }
500             },
501             {#State 55
502             DEFAULT => -75
503             },
504             {#State 56
505             DEFAULT => -74
506             },
507             {#State 57
508             ACTIONS => {
509             "3" => 38,
510             "2" => 39,
511             "0" => 67,
512             "7" => 35,
513             "6" => 36,
514             "5" => 41,
515             "9" => 27,
516             "4" => 25,
517             "8" => 33,
518             "1" => 64
519             },
520             DEFAULT => -66,
521             GOTOS => {
522             'digit' => 85,
523             'twoplus' => 65
524             }
525             },
526             {#State 58
527             ACTIONS => {
528             "5" => 41,
529             "2" => 39,
530             "3" => 38,
531             "6" => 36,
532             "7" => 35,
533             "0" => 67,
534             "8" => 33,
535             "1" => 64,
536             "9" => 27,
537             "4" => 25
538             },
539             DEFAULT => -67,
540             GOTOS => {
541             'twoplus' => 65,
542             'digit' => 85
543             }
544             },
545             {#State 59
546             DEFAULT => -14
547             },
548             {#State 60
549             ACTIONS => {
550             "," => 74
551             },
552             DEFAULT => -22
553             },
554             {#State 61
555             ACTIONS => {
556             "," => 86
557             },
558             DEFAULT => -39
559             },
560             {#State 62
561             ACTIONS => {
562             "9" => 27,
563             "2" => 39,
564             "3" => 38,
565             "6" => 36,
566             "7" => 35,
567             "4" => 25,
568             "(" => 37,
569             "8" => 33,
570             "1" => 32,
571             "5" => 41
572             },
573             GOTOS => {
574             'virtual_hydrogens' => 87,
575             'twoplus' => 26,
576             'mobile_hydrogens' => 42,
577             'index' => 43,
578             'count' => 46,
579             'mh_count' => 88,
580             'virtual_hydrogen_receivers' => 40
581             }
582             },
583             {#State 63
584             DEFAULT => -46
585             },
586             {#State 64
587             DEFAULT => -78
588             },
589             {#State 65
590             DEFAULT => -79
591             },
592             {#State 66
593             DEFAULT => -71
594             },
595             {#State 67
596             DEFAULT => -77
597             },
598             {#State 68
599             DEFAULT => -72
600             },
601             {#State 69
602             ACTIONS => {
603             "8" => 33,
604             "5" => 41,
605             "1" => 32,
606             "3" => 38,
607             "2" => 39,
608             "9" => 27,
609             "4" => 25,
610             "6" => 36,
611             "7" => 35
612             },
613             GOTOS => {
614             'virtual_hydrogens' => 29,
615             'vh_count' => 89,
616             'index' => 43,
617             'count' => 46,
618             'virtual_hydrogen_receivers' => 40,
619             'twoplus' => 26
620             }
621             },
622             {#State 70
623             ACTIONS => {
624             "7" => 35,
625             "6" => 36,
626             "4" => 25,
627             "," => 92,
628             "9" => 27,
629             "2" => 39,
630             "3" => 38,
631             "-" => 90,
632             "1" => 93,
633             "5" => 41,
634             "8" => 33
635             },
636             GOTOS => {
637             'count' => 94,
638             'comma_separated_indexes' => 91,
639             'twoplus' => 26
640             }
641             },
642             {#State 71
643             ACTIONS => {
644             "9" => 27,
645             "3" => 38,
646             "2" => 39,
647             "4" => 25,
648             "7" => 35,
649             "6" => 36,
650             "8" => 33,
651             "5" => 41,
652             "1" => 32
653             },
654             GOTOS => {
655             'twoplus' => 26,
656             'count' => 46,
657             'index' => 95
658             }
659             },
660             {#State 72
661             ACTIONS => {
662             "5" => 41,
663             "3" => 38,
664             "2" => 39,
665             "6" => 36,
666             "7" => 35,
667             "8" => 33,
668             "1" => 93,
669             "9" => 27,
670             "4" => 25
671             },
672             DEFAULT => -49,
673             GOTOS => {
674             'count' => 96,
675             'twoplus' => 26
676             }
677             },
678             {#State 73
679             ACTIONS => {
680             "5" => 41,
681             "1" => 32,
682             "4" => 25,
683             "7" => 35,
684             "6" => 36,
685             "3" => 38,
686             "2" => 39,
687             "9" => 27,
688             "8" => 33
689             },
690             GOTOS => {
691             'twoplus' => 26,
692             'count' => 46,
693             'index' => 97
694             }
695             },
696             {#State 74
697             ACTIONS => {
698             "7" => 35,
699             "6" => 36,
700             "4" => 25,
701             "1" => 32,
702             "5" => 41,
703             "8" => 33,
704             "9" => 27,
705             "2" => 39,
706             "3" => 38
707             },
708             GOTOS => {
709             'index' => 48,
710             'count' => 46,
711             'tetrahedral_center' => 98,
712             'twoplus' => 26
713             }
714             },
715             {#State 75
716             DEFAULT => -60
717             },
718             {#State 76
719             DEFAULT => -61
720             },
721             {#State 77
722             DEFAULT => -62
723             },
724             {#State 78
725             ACTIONS => {
726             "9" => 27,
727             "8" => 33,
728             "3" => 38,
729             "2" => 39,
730             "4" => 25,
731             "7" => 35,
732             "6" => 36,
733             "5" => 41,
734             "1" => 32
735             },
736             GOTOS => {
737             'branch_body' => 100,
738             'count' => 46,
739             'index' => 99,
740             'twoplus' => 26
741             }
742             },
743             {#State 79
744             ACTIONS => {
745             "8" => 33,
746             "1" => 32,
747             "5" => 41,
748             "9" => 27,
749             "2" => 39,
750             "3" => 38,
751             "7" => 35,
752             "6" => 36,
753             "4" => 25,
754             "(" => 78
755             },
756             GOTOS => {
757             'count' => 46,
758             'index' => 102,
759             'branch' => 101,
760             'twoplus' => 26
761             }
762             },
763             {#State 80
764             ACTIONS => {
765             "2" => 39,
766             "3" => 38,
767             "9" => 27,
768             "6" => 36,
769             "7" => 35,
770             "4" => 25,
771             "8" => 33,
772             "1" => 32,
773             "5" => 41
774             },
775             GOTOS => {
776             'index' => 103,
777             'count' => 46,
778             'twoplus' => 26
779             }
780             },
781             {#State 81
782             DEFAULT => -36
783             },
784             {#State 82
785             ACTIONS => {
786             "5" => 41,
787             "1" => 32,
788             "4" => 25,
789             "7" => 35,
790             "6" => 36,
791             "3" => 38,
792             "2" => 39,
793             "9" => 27,
794             "8" => 33
795             },
796             GOTOS => {
797             'index' => 52,
798             'count' => 46,
799             'chain' => 104,
800             'twoplus' => 26
801             }
802             },
803             {#State 83
804             ACTIONS => {
805             "9" => 27,
806             "8" => 33,
807             "3" => 38,
808             "2" => 39,
809             "4" => 25,
810             "7" => 35,
811             "6" => 36,
812             "5" => 41,
813             "1" => 32
814             },
815             GOTOS => {
816             'count' => 46,
817             'index' => 105,
818             'twoplus' => 26
819             }
820             },
821             {#State 84
822             ACTIONS => {
823             "(" => 78,
824             "7" => 35,
825             "6" => 36,
826             "4" => 25,
827             "2" => 39,
828             "3" => 38,
829             "9" => 27,
830             "1" => 32,
831             "5" => 41,
832             "8" => 33
833             },
834             GOTOS => {
835             'twoplus' => 26,
836             'index' => 106,
837             'branch' => 101,
838             'count' => 46
839             }
840             },
841             {#State 85
842             DEFAULT => -76
843             },
844             {#State 86
845             ACTIONS => {
846             "(" => 37
847             },
848             GOTOS => {
849             'mobile_hydrogens' => 42,
850             'mh_count' => 107
851             }
852             },
853             {#State 87
854             DEFAULT => -44
855             },
856             {#State 88
857             ACTIONS => {
858             "(" => 37
859             },
860             DEFAULT => -47,
861             GOTOS => {
862             'mobile_hydrogens' => 63
863             }
864             },
865             {#State 89
866             ACTIONS => {
867             "," => 62
868             },
869             DEFAULT => -40,
870             GOTOS => {
871             'mh_counts' => 108
872             }
873             },
874             {#State 90
875             ACTIONS => {
876             "," => 92
877             },
878             GOTOS => {
879             'comma_separated_indexes' => 109
880             }
881             },
882             {#State 91
883             ACTIONS => {
884             ")" => 111,
885             "," => 110
886             }
887             },
888             {#State 92
889             ACTIONS => {
890             "8" => 33,
891             "5" => 41,
892             "1" => 32,
893             "9" => 27,
894             "3" => 38,
895             "2" => 39,
896             "4" => 25,
897             "7" => 35,
898             "6" => 36
899             },
900             GOTOS => {
901             'twoplus' => 26,
902             'index' => 112,
903             'count' => 46
904             }
905             },
906             {#State 93
907             ACTIONS => {
908             "6" => 36,
909             "7" => 35,
910             "4" => 25,
911             "0" => 67,
912             "2" => 39,
913             "3" => 38,
914             "9" => 27,
915             "1" => 64,
916             "5" => 41,
917             "8" => 33
918             },
919             GOTOS => {
920             'digit' => 66,
921             'twoplus' => 65
922             }
923             },
924             {#State 94
925             ACTIONS => {
926             "9" => 27,
927             "4" => 25,
928             "8" => 33,
929             "1" => 64,
930             "2" => 39,
931             "3" => 38,
932             "," => 92,
933             "7" => 35,
934             "6" => 36,
935             "0" => 67,
936             "5" => 41,
937             "-" => 113
938             },
939             GOTOS => {
940             'twoplus' => 65,
941             'comma_separated_indexes' => 114,
942             'digit' => 68
943             }
944             },
945             {#State 95
946             DEFAULT => -52
947             },
948             {#State 96
949             ACTIONS => {
950             "1" => 64,
951             "8" => 33,
952             "4" => 25,
953             "9" => 27,
954             "5" => 41,
955             "7" => 35,
956             "6" => 36,
957             "0" => 67,
958             "2" => 39,
959             "3" => 38
960             },
961             DEFAULT => -50,
962             GOTOS => {
963             'twoplus' => 65,
964             'digit' => 68
965             }
966             },
967             {#State 97
968             DEFAULT => -53
969             },
970             {#State 98
971             DEFAULT => -64
972             },
973             {#State 99
974             DEFAULT => -32
975             },
976             {#State 100
977             ACTIONS => {
978             "," => 115,
979             "-" => 117,
980             "(" => 78,
981             ")" => 118
982             },
983             GOTOS => {
984             'branches' => 116,
985             'branch' => 81
986             }
987             },
988             {#State 101
989             DEFAULT => -37
990             },
991             {#State 102
992             DEFAULT => -28
993             },
994             {#State 103
995             DEFAULT => -27
996             },
997             {#State 104
998             ACTIONS => {
999             "(" => 78,
1000             "-" => 83
1001             },
1002             DEFAULT => -26,
1003             GOTOS => {
1004             'branch' => 81,
1005             'branches' => 84
1006             }
1007             },
1008             {#State 105
1009             DEFAULT => -29
1010             },
1011             {#State 106
1012             DEFAULT => -30
1013             },
1014             {#State 107
1015             ACTIONS => {
1016             "(" => 37
1017             },
1018             DEFAULT => -48,
1019             GOTOS => {
1020             'mobile_hydrogens' => 63
1021             }
1022             },
1023             {#State 108
1024             ACTIONS => {
1025             "," => 86
1026             },
1027             DEFAULT => -41
1028             },
1029             {#State 109
1030             ACTIONS => {
1031             "," => 110,
1032             ")" => 119
1033             }
1034             },
1035             {#State 110
1036             ACTIONS => {
1037             "1" => 32,
1038             "5" => 41,
1039             "6" => 36,
1040             "7" => 35,
1041             "4" => 25,
1042             "2" => 39,
1043             "3" => 38,
1044             "8" => 33,
1045             "9" => 27
1046             },
1047             GOTOS => {
1048             'count' => 46,
1049             'index' => 120,
1050             'twoplus' => 26
1051             }
1052             },
1053             {#State 111
1054             DEFAULT => -54
1055             },
1056             {#State 112
1057             DEFAULT => -58
1058             },
1059             {#State 113
1060             ACTIONS => {
1061             "," => 92
1062             },
1063             GOTOS => {
1064             'comma_separated_indexes' => 121
1065             }
1066             },
1067             {#State 114
1068             ACTIONS => {
1069             ")" => 122,
1070             "," => 110
1071             }
1072             },
1073             {#State 115
1074             ACTIONS => {
1075             "4" => 25,
1076             "7" => 35,
1077             "6" => 36,
1078             "3" => 38,
1079             "2" => 39,
1080             "9" => 27,
1081             "5" => 41,
1082             "1" => 32,
1083             "8" => 33
1084             },
1085             GOTOS => {
1086             'count' => 46,
1087             'index' => 123,
1088             'twoplus' => 26
1089             }
1090             },
1091             {#State 116
1092             ACTIONS => {
1093             "8" => 33,
1094             "1" => 32,
1095             "5" => 41,
1096             "9" => 27,
1097             "2" => 39,
1098             "3" => 38,
1099             "6" => 36,
1100             "7" => 35,
1101             "4" => 25,
1102             "(" => 78
1103             },
1104             GOTOS => {
1105             'twoplus' => 26,
1106             'index' => 124,
1107             'branch' => 101,
1108             'count' => 46
1109             }
1110             },
1111             {#State 117
1112             ACTIONS => {
1113             "2" => 39,
1114             "3" => 38,
1115             "8" => 33,
1116             "9" => 27,
1117             "1" => 32,
1118             "5" => 41,
1119             "7" => 35,
1120             "6" => 36,
1121             "4" => 25
1122             },
1123             GOTOS => {
1124             'count' => 46,
1125             'index' => 125,
1126             'twoplus' => 26
1127             }
1128             },
1129             {#State 118
1130             DEFAULT => -31
1131             },
1132             {#State 119
1133             DEFAULT => -55
1134             },
1135             {#State 120
1136             DEFAULT => -59
1137             },
1138             {#State 121
1139             ACTIONS => {
1140             ")" => 126,
1141             "," => 110
1142             }
1143             },
1144             {#State 122
1145             DEFAULT => -57
1146             },
1147             {#State 123
1148             DEFAULT => -33
1149             },
1150             {#State 124
1151             DEFAULT => -35
1152             },
1153             {#State 125
1154             DEFAULT => -34
1155             },
1156             {#State 126
1157             DEFAULT => -56
1158             }
1159             ],
1160             yyrules =>
1161             [
1162             [#Rule 0
1163             '$start', 2, undef
1164             ],
1165             [#Rule 1
1166             'string', 1,
1167             sub
1168             #line 24 "lib/Chemistry/File/InChI/Parser.yp"
1169             { 'PREFIX' }
1170             ],
1171             [#Rule 2
1172             'string', 2,
1173             sub
1174             #line 26 "lib/Chemistry/File/InChI/Parser.yp"
1175             {
1176             my $layer1_id = first { $LAYER_ORDER[$_] eq $_[1] } 0..$#LAYER_ORDER;
1177             my $layer2_id = first { $LAYER_ORDER[$_] eq $_[2] } 0..$#LAYER_ORDER;
1178             die "unknown layer $_[2]\n" unless defined $layer2_id;
1179             die "duplicated layer $_[1]\n" if $layer1_id == $layer2_id;
1180             die "incorrect layer order, $_[2] must appear before $_[1]\n" if $layer1_id > $layer2_id;
1181             $_[2];
1182             }
1183             ],
1184             [#Rule 3
1185             'layer', 1,
1186             sub
1187             #line 37 "lib/Chemistry/File/InChI/Parser.yp"
1188             { 'FORMULA' }
1189             ],
1190             [#Rule 4
1191             'layer', 1,
1192             sub
1193             #line 39 "lib/Chemistry/File/InChI/Parser.yp"
1194             { 'CONNECTIONS' }
1195             ],
1196             [#Rule 5
1197             'layer', 1,
1198             sub
1199             #line 41 "lib/Chemistry/File/InChI/Parser.yp"
1200             { 'H_ATOMS' }
1201             ],
1202             [#Rule 6
1203             'layer', 1,
1204             sub
1205             #line 43 "lib/Chemistry/File/InChI/Parser.yp"
1206             { 'CHARGE' }
1207             ],
1208             [#Rule 7
1209             'layer', 1,
1210             sub
1211             #line 45 "lib/Chemistry/File/InChI/Parser.yp"
1212             { 'TETRAHEDRAL' }
1213             ],
1214             [#Rule 8
1215             'layer', 1,
1216             sub
1217             #line 47 "lib/Chemistry/File/InChI/Parser.yp"
1218             { 'STEREOCHEMISTRY' }
1219             ],
1220             [#Rule 9
1221             'formula', 1,
1222             sub
1223             #line 51 "lib/Chemistry/File/InChI/Parser.yp"
1224             { [ $_[1] ] }
1225             ],
1226             [#Rule 10
1227             'formula', 2,
1228             sub
1229             #line 53 "lib/Chemistry/File/InChI/Parser.yp"
1230             { push @{$_[1]}, $_[2] }
1231             ],
1232             [#Rule 11
1233             'connections', 2,
1234             sub
1235             #line 57 "lib/Chemistry/File/InChI/Parser.yp"
1236             { $_[0]->{USER}{CURSOR}++ }
1237             ],
1238             [#Rule 12
1239             'connections', 3,
1240             sub
1241             #line 59 "lib/Chemistry/File/InChI/Parser.yp"
1242             { $_[0]->{USER}{CURSOR}++ }
1243             ],
1244             [#Rule 13
1245             'connections', 2,
1246             sub
1247             #line 61 "lib/Chemistry/File/InChI/Parser.yp"
1248             { $_[0]->{USER}{CURSOR}++ }
1249             ],
1250             [#Rule 14
1251             'connections', 3,
1252             sub
1253             #line 63 "lib/Chemistry/File/InChI/Parser.yp"
1254             { $_[0]->{USER}{CURSOR}++ }
1255             ],
1256             [#Rule 15
1257             'h_atoms', 2,
1258             sub
1259             #line 67 "lib/Chemistry/File/InChI/Parser.yp"
1260             { $_[0]->{USER}{CURSOR}++ }
1261             ],
1262             [#Rule 16
1263             'h_atoms', 3,
1264             sub
1265             #line 69 "lib/Chemistry/File/InChI/Parser.yp"
1266             { $_[0]->{USER}{CURSOR}++ }
1267             ],
1268             [#Rule 17
1269             'h_atoms', 2,
1270             sub
1271             #line 71 "lib/Chemistry/File/InChI/Parser.yp"
1272             { $_[0]->{USER}{CURSOR}++ }
1273             ],
1274             [#Rule 18
1275             'h_atoms', 3,
1276             sub
1277             #line 73 "lib/Chemistry/File/InChI/Parser.yp"
1278             { $_[0]->{USER}{CURSOR}++ }
1279             ],
1280             [#Rule 19
1281             'tetrahedral', 2, undef
1282             ],
1283             [#Rule 20
1284             'tetrahedral', 3, undef
1285             ],
1286             [#Rule 21
1287             'tetrahedral', 2, undef
1288             ],
1289             [#Rule 22
1290             'tetrahedral', 3, undef
1291             ],
1292             [#Rule 23
1293             'stereochemistry', 3,
1294             sub
1295             #line 83 "lib/Chemistry/File/InChI/Parser.yp"
1296             { $_[0]->{USER}{MOL}->attr( 'inchi/stereochemistry', $_[3] ) }
1297             ],
1298             [#Rule 24
1299             'stereochemistry', 3,
1300             sub
1301             #line 85 "lib/Chemistry/File/InChI/Parser.yp"
1302             { $_[0]->{USER}{MOL}->attr( 'inchi/stereochemistry', $_[3] ) }
1303             ],
1304             [#Rule 25
1305             'graph', 1, undef
1306             ],
1307             [#Rule 26
1308             'graph', 3, undef
1309             ],
1310             [#Rule 27
1311             'chain', 3,
1312             sub
1313             #line 96 "lib/Chemistry/File/InChI/Parser.yp"
1314             { $_[0]->_add_bonds( $_[1], $_[3] ); return $_[3] }
1315             ],
1316             [#Rule 28
1317             'chain', 3,
1318             sub
1319             #line 98 "lib/Chemistry/File/InChI/Parser.yp"
1320             { $_[0]->_add_bonds( $_[1], [ @{$_[2]}, $_[3] ] ); return $_[3] }
1321             ],
1322             [#Rule 29
1323             'chain', 3,
1324             sub
1325             #line 100 "lib/Chemistry/File/InChI/Parser.yp"
1326             { $_[0]->_add_bonds( $_[1], $_[3] ); return $_[3] }
1327             ],
1328             [#Rule 30
1329             'chain', 3,
1330             sub
1331             #line 102 "lib/Chemistry/File/InChI/Parser.yp"
1332             { $_[0]->_add_bonds( $_[1], [ @{$_[2]}, $_[3] ] ); return $_[3] }
1333             ],
1334             [#Rule 31
1335             'branch', 3,
1336             sub
1337             #line 105 "lib/Chemistry/File/InChI/Parser.yp"
1338             { $_[2]->{bonds} }
1339             ],
1340             [#Rule 32
1341             'branch_body', 1,
1342             sub
1343             #line 109 "lib/Chemistry/File/InChI/Parser.yp"
1344             { { bonds => [ $_[1] ], last => $_[1] } }
1345             ],
1346             [#Rule 33
1347             'branch_body', 3,
1348             sub
1349             #line 111 "lib/Chemistry/File/InChI/Parser.yp"
1350             {
1351             push @{$_[1]->{bonds}}, $_[3];
1352             $_[1]->{last} = $_[3];
1353             return $_[1];
1354             }
1355             ],
1356             [#Rule 34
1357             'branch_body', 3,
1358             sub
1359             #line 117 "lib/Chemistry/File/InChI/Parser.yp"
1360             {
1361             $_[0]->_add_bonds( $_[1]->{last}, $_[3] );
1362             $_[1]->{last} = $_[3];
1363             return $_[1];
1364             }
1365             ],
1366             [#Rule 35
1367             'branch_body', 3,
1368             sub
1369             #line 123 "lib/Chemistry/File/InChI/Parser.yp"
1370             {
1371             $_[0]->_add_bonds( $_[1]->{last}, [ @{$_[2]}, $_[3] ] );
1372             $_[1]->{last} = $_[3];
1373             return $_[1];
1374             }
1375             ],
1376             [#Rule 36
1377             'branches', 1,
1378             sub
1379             #line 131 "lib/Chemistry/File/InChI/Parser.yp"
1380             { $_[1] }
1381             ],
1382             [#Rule 37
1383             'branches', 2,
1384             sub
1385             #line 133 "lib/Chemistry/File/InChI/Parser.yp"
1386             { [ @{$_[1]}, @{$_[2]} ] }
1387             ],
1388             [#Rule 38
1389             'hydrogens', 1, undef
1390             ],
1391             [#Rule 39
1392             'hydrogens', 2, undef
1393             ],
1394             [#Rule 40
1395             'hydrogens', 3, undef
1396             ],
1397             [#Rule 41
1398             'hydrogens', 4, undef
1399             ],
1400             [#Rule 42
1401             'hydrogens', 1, undef
1402             ],
1403             [#Rule 43
1404             'vh_count', 1, undef
1405             ],
1406             [#Rule 44
1407             'vh_count', 3, undef
1408             ],
1409             [#Rule 45
1410             'mh_count', 1, undef
1411             ],
1412             [#Rule 46
1413             'mh_count', 2, undef
1414             ],
1415             [#Rule 47
1416             'mh_counts', 2, undef
1417             ],
1418             [#Rule 48
1419             'mh_counts', 3, undef
1420             ],
1421             [#Rule 49
1422             'virtual_hydrogens', 2,
1423             sub
1424             #line 156 "lib/Chemistry/File/InChI/Parser.yp"
1425             { $_[0]->_add_hydrogens( $_[1] ) }
1426             ],
1427             [#Rule 50
1428             'virtual_hydrogens', 3,
1429             sub
1430             #line 158 "lib/Chemistry/File/InChI/Parser.yp"
1431             { $_[0]->_add_hydrogens( $_[1], $_[3] ) }
1432             ],
1433             [#Rule 51
1434             'virtual_hydrogen_receivers', 1,
1435             sub
1436             #line 162 "lib/Chemistry/File/InChI/Parser.yp"
1437             { [ $_[1] ] }
1438             ],
1439             [#Rule 52
1440             'virtual_hydrogen_receivers', 3,
1441             sub
1442             #line 164 "lib/Chemistry/File/InChI/Parser.yp"
1443             {
1444             push @{$_[1]}, $_[3];
1445             return $_[1];
1446             }
1447             ],
1448             [#Rule 53
1449             'virtual_hydrogen_receivers', 3,
1450             sub
1451             #line 169 "lib/Chemistry/File/InChI/Parser.yp"
1452             {
1453             push @{$_[1]}, ($_[1]->[-1] + 1)..$_[3];
1454             return $_[1]
1455             }
1456             ],
1457             [#Rule 54
1458             'mobile_hydrogens', 4, undef
1459             ],
1460             [#Rule 55
1461             'mobile_hydrogens', 5, undef
1462             ],
1463             [#Rule 56
1464             'mobile_hydrogens', 6, undef
1465             ],
1466             [#Rule 57
1467             'mobile_hydrogens', 5, undef
1468             ],
1469             [#Rule 58
1470             'comma_separated_indexes', 2,
1471             sub
1472             #line 182 "lib/Chemistry/File/InChI/Parser.yp"
1473             { [ $_[2] ] }
1474             ],
1475             [#Rule 59
1476             'comma_separated_indexes', 3,
1477             sub
1478             #line 184 "lib/Chemistry/File/InChI/Parser.yp"
1479             {
1480             push @{$_[1]}, $_[3];
1481             return $_[1];
1482             }
1483             ],
1484             [#Rule 60
1485             'tetrahedral_center', 2,
1486             sub
1487             #line 191 "lib/Chemistry/File/InChI/Parser.yp"
1488             { $_[0]->_get_atom( $_[1] )->attr( 'inchi/chirality', $_[2] ) }
1489             ],
1490             [#Rule 61
1491             'tetrahedral_center', 2,
1492             sub
1493             #line 193 "lib/Chemistry/File/InChI/Parser.yp"
1494             { $_[0]->_get_atom( $_[1] )->attr( 'inchi/chirality', $_[2] ) }
1495             ],
1496             [#Rule 62
1497             'tetrahedral_center', 2, undef
1498             ],
1499             [#Rule 63
1500             'tetrahedral_centers', 1, undef
1501             ],
1502             [#Rule 64
1503             'tetrahedral_centers', 3, undef
1504             ],
1505             [#Rule 65
1506             'charge', 2,
1507             sub
1508             #line 202 "lib/Chemistry/File/InChI/Parser.yp"
1509             { $_[0]->{USER}{MOL}->attr( 'inchi/charges', [] ) }
1510             ],
1511             [#Rule 66
1512             'charge', 3,
1513             sub
1514             #line 204 "lib/Chemistry/File/InChI/Parser.yp"
1515             { $_[0]->{USER}{MOL}->attr( 'inchi/charges' )->[$_[0]->{USER}{CURSOR}] = int( $_[3] ) }
1516             ],
1517             [#Rule 67
1518             'charge', 3,
1519             sub
1520             #line 206 "lib/Chemistry/File/InChI/Parser.yp"
1521             { $_[0]->{USER}{MOL}->attr( 'inchi/charges' )->[$_[0]->{USER}{CURSOR}] = int( -$_[3] ) }
1522             ],
1523             [#Rule 68
1524             'charge', 2,
1525             sub
1526             #line 208 "lib/Chemistry/File/InChI/Parser.yp"
1527             { $_[0]->{USER}{CURSOR}++ }
1528             ],
1529             [#Rule 69
1530             'index', 1, undef
1531             ],
1532             [#Rule 70
1533             'index', 1, undef
1534             ],
1535             [#Rule 71
1536             'count', 2,
1537             sub
1538             #line 214 "lib/Chemistry/File/InChI/Parser.yp"
1539             { join '', @_[1..2] }
1540             ],
1541             [#Rule 72
1542             'count', 2,
1543             sub
1544             #line 216 "lib/Chemistry/File/InChI/Parser.yp"
1545             { join '', @_[1..2] }
1546             ],
1547             [#Rule 73
1548             'count', 1, undef
1549             ],
1550             [#Rule 74
1551             'natural', 1, undef
1552             ],
1553             [#Rule 75
1554             'natural', 1, undef
1555             ],
1556             [#Rule 76
1557             'natural', 2,
1558             sub
1559             #line 223 "lib/Chemistry/File/InChI/Parser.yp"
1560             { join '', @_[1..2] }
1561             ],
1562             [#Rule 77
1563             'digit', 1, undef
1564             ],
1565             [#Rule 78
1566             'digit', 1, undef
1567             ],
1568             [#Rule 79
1569             'digit', 1, undef
1570             ],
1571             [#Rule 80
1572             'twoplus', 1, undef
1573             ],
1574             [#Rule 81
1575             'twoplus', 1, undef
1576             ],
1577             [#Rule 82
1578             'twoplus', 1, undef
1579             ],
1580             [#Rule 83
1581             'twoplus', 1, undef
1582             ],
1583             [#Rule 84
1584             'twoplus', 1, undef
1585             ],
1586             [#Rule 85
1587             'twoplus', 1, undef
1588             ],
1589             [#Rule 86
1590             'twoplus', 1, undef
1591             ],
1592             [#Rule 87
1593             'twoplus', 1, undef
1594             ]
1595             ],
1596             @_);
1597             bless($self,$class);
1598             }
1599              
1600             #line 230 "lib/Chemistry/File/InChI/Parser.yp"
1601              
1602              
1603             # Footer section
1604              
1605             sub parse
1606             {
1607             my( $self, $string ) = @_;
1608              
1609             $self->YYData->{INPUT} = $string;
1610             $self->{USER}{MOL} = Chemistry::Mol->new;
1611             $self->{USER}{CURSOR} = 0;
1612             $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error, yydebug => 0 );
1613              
1614             return $self->{USER}{MOL};
1615             }
1616              
1617             sub _Lexer
1618             {
1619             my( $self ) = @_;
1620              
1621             # If the line is empty and the input is originating from the file,
1622             # another line is read.
1623             if( !$self->YYData->{INPUT} && $self->{USER}{FILEIN} ) {
1624             my $filein = $self->{USER}{FILEIN};
1625             $self->YYData->{INPUT} = <$filein>;
1626             $self->{USER}{CHARNO} = 0;
1627             }
1628              
1629             # Prefix
1630             if( $self->YYData->{INPUT} =~ s/^(InChI=1S?)// ) {
1631             return ( 'prefix', $1 );
1632             }
1633              
1634             # Formula parts
1635             # TODO: Check Hill order, require counts > 1
1636             if( $self->YYData->{INPUT} =~ s/^([\/\.])([2-9]|[1-9][0-9]+)?(([A-Z][a-z]?\d*)+)// ) {
1637             my( $sep, $count, $formula ) = ( $1, $2, $3 );
1638             $count = 1 unless $count;
1639             my %atom_map;
1640              
1641             while( $formula =~ /([A-Z][a-z]?)(\d*)/g ) {
1642             my( $element, $count ) = ( $1, $2 );
1643             next if $element eq 'H'; # H atoms will be added later
1644             $count = 1 unless $count;
1645             for (1..$count) {
1646             my $atom = Chemistry::Atom->new( symbol => $element );
1647             $self->{USER}{MOL}->add_atom( $atom );
1648             $atom_map{scalar( keys %atom_map ) + 1} = $atom;
1649             }
1650             }
1651              
1652             if( $sep eq '/') {
1653             $self->{USER}{ATOM_MAPS} = [ \%atom_map ];
1654             $self->{USER}{MOL}->attr( 'inchi/counts', [ $count ] );
1655             return ( 'formula_first', $formula );
1656             } else {
1657             push @{$self->{USER}{ATOM_MAPS}}, \%atom_map;
1658             push @{$self->{USER}{MOL}->attr( 'inchi/counts' )}, $count;
1659             return ( 'formula_continuation', $formula );
1660             }
1661             }
1662              
1663             # Reset cursor on 'h', 'q' or 't'
1664             if( $self->YYData->{INPUT} =~ s/^([hqt])// ) {
1665             $self->{USER}{CURSOR} = 0;
1666             return ( $1, $1 );
1667             }
1668              
1669             # Remove unsupported layers
1670             $self->YYData->{INPUT} =~ s/^(\/[pbmsifo][^\/]*)+//;
1671              
1672             # Any other character
1673             if( $self->YYData->{INPUT} =~ s/^(.)// ) {
1674             return ( $1, $1 );
1675             }
1676              
1677             return ( '', '' );
1678             }
1679              
1680             sub _Error
1681             {
1682             my( $self ) = @_;
1683             die 'ERROR: ', $self->YYData->{INPUT}, "\n";
1684             }
1685              
1686             sub _add_bonds
1687             {
1688             my( $self, $a, $b ) = @_;
1689              
1690             my @bonds = ref $b eq 'ARRAY' ? @$b : $b;
1691             for (@bonds) {
1692             $self->{USER}{MOL}->new_bond( atoms => [ $self->_get_atom( $a ),
1693             $self->_get_atom( $_ ) ] );
1694             }
1695             }
1696              
1697             sub _add_hydrogens
1698             {
1699             my( $self, $atoms, $count ) = @_;
1700              
1701             my $atom_map = $self->{USER}{ATOM_MAPS}[$self->{USER}{CURSOR}];
1702             my @atoms = map { $atom_map->{$_} }
1703             ref $atoms ? @$atoms : ( $atoms );
1704             $count = 1 unless $count;
1705             for my $atom (@atoms) {
1706             for (1..$count) {
1707             my $H = Chemistry::Atom->new( symbol => 'H' );
1708             $self->{USER}{MOL}->add_atom( $H );
1709             $self->{USER}{MOL}->new_bond( atoms => [ $atom, $H ] );
1710             }
1711             }
1712             }
1713              
1714             sub _get_atom
1715             {
1716             my( $self, $atom ) = @_;
1717              
1718             my $atom_map = $self->{USER}{ATOM_MAPS}[$self->{USER}{CURSOR}];
1719              
1720             if( !exists $atom_map->{$atom} ) {
1721             # If an atom with given index does not exist, this is probably a hydrogen.
1722             # FIXME: Check if there are unused hydrogen atoms.
1723              
1724             my $H = Chemistry::Atom->new( symbol => 'H' );
1725             $self->{USER}{MOL}->add_atom( $H );
1726             $atom_map->{$atom} = $H;
1727             }
1728              
1729             return $atom_map->{$atom};
1730             }
1731              
1732             1;
1733              
1734             1;