blib/lib/Chemistry/File/InChI/Parser.pm

filter: Statementstmt 100% 10 / 10 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 13 / 13 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Chemistry/File/InChI.pm ↑ Summary
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 ▶use vars qw ( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 @ISA= qw ( Parse::Yapp::Driver );
15 3 ▶use Parse::Yapp::Driver;
Subroutine BEGIN: called CC=1 SCAR=0.0
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' => 2
43 },
44 GOTOS => {
45 'string' => 1
46 }
47 },
48 {#State 1
49 ACTIONS => {
50 "/" => 6,
51 '' => 12,
52 'formula_first' => 3
53 },
54 GOTOS => {
55 'connections' => 10,
56 'tetrahedral' => 9,
57 'h_atoms' => 8,
58 'layer' => 11,
59 'stereochemistry' => 7,
60 'charge' => 5,
61 'formula' => 4
62 }
63 },
64 {#State 2
65 DEFAULT => -1
66 },
67 {#State 3
68 DEFAULT => -9
69 },
70 {#State 4
71 ACTIONS => {
72 'formula_continuation' => 13
73 },
74 DEFAULT => -3
75 },
76 {#State 5
77 ACTIONS => {
78 ";" => 14,
79 "-" => 16,
80 "+" => 15
81 },
82 DEFAULT => -6
83 },
84 {#State 6
85 ACTIONS => {
86 "s" => 17,
87 "q" => 20,
88 "h" => 19,
89 "t" => 21,
90 "c" => 18
91 }
92 },
93 {#State 7
94 DEFAULT => -8
95 },
96 {#State 8
97 ACTIONS => {
98 ";" => 22
99 },
100 DEFAULT => -5
101 },
102 {#State 9
103 ACTIONS => {
104 ";" => 23
105 },
106 DEFAULT => -7
107 },
108 {#State 10
109 ACTIONS => {
110 ";" => 24
111 },
112 DEFAULT => -4
113 },
114 {#State 11
115 DEFAULT => -2
116 },
117 {#State 12
118 DEFAULT => 0
119 },
120 {#State 13
121 DEFAULT => -10
122 },
123 {#State 14
124 DEFAULT => -68
125 },
126 {#State 15
127 ACTIONS => {
128 "1" => 35,
129 "2" => 30,
130 "6" => 26,
131 "7" => 27,
132 "8" => 33,
133 "3" => 32,
134 "9" => 28,
135 "5" => 25,
136 "4" => 29
137 },
138 GOTOS => {
139 'natural' => 31,
140 'twoplus' => 34
141 }
142 },
143 {#State 16
144 ACTIONS => {
145 "2" => 30,
146 "7" => 27,
147 "6" => 26,
148 "3" => 32,
149 "9" => 28,
150 "8" => 33,
151 "1" => 35,
152 "4" => 29,
153 "5" => 25
154 },
155 GOTOS => {
156 'twoplus' => 34,
157 'natural' => 36
158 }
159 },
160 {#State 17
161 ACTIONS => {
162 "2" => 37,
163 "1" => 38
164 }
165 },
166 {#State 18
167 ACTIONS => {
168 "5" => 25,
169 "9" => 28,
170 "7" => 27,
171 "6" => 26,
172 "4" => 29,
173 "1" => 42,
174 "8" => 33,
175 "3" => 32,
176 "2" => 30
177 },
178 DEFAULT => -11,
179 GOTOS => {
180 'chain' => 39,
181 'index' => 44,
182 'twoplus' => 43,
183 'count' => 40,
184 'graph' => 41
185 }
186 },
187 {#State 19
188 ACTIONS => {
189 "9" => 28,
190 "6" => 26,
191 "7" => 27,
192 "5" => 25,
193 "1" => 42,
194 "3" => 32,
195 "8" => 33,
196 "2" => 30,
197 "(" => 47,
198 "4" => 29
199 },
200 DEFAULT => -15,
201 GOTOS => {
202 'vh_count' => 49,
203 'hydrogens' => 50,
204 'count' => 53,
205 'twoplus' => 43,
206 'index' => 48,
207 'mh_count' => 46,
208 'virtual_hydrogen_receivers' => 52,
209 'virtual_hydrogens' => 51,
210 'mobile_hydrogens' => 45
211 }
212 },
213 {#State 20
214 DEFAULT => -65
215 },
216 {#State 21
217 ACTIONS => {
218 "1" => 42,
219 "3" => 32,
220 "8" => 33,
221 "2" => 30,
222 "4" => 29,
223 "9" => 28,
224 "6" => 26,
225 "7" => 27,
226 "5" => 25
227 },
228 DEFAULT => -19,
229 GOTOS => {
230 'tetrahedral_center' => 56,
231 'count' => 55,
232 'index' => 54,
233 'twoplus' => 43,
234 'tetrahedral_centers' => 57
235 }
236 },
237 {#State 22
238 ACTIONS => {
239 "6" => 26,
240 "7" => 27,
241 "9" => 28,
242 "5" => 25,
243 "1" => 42,
244 "2" => 30,
245 "8" => 33,
246 "3" => 32,
247 "4" => 29,
248 "(" => 47
249 },
250 DEFAULT => -17,
251 GOTOS => {
252 'twoplus' => 43,
253 'count' => 53,
254 'index' => 48,
255 'hydrogens' => 58,
256 'vh_count' => 49,
257 'virtual_hydrogens' => 51,
258 'virtual_hydrogen_receivers' => 52,
259 'mobile_hydrogens' => 45,
260 'mh_count' => 46
261 }
262 },
263 {#State 23
264 ACTIONS => {
265 "5" => 25,
266 "9" => 28,
267 "6" => 26,
268 "7" => 27,
269 "4" => 29,
270 "1" => 42,
271 "8" => 33,
272 "3" => 32,
273 "2" => 30
274 },
275 DEFAULT => -21,
276 GOTOS => {
277 'tetrahedral_centers' => 59,
278 'twoplus' => 43,
279 'index' => 54,
280 'count' => 55,
281 'tetrahedral_center' => 56
282 }
283 },
284 {#State 24
285 ACTIONS => {
286 "5" => 25,
287 "9" => 28,
288 "7" => 27,
289 "6" => 26,
290 "4" => 29,
291 "8" => 33,
292 "3" => 32,
293 "2" => 30,
294 "1" => 42
295 },
296 DEFAULT => -13,
297 GOTOS => {
298 'chain' => 39,
299 'twoplus' => 43,
300 'count' => 40,
301 'index' => 44,
302 'graph' => 60
303 }
304 },
305 {#State 25
306 DEFAULT => -83
307 },
308 {#State 26
309 DEFAULT => -84
310 },
311 {#State 27
312 DEFAULT => -85
313 },
314 {#State 28
315 DEFAULT => -87
316 },
317 {#State 29
318 DEFAULT => -82
319 },
320 {#State 30
321 DEFAULT => -80
322 },
323 {#State 31
324 ACTIONS => {
325 "4" => 29,
326 "0" => 61,
327 "2" => 30,
328 "3" => 32,
329 "8" => 33,
330 "1" => 63,
331 "5" => 25,
332 "7" => 27,
333 "6" => 26,
334 "9" => 28
335 },
336 DEFAULT => -66,
337 GOTOS => {
338 'digit' => 64,
339 'twoplus' => 62
340 }
341 },
342 {#State 32
343 DEFAULT => -81
344 },
345 {#State 33
346 DEFAULT => -86
347 },
348 {#State 34
349 DEFAULT => -75
350 },
351 {#State 35
352 DEFAULT => -74
353 },
354 {#State 36
355 ACTIONS => {
356 "7" => 27,
357 "6" => 26,
358 "9" => 28,
359 "5" => 25,
360 "1" => 63,
361 "2" => 30,
362 "3" => 32,
363 "8" => 33,
364 "0" => 61,
365 "4" => 29
366 },
367 DEFAULT => -67,
368 GOTOS => {
369 'digit' => 64,
370 'twoplus' => 62
371 }
372 },
373 {#State 37
374 DEFAULT => -24
375 },
376 {#State 38
377 DEFAULT => -23
378 },
379 {#State 39
380 ACTIONS => {
381 "-" => 68,
382 "(" => 66
383 },
384 DEFAULT => -25,
385 GOTOS => {
386 'branches' => 67,
387 'branch' => 65
388 }
389 },
390 {#State 40
391 ACTIONS => {
392 "7" => 27,
393 "6" => 26,
394 "*" => 70,
395 "9" => 28,
396 "5" => 25,
397 "2" => 30,
398 "3" => 32,
399 "8" => 33,
400 "1" => 63,
401 "4" => 29,
402 "0" => 61
403 },
404 DEFAULT => -70,
405 GOTOS => {
406 'digit' => 69,
407 'twoplus' => 62
408 }
409 },
410 {#State 41
411 DEFAULT => -12
412 },
413 {#State 42
414 ACTIONS => {
415 "7" => 27,
416 "6" => 26,
417 "9" => 28,
418 "5" => 25,
419 "2" => 30,
420 "3" => 32,
421 "8" => 33,
422 "1" => 63,
423 "4" => 29,
424 "0" => 61
425 },
426 DEFAULT => -69,
427 GOTOS => {
428 'twoplus' => 62,
429 'digit' => 71
430 }
431 },
432 {#State 43
433 DEFAULT => -73
434 },
435 {#State 44
436 ACTIONS => {
437 "(" => 66,
438 "-" => 73
439 },
440 GOTOS => {
441 'branches' => 72,
442 'branch' => 65
443 }
444 },
445 {#State 45
446 DEFAULT => -45
447 },
448 {#State 46
449 ACTIONS => {
450 "(" => 47
451 },
452 DEFAULT => -42,
453 GOTOS => {
454 'mobile_hydrogens' => 74
455 }
456 },
457 {#State 47
458 ACTIONS => {
459 "H" => 75
460 }
461 },
462 {#State 48
463 DEFAULT => -51
464 },
465 {#State 49
466 ACTIONS => {
467 "," => 77
468 },
469 DEFAULT => -38,
470 GOTOS => {
471 'mh_counts' => 76
472 }
473 },
474 {#State 50
475 DEFAULT => -16
476 },
477 {#State 51
478 DEFAULT => -43
479 },
480 {#State 52
481 ACTIONS => {
482 "-" => 80,
483 "H" => 79,
484 "," => 78
485 }
486 },
487 {#State 53
488 ACTIONS => {
489 "*" => 81,
490 "6" => 26,
491 "7" => 27,
492 "9" => 28,
493 "5" => 25,
494 "1" => 63,
495 "2" => 30,
496 "8" => 33,
497 "3" => 32,
498 "0" => 61,
499 "4" => 29
500 },
501 DEFAULT => -70,
502 GOTOS => {
503 'digit' => 69,
504 'twoplus' => 62
505 }
506 },
507 {#State 54
508 ACTIONS => {
509 "?" => 82,
510 "-" => 84,
511 "+" => 83
512 }
513 },
514 {#State 55
515 ACTIONS => {
516 "1" => 63,
517 "2" => 30,
518 "3" => 32,
519 "8" => 33,
520 "0" => 61,
521 "4" => 29,
522 "6" => 26,
523 "7" => 27,
524 "9" => 28,
525 "5" => 25
526 },
527 DEFAULT => -70,
528 GOTOS => {
529 'digit' => 69,
530 'twoplus' => 62
531 }
532 },
533 {#State 56
534 DEFAULT => -63
535 },
536 {#State 57
537 ACTIONS => {
538 "," => 85
539 },
540 DEFAULT => -20
541 },
542 {#State 58
543 DEFAULT => -18
544 },
545 {#State 59
546 ACTIONS => {
547 "," => 85
548 },
549 DEFAULT => -22
550 },
551 {#State 60
552 DEFAULT => -14
553 },
554 {#State 61
555 DEFAULT => -77
556 },
557 {#State 62
558 DEFAULT => -79
559 },
560 {#State 63
561 DEFAULT => -78
562 },
563 {#State 64
564 DEFAULT => -76
565 },
566 {#State 65
567 DEFAULT => -36
568 },
569 {#State 66
570 ACTIONS => {
571 "3" => 32,
572 "9" => 28,
573 "8" => 33,
574 "6" => 26,
575 "7" => 27,
576 "2" => 30,
577 "1" => 42,
578 "4" => 29,
579 "5" => 25
580 },
581 GOTOS => {
582 'count' => 55,
583 'branch_body' => 87,
584 'twoplus' => 43,
585 'index' => 86
586 }
587 },
588 {#State 67
589 ACTIONS => {
590 "(" => 66,
591 "4" => 29,
592 "5" => 25,
593 "3" => 32,
594 "9" => 28,
595 "8" => 33,
596 "6" => 26,
597 "7" => 27,
598 "2" => 30,
599 "1" => 42
600 },
601 GOTOS => {
602 'twoplus' => 43,
603 'count' => 55,
604 'index' => 88,
605 'branch' => 89
606 }
607 },
608 {#State 68
609 ACTIONS => {
610 "1" => 42,
611 "7" => 27,
612 "6" => 26,
613 "2" => 30,
614 "8" => 33,
615 "9" => 28,
616 "3" => 32,
617 "5" => 25,
618 "4" => 29
619 },
620 GOTOS => {
621 'twoplus' => 43,
622 'count' => 55,
623 'index' => 90
624 }
625 },
626 {#State 69
627 DEFAULT => -72
628 },
629 {#State 70
630 ACTIONS => {
631 "4" => 29,
632 "5" => 25,
633 "7" => 27,
634 "6" => 26,
635 "2" => 30,
636 "3" => 32,
637 "9" => 28,
638 "8" => 33,
639 "1" => 42
640 },
641 GOTOS => {
642 'index' => 44,
643 'count' => 55,
644 'twoplus' => 43,
645 'chain' => 91
646 }
647 },
648 {#State 71
649 DEFAULT => -71
650 },
651 {#State 72
652 ACTIONS => {
653 "1" => 42,
654 "8" => 33,
655 "9" => 28,
656 "3" => 32,
657 "2" => 30,
658 "6" => 26,
659 "7" => 27,
660 "5" => 25,
661 "4" => 29,
662 "(" => 66
663 },
664 GOTOS => {
665 'branch' => 89,
666 'twoplus' => 43,
667 'count' => 55,
668 'index' => 92
669 }
670 },
671 {#State 73
672 ACTIONS => {
673 "1" => 42,
674 "3" => 32,
675 "9" => 28,
676 "8" => 33,
677 "6" => 26,
678 "7" => 27,
679 "2" => 30,
680 "5" => 25,
681 "4" => 29
682 },
683 GOTOS => {
684 'index' => 93,
685 'count' => 55,
686 'twoplus' => 43
687 }
688 },
689 {#State 74
690 DEFAULT => -46
691 },
692 {#State 75
693 ACTIONS => {
694 "3" => 32,
695 "8" => 33,
696 "-" => 95,
697 "2" => 30,
698 "1" => 97,
699 "4" => 29,
700 "," => 94,
701 "9" => 28,
702 "7" => 27,
703 "6" => 26,
704 "5" => 25
705 },
706 GOTOS => {
707 'comma_separated_indexes' => 96,
708 'count' => 98,
709 'twoplus' => 43
710 }
711 },
712 {#State 76
713 ACTIONS => {
714 "," => 99
715 },
716 DEFAULT => -39
717 },
718 {#State 77
719 ACTIONS => {
720 "(" => 47,
721 "4" => 29,
722 "5" => 25,
723 "8" => 33,
724 "9" => 28,
725 "3" => 32,
726 "7" => 27,
727 "6" => 26,
728 "2" => 30,
729 "1" => 42
730 },
731 GOTOS => {
732 'mh_count' => 101,
733 'virtual_hydrogen_receivers' => 52,
734 'virtual_hydrogens' => 100,
735 'mobile_hydrogens' => 45,
736 'twoplus' => 43,
737 'index' => 48,
738 'count' => 55
739 }
740 },
741 {#State 78
742 ACTIONS => {
743 "6" => 26,
744 "7" => 27,
745 "2" => 30,
746 "3" => 32,
747 "8" => 33,
748 "9" => 28,
749 "1" => 42,
750 "4" => 29,
751 "5" => 25
752 },
753 GOTOS => {
754 'count' => 55,
755 'index' => 102,
756 'twoplus' => 43
757 }
758 },
759 {#State 79
760 ACTIONS => {
761 "4" => 29,
762 "1" => 97,
763 "2" => 30,
764 "3" => 32,
765 "8" => 33,
766 "5" => 25,
767 "6" => 26,
768 "7" => 27,
769 "9" => 28
770 },
771 DEFAULT => -49,
772 GOTOS => {
773 'twoplus' => 43,
774 'count' => 103
775 }
776 },
777 {#State 80
778 ACTIONS => {
779 "9" => 28,
780 "3" => 32,
781 "8" => 33,
782 "2" => 30,
783 "7" => 27,
784 "6" => 26,
785 "1" => 42,
786 "4" => 29,
787 "5" => 25
788 },
789 GOTOS => {
790 'index' => 104,
791 'count' => 55,
792 'twoplus' => 43
793 }
794 },
795 {#State 81
796 ACTIONS => {
797 "6" => 26,
798 "7" => 27,
799 "2" => 30,
800 "9" => 28,
801 "3" => 32,
802 "8" => 33,
803 "1" => 42,
804 "4" => 29,
805 "5" => 25
806 },
807 GOTOS => {
808 'vh_count' => 105,
809 'count' => 55,
810 'index' => 48,
811 'twoplus' => 43,
812 'virtual_hydrogens' => 51,
813 'virtual_hydrogen_receivers' => 52
814 }
815 },
816 {#State 82
817 DEFAULT => -62
818 },
819 {#State 83
820 DEFAULT => -60
821 },
822 {#State 84
823 DEFAULT => -61
824 },
825 {#State 85
826 ACTIONS => {
827 "5" => 25,
828 "4" => 29,
829 "1" => 42,
830 "3" => 32,
831 "9" => 28,
832 "8" => 33,
833 "2" => 30,
834 "6" => 26,
835 "7" => 27
836 },
837 GOTOS => {
838 'tetrahedral_center' => 106,
839 'count' => 55,
840 'index' => 54,
841 'twoplus' => 43
842 }
843 },
844 {#State 86
845 DEFAULT => -32
846 },
847 {#State 87
848 ACTIONS => {
849 ")" => 108,
850 "-" => 107,
851 "(" => 66,
852 "," => 110
853 },
854 GOTOS => {
855 'branches' => 109,
856 'branch' => 65
857 }
858 },
859 {#State 88
860 DEFAULT => -30
861 },
862 {#State 89
863 DEFAULT => -37
864 },
865 {#State 90
866 DEFAULT => -29
867 },
868 {#State 91
869 ACTIONS => {
870 "(" => 66,
871 "-" => 68
872 },
873 DEFAULT => -26,
874 GOTOS => {
875 'branches' => 67,
876 'branch' => 65
877 }
878 },
879 {#State 92
880 DEFAULT => -28
881 },
882 {#State 93
883 DEFAULT => -27
884 },
885 {#State 94
886 ACTIONS => {
887 "5" => 25,
888 "4" => 29,
889 "1" => 42,
890 "2" => 30,
891 "6" => 26,
892 "7" => 27,
893 "9" => 28,
894 "3" => 32,
895 "8" => 33
896 },
897 GOTOS => {
898 'twoplus' => 43,
899 'count' => 55,
900 'index' => 111
901 }
902 },
903 {#State 95
904 ACTIONS => {
905 "," => 94
906 },
907 GOTOS => {
908 'comma_separated_indexes' => 112
909 }
910 },
911 {#State 96
912 ACTIONS => {
913 ")" => 114,
914 "," => 113
915 }
916 },
917 {#State 97
918 ACTIONS => {
919 "1" => 63,
920 "2" => 30,
921 "6" => 26,
922 "7" => 27,
923 "3" => 32,
924 "8" => 33,
925 "9" => 28,
926 "0" => 61,
927 "5" => 25,
928 "4" => 29
929 },
930 GOTOS => {
931 'twoplus' => 62,
932 'digit' => 71
933 }
934 },
935 {#State 98
936 ACTIONS => {
937 "," => 94,
938 "0" => 61,
939 "4" => 29,
940 "1" => 63,
941 "-" => 115,
942 "2" => 30,
943 "8" => 33,
944 "3" => 32,
945 "5" => 25,
946 "6" => 26,
947 "7" => 27,
948 "9" => 28
949 },
950 GOTOS => {
951 'twoplus' => 62,
952 'digit' => 69,
953 'comma_separated_indexes' => 116
954 }
955 },
956 {#State 99
957 ACTIONS => {
958 "(" => 47
959 },
960 GOTOS => {
961 'mh_count' => 117,
962 'mobile_hydrogens' => 45
963 }
964 },
965 {#State 100
966 DEFAULT => -44
967 },
968 {#State 101
969 ACTIONS => {
970 "(" => 47
971 },
972 DEFAULT => -47,
973 GOTOS => {
974 'mobile_hydrogens' => 74
975 }
976 },
977 {#State 102
978 DEFAULT => -52
979 },
980 {#State 103
981 ACTIONS => {
982 "0" => 61,
983 "4" => 29,
984 "1" => 63,
985 "8" => 33,
986 "3" => 32,
987 "2" => 30,
988 "5" => 25,
989 "9" => 28,
990 "6" => 26,
991 "7" => 27
992 },
993 DEFAULT => -50,
994 GOTOS => {
995 'digit' => 69,
996 'twoplus' => 62
997 }
998 },
999 {#State 104
1000 DEFAULT => -53
1001 },
1002 {#State 105
1003 ACTIONS => {
1004 "," => 77
1005 },
1006 DEFAULT => -40,
1007 GOTOS => {
1008 'mh_counts' => 118
1009 }
1010 },
1011 {#State 106
1012 DEFAULT => -64
1013 },
1014 {#State 107
1015 ACTIONS => {
1016 "2" => 30,
1017 "7" => 27,
1018 "6" => 26,
1019 "8" => 33,
1020 "9" => 28,
1021 "3" => 32,
1022 "1" => 42,
1023 "4" => 29,
1024 "5" => 25
1025 },
1026 GOTOS => {
1027 'count' => 55,
1028 'twoplus' => 43,
1029 'index' => 119
1030 }
1031 },
1032 {#State 108
1033 DEFAULT => -31
1034 },
1035 {#State 109
1036 ACTIONS => {
1037 "5" => 25,
1038 "(" => 66,
1039 "4" => 29,
1040 "1" => 42,
1041 "9" => 28,
1042 "8" => 33,
1043 "3" => 32,
1044 "6" => 26,
1045 "7" => 27,
1046 "2" => 30
1047 },
1048 GOTOS => {
1049 'branch' => 89,
1050 'index' => 120,
1051 'count' => 55,
1052 'twoplus' => 43
1053 }
1054 },
1055 {#State 110
1056 ACTIONS => {
1057 "4" => 29,
1058 "5" => 25,
1059 "7" => 27,
1060 "6" => 26,
1061 "2" => 30,
1062 "9" => 28,
1063 "3" => 32,
1064 "8" => 33,
1065 "1" => 42
1066 },
1067 GOTOS => {
1068 'twoplus' => 43,
1069 'index' => 121,
1070 'count' => 55
1071 }
1072 },
1073 {#State 111
1074 DEFAULT => -58
1075 },
1076 {#State 112
1077 ACTIONS => {
1078 ")" => 122,
1079 "," => 113
1080 }
1081 },
1082 {#State 113
1083 ACTIONS => {
1084 "4" => 29,
1085 "5" => 25,
1086 "3" => 32,
1087 "8" => 33,
1088 "9" => 28,
1089 "6" => 26,
1090 "7" => 27,
1091 "2" => 30,
1092 "1" => 42
1093 },
1094 GOTOS => {
1095 'count' => 55,
1096 'twoplus' => 43,
1097 'index' => 123
1098 }
1099 },
1100 {#State 114
1101 DEFAULT => -54
1102 },
1103 {#State 115
1104 ACTIONS => {
1105 "," => 94
1106 },
1107 GOTOS => {
1108 'comma_separated_indexes' => 124
1109 }
1110 },
1111 {#State 116
1112 ACTIONS => {
1113 ")" => 125,
1114 "," => 113
1115 }
1116 },
1117 {#State 117
1118 ACTIONS => {
1119 "(" => 47
1120 },
1121 DEFAULT => -48,
1122 GOTOS => {
1123 'mobile_hydrogens' => 74
1124 }
1125 },
1126 {#State 118
1127 ACTIONS => {
1128 "," => 99
1129 },
1130 DEFAULT => -41
1131 },
1132 {#State 119
1133 DEFAULT => -34
1134 },
1135 {#State 120
1136 DEFAULT => -35
1137 },
1138 {#State 121
1139 DEFAULT => -33
1140 },
1141 {#State 122
1142 DEFAULT => -55
1143 },
1144 {#State 123
1145 DEFAULT => -59
1146 },
1147 {#State 124
1148 ACTIONS => {
1149 ")" => 126,
1150 "," => 113
1151 }
1152 },
1153 {#State 125
1154 DEFAULT => -57
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;
« blib/lib/Chemistry/File/InChI.pm ↑ Summary