UNPKG

abnf

Version:

Augmented Backus-Naur Form (ABNF) parsing. See RFC 5234.

2,059 lines (1,879 loc) 48.8 kB
// @generated by Peggy 5.0.4. // // https://peggyjs.org/ import * as ast from "./ast.js"; class peg$SyntaxError extends SyntaxError { constructor(message, expected, found, location) { super(message); this.expected = expected; this.found = found; this.location = location; this.name = "SyntaxError"; } format(sources) { let str = "Error: " + this.message; if (this.location) { let src = null; const st = sources.find(s => s.source === this.location.source); if (st) { src = st.text.split(/\r\n|\n|\r/g); } const s = this.location.start; const offset_s = (this.location.source && (typeof this.location.source.offset === "function")) ? this.location.source.offset(s) : s; const loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column; if (src) { const e = this.location.end; const filler = "".padEnd(offset_s.line.toString().length, " "); const line = src[s.line - 1]; const last = s.line === e.line ? e.column : line.length + 1; const hatLen = (last - s.column) || 1; str += "\n --> " + loc + "\n" + filler + " |\n" + offset_s.line + " | " + line + "\n" + filler + " | " + "".padEnd(s.column - 1, " ") + "".padEnd(hatLen, "^"); } else { str += "\n at " + loc; } } return str; } static buildMessage(expected, found) { function hex(ch) { return ch.codePointAt(0).toString(16).toUpperCase(); } const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode") ? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu") : null; function unicodeEscape(s) { if (nonPrintable) { return s.replace(nonPrintable, ch => "\\u{" + hex(ch) + "}"); } return s; } function literalEscape(s) { return unicodeEscape(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, ch => "\\x0" + hex(ch)) .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch))); } function classEscape(s) { return unicodeEscape(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, ch => "\\x0" + hex(ch)) .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch))); } const DESCRIBE_EXPECTATION_FNS = { literal(expectation) { return "\"" + literalEscape(expectation.text) + "\""; }, class(expectation) { const escapedParts = expectation.parts.map( part => (Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part)) ); return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : ""); }, any() { return "any character"; }, end() { return "end of input"; }, other(expectation) { return expectation.description; }, }; function describeExpectation(expectation) { return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); } function describeExpected(expected) { const descriptions = expected.map(describeExpectation); descriptions.sort(); if (descriptions.length > 0) { let j = 1; for (let i = 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 !== undefined ? options : {}; const peg$FAILED = {}; const peg$source = options.grammarSource; const peg$startRuleFunctions = { rulelist: peg$parserulelist, }; let peg$startRuleFunction = peg$parserulelist; const peg$c0 = "=/"; const peg$c1 = ":"; const peg$c2 = "="; const peg$c3 = ";"; const peg$c4 = "/"; const peg$c5 = "*"; const peg$c6 = "#"; const peg$c7 = "("; const peg$c8 = ")"; const peg$c9 = "["; const peg$c10 = "]"; const peg$c11 = "%i"; const peg$c12 = "%s"; const peg$c13 = "%"; const peg$c14 = "<"; const peg$c15 = ">"; const peg$c16 = "\""; const peg$c17 = "b"; const peg$c18 = "."; const peg$c19 = "-"; const peg$c20 = "d"; const peg$c21 = "x"; const peg$c22 = "\r"; const peg$c23 = "\n"; const peg$r0 = /^[\-0-9A-Za-z]/; const peg$r1 = /^[\t -~]/; const peg$r2 = /^[ -!#-~]/; const peg$r3 = /^[ -=?-~]/; const peg$r4 = /^[0-1]/; const peg$r5 = /^[A-F]/i; const peg$r6 = /^[A-Za-z]/; const peg$r7 = /^[0-9]/; const peg$r8 = /^[\t ]/; const peg$r9 = /^[\n\r]/; const peg$e0 = peg$classExpectation(["-", ["0", "9"], ["A", "Z"], ["a", "z"]], false, false, false); const peg$e1 = peg$literalExpectation("=/", false); const peg$e2 = peg$literalExpectation(":", false); const peg$e3 = peg$literalExpectation("=", false); const peg$e4 = peg$literalExpectation(";", false); const peg$e5 = peg$classExpectation(["\t", [" ", "~"]], false, false, false); const peg$e6 = peg$literalExpectation("/", false); const peg$e7 = peg$literalExpectation("*", false); const peg$e8 = peg$literalExpectation("#", false); const peg$e9 = peg$literalExpectation("(", false); const peg$e10 = peg$literalExpectation(")", false); const peg$e11 = peg$literalExpectation("[", false); const peg$e12 = peg$literalExpectation("]", false); const peg$e13 = peg$literalExpectation("%i", true); const peg$e14 = peg$classExpectation([[" ", "!"], ["#", "~"]], false, false, false); const peg$e15 = peg$literalExpectation("%s", true); const peg$e16 = peg$literalExpectation("%", false); const peg$e17 = peg$literalExpectation("<", false); const peg$e18 = peg$classExpectation([[" ", "="], ["?", "~"]], false, false, false); const peg$e19 = peg$literalExpectation(">", false); const peg$e20 = peg$literalExpectation("\"", false); const peg$e21 = peg$literalExpectation("b", true); const peg$e22 = peg$literalExpectation(".", false); const peg$e23 = peg$literalExpectation("-", false); const peg$e24 = peg$literalExpectation("d", true); const peg$e25 = peg$literalExpectation("x", true); const peg$e26 = peg$anyExpectation(); const peg$e27 = peg$classExpectation([["0", "1"]], false, false, false); const peg$e28 = peg$classExpectation([["A", "F"]], false, true, false); const peg$e29 = peg$classExpectation([["A", "Z"], ["a", "z"]], false, false, false); const peg$e30 = peg$classExpectation([["0", "9"]], false, false, false); const peg$e31 = peg$classExpectation(["\t", " "], false, false, false); const peg$e32 = peg$classExpectation(["\n", "\r"], false, false, false); const peg$e33 = peg$literalExpectation("\r", false); const peg$e34 = peg$literalExpectation("\n", false); function peg$f0() { rules.loc = location(); return rules; } function peg$f1(name, operator, children) { if (operator === "=/") { rules.addAlternate(name, children, location()) } else { rules.addRule(name, children, location()) } } function peg$f2(alts) { if (alts.length > 1) { return new ast.Alternation(alts, location()); } return alts[0]; } function peg$f3(reps) { if (reps.length > 1) { return new ast.Concatenation(reps, location()); } return reps[0]; } function peg$f4(repeat, e) { if (repeat) { return new ast.Repetition(repeat, e, location()); } return e; } function peg$f5(min, max) { min |= 0; if (max === 0) { error("max must not be zero"); return; } if ((typeof max === "number") && (max < min)) { error(`max must be greater than or equal to min, but ${max} < ${min}`) return; } return new ast.Repeat(min, max, location()); } function peg$f6(n) { return new ast.Repeat(n, n, location()); } function peg$f7(min, max) { min |= 0; if (max === 0) { error("max must not be zero"); return; } if ((typeof max === "number") && (max < min)) { error(`max must be greater than or equal to min, but ${max} < ${min}`) return; } return new ast.HashRepeat(min, max, location()); } function peg$f8(name) { return rules.addRef(name, location()) } function peg$f9(alt) { return new ast.Group(alt, location()); } function peg$f10(alt) { const loc = location(); return new ast.Repetition(new ast.Repeat(0, 1, loc), alt, loc); } function peg$f11(txt) { return new ast.CaseInsensitiveString(txt, location()); } function peg$f12(txt) { return new ast.CaseSensitiveString(txt, 0, location()); } function peg$f13(prose) { return new ast.Prose(prose, location()); } function peg$f14(nums) { return new ast.CaseSensitiveString( nums.map(b => String.fromCodePoint(b)).join(""), 2, location() ); } function peg$f15(min, max) { return ast.Range.create(2, min, max, location(), options.utf16); } function peg$f16(n) { return new ast.CaseSensitiveString(String.fromCodePoint(n), 2, location()) } function peg$f17(nums) { return new ast.CaseSensitiveString( nums.map(d => String.fromCodePoint(d)).join(""), 10, location() ); } function peg$f18(min, max) { return ast.Range.create(10, min, max, location(), options.utf16); } function peg$f19(n) { return new ast.CaseSensitiveString(String.fromCodePoint(n), 10, location()) } function peg$f20(nums) { return new ast.CaseSensitiveString( nums.map(x => String.fromCodePoint(x)).join(""), 16, location() ); } function peg$f21(min, max) { return ast.Range.create(16, min, max, location(), options.utf16); } function peg$f22(n) { return new ast.CaseSensitiveString(String.fromCodePoint(n), 10, location()) } function peg$f23(b) { return parseInt(b, 2) } function peg$f24(d) { return parseInt(d, 10) } function peg$f25(h) { return parseInt(h, 16) } let peg$currPos = options.peg$currPos | 0; let peg$savedPos = peg$currPos; const peg$posDetailsCache = [{ line: 1, column: 1 }]; let peg$maxFailPos = peg$currPos; let peg$maxFailExpected = options.peg$maxFailExpected || []; let peg$silentFails = options.peg$silentFails | 0; let peg$result; if (options.startRule) { 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 offset() { return peg$savedPos; } function range() { return { source: peg$source, start: peg$savedPos, end: peg$currPos, }; } function location() { return peg$computeLocation(peg$savedPos, peg$currPos); } function expected(description, location) { location = location !== undefined ? 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 !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos); throw peg$buildSimpleError(message, location); } function peg$getUnicode(pos = peg$currPos) { const cp = input.codePointAt(pos); if (cp === undefined) { return ""; } return String.fromCodePoint(cp); } function peg$literalExpectation(text, ignoreCase) { return { type: "literal", text, ignoreCase }; } function peg$classExpectation(parts, inverted, ignoreCase, unicode) { return { type: "class", parts, inverted, ignoreCase, unicode }; } function peg$anyExpectation() { return { type: "any" }; } function peg$endExpectation() { return { type: "end" }; } function peg$otherExpectation(description) { return { type: "other", description }; } function peg$computePosDetails(pos) { let details = peg$posDetailsCache[pos]; let p; if (details) { return details; } else { if (pos >= peg$posDetailsCache.length) { p = peg$posDetailsCache.length - 1; } else { p = pos; while (!peg$posDetailsCache[--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, offset) { const startPosDetails = peg$computePosDetails(startPos); const endPosDetails = peg$computePosDetails(endPos); const res = { source: peg$source, start: { offset: startPos, line: startPosDetails.line, column: startPosDetails.column, }, end: { offset: endPos, line: endPosDetails.line, column: endPosDetails.column, }, }; if (offset && peg$source && (typeof peg$source.offset === "function")) { res.start = peg$source.offset(res.start); res.end = peg$source.offset(res.end); } return res; } 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$parserulelist() { let s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parserule(); if (s2 === peg$FAILED) { s2 = peg$parseempty(); } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parserule(); if (s2 === peg$FAILED) { s2 = peg$parseempty(); } } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f0(); } s0 = s1; return s0; } function peg$parseempty() { let s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parseWSP(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseWSP(); } s2 = peg$parsecomment(); if (s2 !== peg$FAILED) { s1 = [s1, s2]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parseWSP(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseWSP(); } s2 = peg$parseCRLF(); if (s2 !== peg$FAILED) { s1 = [s1, s2]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } return s0; } function peg$parserule() { let s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = []; s2 = peg$parseWSP(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseWSP(); } s2 = peg$parserulename(); if (s2 !== peg$FAILED) { s3 = peg$parsedefined_as(); if (s3 !== peg$FAILED) { s4 = peg$parseelements(); if (s4 !== peg$FAILED) { s5 = peg$parsec_nl(); if (s5 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f1(s2, s3, s4); } 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$parserulename() { let s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$parseALPHA(); if (s2 !== peg$FAILED) { s3 = []; s4 = input.charAt(peg$currPos); if (peg$r0.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e0); } } while (s4 !== peg$FAILED) { s3.push(s4); s4 = input.charAt(peg$currPos); if (peg$r0.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e0); } } } s2 = [s2, s3]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { s0 = input.substring(s0, peg$currPos); } else { s0 = s1; } return s0; } function peg$parsedefined_as() { let s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = []; s2 = peg$parsec_wsp(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsec_wsp(); } if (input.substr(peg$currPos, 2) === peg$c0) { s2 = peg$c0; peg$currPos += 2; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e1); } } if (s2 === peg$FAILED) { s2 = peg$currPos; s3 = []; if (input.charCodeAt(peg$currPos) === 58) { s4 = peg$c1; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e2); } } while (s4 !== peg$FAILED) { s3.push(s4); if (s3.length >= 2) { s4 = peg$FAILED; } else { if (input.charCodeAt(peg$currPos) === 58) { s4 = peg$c1; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e2); } } } } if (input.charCodeAt(peg$currPos) === 61) { s4 = peg$c2; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e3); } } if (s4 !== peg$FAILED) { s3 = [s3, s4]; s2 = s3; } else { peg$currPos = s2; s2 = peg$FAILED; } } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsec_wsp(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsec_wsp(); } s0 = s2; } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseelements() { let s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parsealternation(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsec_wsp(); while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsec_wsp(); } s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsecomment() { let s0, s1, s2, s3, s4; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 59) { s1 = peg$c3; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; s4 = input.charAt(peg$currPos); if (peg$r1.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e5); } } while (s4 !== peg$FAILED) { s3.push(s4); s4 = input.charAt(peg$currPos); if (peg$r1.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e5); } } } s2 = input.substring(s2, peg$currPos); s3 = peg$parseEOL(); if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsealternation() { let s0, s1, s2, s3, s4, s5, s6, s7, s8; s0 = peg$currPos; s1 = peg$currPos; s2 = []; s3 = peg$parseconcatenation(); while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$currPos; s5 = []; s6 = peg$parsec_wsp(); while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parsec_wsp(); } if (input.charCodeAt(peg$currPos) === 47) { s6 = peg$c4; peg$currPos++; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s6 !== peg$FAILED) { s7 = []; s8 = peg$parsec_wsp(); while (s8 !== peg$FAILED) { s7.push(s8); s8 = peg$parsec_wsp(); } s5 = [s5, s6, s7]; s4 = s5; } else { peg$currPos = s4; s4 = peg$FAILED; } if (s4 !== peg$FAILED) { s4 = peg$parseconcatenation(); if (s4 === peg$FAILED) { peg$currPos = s3; s3 = peg$FAILED; } else { s3 = s4; } } else { s3 = s4; } } if (s2.length < 1) { peg$currPos = s1; s1 = peg$FAILED; } else { s1 = s2; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f2(s1); } s0 = s1; return s0; } function peg$parseconcatenation() { let s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$currPos; s2 = []; s3 = peg$parserepetition(); while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = []; s5 = peg$parsec_wsp(); if (s5 !== peg$FAILED) { while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parsec_wsp(); } } else { s4 = peg$FAILED; } if (s4 !== peg$FAILED) { s4 = peg$parserepetition(); if (s4 === peg$FAILED) { peg$currPos = s3; s3 = peg$FAILED; } else { s3 = s4; } } else { s3 = s4; } } if (s2.length < 1) { peg$currPos = s1; s1 = peg$FAILED; } else { s1 = s2; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f3(s1); } s0 = s1; return s0; } function peg$parserepetition() { let s0, s1, s2; s0 = peg$currPos; s1 = peg$parsehash_repeat(); if (s1 === peg$FAILED) { s1 = peg$parserepeat(); } if (s1 === peg$FAILED) { s1 = null; } s2 = peg$parseelement(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f4(s1, s2); } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parserepeat() { let s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parsedecnum(); if (s1 === peg$FAILED) { s1 = null; } if (input.charCodeAt(peg$currPos) === 42) { s2 = peg$c5; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e7); } } if (s2 !== peg$FAILED) { s3 = peg$parsedecnum(); if (s3 === peg$FAILED) { s3 = null; } peg$savedPos = s0; s0 = peg$f5(s1, s3); } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parsedecnum(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f6(s1); } s0 = s1; } return s0; } function peg$parsehash_repeat() { let s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parsedecnum(); if (s1 === peg$FAILED) { s1 = null; } if (input.charCodeAt(peg$currPos) === 35) { s2 = peg$c6; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e8); } } if (s2 !== peg$FAILED) { s3 = peg$parsedecnum(); if (s3 === peg$FAILED) { s3 = null; } peg$savedPos = s0; s0 = peg$f7(s1, s3); } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseelement() { let s0, s1; s0 = peg$currPos; s1 = peg$parserulename(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f8(s1); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$parsegroup(); if (s0 === peg$FAILED) { s0 = peg$parseoption(); if (s0 === peg$FAILED) { s0 = peg$parsechar_val(); if (s0 === peg$FAILED) { s0 = peg$parsenum_val(); if (s0 === peg$FAILED) { s0 = peg$parseprose_val(); } } } } } return s0; } function peg$parsegroup() { let s0, s1, s2, s3, s4, s5; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { s1 = peg$c7; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e9); } } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsec_wsp(); while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsec_wsp(); } s3 = peg$parsealternation(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsec_wsp(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parsec_wsp(); } if (input.charCodeAt(peg$currPos) === 41) { s5 = peg$c8; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e10); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f9(s3); } 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$parseoption() { let s0, s1, s2, s3, s4, s5; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { s1 = peg$c9; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e11); } } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsec_wsp(); while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsec_wsp(); } s3 = peg$parsealternation(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsec_wsp(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parsec_wsp(); } if (input.charCodeAt(peg$currPos) === 93) { s5 = peg$c10; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e12); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f10(s3); } 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$parsechar_val() { let s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = input.substr(peg$currPos, 2); if (s1.toLowerCase() === peg$c11) { peg$currPos += (2); } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e13); } } if (s1 === peg$FAILED) { s1 = null; } s2 = peg$parseDQUOTE(); if (s2 !== peg$FAILED) { s3 = peg$currPos; s4 = []; s5 = input.charAt(peg$currPos); if (peg$r2.test(s5)) { peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e14); } } while (s5 !== peg$FAILED) { s4.push(s5); s5 = input.charAt(peg$currPos); if (peg$r2.test(s5)) { peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e14); } } } s3 = input.substring(s3, peg$currPos); s4 = peg$parseDQUOTE(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f11(s3); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = input.substr(peg$currPos, 2); if (s1.toLowerCase() === peg$c12) { peg$currPos += (2); } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e15); } } if (s1 !== peg$FAILED) { s2 = peg$parseDQUOTE(); if (s2 !== peg$FAILED) { s3 = peg$currPos; s4 = []; s5 = input.charAt(peg$currPos); if (peg$r2.test(s5)) { peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e14); } } while (s5 !== peg$FAILED) { s4.push(s5); s5 = input.charAt(peg$currPos); if (peg$r2.test(s5)) { peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e14); } } } s3 = input.substring(s3, peg$currPos); s4 = peg$parseDQUOTE(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f12(s3); } 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$parsenum_val() { let s0, s1, s2; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 37) { s1 = peg$c13; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e16); } } if (s1 !== peg$FAILED) { s2 = peg$parsebin_val(); if (s2 === peg$FAILED) { s2 = peg$parsedec_val(); if (s2 === peg$FAILED) { s2 = peg$parsehex_val(); } } if (s2 !== peg$FAILED) { s0 = s2; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseprose_val() { let s0, s1, s2, s3, s4; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { s1 = peg$c14; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e17); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; s4 = input.charAt(peg$currPos); if (peg$r3.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e18); } } if (s4 === peg$FAILED) { s4 = peg$parseCRLF(); } while (s4 !== peg$FAILED) { s3.push(s4); s4 = input.charAt(peg$currPos); if (peg$r3.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e18); } } if (s4 === peg$FAILED) { s4 = peg$parseCRLF(); } } s2 = input.substring(s2, peg$currPos); if (input.charCodeAt(peg$currPos) === 62) { s3 = peg$c15; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e19); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f13(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseDQUOTE() { let s0; if (input.charCodeAt(peg$currPos) === 34) { s0 = peg$c16; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e20); } } return s0; } function peg$parsebin_val() { let s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c17) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e21); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; s4 = peg$parsebinnum(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 46) { s5 = peg$c18; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e22); } } if (s5 !== peg$FAILED) { s5 = peg$parsebinnum(); if (s5 === peg$FAILED) { peg$currPos = s4; s4 = peg$FAILED; } else { s4 = s5; } } else { s4 = s5; } } if (s3.length < 2) { peg$currPos = s2; s2 = peg$FAILED; } else { s2 = s3; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f14(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c17) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e21); } } if (s1 !== peg$FAILED) { s2 = peg$parsebinnum(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s3 = peg$c19; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e23); } } if (s3 !== peg$FAILED) { s4 = peg$parsebinnum(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f15(s2, s4); } 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; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c17) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e21); } } if (s1 !== peg$FAILED) { s2 = peg$parsebinnum(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f16(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } } return s0; } function peg$parsedec_val() { let s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c20) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e24); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; s4 = peg$parsedecnum(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 46) { s5 = peg$c18; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e22); } } if (s5 !== peg$FAILED) { s5 = peg$parsedecnum(); if (s5 === peg$FAILED) { peg$currPos = s4; s4 = peg$FAILED; } else { s4 = s5; } } else { s4 = s5; } } if (s3.length < 2) { peg$currPos = s2; s2 = peg$FAILED; } else { s2 = s3; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f17(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c20) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e24); } } if (s1 !== peg$FAILED) { s2 = peg$parsedecnum(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s3 = peg$c19; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e23); } } if (s3 !== peg$FAILED) { s4 = peg$parsedecnum(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f18(s2, s4); } 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; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c20) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e24); } } if (s1 !== peg$FAILED) { s2 = peg$parsedecnum(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f19(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } } return s0; } function peg$parsehex_val() { let s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c21) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e25); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; s4 = peg$parsehexnum(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 46) { s5 = peg$c18; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e22); } } if (s5 !== peg$FAILED) { s5 = peg$parsehexnum(); if (s5 === peg$FAILED) { peg$currPos = s4; s4 = peg$FAILED; } else { s4 = s5; } } else { s4 = s5; } } if (s3.length < 2) { peg$currPos = s2; s2 = peg$FAILED; } else { s2 = s3; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f20(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c21) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e25); } } if (s1 !== peg$FAILED) { s2 = peg$parsehexnum(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s3 = peg$c19; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e23); } } if (s3 !== peg$FAILED) { s4 = peg$parsehexnum(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f21(s2, s4); } 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; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (s1.toLowerCase() === peg$c21) { peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e25); } } if (s1 !== peg$FAILED) { s2 = peg$parsehexnum(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f22(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } } return s0; } function peg$parsebinnum() { let s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$currPos; s2 = []; s3 = peg$parseBIT(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseBIT(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f23(s1); } s0 = s1; return s0; } function peg$parsedecnum() { let s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$currPos; s2 = []; s3 = peg$parseDIGIT(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseDIGIT(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f24(s1); } s0 = s1; return s0; } function peg$parsehexnum() { let s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$currPos; s2 = []; s3 = peg$parseHEXDIG(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseHEXDIG(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f25(s1); } s0 = s1; return s0; } function peg$parsec_wsp() { let s0, s1, s2; s0 = peg$currPos; s1 = peg$parsec_nl(); if (s1 !== peg$FAILED) { s2 = peg$parseWSP(); if (s2 !== peg$FAILED) { s1 = [s1, s2]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$parseWSP(); } return s0; } function peg$parsec_nl() { let s0; s0 = peg$parseEOL(); if (s0 === peg$FAILED) { s0 = peg$parsecomment(); } return s0; } function peg$parseEOL() { let s0; s0 = peg$parseCRLF(); if (s0 === peg$FAILED) { s0 = peg$parseEOF(); } return s0; } function peg$parseEOF() { let s0, s1; s0 = peg$currPos; peg$silentFails++; if (input.length > peg$currPos) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e26); } } peg$silentFails--; if (s1 === peg$FAILED) { s0 = undefined; } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseBIT() { let s0; s0 = input.charAt(peg$currPos); if (peg$r4.test(s0)) { peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e27); } } return s0; } function peg$parseHEXDIG() { let s0; s0 = peg$parseDIGIT(); if (s0 === peg$FAILED) { s0 = input.charAt(peg$currPos); if (peg$r5.test(s0)) { peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e28); } } } return s0; } function peg$parseALPHA() { let s0; s0 = input.charAt(peg$currPos); if (peg$r6.test(s0)) { peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e29); } } return s0; } function peg$parseDIGIT() { let s0; s0 = input.charAt(peg$currPos); if (peg$r7.test(s0)) { peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e30); } } return s0; } function peg$parseWSP() { let s0; s0 = input.charAt(peg$currPos); if (peg$r8.test(s0)) { peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e31); } } return s0; } function peg$parseCRLF() { let s0, s1, s2; s0 = peg$currPos; s1 = peg$parseCR(); if (s1 !== peg$FAILED) { s2 = peg$parseLF(); if (s2 !== peg$FAILED) { s1 = [s1, s2]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = input.charAt(peg$currPos); if (peg$r9.test(s0)) { peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e32); } } } return s0; } function peg$parseCR() { let s0; if (input.charCodeAt(peg$currPos) === 13) { s0 = peg$c22; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e33); } } return s0; } function peg$parseLF() { let s0; if (input.charCodeAt(peg$currPos) === 10) { s0 = peg$c23; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e34); } } return s0; } const rules = new ast.Rules(); peg$result = peg$startRuleFunction(); const peg$success = (peg$result !== peg$FAILED && peg$currPos === input.length); function peg$throw() { if (peg$result !== peg$FAILED && peg$currPos < input.length) { peg$fail(peg$endExpectation()); } throw peg$buildStructuredError( peg$maxFailExpected, peg$maxFailPos < input.length ? peg$getUnicode(peg$maxFailPos) : null, peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) ); } if (options.peg$library) { return /** @type {any} */ ({ peg$result, peg$currPos, peg$FAILED, peg$maxFailExpected, peg$maxFailPos, peg$success, peg$throw: peg$success ? undefined : peg$throw, }); } if (peg$success) { return peg$result; } else { peg$throw(); } } const peg$allowedStartRules = [ "rulelist" ]; export { peg$allowedStartRules as StartRules, peg$SyntaxError as SyntaxError, peg$parse as parse };