UNPKG

ca-highway-conditions-parser

Version:

A library that parses the highway conditions format into JSON

1,446 lines (1,345 loc) 38.6 kB
'use strict'; var toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; var Parser = /* * Generated by PEG.js 0.10.0. * * http://pegjs.org/ */ (function () { "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 literal(expectation) { return "\"" + literalEscape(expectation.text) + "\""; }, "class": function _class(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 any(expectation) { return "any character"; }, end: function end(expectation) { return "end of input"; }, other: function other(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 = { File: peg$parseFile }, peg$startRuleFunction = peg$parseFile, peg$c0 = peg$otherExpectation("File"), peg$c1 = function peg$c1(parts) { return parts.filter(Boolean); }, peg$c2 = peg$otherExpectation("Notice"), peg$c3 = function peg$c3(highway, title, messages) { return { title: title, messages: messages.reduce(function (state, message) { return state.concat(message); }, []) }; }, peg$c4 = function peg$c4(highway, notices) { return Object.assign({}, highway, { notices: notices }); }, peg$c5 = peg$otherExpectation("Highway"), peg$c6 = /^[A-Z]/, peg$c7 = peg$classExpectation([["A", "Z"]], false, false), peg$c8 = /^[0-9]/, peg$c9 = peg$classExpectation([["0", "9"]], false, false), peg$c10 = function peg$c10(type, highway) { return { type: type, highway: highway }; }, peg$c11 = peg$otherExpectation("Title"), peg$c12 = "[", peg$c13 = peg$literalExpectation("[", false), peg$c14 = "]", peg$c15 = peg$literalExpectation("]", false), peg$c16 = function peg$c16(title) { return title; }, peg$c17 = peg$otherExpectation("Message"), peg$c18 = function peg$c18(start, lines) { return lines.concat('\n\n').join(' '); }, peg$c19 = function peg$c19(start, rest) { return [start].concat(toConsumableArray(rest)).join(' ').split('\n\n').map(function (s) { return s.trim(); }).filter(Boolean); }, peg$c20 = peg$otherExpectation("MessageStart"), peg$c21 = function peg$c21(message) { return message.trim(); }, peg$c22 = peg$otherExpectation("MessageLine"), peg$c23 = peg$otherExpectation("BlankLine"), peg$c24 = function peg$c24() { return '\n'; }, peg$c25 = peg$otherExpectation("EOL"), peg$c26 = /^[\r]/, peg$c27 = peg$classExpectation(["\r"], false, false), peg$c28 = /^[\n]/, peg$c29 = peg$classExpectation(["\n"], false, false), peg$c30 = peg$otherExpectation("Text"), peg$c31 = peg$otherExpectation("Character"), peg$c32 = /^[A-Z0-9]/, peg$c33 = peg$classExpectation([["A", "Z"], ["0", "9"]], false, false), peg$c34 = /^[.\/\\\-?(),&'";{}@#!$%\^*=+:|><~`]/, peg$c35 = peg$classExpectation([".", "/", "\\", "-", "?", "(", ")", ",", "&", "'", "\"", ";", "{", "}", "@", "#", "!", "$", "%", "^", "*", "=", "+", ":", "|", ">", "<", "~", "`"], false, false), peg$c36 = "<", peg$c37 = peg$literalExpectation("<", false), peg$c38 = /^[a-z]/, peg$c39 = peg$classExpectation([["a", "z"]], false, false), peg$c40 = ">", peg$c41 = peg$literalExpectation(">", false), peg$c42 = function peg$c42() { return null; }, peg$c43 = "/", peg$c44 = peg$literalExpectation("/", false), peg$c45 = "=", peg$c46 = peg$literalExpectation("=", false), peg$c47 = "\"", peg$c48 = peg$literalExpectation("\"", false), peg$c49 = peg$otherExpectation("Space"), peg$c50 = /^[ ]/, peg$c51 = peg$classExpectation([" "], false, false), peg$c52 = peg$otherExpectation("Whitespace"), peg$c53 = /^[ \t\n\r]/, peg$c54 = peg$classExpectation([" ", "\t", "\n", "\r"], 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 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$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$buildStructuredError(expected, found, location) { return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location); } function peg$parseFile() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; s1 = peg$parse_(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parseHTML(); if (s3 === peg$FAILED) { s3 = peg$parseNotice(); if (s3 === peg$FAILED) { s3 = peg$parseBlankLine(); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseHTML(); if (s3 === peg$FAILED) { s3 = peg$parseNotice(); if (s3 === peg$FAILED) { s3 = peg$parseBlankLine(); } } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c1(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c0); } } return s0; } function peg$parseNotice() { var s0, s1, s2, s3, s4, s5, s6; peg$silentFails++; s0 = peg$currPos; s1 = peg$parseHighway(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parseTitle(); if (s4 !== peg$FAILED) { s5 = []; s6 = peg$parseMessage(); if (s6 !== peg$FAILED) { while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parseMessage(); } } else { s5 = peg$FAILED; } if (s5 !== peg$FAILED) { peg$savedPos = s3; s4 = peg$c3(s1, s4, s5); s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parseTitle(); if (s4 !== peg$FAILED) { s5 = []; s6 = peg$parseMessage(); if (s6 !== peg$FAILED) { while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parseMessage(); } } else { s5 = peg$FAILED; } if (s5 !== peg$FAILED) { peg$savedPos = s3; s4 = peg$c3(s1, s4, s5); s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c4(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c2); } } return s0; } function peg$parseHighway() { var s0, s1, s2, s3, s4, s5; peg$silentFails++; s0 = peg$currPos; s1 = peg$currPos; s2 = []; if (peg$c6.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); if (peg$c6.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parseSpace(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseSpace(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$currPos; s4 = []; if (peg$c8.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c9); } } if (s5 !== peg$FAILED) { while (s5 !== peg$FAILED) { s4.push(s5); if (peg$c8.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c9); } } } } else { s4 = peg$FAILED; } if (s4 !== peg$FAILED) { s3 = input.substring(s3, peg$currPos); } else { s3 = s4; } if (s3 !== peg$FAILED) { s4 = peg$parseEOL(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c10(s1, s3); 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; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c5); } } return s0; } function peg$parseTitle() { var s0, s1, s2, s3, s4, s5; peg$silentFails++; s0 = peg$currPos; s1 = []; s2 = peg$parseSpace(); if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseSpace(); } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 91) { s2 = peg$c12; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s2 !== peg$FAILED) { s3 = peg$currPos; s4 = []; s5 = peg$parseText(); if (s5 !== peg$FAILED) { while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parseText(); } } else { s4 = peg$FAILED; } if (s4 !== peg$FAILED) { s3 = input.substring(s3, peg$currPos); } else { s3 = s4; } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { s4 = peg$c14; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c15); } } if (s4 !== peg$FAILED) { s5 = peg$parseEOL(); if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c16(s3); 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; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } return s0; } function peg$parseMessage() { var s0, s1, s2, s3, s4, s5; peg$silentFails++; s0 = peg$currPos; s1 = peg$parseMessageStart(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = []; s5 = peg$parseMessageLine(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parseMessageLine(); } if (s4 !== peg$FAILED) { s5 = peg$parseBlankLine(); if (s5 !== peg$FAILED) { peg$savedPos = s3; s4 = peg$c18(s1, s4); s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = []; s5 = peg$parseMessageLine(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parseMessageLine(); } if (s4 !== peg$FAILED) { s5 = peg$parseBlankLine(); if (s5 !== peg$FAILED) { peg$savedPos = s3; s4 = peg$c18(s1, s4); s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c19(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c17); } } return s0; } function peg$parseMessageStart() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; s1 = []; s2 = peg$parseSpace(); if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseSpace(); } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = peg$parseMessageLine(); if (s3 !== peg$FAILED) { s2 = input.substring(s2, peg$currPos); } else { s2 = s3; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c21(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c20); } } return s0; } function peg$parseMessageLine() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; s1 = peg$currPos; s2 = []; s3 = peg$parseText(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseText(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { s2 = peg$parseEOL(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c21(s1); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c22); } } return s0; } function peg$parseBlankLine() { var s0, s1; peg$silentFails++; s0 = peg$currPos; s1 = peg$parseEOL(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c24(); } s0 = s1; peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } return s0; } function peg$parseEOL() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; s1 = []; s2 = peg$parseSpace(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseSpace(); } if (s1 !== peg$FAILED) { if (peg$c26.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c27); } } if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { if (peg$c28.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c29); } } if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c25); } } return s0; } function peg$parseText() { var s0, s1, s2, s3, s4; peg$silentFails++; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$parseCharacter(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parseSpace(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parseSpace(); } 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) { s0 = input.substring(s0, peg$currPos); } else { s0 = s1; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c30); } } return s0; } function peg$parseCharacter() { var s0, s1; peg$silentFails++; if (peg$c32.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c33); } } if (s0 === peg$FAILED) { if (peg$c34.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c35); } } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c31); } } return s0; } function peg$parseHTML() { var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { s1 = peg$c36; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c37); } } if (s1 !== peg$FAILED) { s2 = []; if (peg$c38.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); if (peg$c38.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$currPos; s5 = []; s6 = peg$parseSpace(); if (s6 !== peg$FAILED) { while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parseSpace(); } } else { s5 = peg$FAILED; } if (s5 !== peg$FAILED) { s6 = peg$parseAttribute(); if (s6 !== peg$FAILED) { s5 = [s5, s6]; s4 = s5; } else { peg$currPos = s4; s4 = peg$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$currPos; s5 = []; s6 = peg$parseSpace(); if (s6 !== peg$FAILED) { while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parseSpace(); } } else { s5 = peg$FAILED; } if (s5 !== peg$FAILED) { s6 = peg$parseAttribute(); if (s6 !== peg$FAILED) { s5 = [s5, s6]; s4 = s5; } else { peg$currPos = s4; s4 = peg$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 62) { s4 = peg$c40; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c42(); 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; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { s1 = peg$c36; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c37); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 47) { s2 = peg$c43; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c44); } } if (s2 !== peg$FAILED) { s3 = []; if (peg$c38.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } if (s4 !== peg$FAILED) { while (s4 !== peg$FAILED) { s3.push(s4); if (peg$c38.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } } } else { s3 = peg$FAILED; } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 62) { s4 = peg$c40; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c42(); 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; } } return s0; } function peg$parseAttribute() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; s1 = []; if (peg$c38.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); if (peg$c38.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { s2 = peg$parseSpace(); if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 61) { s3 = peg$c45; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s3 !== peg$FAILED) { s4 = peg$parseSpace(); if (s4 === peg$FAILED) { s4 = null; } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { s5 = peg$c47; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s5 !== peg$FAILED) { s6 = []; if (peg$c38.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } if (s7 !== peg$FAILED) { while (s7 !== peg$FAILED) { s6.push(s7); if (peg$c38.test(input.charAt(peg$currPos))) { s7 = input.charAt(peg$currPos); peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } } } else { s6 = peg$FAILED; } if (s6 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { s7 = peg$c47; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s7 !== peg$FAILED) { s1 = [s1, s2, s3, s4, s5, s6, s7]; 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; } return s0; } function peg$parseSpace() { var s0, s1; peg$silentFails++; if (peg$c50.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c51); } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c49); } } return s0; } function peg$parse_() { var s0, s1; peg$silentFails++; s0 = []; if (peg$c53.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } while (s1 !== peg$FAILED) { s0.push(s1); if (peg$c53.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c52); } } return s0; } peg$result = peg$startRuleFunction(); if (peg$result !== peg$FAILED && peg$currPos === input.length) { return peg$result; } else { if (peg$result !== peg$FAILED && peg$currPos < input.length) { peg$fail(peg$endExpectation()); } throw peg$buildStructuredError(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 }; })(); var index = (function (input, options) { return new Promise(function (resolve, reject) { var cleanInput = input && input.replace(/\r/g, ''); if (!cleanInput || !cleanInput.replace(/[\s]/g, '')) { return reject('No data found'); } try { return resolve(Parser.parse(cleanInput)); } catch (e) { return reject('Failed to parse road conditions'); } }); }); module.exports = index; //# sourceMappingURL=index.speed.js.map