UNPKG

mathpix-markdown-it

Version:

Mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript. It relies on the following open source libraries: MathJax v3 (to render math with SVGs), markdown-it (for standard Markdown parsing)

1,415 lines 58.8 kB
// WHEN REPLACING, CHECK FOR: // KEEP THIS WHEN REGENERATING THE PARSER !! "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); /* * Generated by PEG.js 0.10.0. * * http://pegjs.org/ */ function buildMessage(expected, found) { var DESCRIBE_EXPECTATION_FNS = { literal: function (expectation) { return "\"" + literalEscape(expectation.text) + "\""; }, "class": function (expectation) { var _a; var escapedParts = "", i; for (i = 0; i < expectation.parts.length; i++) { escapedParts += expectation.parts[i] instanceof Array ? ((_a = expectation.parts[i]) === null || _a === void 0 ? void 0 : _a.length) > 3 ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) + ", " + classEscape(expectation.parts[i][2]) + "-" + classEscape(expectation.parts[i][3]) : 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."; } ; var pegSyntaxError = /** @class */ (function (_super) { tslib_1.__extends(pegSyntaxError, _super); function pegSyntaxError(message, expected, found, location) { var _this = _super.call(this, message) || this; _this.message = message; _this.expected = expected; _this.found = found; _this.location = location; _this.name = "SyntaxError"; if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(_this, pegSyntaxError); } return _this; } return pegSyntaxError; }(Error)); function peg$parse(input, options) { options = options !== void 0 ? options : {}; // KEEP THIS WHEN REGENERATING THE PARSER !! var nOpenParentheses = input.split("(").length - 1; var nCloseParentheses = input.split(")").length - 1; if (nOpenParentheses !== nCloseParentheses) { throw peg$buildSimpleError("The number of opening parentheses does not match the number of closing parentheses.", 0); } // KEEP THIS WHEN REGENERATING THE PARSER !! var peg$FAILED = {}, peg$startRuleFunctions = { chain: peg$parsechain }, peg$startRuleFunction = peg$parsechain, peg$c0 = function (s) { var branches = []; var rings = []; for (var i = 0; i < s[1].length; i++) { branches.push(s[1][i]); } for (var i = 0; i < s[2].length; i++) { var bond = (s[2][i][0]) ? s[2][i][0] : "-"; rings.push({ "bond": bond, "id": s[2][i][1] }); } for (var i = 0; i < s[3].length; i++) { branches.push(s[3][i]); } for (var i = 0; i < s[6].length; i++) { branches.push(s[6][i]); } return { "atom": s[0], "isBracket": s[0].element ? true : false, "branches": branches, "branchCount": branches.length, "ringbonds": rings, "ringbondCount": rings.length, "bond": s[4] ? s[4] : "-", "next": s[5], "hasNext": s[5] ? true : false }; return s; }, peg$c1 = "(", peg$c2 = peg$literalExpectation("(", false), peg$c3 = ")", peg$c4 = peg$literalExpectation(")", false), peg$c5 = function (b) { var bond = (b[1]) ? b[1] : "-"; b[2].branchBond = bond; return b[2]; }, peg$c6 = function (a) { return a; }, peg$c7 = /^[\-=#$:\/\\.]/, peg$c8 = peg$classExpectation(["-", "=", "#", "$", ":", "/", "\\", "."], false, false), peg$c9 = function (b) { return b; }, peg$c10 = "[", peg$c11 = peg$literalExpectation("[", false), peg$c12 = "se", peg$c13 = peg$literalExpectation("se", false), peg$c14 = "as", peg$c15 = peg$literalExpectation("as", false), peg$c16 = "]", peg$c17 = peg$literalExpectation("]", false), peg$c18 = function (b) { return { "isotope": b[1], "element": b[2], "chirality": b[3], "hcount": b[4], "charge": b[5], "class": b[6] }; }, peg$c19 = "B", peg$c20 = peg$literalExpectation("B", false), peg$c21 = "r", peg$c22 = peg$literalExpectation("r", false), peg$c23 = "C", peg$c24 = peg$literalExpectation("C", false), peg$c25 = "l", peg$c26 = peg$literalExpectation("l", false), peg$c27 = /^[NOPSFI]/, peg$c28 = peg$classExpectation(["N", "O", "P", "S", "F", "I"], false, false), peg$c29 = function (o) { if (o.length > 1) return o.join(""); return o; }, peg$c30 = /^[bcnops]/, peg$c31 = peg$classExpectation(["b", "c", "n", "o", "p", "s"], false, false), peg$c32 = "*", peg$c33 = peg$literalExpectation("*", false), peg$c34 = function (w) { return w; }, peg$c35 = /^[A-Z]/, peg$c36 = peg$classExpectation([ ["A", "Z"] ], false, false), peg$c37 = /^[a-z]/, peg$c38 = peg$classExpectation([ ["a", "z"] ], false, false), peg$c39 = function (e) { return e.join(""); }, peg$c40 = "%", peg$c41 = peg$literalExpectation("%", false), peg$c42 = /^[1-9]/, peg$c43 = peg$classExpectation([ ["1", "9"] ], false, false), peg$c44 = /^[0-9]/, peg$c45 = peg$classExpectation([ ["0", "9"] ], false, false), peg$c46 = function (r) { if (r.length == 1) return Number(r); return Number(r.join("").replace("%", "")); }, peg$c47 = "@", peg$c48 = peg$literalExpectation("@", false), peg$c49 = "TH", peg$c50 = peg$literalExpectation("TH", false), peg$c51 = /^[12]/, peg$c52 = peg$classExpectation(["1", "2"], false, false), peg$c53 = "AL", peg$c54 = peg$literalExpectation("AL", false), peg$c55 = "SP", peg$c56 = peg$literalExpectation("SP", false), peg$c57 = /^[1-3]/, peg$c58 = peg$classExpectation([ ["1", "3"] ], false, false), peg$c59 = "TB", peg$c60 = peg$literalExpectation("TB", false), peg$c61 = "OH", peg$c62 = peg$literalExpectation("OH", false), peg$c63 = function (c) { if (!c[1]) return "@"; if (c[1] == "@") return "@@"; return c[1].join("").replace(",", ""); }, peg$c64 = function (c) { return c; }, peg$c65 = "+", peg$c66 = peg$literalExpectation("+", false), peg$c67 = function (c) { if (!c[1]) return 1; if (c[1] != "+") return Number(c[1].join("")); return 2; }, peg$c68 = "-", peg$c69 = peg$literalExpectation("-", false), peg$c70 = function (c) { if (!c[1]) return -1; if (c[1] != "-") return -Number(c[1].join("")); return -2; }, peg$c71 = "H", peg$c72 = peg$literalExpectation("H", false), peg$c73 = function (h) { if (h[1]) return Number(h[1]); return 1; }, peg$c74 = ":", peg$c75 = peg$literalExpectation(":", false), peg$c76 = /^[0]/, peg$c77 = peg$classExpectation(["0"], false, false), peg$c78 = function (c) { return Number(c[1][0] + c[1][1].join("")); }, peg$c79 = function (i) { return Number(i.join("")); }, /** Markush symbols */ peg$c80 = /^[RXYZ]/, peg$c81 = peg$classExpectation([ ["a", "z", "1", "9"] ], false, false), 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 pegSyntaxError(message, null, null, location); } function peg$buildStructuredError(expected, found, location) { return new pegSyntaxError(buildMessage(expected, found), expected, found, location); } function peg$parsechain() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$parseatom(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsebranch(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsebranch(); } if (s3 !== peg$FAILED) { s4 = []; s5 = peg$currPos; s6 = peg$parsebond(); if (s6 === peg$FAILED) { s6 = null; } if (s6 !== peg$FAILED) { s7 = peg$parsering(); if (s7 !== peg$FAILED) { s6 = [s6, s7]; s5 = s6; } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$currPos; s6 = peg$parsebond(); if (s6 === peg$FAILED) { s6 = null; } if (s6 !== peg$FAILED) { s7 = peg$parsering(); if (s7 !== peg$FAILED) { s6 = [s6, s7]; s5 = s6; } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } } if (s4 !== peg$FAILED) { s5 = []; s6 = peg$parsebranch(); while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parsebranch(); } if (s5 !== peg$FAILED) { s6 = peg$parsebond(); if (s6 === peg$FAILED) { s6 = null; } if (s6 !== peg$FAILED) { s7 = peg$parsechain(); if (s7 === peg$FAILED) { s7 = null; } if (s7 !== peg$FAILED) { s8 = []; s9 = peg$parsebranch(); while (s9 !== peg$FAILED) { s8.push(s9); s9 = peg$parsebranch(); } if (s8 !== peg$FAILED) { s2 = [s2, s3, s4, s5, s6, s7, s8]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c0(s1); } s0 = s1; return s0; } function peg$parsebranch() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { s2 = peg$c1; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c2); } } if (s2 !== peg$FAILED) { s3 = peg$parsebond(); if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { s4 = peg$parsechain(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s5 = peg$c3; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s5 !== peg$FAILED) { s2 = [s2, s3, s4, s5]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c5(s1); } s0 = s1; return s0; } function peg$parseatom() { var s0, s1; s0 = peg$currPos; s1 = peg$parseorganicsymbol(); if (s1 === peg$FAILED) { s1 = peg$parsearomaticsymbol(); if (s1 === peg$FAILED) { s1 = peg$parsebracketatom(); if (s1 === peg$FAILED) { s1 = peg$parsewildcard(); } } } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c6(s1); } s0 = s1; return s0; } function peg$parsebond() { var s0, s1; s0 = peg$currPos; if (peg$c7.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); // Hack to resolve problem caused by: // O=C(N[C@@H](CC(O)=O)C(N[C@H](C1=CC=C(O)C=C1)C(N[C@@H](CC(O)=O)C(NCC(N[C@@H](C(N[C@@H]([C@H](C)CC(O)=O)C(N/C(C(O[C@H](C)[C@@H]2NC([C@H](CO)NC(C(O3)C3CCC)=O)=O)=O)=C\\\\C4=CNC5=C4C=CC=C5)=O)=O)[C@H](O)C(N)=O)=O)=O)=O)=O)[C@H](CC(O)=O)NC([C@@H](CC6=CNC7=C6C=CC=C7)NC2=O)=O // KEEP THIS WHEN REGENERATING THE PARSER !! if (s1 === input.charAt(peg$currPos + 1)) { s1 = peg$FAILED; if (peg$silentFails === 0) { throw peg$buildSimpleError("The parser encountered a bond repetition.", peg$currPos + 1); } } // KEEP THIS WHEN REGENERATING THE PARSER !! peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c8); } } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c9(s1); } s0 = s1; return s0; } function peg$parsebracketatom() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { s2 = peg$c10; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s2 !== peg$FAILED) { s3 = peg$parseisotope(); if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c12) { s4 = peg$c12; peg$currPos += 2; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s4 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c14) { s4 = peg$c14; peg$currPos += 2; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c15); } } if (s4 === peg$FAILED) { s4 = peg$parsearomaticsymbol(); if (s4 === peg$FAILED) { s4 = peg$parseelementsymbol(); if (s4 === peg$FAILED) { s4 = peg$parsewildcard(); } } } } if (s4 !== peg$FAILED) { s5 = peg$parsechiral(); if (s5 === peg$FAILED) { s5 = null; } if (s5 !== peg$FAILED) { s6 = peg$parsehcount(); if (s6 === peg$FAILED) { s6 = null; } if (s6 !== peg$FAILED) { s7 = peg$parsecharge(); if (s7 === peg$FAILED) { s7 = null; } if (s7 !== peg$FAILED) { s8 = peg$parseclass(); if (s8 === peg$FAILED) { s8 = null; } if (s8 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { s9 = peg$c16; peg$currPos++; } else { s9 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c17); } } if (s9 !== peg$FAILED) { s2 = [s2, s3, s4, s5, s6, s7, s8, s9]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c18(s1); } s0 = s1; return s0; } function peg$parseorganicsymbol() { var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 66) { s2 = peg$c19; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c20); } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 114) { s3 = peg$c21; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c22); } } if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { s2 = [s2, s3]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 === peg$FAILED) { s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 67) { s2 = peg$c23; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c24); } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 108) { s3 = peg$c25; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c26); } } if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { s2 = [s2, s3]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 === peg$FAILED) { if (peg$c27.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c28); } } } } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c29(s1); } s0 = s1; return s0; } function peg$parsearomaticsymbol() { var s0, s1; s0 = peg$currPos; if (peg$c30.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c31); } } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c6(s1); } s0 = s1; return s0; } function peg$parsewildcard() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 42) { s1 = peg$c32; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c33); } } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c34(s1); } s0 = s1; return s0; } function peg$parseelementsymbol() { var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$currPos; if (peg$c35.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s2 !== peg$FAILED) { /** Markush: * first symbol can be R,X,Y,Z * max number 199 - [R199] * */ if (peg$c80.test(s2) && !peg$c37.test(input.charAt(peg$currPos))) { if (peg$c42.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; if (peg$c44.test(input.charAt(peg$currPos))) { s3 += input.charAt(peg$currPos); peg$currPos++; if (peg$c44.test(input.charAt(peg$currPos))) { s3 += input.charAt(peg$currPos); peg$currPos++; } } } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c81); } } } else { if (peg$c37.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c38); } } } if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { s2 = [s2, s3]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c39(s1); } s0 = s1; return s0; } function peg$parsering() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 37) { s2 = peg$c40; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s2 !== peg$FAILED) { if (peg$c42.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c43); } } if (s3 !== peg$FAILED) { if (peg$c44.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c45); } } if (s4 !== peg$FAILED) { s2 = [s2, s3, s4]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 === peg$FAILED) { if (peg$c44.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c45); } } } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c46(s1); } s0 = s1; return s0; } function peg$parsechiral() { var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 64) { s2 = peg$c47; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 64) { s3 = peg$c47; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s3 === peg$FAILED) { s3 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c49) { s4 = peg$c49; peg$currPos += 2; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c50); } } if (s4 !== peg$FAILED) { if (peg$c51.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 === peg$FAILED) { s3 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c53) { s4 = peg$c53; peg$currPos += 2; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s4 !== peg$FAILED) { if (peg$c51.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 === peg$FAILED) { s3 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c55) { s4 = peg$c55; peg$currPos += 2; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c56); } } if (s4 !== peg$FAILED) { if (peg$c57.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c58); } } if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 === peg$FAILED) { s3 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c59) { s4 = peg$c59; peg$currPos += 2; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c60); } } if (s4 !== peg$FAILED) { if (peg$c42.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c43); } } if (s5 !== peg$FAILED) { if (peg$c44.test(input.charAt(peg$currPos))) { s6 = input.charAt(peg$currPos); peg$currPos++; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c45); } } if (s6 === peg$FAILED) { s6 = null; } if (s6 !== peg$FAILED) { s4 = [s4, s5, s6]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 === peg$FAILED) { s3 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c61) { s4 = peg$c61; peg$currPos += 2; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c62); } } if (s4 !== peg$FAILED) { if (peg$c42.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c43); } } if (s5 !== peg$FAILED) { if (peg$c44.test(input.charAt(peg$currPos))) { s6 = input.charAt(peg$currPos); peg$currPos++; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c45); } } if (s6 === peg$FAILED) { s6 = null; } if (s6 !== peg$FAILED) { s4 = [s4, s5, s6]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } } } } } if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { s2 = [s2, s3]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c63(s1); } s0 = s1; return s0; } function peg$parsecharge() { var s0, s1; s0 = peg$currPos; s1 = peg$parseposcharge(); if (s1 === peg$FAILED) { s1 = peg$parsenegcharge(); } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c64(s1); } s0 = s1; return s0; } function peg$parseposcharge() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 43) { s2 = peg$c65; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c66); } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 43) { s3 = peg$c65; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c66); } } if (s3 === peg$FAILED) { s3 = peg$currPos; if (peg$c42.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c43); } } if (s4 !== peg$FAILED) { if (peg$c44.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c45); } } if (s5 === peg$FAILED) { s5 = null; } if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { s2 = [s2, s3]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { // peg$savedPos = s0; s1 = peg$c67(s1); } s0 = s1; return s0; } function peg$parsenegcharge() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { s2 = peg$c68; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c69); } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s3 = peg$c68; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$f