UNPKG

zonefile-parser

Version:
870 lines (769 loc) 32.8 kB
module.exports = (function() { "use strict"; /* * Generated by PEG.js 0.9.0. * * http://pegjs.org/ */ 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); function peg$parse(input) { var options = arguments.length > 1 ? arguments[1] : {}, parser = this, peg$FAILED = {}, peg$startRuleIndices = { Zonefile: 0 }, peg$startRuleIndex = 0, peg$consts = [ function(directives, records) { return { origin: findNoneOneOrError(directives, 'origin'), ttl: findNoneOneOrError(directives, 'ttl'), records: records.filter(r => !Array.isArray(r)) // Remove blank lines / comments } function findNoneOneOrError (arr, prop) { var results = arr.filter(item => !!item[prop]) if (results.length === 0) return null if (results.length === 1) return results[0][prop] return error('Zonefile has ' + results.length + ' $' + prop.toUpperCase() + ' directives. A valid zonefile has 1 or none.') } }, "$ORIGIN", { type: "literal", value: "$ORIGIN", description: "\"$ORIGIN\"" }, function(origin) { return { origin: origin } }, "$TTL", { type: "literal", value: "$TTL", description: "\"$TTL\"" }, function(ttl) { return { ttl: ttl } }, "A", { type: "literal", value: "A", description: "\"A\"" }, function(intro, type, address) { return { name: intro.name, ttl: intro.ttl, type: type, data: address } }, "AAAA", { type: "literal", value: "AAAA", description: "\"AAAA\"" }, "CNAME", { type: "literal", value: "CNAME", description: "\"CNAME\"" }, function(intro, type, domain) { return { name: intro.name, ttl: intro.ttl, type: type, data: domain } }, "MX", { type: "literal", value: "MX", description: "\"MX\"" }, function(intro, type, preference, domain) { return { name: intro.name, ttl: intro.ttl, type: type, data: { preference: preference, domain: domain } } }, "NS", { type: "literal", value: "NS", description: "\"NS\"" }, function(intro, type, nameServer) { return { name: intro.name, ttl: intro.ttl, type: type, data: nameServer } }, "SOA", { type: "literal", value: "SOA", description: "\"SOA\"" }, "(", { type: "literal", value: "(", description: "\"(\"" }, ")", { type: "literal", value: ")", description: "\")\"" }, function(intro, type, nameServer, email, serial, refresh, retry, expiry, minimum) { return { name: intro.name, ttl: intro.ttl, type: type, data: { nameServer: nameServer, email:email, serial:serial, refresh:refresh, retry:retry, expiry:expiry, minimum:minimum } } }, "SRV", { type: "literal", value: "SRV", description: "\"SRV\"" }, function(intro, type, priority, weight, port, target) { return { name: intro.name, ttl: intro.ttl, type: type, data: { priority: priority, weight: weight, port: port, target: target } } }, "TXT", { type: "literal", value: "TXT", description: "\"TXT\"" }, function(intro, type, strings) { return { name: intro.name, ttl: intro.ttl, type: type, data: strings.join('') } }, function(intro, type, data) { return { name: intro.name, ttl: intro.ttl, type: type, data: data } }, function(name, ttl) { return { name:name, ttl: ttl } }, "@", { type: "literal", value: "@", description: "\"@\"" }, function(name) { return name }, "IN", { type: "literal", value: "IN", description: "\"IN\"" }, "X25", { type: "literal", value: "X25", description: "\"X25\"" }, "WKS", { type: "literal", value: "WKS", description: "\"WKS\"" }, "URI", { type: "literal", value: "URI", description: "\"URI\"" }, "UNSPEC", { type: "literal", value: "UNSPEC", description: "\"UNSPEC\"" }, "UINFO", { type: "literal", value: "UINFO", description: "\"UINFO\"" }, "UID", { type: "literal", value: "UID", description: "\"UID\"" }, "TSIG", { type: "literal", value: "TSIG", description: "\"TSIG\"" }, "TLSA", { type: "literal", value: "TLSA", description: "\"TLSA\"" }, "TKEY", { type: "literal", value: "TKEY", description: "\"TKEY\"" }, "TALINK", { type: "literal", value: "TALINK", description: "\"TALINK\"" }, "TA", { type: "literal", value: "TA", description: "\"TA\"" }, "SSHFP", { type: "literal", value: "SSHFP", description: "\"SSHFP\"" }, "SPF", { type: "literal", value: "SPF", description: "\"SPF\"" }, "SMIMEA", { type: "literal", value: "SMIMEA", description: "\"SMIMEA\"" }, "SINK", { type: "literal", value: "SINK", description: "\"SINK\"" }, "SIG", { type: "literal", value: "SIG", description: "\"SIG\"" }, "RT", { type: "literal", value: "RT", description: "\"RT\"" }, "RRSIG", { type: "literal", value: "RRSIG", description: "\"RRSIG\"" }, "RP", { type: "literal", value: "RP", description: "\"RP\"" }, "RKEY", { type: "literal", value: "RKEY", description: "\"RKEY\"" }, "PX", { type: "literal", value: "PX", description: "\"PX\"" }, "PTR", { type: "literal", value: "PTR", description: "\"PTR\"" }, "OPT", { type: "literal", value: "OPT", description: "\"OPT\"" }, "OPENPGPKEY", { type: "literal", value: "OPENPGPKEY", description: "\"OPENPGPKEY\"" }, "NXT", { type: "literal", value: "NXT", description: "\"NXT\"" }, "NULL", { type: "literal", value: "NULL", description: "\"NULL\"" }, "NSEC3PARAM", { type: "literal", value: "NSEC3PARAM", description: "\"NSEC3PARAM\"" }, "NSEC3", { type: "literal", value: "NSEC3", description: "\"NSEC3\"" }, "NSEC", { type: "literal", value: "NSEC", description: "\"NSEC\"" }, "NSAP-PTR", { type: "literal", value: "NSAP-PTR", description: "\"NSAP-PTR\"" }, "NSAP", { type: "literal", value: "NSAP", description: "\"NSAP\"" }, "NINFO", { type: "literal", value: "NINFO", description: "\"NINFO\"" }, "NIMLOC", { type: "literal", value: "NIMLOC", description: "\"NIMLOC\"" }, "NID", { type: "literal", value: "NID", description: "\"NID\"" }, "NAPTR", { type: "literal", value: "NAPTR", description: "\"NAPTR\"" }, "MR", { type: "literal", value: "MR", description: "\"MR\"" }, "MINFO", { type: "literal", value: "MINFO", description: "\"MINFO\"" }, "MG", { type: "literal", value: "MG", description: "\"MG\"" }, "MF", { type: "literal", value: "MF", description: "\"MF\"" }, "MD", { type: "literal", value: "MD", description: "\"MD\"" }, "MB", { type: "literal", value: "MB", description: "\"MB\"" }, "MAILB", { type: "literal", value: "MAILB", description: "\"MAILB\"" }, "MAILA", { type: "literal", value: "MAILA", description: "\"MAILA\"" }, "LP", { type: "literal", value: "LP", description: "\"LP\"" }, "LOC", { type: "literal", value: "LOC", description: "\"LOC\"" }, "L64", { type: "literal", value: "L64", description: "\"L64\"" }, "L32", { type: "literal", value: "L32", description: "\"L32\"" }, "KX", { type: "literal", value: "KX", description: "\"KX\"" }, "KEY", { type: "literal", value: "KEY", description: "\"KEY\"" }, "IXFR", { type: "literal", value: "IXFR", description: "\"IXFR\"" }, "ISDN", { type: "literal", value: "ISDN", description: "\"ISDN\"" }, "IPSECKEY", { type: "literal", value: "IPSECKEY", description: "\"IPSECKEY\"" }, "HIP", { type: "literal", value: "HIP", description: "\"HIP\"" }, "HINFO", { type: "literal", value: "HINFO", description: "\"HINFO\"" }, "GPOS", { type: "literal", value: "GPOS", description: "\"GPOS\"" }, "GID", { type: "literal", value: "GID", description: "\"GID\"" }, "EUI64", { type: "literal", value: "EUI64", description: "\"EUI64\"" }, "EUI48", { type: "literal", value: "EUI48", description: "\"EUI48\"" }, "EID", { type: "literal", value: "EID", description: "\"EID\"" }, "DS", { type: "literal", value: "DS", description: "\"DS\"" }, "DNSKEY", { type: "literal", value: "DNSKEY", description: "\"DNSKEY\"" }, "DNAME", { type: "literal", value: "DNAME", description: "\"DNAME\"" }, "DLV", { type: "literal", value: "DLV", description: "\"DLV\"" }, "DHCID", { type: "literal", value: "DHCID", description: "\"DHCID\"" }, "CSYNC", { type: "literal", value: "CSYNC", description: "\"CSYNC\"" }, "CERT", { type: "literal", value: "CERT", description: "\"CERT\"" }, "CDS", { type: "literal", value: "CDS", description: "\"CDS\"" }, "CDNSKEY", { type: "literal", value: "CDNSKEY", description: "\"CDNSKEY\"" }, "CAA", { type: "literal", value: "CAA", description: "\"CAA\"" }, "AXFR", { type: "literal", value: "AXFR", description: "\"AXFR\"" }, "ATMA", { type: "literal", value: "ATMA", description: "\"ATMA\"" }, "APL", { type: "literal", value: "APL", description: "\"APL\"" }, "AFSDB", { type: "literal", value: "AFSDB", description: "\"AFSDB\"" }, "A6", { type: "literal", value: "A6", description: "\"A6\"" }, { type: "any", description: "any character" }, ".", { type: "literal", value: ".", description: "\".\"" }, /^[a-z0-9\-_*]/i, { type: "class", value: "[a-z0-9-_\\*]i", description: "[a-z0-9-_\\*]i" }, /^[smhdw]/i, { type: "class", value: "[smhdw]i", description: "[smhdw]i" }, /^[0-9]/, { type: "class", value: "[0-9]", description: "[0-9]" }, ":", { type: "literal", value: ":", description: "\":\"" }, /^[0-9a-f]/i, { type: "class", value: "[0-9a-f]i", description: "[0-9a-f]i" }, "0", { type: "literal", value: "0", description: "\"0\"" }, /^[1-9]/, { type: "class", value: "[1-9]", description: "[1-9]" }, { type: "other", description: "Comment" }, ";", { type: "literal", value: ";", description: "\";\"" }, function(message) { return message }, { type: "other", description: "Newline" }, "\n", { type: "literal", value: "\n", description: "\"\\n\"" }, "\r\n", { type: "literal", value: "\r\n", description: "\"\\r\\n\"" }, "\r", { type: "literal", value: "\r", description: "\"\\r\"" }, "\u2028", { type: "literal", value: "\u2028", description: "\"\\u2028\"" }, "\u2029", { type: "literal", value: "\u2029", description: "\"\\u2029\"" }, { type: "other", description: "Whitespace or Newline" }, { type: "other", description: "Whitespace" }, /^[ \t]/, { type: "class", value: "[ \\t]", description: "[ \\t]" }, "\"", { type: "literal", value: "\"", description: "\"\\\"\"" }, /^[^"]/, { type: "class", value: "[^\"]", description: "[^\"]" }, function(txt) { return txt }, function(str) { return str } ], peg$bytecode = [ peg$decode("%$;!.# &;=0)*;!.# &;=&/E#$;$.# &;=0)*;$.# &;=&/)$8\": \"\"! )(\"'#&'#"), peg$decode(";#.# &;\""), peg$decode("%2!\"\"6!7\"/H#;@/?$;3/6$;=.\" &\"/($8$:#$!!)($'#(#'#(\"'#&'#"), peg$decode("%2$\"\"6$7%/H#;@/?$;5/6$;=.\" &\"/($8$:&$!!)($'#(#'#(\"'#&'#"), peg$decode(";%.M &;&.G &;'.A &;(.; &;).5 &;+./ &;*.) &;,.# &;-"), peg$decode("%;./a#2'\"\"6'7(/R$$;@/&#0#*;@&&&#/<$;6/3$;?/*$8%:)%#$#!)(%'#($'#(#'#(\"'#&'#"), peg$decode("%;./a#2*\"\"6*7+/R$$;@/&#0#*;@&&&#/<$;8/3$;?/*$8%:)%#$#!)(%'#($'#(#'#(\"'#&'#"), peg$decode("%;./a#2,\"\"6,7-/R$$;@/&#0#*;@&&&#/<$;3/3$;?/*$8%:.%#$#!)(%'#($'#(#'#(\"'#&'#"), peg$decode("%;./\x86#2/\"\"6/70/w$$;@/&#0#*;@&&&#/a$;;/X$$;@/&#0#*;@&&&#/B$;3/9$;=.\" &\"/+$8':1'$&%#!)(''#(&'#(%'#($'#(#'#(\"'#&'#"), peg$decode("%;./f#22\"\"6273/W$$;@/&#0#*;@&&&#/A$;3/8$;=.\" &\"/*$8%:4%#$#!)(%'#($'#(#'#(\"'#&'#"), peg$decode("%;./\u016A#25\"\"6576/\u015B$$;@/&#0#*;@&&&#/\u0145$;3/\u013C$$;@/&#0#*;@&&&#/\u0126$;3/\u011D$$;@/&#0#*;@&&&#/\u0107$27\"\"6778/\xF8$$;?/&#0#*;?&&&#/\xE2$;;/\xD9$$;?/&#0#*;?&&&#/\xC3$;5/\xBA$$;?/&#0#*;?&&&#/\xA4$;5/\x9B$$;?/&#0#*;?&&&#/\x85$;5/|$$;?/&#0#*;?&&&#/f$;5/]$$;?0#*;?&/M$29\"\"697:/>$;=.\" &\"/0$85:;5)431/+)'%#)(5'#(4'#(3'#(2'#(1'#(0'#(/'#(.'#(-'#(,'#(+'#(*'#()'#(('#(''#(&'#(%'#($'#(#'#(\"'#&'#"), peg$decode("%;./\xC6#2<\"\"6<7=/\xB7$$;@/&#0#*;@&&&#/\xA1$;;/\x98$$;@/&#0#*;@&&&#/\x82$;;/y$$;@/&#0#*;@&&&#/c$;;/Z$$;@/&#0#*;@&&&#/D$;3/;$;=.\" &\"/-$8+:>+&*)'%#!)(+'#(*'#()'#(('#(''#(&'#(%'#($'#(#'#(\"'#&'#"), peg$decode("%;./y#2?\"\"6?7@/j$$;@/&#0#*;@&&&#/T$$;B/&#0#*;B&&&#.# &;D/8$;=.\" &\"/*$8%:A%#$#!)(%'#($'#(#'#(\"'#&'#"), peg$decode("%;./`#;1/W$$;@/&#0#*;@&&&#/A$;2/8$;=.\" &\"/*$8%:B%#$#!)(%'#($'#(#'#(\"'#&'#"), peg$decode("%;//u#$;@0#*;@&/e$;5.\" &\"/W$$;@0#*;@&/G$;0.\" &\"/9$$;@0#*;@&/)$8&:C&\"%#)(&'#(%'#($'#(#'#(\"'#&'#"), peg$decode("%%<;0=.##&&!&'#/X#%<;1=.##&&!&'#/C$;@./ &2D\"\"6D7E.# &;3/($8#:F#! )(#'#(\"'#&'#"), peg$decode("2G\"\"6G7H"), peg$decode("2I\"\"6I7J.\u03E9 &2K\"\"6K7L.\u03DD &2M\"\"6M7N.\u03D1 &2O\"\"6O7P.\u03C5 &2Q\"\"6Q7R.\u03B9 &2S\"\"6S7T.\u03AD &2?\"\"6?7@.\u03A1 &2U\"\"6U7V.\u0395 &2W\"\"6W7X.\u0389 &2Y\"\"6Y7Z.\u037D &2[\"\"6[7\\.\u0371 &2]\"\"6]7^.\u0365 &2_\"\"6_7`.\u0359 &2<\"\"6<7=.\u034D &2a\"\"6a7b.\u0341 &25\"\"6576.\u0335 &2c\"\"6c7d.\u0329 &2e\"\"6e7f.\u031D &2g\"\"6g7h.\u0311 &2i\"\"6i7j.\u0305 &2k\"\"6k7l.\u02F9 &2m\"\"6m7n.\u02ED &2o\"\"6o7p.\u02E1 &2q\"\"6q7r.\u02D5 &2s\"\"6s7t.\u02C9 &2u\"\"6u7v.\u02BD &2w\"\"6w7x.\u02B1 &2y\"\"6y7z.\u02A5 &2{\"\"6{7|.\u0299 &2}\"\"6}7~.\u028D &2\"\"67\x80.\u0281 &2\x81\"\"6\x817\x82.\u0275 &2\x83\"\"6\x837\x84.\u0269 &2\x85\"\"6\x857\x86.\u025D &22\"\"6273.\u0251 &2\x87\"\"6\x877\x88.\u0245 &2\x89\"\"6\x897\x8A.\u0239 &2\x8B\"\"6\x8B7\x8C.\u022D &2\x8D\"\"6\x8D7\x8E.\u0221 &2/\"\"6/70.\u0215 &2\x8F\"\"6\x8F7\x90.\u0209 &2\x91\"\"6\x917\x92.\u01FD &2\x93\"\"6\x937\x94.\u01F1 &2\x95\"\"6\x957\x96.\u01E5 &2\x97\"\"6\x977\x98.\u01D9 &2\x99\"\"6\x997\x9A.\u01CD &2\x9B\"\"6\x9B7\x9C.\u01C1 &2\x9D\"\"6\x9D7\x9E.\u01B5 &2\x9F\"\"6\x9F7\xA0.\u01A9 &2\xA1\"\"6\xA17\xA2.\u019D &2\xA3\"\"6\xA37\xA4.\u0191 &2\xA5\"\"6\xA57\xA6.\u0185 &2\xA7\"\"6\xA77\xA8.\u0179 &2\xA9\"\"6\xA97\xAA.\u016D &2\xAB\"\"6\xAB7\xAC.\u0161 &2\xAD\"\"6\xAD7\xAE.\u0155 &2\xAF\"\"6\xAF7\xB0.\u0149 &2\xB1\"\"6\xB17\xB2.\u013D &2\xB3\"\"6\xB37\xB4.\u0131 &2\xB5\"\"6\xB57\xB6.\u0125 &2\xB7\"\"6\xB77\xB8.\u0119 &2\xB9\"\"6\xB97\xBA.\u010D &2\xBB\"\"6\xBB7\xBC.\u0101 &2\xBD\"\"6\xBD7\xBE.\xF5 &2\xBF\"\"6\xBF7\xC0.\xE9 &2\xC1\"\"6\xC17\xC2.\xDD &2\xC3\"\"6\xC37\xC4.\xD1 &2\xC5\"\"6\xC57\xC6.\xC5 &2\xC7\"\"6\xC77\xC8.\xB9 &2\xC9\"\"6\xC97\xCA.\xAD &2,\"\"6,7-.\xA1 &2\xCB\"\"6\xCB7\xCC.\x95 &2\xCD\"\"6\xCD7\xCE.\x89 &2\xCF\"\"6\xCF7\xD0.} &2\xD1\"\"6\xD17\xD2.q &2\xD3\"\"6\xD37\xD4.e &2\xD5\"\"6\xD57\xD6.Y &2\xD7\"\"6\xD77\xD8.M &2\xD9\"\"6\xD97\xDA.A &2*\"\"6*7+.5 &2\xDB\"\"6\xDB7\xDC.) &2'\"\"6'7("), peg$decode("%$%%<;==.##&&!&'#/1#1\"\"5!7\xDD/#$+\")(\"'#&'#0G*%%<;==.##&&!&'#/1#1\"\"5!7\xDD/#$+\")(\"'#&'#&/\"!&,)"), peg$decode("%%;4/y#$%2\xDE\"\"6\xDE7\xDF/,#;4/#$+\")(\"'#&'#0<*%2\xDE\"\"6\xDE7\xDF/,#;4/#$+\")(\"'#&'#&/7$2\xDE\"\"6\xDE7\xDF.\" &\"/#$+#)(#'#(\"'#&'#/\"!&,)"), peg$decode("$4\xE0\"\"5!7\xE1/,#0)*4\xE0\"\"5!7\xE1&&&#"), peg$decode("%$%;;/2#4\xE2\"\"5!7\xE3/#$+\")(\"'#&'#/?#0<*%;;/2#4\xE2\"\"5!7\xE3/#$+\")(\"'#&'#&&&#.# &;;/\"!&,)"), peg$decode("%%;7/k#2\xDE\"\"6\xDE7\xDF/\\$;7/S$2\xDE\"\"6\xDE7\xDF/D$;7/;$2\xDE\"\"6\xDE7\xDF/,$;7/#$+')(''#(&'#(%'#($'#(#'#(\"'#&'#/\"!&,)"), peg$decode("%%4\xE4\"\"5!7\xE5/K#4\xE4\"\"5!7\xE5.\" &\"/7$4\xE4\"\"5!7\xE5.\" &\"/#$+#)(#'#(\"'#&'#/\"!&,)"), peg$decode("%%;9/\u0116#2\xE6\"\"6\xE67\xE7/\u0107$;9/\xFE$2\xE6\"\"6\xE67\xE7/\xEF$%;9/2#2\xE6\"\"6\xE67\xE7/#$+\")(\"'#&'#.\" &\"/\xC8$%;9/2#2\xE6\"\"6\xE67\xE7/#$+\")(\"'#&'#.\" &\"/\xA1$%;9/2#2\xE6\"\"6\xE67\xE7/#$+\")(\"'#&'#.\" &\"/z$%;9/2#2\xE6\"\"6\xE67\xE7/#$+\")(\"'#&'#.\" &\"/S$%;9/2#2\xE6\"\"6\xE67\xE7/#$+\")(\"'#&'#.\" &\"/,$;9/#$+*)(*'#()'#(('#(''#(&'#(%'#($'#(#'#(\"'#&'#/\"!&,)"), peg$decode("%;:.\" &\"/M#;:.\" &\"/?$;:.\" &\"/1$;:.\" &\"/#$+$)($'#(#'#(\"'#&'#"), peg$decode("4\xE8\"\"5!7\xE9"), peg$decode("%2\xEA\"\"6\xEA7\xEB.O &%4\xEC\"\"5!7\xED/?#$4\xE4\"\"5!7\xE50)*4\xE4\"\"5!7\xE5&/#$+\")(\"'#&'#/\"!&,)"), peg$decode("<%2\xEF\"\"6\xEF7\xF0/\x95#%$%%<;>=.##&&!&'#/1#1\"\"5!7\xDD/#$+\")(\"'#&'#0G*%%<;>=.##&&!&'#/1#1\"\"5!7\xDD/#$+\")(\"'#&'#&/\"!&,)/6$;>.\" &\"/($8#:\xF1#!!)(#'#(\"'#&'#=.\" 7\xEE"), peg$decode("%$;@0#*;@&/2#;>.# &;</#$+\")(\"'#&'#"), peg$decode("<2\xF3\"\"6\xF37\xF4.M &2\xF5\"\"6\xF57\xF6.A &2\xF7\"\"6\xF77\xF8.5 &2\xF9\"\"6\xF97\xFA.) &2\xFB\"\"6\xFB7\xFC=.\" 7\xF2"), peg$decode("<;@.) &;>.# &;<=.\" 7\xFD"), peg$decode("<4\xFF\"\"5!7\u0100=.\" 7\xFE"), peg$decode("%2\u0101\"\"6\u01017\u0102/Z#%$4\u0103\"\"5!7\u01040)*4\u0103\"\"5!7\u0104&/\"!&,)/7$2\u0101\"\"6\u01017\u0102/($8#:\u0105#!!)(#'#(\"'#&'#"), peg$decode("%;A/6#;@.\" &\"/($8\":\u0106\"!!)(\"'#&'#"), peg$decode("%;A/8#$;?0#*;?&/($8\":\u0106\"!!)(\"'#&'#"), peg$decode("%27\"\"6778/M#$;C/&#0#*;C&&&#/7$29\"\"697:/($8#:\u0106#!!)(#'#(\"'#&'#") ], peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ line: 1, column: 1, seenCR: false }], peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result; if ("startRule" in options) { if (!(options.startRule in peg$startRuleIndices)) { throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } peg$startRuleIndex = peg$startRuleIndices[options.startRule]; } function text() { return input.substring(peg$savedPos, peg$currPos); } function location() { return peg$computeLocation(peg$savedPos, peg$currPos); } function expected(description) { throw peg$buildException( null, [{ type: "other", description: description }], input.substring(peg$savedPos, peg$currPos), peg$computeLocation(peg$savedPos, peg$currPos) ); } function error(message) { throw peg$buildException( message, null, input.substring(peg$savedPos, peg$currPos), peg$computeLocation(peg$savedPos, peg$currPos) ); } function peg$computePosDetails(pos) { var details = peg$posDetailsCache[pos], p, ch; if (details) { return details; } else { p = pos - 1; while (!peg$posDetailsCache[p]) { p--; } details = peg$posDetailsCache[p]; details = { line: details.line, column: details.column, seenCR: details.seenCR }; while (p < pos) { ch = input.charAt(p); if (ch === "\n") { if (!details.seenCR) { details.line++; } details.column = 1; details.seenCR = false; } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { details.line++; details.column = 1; details.seenCR = true; } else { details.column++; details.seenCR = false; } 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$buildException(message, expected, found, location) { function cleanupExpected(expected) { var i = 1; expected.sort(function(a, b) { if (a.description < b.description) { return -1; } else if (a.description > b.description) { return 1; } else { return 0; } }); while (i < expected.length) { if (expected[i - 1] === expected[i]) { expected.splice(i, 1); } else { i++; } } } function buildMessage(expected, found) { function stringEscape(s) { function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } return s .replace(/\\/g, '\\\\') .replace(/"/g, '\\"') .replace(/\x08/g, '\\b') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\f/g, '\\f') .replace(/\r/g, '\\r') .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); }) .replace(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); }) .replace(/[\u1000-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); }); } var expectedDescs = new Array(expected.length), expectedDesc, foundDesc, i; for (i = 0; i < expected.length; i++) { expectedDescs[i] = expected[i].description; } expectedDesc = expected.length > 1 ? expectedDescs.slice(0, -1).join(", ") + " or " + expectedDescs[expected.length - 1] : expectedDescs[0]; foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input"; return "Expected " + expectedDesc + " but " + foundDesc + " found."; } if (expected !== null) { cleanupExpected(expected); } return new peg$SyntaxError( message !== null ? message : buildMessage(expected, found), expected, found, location ); } function peg$decode(s) { var bc = new Array(s.length), i; for (i = 0; i < s.length; i++) { bc[i] = s.charCodeAt(i) - 32; } return bc; } function peg$parseRule(index) { var bc = peg$bytecode[index], ip = 0, ips = [], end = bc.length, ends = [], stack = [], params, i; while (true) { while (ip < end) { switch (bc[ip]) { case 0: stack.push(peg$consts[bc[ip + 1]]); ip += 2; break; case 1: stack.push(void 0); ip++; break; case 2: stack.push(null); ip++; break; case 3: stack.push(peg$FAILED); ip++; break; case 4: stack.push([]); ip++; break; case 5: stack.push(peg$currPos); ip++; break; case 6: stack.pop(); ip++; break; case 7: peg$currPos = stack.pop(); ip++; break; case 8: stack.length -= bc[ip + 1]; ip += 2; break; case 9: stack.splice(-2, 1); ip++; break; case 10: stack[stack.length - 2].push(stack.pop()); ip++; break; case 11: stack.push(stack.splice(stack.length - bc[ip + 1], bc[ip + 1])); ip += 2; break; case 12: stack.push(input.substring(stack.pop(), peg$currPos)); ip++; break; case 13: ends.push(end); ips.push(ip + 3 + bc[ip + 1] + bc[ip + 2]); if (stack[stack.length - 1]) { end = ip + 3 + bc[ip + 1]; ip += 3; } else { end = ip + 3 + bc[ip + 1] + bc[ip + 2]; ip += 3 + bc[ip + 1]; } break; case 14: ends.push(end); ips.push(ip + 3 + bc[ip + 1] + bc[ip + 2]); if (stack[stack.length - 1] === peg$FAILED) { end = ip + 3 + bc[ip + 1]; ip += 3; } else { end = ip + 3 + bc[ip + 1] + bc[ip + 2]; ip += 3 + bc[ip + 1]; } break; case 15: ends.push(end); ips.push(ip + 3 + bc[ip + 1] + bc[ip + 2]); if (stack[stack.length - 1] !== peg$FAILED) { end = ip + 3 + bc[ip + 1]; ip += 3; } else { end = ip + 3 + bc[ip + 1] + bc[ip + 2]; ip += 3 + bc[ip + 1]; } break; case 16: if (stack[stack.length - 1] !== peg$FAILED) { ends.push(end); ips.push(ip); end = ip + 2 + bc[ip + 1]; ip += 2; } else { ip += 2 + bc[ip + 1]; } break; case 17: ends.push(end); ips.push(ip + 3 + bc[ip + 1] + bc[ip + 2]); if (input.length > peg$currPos) { end = ip + 3 + bc[ip + 1]; ip += 3; } else { end = ip + 3 + bc[ip + 1] + bc[ip + 2]; ip += 3 + bc[ip + 1]; } break; case 18: ends.push(end); ips.push(ip + 4 + bc[ip + 2] + bc[ip + 3]); if (input.substr(peg$currPos, peg$consts[bc[ip + 1]].length) === peg$consts[bc[ip + 1]]) { end = ip + 4 + bc[ip + 2]; ip += 4; } else { end = ip + 4 + bc[ip + 2] + bc[ip + 3]; ip += 4 + bc[ip + 2]; } break; case 19: ends.push(end); ips.push(ip + 4 + bc[ip + 2] + bc[ip + 3]); if (input.substr(peg$currPos, peg$consts[bc[ip + 1]].length).toLowerCase() === peg$consts[bc[ip + 1]]) { end = ip + 4 + bc[ip + 2]; ip += 4; } else { end = ip + 4 + bc[ip + 2] + bc[ip + 3]; ip += 4 + bc[ip + 2]; } break; case 20: ends.push(end); ips.push(ip + 4 + bc[ip + 2] + bc[ip + 3]); if (peg$consts[bc[ip + 1]].test(input.charAt(peg$currPos))) { end = ip + 4 + bc[ip + 2]; ip += 4; } else { end = ip + 4 + bc[ip + 2] + bc[ip + 3]; ip += 4 + bc[ip + 2]; } break; case 21: stack.push(input.substr(peg$currPos, bc[ip + 1])); peg$currPos += bc[ip + 1]; ip += 2; break; case 22: stack.push(peg$consts[bc[ip + 1]]); peg$currPos += peg$consts[bc[ip + 1]].length; ip += 2; break; case 23: stack.push(peg$FAILED); if (peg$silentFails === 0) { peg$fail(peg$consts[bc[ip + 1]]); } ip += 2; break; case 24: peg$savedPos = stack[stack.length - 1 - bc[ip + 1]]; ip += 2; break; case 25: peg$savedPos = peg$currPos; ip++; break; case 26: params = bc.slice(ip + 4, ip + 4 + bc[ip + 3]); for (i = 0; i < bc[ip + 3]; i++) { params[i] = stack[stack.length - 1 - params[i]]; } stack.splice( stack.length - bc[ip + 2], bc[ip + 2], peg$consts[bc[ip + 1]].apply(null, params) ); ip += 4 + bc[ip + 3]; break; case 27: stack.push(peg$parseRule(bc[ip + 1])); ip += 2; break; case 28: peg$silentFails++; ip++; break; case 29: peg$silentFails--; ip++; break; default: throw new Error("Invalid opcode: " + bc[ip] + "."); } } if (ends.length > 0) { end = ends.pop(); ip = ips.pop(); } else { break; } } return stack[0]; } peg$result = peg$parseRule(peg$startRuleIndex); if (peg$result !== peg$FAILED && peg$currPos === input.length) { return peg$result; } else { if (peg$result !== peg$FAILED && peg$currPos < input.length) { peg$fail({ type: "end", description: "end of input" }); } throw peg$buildException( null, peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) ); } } return { SyntaxError: peg$SyntaxError, parse: peg$parse }; })();