UNPKG

smiles

Version:

OpenSMILES compatible parser and serializer

1,316 lines (1,220 loc) 186 kB
/* * Generated by PEG.js 0.10.0. * * http://pegjs.org/ */ "use strict"; function peg$subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); } function peg$SyntaxError(message, expected, found, location) { this.message = message; this.expected = expected; this.found = found; this.location = location; this.name = "SyntaxError"; if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(this, peg$SyntaxError); } } peg$subclass(peg$SyntaxError, Error); peg$SyntaxError.buildMessage = function(expected, found) { var DESCRIBE_EXPECTATION_FNS = { literal: function(expectation) { return "\"" + literalEscape(expectation.text) + "\""; }, "class": function(expectation) { var escapedParts = "", i; for (i = 0; i < expectation.parts.length; i++) { escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]); } return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; }, any: function(expectation) { return "any character"; }, end: function(expectation) { return "end of input"; }, other: function(expectation) { return expectation.description; } }; function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } function literalEscape(s) { return s .replace(/\\/g, '\\\\') .replace(/"/g, '\\"') .replace(/\0/g, '\\0') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); } function classEscape(s) { return s .replace(/\\/g, '\\\\') .replace(/\]/g, '\\]') .replace(/\^/g, '\\^') .replace(/-/g, '\\-') .replace(/\0/g, '\\0') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); } function describeExpectation(expectation) { return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); } function describeExpected(expected) { var descriptions = new Array(expected.length), i, j; for (i = 0; i < expected.length; i++) { descriptions[i] = describeExpectation(expected[i]); } descriptions.sort(); if (descriptions.length > 0) { for (i = 1, j = 1; i < descriptions.length; i++) { if (descriptions[i - 1] !== descriptions[i]) { descriptions[j] = descriptions[i]; j++; } } descriptions.length = j; } switch (descriptions.length) { case 1: return descriptions[0]; case 2: return descriptions[0] + " or " + descriptions[1]; default: return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1]; } } function describeFound(found) { return found ? "\"" + literalEscape(found) + "\"" : "end of input"; } return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; }; function peg$parse(input, options) { options = options !== void 0 ? options : {}; var peg$FAILED = {}, peg$startRuleFunctions = { start: peg$parsestart }, peg$startRuleFunction = peg$parsestart, peg$c0 = function(value) { return flat(value) }, peg$c1 = "*", peg$c2 = peg$literalExpectation("*", false), peg$c3 = function(value) { return {type: 'AliphaticOrganic', value: value} }, peg$c4 = "Br", peg$c5 = peg$literalExpectation("Br", false), peg$c6 = "B", peg$c7 = peg$literalExpectation("B", false), peg$c8 = "Cl", peg$c9 = peg$literalExpectation("Cl", false), peg$c10 = "C", peg$c11 = peg$literalExpectation("C", false), peg$c12 = "N", peg$c13 = peg$literalExpectation("N", false), peg$c14 = "O", peg$c15 = peg$literalExpectation("O", false), peg$c16 = "S", peg$c17 = peg$literalExpectation("S", false), peg$c18 = "P", peg$c19 = peg$literalExpectation("P", false), peg$c20 = "F", peg$c21 = peg$literalExpectation("F", false), peg$c22 = "I", peg$c23 = peg$literalExpectation("I", false), peg$c24 = function(value) { return {type: 'AromaticOrganic', value: value} }, peg$c25 = "b", peg$c26 = peg$literalExpectation("b", false), peg$c27 = "c", peg$c28 = peg$literalExpectation("c", false), peg$c29 = "n", peg$c30 = peg$literalExpectation("n", false), peg$c31 = "o", peg$c32 = peg$literalExpectation("o", false), peg$c33 = "s", peg$c34 = peg$literalExpectation("s", false), peg$c35 = "p", peg$c36 = peg$literalExpectation("p", false), peg$c37 = "[", peg$c38 = peg$literalExpectation("[", false), peg$c39 = function() { return {type: 'BracketAtom', value: 'begin'} }, peg$c40 = "]", peg$c41 = peg$literalExpectation("]", false), peg$c42 = function() { return {type: 'BracketAtom', value: 'end'} }, peg$c43 = function(value) { return value ? {type: 'Isotope', value: value} : null }, peg$c44 = function(value) { return {type: 'ElementSymbol', value: value} }, peg$c45 = "Ac", peg$c46 = peg$literalExpectation("Ac", false), peg$c47 = "Ag", peg$c48 = peg$literalExpectation("Ag", false), peg$c49 = "Al", peg$c50 = peg$literalExpectation("Al", false), peg$c51 = "Am", peg$c52 = peg$literalExpectation("Am", false), peg$c53 = "Ar", peg$c54 = peg$literalExpectation("Ar", false), peg$c55 = "As", peg$c56 = peg$literalExpectation("As", false), peg$c57 = "At", peg$c58 = peg$literalExpectation("At", false), peg$c59 = "Au", peg$c60 = peg$literalExpectation("Au", false), peg$c61 = "Ba", peg$c62 = peg$literalExpectation("Ba", false), peg$c63 = "Be", peg$c64 = peg$literalExpectation("Be", false), peg$c65 = "Bh", peg$c66 = peg$literalExpectation("Bh", false), peg$c67 = "Bi", peg$c68 = peg$literalExpectation("Bi", false), peg$c69 = "Bk", peg$c70 = peg$literalExpectation("Bk", false), peg$c71 = "Ca", peg$c72 = peg$literalExpectation("Ca", false), peg$c73 = "Cd", peg$c74 = peg$literalExpectation("Cd", false), peg$c75 = "Ce", peg$c76 = peg$literalExpectation("Ce", false), peg$c77 = "Cf", peg$c78 = peg$literalExpectation("Cf", false), peg$c79 = "Cm", peg$c80 = peg$literalExpectation("Cm", false), peg$c81 = "Cn", peg$c82 = peg$literalExpectation("Cn", false), peg$c83 = "Co", peg$c84 = peg$literalExpectation("Co", false), peg$c85 = "Cr", peg$c86 = peg$literalExpectation("Cr", false), peg$c87 = "Cs", peg$c88 = peg$literalExpectation("Cs", false), peg$c89 = "Cu", peg$c90 = peg$literalExpectation("Cu", false), peg$c91 = "Db", peg$c92 = peg$literalExpectation("Db", false), peg$c93 = "Ds", peg$c94 = peg$literalExpectation("Ds", false), peg$c95 = "Dy", peg$c96 = peg$literalExpectation("Dy", false), peg$c97 = "Er", peg$c98 = peg$literalExpectation("Er", false), peg$c99 = "Es", peg$c100 = peg$literalExpectation("Es", false), peg$c101 = "Eu", peg$c102 = peg$literalExpectation("Eu", false), peg$c103 = "Fe", peg$c104 = peg$literalExpectation("Fe", false), peg$c105 = "Fl", peg$c106 = peg$literalExpectation("Fl", false), peg$c107 = "Fm", peg$c108 = peg$literalExpectation("Fm", false), peg$c109 = "Fr", peg$c110 = peg$literalExpectation("Fr", false), peg$c111 = "Ga", peg$c112 = peg$literalExpectation("Ga", false), peg$c113 = "Gd", peg$c114 = peg$literalExpectation("Gd", false), peg$c115 = "Ge", peg$c116 = peg$literalExpectation("Ge", false), peg$c117 = "He", peg$c118 = peg$literalExpectation("He", false), peg$c119 = "Hf", peg$c120 = peg$literalExpectation("Hf", false), peg$c121 = "Hg", peg$c122 = peg$literalExpectation("Hg", false), peg$c123 = "Ho", peg$c124 = peg$literalExpectation("Ho", false), peg$c125 = "Hs", peg$c126 = peg$literalExpectation("Hs", false), peg$c127 = "H", peg$c128 = peg$literalExpectation("H", false), peg$c129 = "In", peg$c130 = peg$literalExpectation("In", false), peg$c131 = "Ir", peg$c132 = peg$literalExpectation("Ir", false), peg$c133 = "Kr", peg$c134 = peg$literalExpectation("Kr", false), peg$c135 = "K", peg$c136 = peg$literalExpectation("K", false), peg$c137 = "La", peg$c138 = peg$literalExpectation("La", false), peg$c139 = "Li", peg$c140 = peg$literalExpectation("Li", false), peg$c141 = "Lr", peg$c142 = peg$literalExpectation("Lr", false), peg$c143 = "Lu", peg$c144 = peg$literalExpectation("Lu", false), peg$c145 = "Lv", peg$c146 = peg$literalExpectation("Lv", false), peg$c147 = "Md", peg$c148 = peg$literalExpectation("Md", false), peg$c149 = "Mg", peg$c150 = peg$literalExpectation("Mg", false), peg$c151 = "Mn", peg$c152 = peg$literalExpectation("Mn", false), peg$c153 = "Mo", peg$c154 = peg$literalExpectation("Mo", false), peg$c155 = "Mt", peg$c156 = peg$literalExpectation("Mt", false), peg$c157 = "Na", peg$c158 = peg$literalExpectation("Na", false), peg$c159 = "Nb", peg$c160 = peg$literalExpectation("Nb", false), peg$c161 = "Nd", peg$c162 = peg$literalExpectation("Nd", false), peg$c163 = "Ne", peg$c164 = peg$literalExpectation("Ne", false), peg$c165 = "Ni", peg$c166 = peg$literalExpectation("Ni", false), peg$c167 = "No", peg$c168 = peg$literalExpectation("No", false), peg$c169 = "Np", peg$c170 = peg$literalExpectation("Np", false), peg$c171 = "Os", peg$c172 = peg$literalExpectation("Os", false), peg$c173 = "Pa", peg$c174 = peg$literalExpectation("Pa", false), peg$c175 = "Pb", peg$c176 = peg$literalExpectation("Pb", false), peg$c177 = "Pd", peg$c178 = peg$literalExpectation("Pd", false), peg$c179 = "Pm", peg$c180 = peg$literalExpectation("Pm", false), peg$c181 = "Po", peg$c182 = peg$literalExpectation("Po", false), peg$c183 = "Pr", peg$c184 = peg$literalExpectation("Pr", false), peg$c185 = "Pt", peg$c186 = peg$literalExpectation("Pt", false), peg$c187 = "Pu", peg$c188 = peg$literalExpectation("Pu", false), peg$c189 = "Ra", peg$c190 = peg$literalExpectation("Ra", false), peg$c191 = "Rb", peg$c192 = peg$literalExpectation("Rb", false), peg$c193 = "Re", peg$c194 = peg$literalExpectation("Re", false), peg$c195 = "Rf", peg$c196 = peg$literalExpectation("Rf", false), peg$c197 = "Rg", peg$c198 = peg$literalExpectation("Rg", false), peg$c199 = "Rh", peg$c200 = peg$literalExpectation("Rh", false), peg$c201 = "Rn", peg$c202 = peg$literalExpectation("Rn", false), peg$c203 = "Ru", peg$c204 = peg$literalExpectation("Ru", false), peg$c205 = "Sb", peg$c206 = peg$literalExpectation("Sb", false), peg$c207 = "Sc", peg$c208 = peg$literalExpectation("Sc", false), peg$c209 = "Se", peg$c210 = peg$literalExpectation("Se", false), peg$c211 = "Sg", peg$c212 = peg$literalExpectation("Sg", false), peg$c213 = "Si", peg$c214 = peg$literalExpectation("Si", false), peg$c215 = "Sm", peg$c216 = peg$literalExpectation("Sm", false), peg$c217 = "Sn", peg$c218 = peg$literalExpectation("Sn", false), peg$c219 = "Sr", peg$c220 = peg$literalExpectation("Sr", false), peg$c221 = "Ta", peg$c222 = peg$literalExpectation("Ta", false), peg$c223 = "Tb", peg$c224 = peg$literalExpectation("Tb", false), peg$c225 = "Tc", peg$c226 = peg$literalExpectation("Tc", false), peg$c227 = "Te", peg$c228 = peg$literalExpectation("Te", false), peg$c229 = "Th", peg$c230 = peg$literalExpectation("Th", false), peg$c231 = "Ti", peg$c232 = peg$literalExpectation("Ti", false), peg$c233 = "Tl", peg$c234 = peg$literalExpectation("Tl", false), peg$c235 = "Tm", peg$c236 = peg$literalExpectation("Tm", false), peg$c237 = "U", peg$c238 = peg$literalExpectation("U", false), peg$c239 = "V", peg$c240 = peg$literalExpectation("V", false), peg$c241 = "W", peg$c242 = peg$literalExpectation("W", false), peg$c243 = "Xe", peg$c244 = peg$literalExpectation("Xe", false), peg$c245 = "Yb", peg$c246 = peg$literalExpectation("Yb", false), peg$c247 = "Y", peg$c248 = peg$literalExpectation("Y", false), peg$c249 = "Zn", peg$c250 = peg$literalExpectation("Zn", false), peg$c251 = "Zr", peg$c252 = peg$literalExpectation("Zr", false), peg$c253 = function(value) { return {type: 'AromaticSymbol', value: value} }, peg$c254 = "as", peg$c255 = peg$literalExpectation("as", false), peg$c256 = "se", peg$c257 = peg$literalExpectation("se", false), peg$c258 = function(value) { return {type: 'Chiral', value: chiralMap[value]} }, peg$c259 = "@@", peg$c260 = peg$literalExpectation("@@", false), peg$c261 = "@", peg$c262 = peg$literalExpectation("@", false), peg$c263 = function(value) { return {type: 'HydrogenCount', value: value !== null ? value : 1} }, peg$c264 = "-", peg$c265 = peg$literalExpectation("-", false), peg$c266 = function(value) { return {type: 'Charge', value: value ? value * -1 : -1} }, peg$c267 = "+", peg$c268 = peg$literalExpectation("+", false), peg$c269 = function(value) { return {type: 'Charge', value: value ? value: 1} }, peg$c270 = ":", peg$c271 = peg$literalExpectation(":", false), peg$c272 = function(value) { return {type: 'Class', value: value} }, peg$c273 = function(value) { return {type: 'Bond', value: value} }, peg$c274 = "=", peg$c275 = peg$literalExpectation("=", false), peg$c276 = "#", peg$c277 = peg$literalExpectation("#", false), peg$c278 = "$", peg$c279 = peg$literalExpectation("$", false), peg$c280 = "/", peg$c281 = peg$literalExpectation("/", false), peg$c282 = "\\", peg$c283 = peg$literalExpectation("\\", false), peg$c284 = function(bond, value) { return [bond, {type: 'Ringbond', value: value}] }, peg$c285 = "%", peg$c286 = peg$literalExpectation("%", false), peg$c287 = "(", peg$c288 = peg$literalExpectation("(", false), peg$c289 = function() { return {type: 'Branch', value: 'begin'} }, peg$c290 = ")", peg$c291 = peg$literalExpectation(")", false), peg$c292 = function() { return {type: 'Branch', value: 'end'} }, peg$c293 = ".", peg$c294 = peg$literalExpectation(".", false), peg$c295 = function() { return {type: 'Bond', value: '.'} }, peg$c296 = function(Chain) { return flat(Chain) }, peg$c297 = /^[0-9]/, peg$c298 = peg$classExpectation([["0", "9"]], false, false), peg$c299 = function() { return parseInt(text()) }, peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ line: 1, column: 1 }], peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result; if ("startRule" in options) { if (!(options.startRule in peg$startRuleFunctions)) { throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; } function text() { return input.substring(peg$savedPos, peg$currPos); } function location() { return peg$computeLocation(peg$savedPos, peg$currPos); } function expected(description, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) throw peg$buildStructuredError( [peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location ); } function error(message, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) throw peg$buildSimpleError(message, location); } function peg$literalExpectation(text, ignoreCase) { return { type: "literal", text: text, ignoreCase: ignoreCase }; } function peg$classExpectation(parts, inverted, ignoreCase) { return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; } function peg$anyExpectation() { return { type: "any" }; } function peg$endExpectation() { return { type: "end" }; } function peg$otherExpectation(description) { return { type: "other", description: description }; } function peg$computePosDetails(pos) { var details = peg$posDetailsCache[pos], p; if (details) { return details; } else { p = pos - 1; while (!peg$posDetailsCache[p]) { p--; } details = peg$posDetailsCache[p]; details = { line: details.line, column: details.column }; while (p < pos) { if (input.charCodeAt(p) === 10) { details.line++; details.column = 1; } else { details.column++; } p++; } peg$posDetailsCache[pos] = details; return details; } } function peg$computeLocation(startPos, endPos) { var startPosDetails = peg$computePosDetails(startPos), endPosDetails = peg$computePosDetails(endPos); return { start: { offset: startPos, line: startPosDetails.line, column: startPosDetails.column }, end: { offset: endPos, line: endPosDetails.line, column: endPosDetails.column } }; } function peg$fail(expected) { if (peg$currPos < peg$maxFailPos) { return; } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; peg$maxFailExpected = []; } peg$maxFailExpected.push(expected); } function peg$buildSimpleError(message, location) { return new peg$SyntaxError(message, null, null, location); } function peg$buildStructuredError(expected, found, location) { return new peg$SyntaxError( peg$SyntaxError.buildMessage(expected, found), expected, found, location ); } function peg$parsestart() { var s0; s0 = peg$parseSmiles(); return s0; } function peg$parseAtom() { var s0, s1; s0 = peg$currPos; s1 = peg$parseBracketAtom(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c0(s1); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$parseAliphaticOrganic(); if (s0 === peg$FAILED) { s0 = peg$parseAromaticOrganic(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 42) { s0 = peg$c1; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c2); } } } } } return s0; } function peg$parseAliphaticOrganic() { var s0, s1; s0 = peg$currPos; s1 = peg$parseAliphaticOrganicValue(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c3(s1); } s0 = s1; return s0; } function peg$parseAliphaticOrganicValue() { var s0; if (input.substr(peg$currPos, 2) === peg$c4) { s0 = peg$c4; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c5); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 66) { s0 = peg$c6; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c8) { s0 = peg$c8; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c9); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 67) { s0 = peg$c10; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 78) { s0 = peg$c12; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 79) { s0 = peg$c14; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c15); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 83) { s0 = peg$c16; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c17); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 80) { s0 = peg$c18; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c19); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 70) { s0 = peg$c20; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 73) { s0 = peg$c22; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } } } } } } } } } } return s0; } function peg$parseAromaticOrganic() { var s0, s1; s0 = peg$currPos; s1 = peg$parseAromaticOrganicValue(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c24(s1); } s0 = s1; return s0; } function peg$parseAromaticOrganicValue() { var s0; if (input.charCodeAt(peg$currPos) === 98) { s0 = peg$c25; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c26); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 99) { s0 = peg$c27; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 110) { s0 = peg$c29; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c30); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 111) { s0 = peg$c31; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c32); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 115) { s0 = peg$c33; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c34); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 112) { s0 = peg$c35; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } } } } } } return s0; } function peg$parseBracketAtom() { var s0, s1, s2, s3, s4, s5, s6, s7, s8; s0 = peg$currPos; s1 = peg$parseBracketAtomBegin(); if (s1 !== peg$FAILED) { s2 = peg$parseIsotope(); if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { s3 = peg$parseSymbol(); if (s3 !== peg$FAILED) { s4 = peg$parseChiral(); if (s4 === peg$FAILED) { s4 = null; } if (s4 !== peg$FAILED) { s5 = peg$parseHydrogenCount(); if (s5 === peg$FAILED) { s5 = null; } if (s5 !== peg$FAILED) { s6 = peg$parseCharge(); if (s6 === peg$FAILED) { s6 = null; } if (s6 !== peg$FAILED) { s7 = peg$parseClass(); if (s7 === peg$FAILED) { s7 = null; } if (s7 !== peg$FAILED) { s8 = peg$parseBracketAtomEnd(); if (s8 !== peg$FAILED) { s1 = [s1, s2, s3, s4, s5, s6, s7, s8]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseBracketAtomBegin() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { s1 = peg$c37; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c38); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c39(); } s0 = s1; return s0; } function peg$parseBracketAtomEnd() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 93) { s1 = peg$c40; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c42(); } s0 = s1; return s0; } function peg$parseSymbol() { var s0; s0 = peg$parseElementSymbol(); if (s0 === peg$FAILED) { s0 = peg$parseAromaticSymbol(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 42) { s0 = peg$c1; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c2); } } } } return s0; } function peg$parseIsotope() { var s0, s1; s0 = peg$currPos; s1 = peg$parseNUMBER(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c43(s1); } s0 = s1; return s0; } function peg$parseElementSymbol() { var s0, s1; s0 = peg$currPos; s1 = peg$parseElementSymbolValue(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c44(s1); } s0 = s1; return s0; } function peg$parseElementSymbolValue() { var s0; if (input.substr(peg$currPos, 2) === peg$c45) { s0 = peg$c45; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c47) { s0 = peg$c47; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c49) { s0 = peg$c49; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c50); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c51) { s0 = peg$c51; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c53) { s0 = peg$c53; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c55) { s0 = peg$c55; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c56); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c57) { s0 = peg$c57; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c58); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c59) { s0 = peg$c59; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c60); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c61) { s0 = peg$c61; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c62); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c63) { s0 = peg$c63; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c64); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c65) { s0 = peg$c65; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c66); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c67) { s0 = peg$c67; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c68); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c69) { s0 = peg$c69; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c4) { s0 = peg$c4; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c5); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 66) { s0 = peg$c6; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c71) { s0 = peg$c71; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c72); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c73) { s0 = peg$c73; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c74); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c75) { s0 = peg$c75; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c76); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c77) { s0 = peg$c77; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c78); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c8) { s0 = peg$c8; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c9); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c79) { s0 = peg$c79; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c80); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c81) { s0 = peg$c81; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c82); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c83) { s0 = peg$c83; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c84); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c85) { s0 = peg$c85; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c87) { s0 = peg$c87; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c88); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c89) { s0 = peg$c89; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 67) { s0 = peg$c10; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c91) { s0 = peg$c91; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c92); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c93) { s0 = peg$c93; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c94); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c95) { s0 = peg$c95; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c96); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c97) { s0 = peg$c97; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c98); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c99) { s0 = peg$c99; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c100); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c101) { s0 = peg$c101; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c102); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c103) { s0 = peg$c103; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c104); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c105) { s0 = peg$c105; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c106); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c107) { s0 = peg$c107; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c108); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c109) { s0 = peg$c109; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c110); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 70) { s0 = peg$c20; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c111) { s0 = peg$c111; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c112); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c113) { s0 = peg$c113;