github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/chem/element/element.go (about)

     1  package element
     2  
     3  type Element byte
     4  
     5  const (
     6  	Invalid = Element(0)
     7  	Ac      = Element(1)
     8  	Ag      = Element(2)
     9  	Al      = Element(3)
    10  	Am      = Element(4)
    11  	Ar      = Element(5)
    12  	As      = Element(6)
    13  	At      = Element(7)
    14  	Au      = Element(8)
    15  	B       = Element(9)
    16  	Ba      = Element(10)
    17  	Be      = Element(11)
    18  	Bh      = Element(12)
    19  	Bi      = Element(13)
    20  	Bk      = Element(14)
    21  	Br      = Element(15)
    22  	C       = Element(16)
    23  	Ca      = Element(17)
    24  	Cd      = Element(18)
    25  	Ce      = Element(19)
    26  	Cf      = Element(20)
    27  	Cl      = Element(21)
    28  	Cm      = Element(22)
    29  	Co      = Element(23)
    30  	Cr      = Element(24)
    31  	Cs      = Element(25)
    32  	Cu      = Element(26)
    33  	Db      = Element(27)
    34  	Ds      = Element(28)
    35  	Dy      = Element(29)
    36  	Er      = Element(30)
    37  	Es      = Element(31)
    38  	Eu      = Element(32)
    39  	F       = Element(33)
    40  	Fe      = Element(34)
    41  	Fm      = Element(35)
    42  	Fr      = Element(36)
    43  	Ga      = Element(37)
    44  	Gd      = Element(38)
    45  	Ge      = Element(39)
    46  	H       = Element(40)
    47  	He      = Element(41)
    48  	Hf      = Element(42)
    49  	Hg      = Element(43)
    50  	Ho      = Element(44)
    51  	Hs      = Element(45)
    52  	I       = Element(46)
    53  	In      = Element(47)
    54  	Ir      = Element(48)
    55  	K       = Element(49)
    56  	Kr      = Element(50)
    57  	La      = Element(51)
    58  	Li      = Element(52)
    59  	Lr      = Element(53)
    60  	Lu      = Element(54)
    61  	Md      = Element(55)
    62  	Mg      = Element(56)
    63  	Mn      = Element(57)
    64  	Mo      = Element(58)
    65  	Mt      = Element(59)
    66  	N       = Element(60)
    67  	Na      = Element(61)
    68  	Nb      = Element(62)
    69  	Nd      = Element(63)
    70  	Ne      = Element(64)
    71  	Ni      = Element(65)
    72  	No      = Element(66)
    73  	Np      = Element(67)
    74  	O       = Element(68)
    75  	Os      = Element(69)
    76  	P       = Element(70)
    77  	Pa      = Element(71)
    78  	Pb      = Element(72)
    79  	Pd      = Element(73)
    80  	Pm      = Element(74)
    81  	Po      = Element(75)
    82  	Pr      = Element(76)
    83  	Pt      = Element(77)
    84  	Pu      = Element(78)
    85  	Ra      = Element(79)
    86  	Rb      = Element(80)
    87  	Re      = Element(81)
    88  	Rf      = Element(82)
    89  	Rg      = Element(83)
    90  	Rh      = Element(84)
    91  	Rn      = Element(85)
    92  	Ru      = Element(86)
    93  	S       = Element(87)
    94  	Sb      = Element(88)
    95  	Sc      = Element(89)
    96  	Se      = Element(90)
    97  	Sg      = Element(91)
    98  	Si      = Element(92)
    99  	Sm      = Element(93)
   100  	Sn      = Element(94)
   101  	Sr      = Element(95)
   102  	Ta      = Element(96)
   103  	Tb      = Element(97)
   104  	Tc      = Element(98)
   105  	Te      = Element(99)
   106  	Th      = Element(100)
   107  	Ti      = Element(101)
   108  	Tl      = Element(102)
   109  	Tm      = Element(103)
   110  	U       = Element(104)
   111  	Uub     = Element(105)
   112  	Uuh     = Element(106)
   113  	Uuo     = Element(107)
   114  	Uup     = Element(108)
   115  	Uuq     = Element(109)
   116  	Uus     = Element(110)
   117  	Uut     = Element(111)
   118  	V       = Element(112)
   119  	W       = Element(113)
   120  	Xe      = Element(114)
   121  	Y       = Element(115)
   122  	Yb      = Element(116)
   123  	Zn      = Element(117)
   124  	Zr      = Element(118)
   125  )
   126  
   127  var AtomSymbol = [...]string{"<INVALID>",
   128  	"Ac", "Ag", "Al", "Am", "Ar", "As", "At", "Au", "B", "Ba",
   129  	"Be", "Bh", "Bi", "Bk", "Br", "C", "Ca", "Cd", "Ce", "Cf",
   130  	"Cl", "Cm", "Co", "Cr", "Cs", "Cu", "Db", "Ds", "Dy", "Er",
   131  	"Es", "Eu", "F", "Fe", "Fm", "Fr", "Ga", "Gd", "Ge", "H",
   132  	"He", "Hf", "Hg", "Ho", "Hs", "I", "In", "Ir", "K", "Kr",
   133  	"La", "Li", "Lr", "Lu", "Md", "Mg", "Mn", "Mo", "Mt", "N",
   134  	"Na", "Nb", "Nd", "Ne", "Ni", "No", "Np", "O", "Os", "P",
   135  	"Pa", "Pb", "Pd", "Pm", "Po", "Pr", "Pt", "Pu", "Ra", "Rb",
   136  	"Re", "Rf", "Rg", "Rh", "Rn", "Ru", "S", "Sb", "Sc", "Se",
   137  	"Sg", "Si", "Sm", "Sn", "Sr", "Ta", "Tb", "Tc", "Te", "Th",
   138  	"Ti", "Tl", "Tm", "U", "Uub", "Uuh", "Uuo", "Uup", "Uuq", "Uus",
   139  	"Uut", "V", "W", "Xe", "Y", "Yb", "Zn", "Zr",
   140  }
   141  
   142  func (e Element) String() string {
   143  	return AtomSymbol[int(e)]
   144  }
   145  
   146  func (m *Matcher) acceptElement(p, t byte) {
   147  	p0, p1, p2 := m.src[p], m.src[p+1], m.src[p+2]
   148  	switch p0 {
   149  	case 'a':
   150  		switch p1 {
   151  		case 'c':
   152  			m.accepted(Ac, p+2, t)
   153  		case 'g':
   154  			m.accepted(Ag, p+2, t)
   155  		case 'l':
   156  			m.accepted(Al, p+2, t)
   157  		case 'm':
   158  			m.accepted(Am, p+2, t)
   159  		case 'r':
   160  			m.accepted(Ar, p+2, t)
   161  		case 's':
   162  			m.accepted(As, p+2, t)
   163  		case 't':
   164  			m.accepted(At, p+2, t)
   165  		case 'u':
   166  			m.accepted(Au, p+2, t)
   167  		}
   168  	case 'b':
   169  		switch p1 {
   170  		case 'a':
   171  			m.accepted(Ba, p+2, t)
   172  		case 'e':
   173  			m.accepted(Be, p+2, t)
   174  		case 'h':
   175  			m.accepted(Bh, p+2, t)
   176  		case 'i':
   177  			m.accepted(Bi, p+2, t)
   178  		case 'k':
   179  			m.accepted(Bk, p+2, t)
   180  		case 'r':
   181  			m.accepted(Br, p+2, t)
   182  		}
   183  		m.accepted(B, p+1, t)
   184  	case 'c':
   185  		switch p1 {
   186  		case 'a':
   187  			m.accepted(Ca, p+2, t)
   188  		case 'd':
   189  			m.accepted(Cd, p+2, t)
   190  		case 'e':
   191  			m.accepted(Ce, p+2, t)
   192  		case 'f':
   193  			m.accepted(Cf, p+2, t)
   194  		case 'l':
   195  			m.accepted(Cl, p+2, t)
   196  		case 'm':
   197  			m.accepted(Cm, p+2, t)
   198  		case 'o':
   199  			m.accepted(Co, p+2, t)
   200  		case 'r':
   201  			m.accepted(Cr, p+2, t)
   202  		case 's':
   203  			m.accepted(Cs, p+2, t)
   204  		case 'u':
   205  			m.accepted(Cu, p+2, t)
   206  		}
   207  		m.accepted(C, p+1, t)
   208  	case 'd':
   209  		switch p1 {
   210  		case 'b':
   211  			m.accepted(Db, p+2, t)
   212  		case 's':
   213  			m.accepted(Ds, p+2, t)
   214  		case 'y':
   215  			m.accepted(Dy, p+2, t)
   216  		}
   217  	case 'e':
   218  		switch p1 {
   219  		case 'r':
   220  			m.accepted(Er, p+2, t)
   221  		case 's':
   222  			m.accepted(Es, p+2, t)
   223  		case 'u':
   224  			m.accepted(Eu, p+2, t)
   225  		}
   226  	case 'f':
   227  		switch p1 {
   228  		case 'e':
   229  			m.accepted(Fe, p+2, t)
   230  		case 'm':
   231  			m.accepted(Fm, p+2, t)
   232  		case 'r':
   233  			m.accepted(Fr, p+2, t)
   234  		}
   235  		m.accepted(F, p+1, t)
   236  	case 'g':
   237  		switch p1 {
   238  		case 'a':
   239  			m.accepted(Ga, p+2, t)
   240  		case 'd':
   241  			m.accepted(Gd, p+2, t)
   242  		case 'e':
   243  			m.accepted(Ge, p+2, t)
   244  		}
   245  	case 'h':
   246  		switch p1 {
   247  		case 'e':
   248  			m.accepted(He, p+2, t)
   249  		case 'f':
   250  			m.accepted(Hf, p+2, t)
   251  		case 'g':
   252  			m.accepted(Hg, p+2, t)
   253  		case 'o':
   254  			m.accepted(Ho, p+2, t)
   255  		case 's':
   256  			m.accepted(Hs, p+2, t)
   257  		}
   258  		m.accepted(H, p+1, t)
   259  	case 'i':
   260  		switch p1 {
   261  		case 'n':
   262  			m.accepted(In, p+2, t)
   263  		case 'r':
   264  			m.accepted(Ir, p+2, t)
   265  		}
   266  		m.accepted(I, p+1, t)
   267  	case 'k':
   268  		if p1 == 'r' {
   269  			m.accepted(Kr, p+2, t)
   270  		}
   271  		m.accepted(K, p+1, t)
   272  	case 'l':
   273  		switch p1 {
   274  		case 'a':
   275  			m.accepted(La, p+2, t)
   276  		case 'i':
   277  			m.accepted(Li, p+2, t)
   278  		case 'r':
   279  			m.accepted(Lr, p+2, t)
   280  		case 'u':
   281  			m.accepted(Lu, p+2, t)
   282  		}
   283  	case 'm':
   284  		switch p1 {
   285  		case 'd':
   286  			m.accepted(Md, p+2, t)
   287  		case 'g':
   288  			m.accepted(Mg, p+2, t)
   289  		case 'n':
   290  			m.accepted(Mn, p+2, t)
   291  		case 'o':
   292  			m.accepted(Mo, p+2, t)
   293  		case 't':
   294  			m.accepted(Mt, p+2, t)
   295  		}
   296  	case 'n':
   297  		switch p1 {
   298  		case 'a':
   299  			m.accepted(Na, p+2, t)
   300  		case 'b':
   301  			m.accepted(Nb, p+2, t)
   302  		case 'd':
   303  			m.accepted(Nd, p+2, t)
   304  		case 'e':
   305  			m.accepted(Ne, p+2, t)
   306  		case 'i':
   307  			m.accepted(Ni, p+2, t)
   308  		case 'o':
   309  			m.accepted(No, p+2, t)
   310  		case 'p':
   311  			m.accepted(Np, p+2, t)
   312  		}
   313  		m.accepted(N, p+1, t)
   314  	case 'o':
   315  		if p1 == 's' {
   316  			m.accepted(Os, p+2, t)
   317  		}
   318  		m.accepted(O, p+1, t)
   319  	case 'p':
   320  		switch p1 {
   321  		case 'a':
   322  			m.accepted(Pa, p+2, t)
   323  		case 'b':
   324  			m.accepted(Pb, p+2, t)
   325  		case 'd':
   326  			m.accepted(Pd, p+2, t)
   327  		case 'm':
   328  			m.accepted(Pm, p+2, t)
   329  		case 'o':
   330  			m.accepted(Po, p+2, t)
   331  		case 'r':
   332  			m.accepted(Pr, p+2, t)
   333  		case 't':
   334  			m.accepted(Pt, p+2, t)
   335  		case 'u':
   336  			m.accepted(Pu, p+2, t)
   337  		}
   338  		m.accepted(P, p+1, t)
   339  	case 'r':
   340  		switch p1 {
   341  		case 'a':
   342  			m.accepted(Ra, p+2, t)
   343  		case 'b':
   344  			m.accepted(Rb, p+2, t)
   345  		case 'e':
   346  			m.accepted(Re, p+2, t)
   347  		case 'f':
   348  			m.accepted(Rf, p+2, t)
   349  		case 'g':
   350  			m.accepted(Rg, p+2, t)
   351  		case 'h':
   352  			m.accepted(Rh, p+2, t)
   353  		case 'n':
   354  			m.accepted(Rn, p+2, t)
   355  		case 'u':
   356  			m.accepted(Ru, p+2, t)
   357  		}
   358  	case 's':
   359  		switch p1 {
   360  		case 'b':
   361  			m.accepted(Sb, p+2, t)
   362  		case 'c':
   363  			m.accepted(Sc, p+2, t)
   364  		case 'e':
   365  			m.accepted(Se, p+2, t)
   366  		case 'g':
   367  			m.accepted(Sg, p+2, t)
   368  		case 'i':
   369  			m.accepted(Si, p+2, t)
   370  		case 'm':
   371  			m.accepted(Sm, p+2, t)
   372  		case 'n':
   373  			m.accepted(Sn, p+2, t)
   374  		case 'r':
   375  			m.accepted(Sr, p+2, t)
   376  		}
   377  		m.accepted(S, p+1, t)
   378  	case 't':
   379  		switch p1 {
   380  		case 'a':
   381  			m.accepted(Ta, p+2, t)
   382  		case 'b':
   383  			m.accepted(Tb, p+2, t)
   384  		case 'c':
   385  			m.accepted(Tc, p+2, t)
   386  		case 'e':
   387  			m.accepted(Te, p+2, t)
   388  		case 'h':
   389  			m.accepted(Th, p+2, t)
   390  		case 'i':
   391  			m.accepted(Ti, p+2, t)
   392  		case 'l':
   393  			m.accepted(Tl, p+2, t)
   394  		case 'm':
   395  			m.accepted(Tm, p+2, t)
   396  		}
   397  	case 'u':
   398  		if p1 == 'u' {
   399  			switch p2 {
   400  			case 'b':
   401  				m.accepted(Uub, p+3, t)
   402  			case 'h':
   403  				m.accepted(Uuh, p+3, t)
   404  			case 'o':
   405  				m.accepted(Uuo, p+3, t)
   406  			case 'p':
   407  				m.accepted(Uup, p+3, t)
   408  			case 'q':
   409  				m.accepted(Uuq, p+3, t)
   410  			case 's':
   411  				m.accepted(Uus, p+3, t)
   412  			case 't':
   413  				m.accepted(Uut, p+3, t)
   414  			}
   415  		}
   416  		m.accepted(U, p+1, t)
   417  	case 'v':
   418  		m.accepted(V, p+1, t)
   419  	case 'w':
   420  		m.accepted(W, p+1, t)
   421  	case 'x':
   422  		if p1 == 'e' {
   423  			m.accepted(Xe, p+2, t)
   424  		}
   425  	case 'y':
   426  		if p1 == 'b' {
   427  			m.accepted(Yb, p+2, t)
   428  		}
   429  		m.accepted(Y, p+1, t)
   430  	case 'z':
   431  		switch p1 {
   432  		case 'n':
   433  			m.accepted(Zn, p+2, t)
   434  		case 'r':
   435  			m.accepted(Zr, p+2, t)
   436  		}
   437  	}
   438  }