From dba9ed4bf47c349963feda3f836934cd8a1b0c41 Mon Sep 17 00:00:00 2001 From: Brandon Myers Date: Wed, 25 Oct 2017 18:19:37 -0500 Subject: [PATCH 1/2] Fix #57: Allow empty RE sentences. --- src/constants.js | 1 + src/parser.g | 2 + src/parser.js | 2423 ++++++++++++++++++++++++---------------------- 3 files changed, 1280 insertions(+), 1146 deletions(-) diff --git a/src/constants.js b/src/constants.js index b32bbed..6a9118b 100644 --- a/src/constants.js +++ b/src/constants.js @@ -49,6 +49,7 @@ const EVENT = { , TAG: 'tag' , DONE_RET_TAG: 'done_ret_tag' , DONE_TAG: 'done_tag' + , RE: 're' , DATA: 'data' // This is an artifical event, not one from the API }; diff --git a/src/parser.g b/src/parser.g index 1cf1de2..080dde1 100644 --- a/src/parser.g +++ b/src/parser.g @@ -4,8 +4,10 @@ start packet = re s tag:tag data:data+ { return {type: "data", data:data, tag:tag} } + / re s tag:tag { return {type: "re", tag:tag} } / re s data:data+ tag:tag { return {type: "data", data:data, tag:tag} } / re s data:data+ { return {type: "data", data:data} } + / re s { return {type: "re"} } / e:end s {return e} re diff --git a/src/parser.js b/src/parser.js index 5cb1cbe..56a5503 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1,1149 +1,1280 @@ module.exports = /* - * Generated by PEG.js 0.10.0. - * - * http://pegjs.org/ - */ +* 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(expectation) { - return "\"" + literalEscape(expectation.text) + "\""; - }, - - "class": function(expectation) { - var escapedParts = "", - i; - - for (i = 0; i < expectation.parts.length; i++) { - escapedParts += expectation.parts[i] instanceof Array - ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) - : classEscape(expectation.parts[i]); - } - - return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; - }, - - any: function(expectation) { - return "any character"; - }, - - end: function(expectation) { - return "end of input"; - }, - - other: function(expectation) { - return expectation.description; - } - }; - - function hex(ch) { - return ch.charCodeAt(0).toString(16).toUpperCase(); - } - - function literalEscape(s) { - return s - .replace(/\\/g, '\\\\') - .replace(/"/g, '\\"') - .replace(/\0/g, '\\0') - .replace(/\t/g, '\\t') - .replace(/\n/g, '\\n') - .replace(/\r/g, '\\r') - .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) - .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); - } - - function classEscape(s) { - return s - .replace(/\\/g, '\\\\') - .replace(/\]/g, '\\]') - .replace(/\^/g, '\\^') - .replace(/-/g, '\\-') - .replace(/\0/g, '\\0') - .replace(/\t/g, '\\t') - .replace(/\n/g, '\\n') - .replace(/\r/g, '\\r') - .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) - .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); - } - - function describeExpectation(expectation) { - return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); - } - - function describeExpected(expected) { - var descriptions = new Array(expected.length), - i, j; - - for (i = 0; i < expected.length; i++) { - descriptions[i] = describeExpectation(expected[i]); - } - - descriptions.sort(); - - if (descriptions.length > 0) { - for (i = 1, j = 1; i < descriptions.length; i++) { - if (descriptions[i - 1] !== descriptions[i]) { - descriptions[j] = descriptions[i]; - j++; - } - } - descriptions.length = j; - } - - switch (descriptions.length) { - case 1: - return descriptions[0]; - - case 2: - return descriptions[0] + " or " + descriptions[1]; - - default: - return descriptions.slice(0, -1).join(", ") - + ", or " - + descriptions[descriptions.length - 1]; - } - } - - function describeFound(found) { - return found ? "\"" + literalEscape(found) + "\"" : "end of input"; - } - - return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; - }; - - function peg$parse(input, options) { - options = options !== void 0 ? options : {}; - - var peg$FAILED = {}, - - peg$startRuleFunctions = { start: peg$parsestart }, - peg$startRuleFunction = peg$parsestart, - - peg$c0 = function(p) { return p }, - peg$c1 = function(tag, data) { return {type: "data", data:data, tag:tag} }, - peg$c2 = function(data, tag) { return {type: "data", data:data, tag:tag} }, - peg$c3 = function(data) { return {type: "data", data:data} }, - peg$c4 = function(e) {return e}, - peg$c5 = "!re", - peg$c6 = peg$literalExpectation("!re", false), - peg$c7 = function() { return ""}, - peg$c8 = function(id, value) { return {field:id, value:value}}, - peg$c9 = "=", - peg$c10 = peg$literalExpectation("=", false), - peg$c11 = /^[.a-z\-0-9]/, - peg$c12 = peg$classExpectation([".", ["a", "z"], "-", ["0", "9"]], false, false), - peg$c13 = function(id) {return id.join('')}, - peg$c14 = /^[^\r\n\0]/, - peg$c15 = peg$classExpectation(["\r", "\n", "\0"], true, false), - peg$c16 = function(v) {return v.join('')}, - peg$c17 = /^[\r\n\0]/, - peg$c18 = peg$classExpectation(["\r", "\n", "\0"], false, false), - peg$c19 = function(v) {return ''}, - peg$c20 = function(f) {return {type: "fatal", data:f } }, - peg$c21 = function(t) {return t}, - peg$c22 = "!done", - peg$c23 = peg$literalExpectation("!done", false), - peg$c24 = "=ret=", - peg$c25 = peg$literalExpectation("=ret=", false), - peg$c26 = /^[a-z0-9]/, - peg$c27 = peg$classExpectation([["a", "z"], ["0", "9"]], false, false), - peg$c28 = function(ret) {return {type: "done_ret", data:ret.join('')}}, - peg$c29 = function(tag, ret) {return {type: "done_ret", tag: tag, data:ret.join('')}}, - peg$c30 = function(tag) {return {type: "done_tag", tag:tag}}, - peg$c31 = function() {return {type: "done" }}, - peg$c32 = function(tag) {return {type: "tag", tag:tag }}, - peg$c33 = ".tag=", - peg$c34 = peg$literalExpectation(".tag=", false), - peg$c35 = /^[a-zA-Z_\-0-9]/, - peg$c36 = peg$classExpectation([["a", "z"], ["A", "Z"], "_", "-", ["0", "9"]], false, false), - peg$c37 = "!trap", - peg$c38 = peg$literalExpectation("!trap", false), - peg$c39 = function(tag, d) { return {type:"trap", tag:tag, data:d} }, - peg$c40 = function(d) { return {type:"trap", data:d} }, - peg$c41 = "!fatal", - peg$c42 = peg$literalExpectation("!fatal", false), - peg$c43 = function(v) {return v}, - peg$c44 = /^[ \t\r\n\f\0x00]/, - peg$c45 = peg$classExpectation([" ", "\t", "\r", "\n", "\f", "\0", "x", "0", "0"], false, false), - peg$c46 = function() {return ""}, - peg$c47 = /^[^ \t\r\n\f\0x00]/, - peg$c48 = peg$classExpectation([" ", "\t", "\r", "\n", "\f", "\0", "x", "0", "0"], true, false), - peg$c49 = /^[\0x00]/, - peg$c50 = peg$classExpectation(["\0", "x", "0", "0"], false, false), - peg$c51 = /^[:]/, - peg$c52 = peg$classExpectation([":"], 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 peg$SyntaxError(message, null, null, location); - } - - function peg$buildStructuredError(expected, found, location) { - return new peg$SyntaxError( - peg$SyntaxError.buildMessage(expected, found), - expected, - found, - location - ); - } - - function peg$parsestart() { - var s0, s1, s2, s3; - - s0 = peg$currPos; - s1 = peg$parses(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parsepacket(); - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parsepacket(); - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c0(s2); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parsenull(); - } - - return s0; - } - - function peg$parsepacket() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - s1 = peg$parsere(); - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - s3 = peg$parsetag(); - if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parsedata(); - if (s5 !== peg$FAILED) { - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parsedata(); - } - } else { - s4 = peg$FAILED; - } - if (s4 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c1(s3, s4); - 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; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parsere(); - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$parsedata(); - if (s4 !== peg$FAILED) { - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parsedata(); - } - } else { - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - s4 = peg$parsetag(); - if (s4 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c2(s3, s4); - 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; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parsere(); - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$parsedata(); - if (s4 !== peg$FAILED) { - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parsedata(); - } - } else { - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c3(s3); - s0 = s1; - } 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 = peg$parseend(); - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c4(s1); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } - } - } - - return s0; - } - - function peg$parsere() { - var s0, s1; - - s0 = peg$currPos; - if (input.substr(peg$currPos, 3) === peg$c5) { - s1 = peg$c5; - peg$currPos += 3; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c6); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c7(); - } - s0 = s1; - - return s0; - } - - function peg$parsedata() { - var s0, s1, s2, s3; - - s0 = peg$currPos; - s1 = peg$parseidentifier(); - if (s1 !== peg$FAILED) { - s2 = peg$parsevalue(); - if (s2 !== peg$FAILED) { - s3 = peg$parses(); - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c8(s1, s2); - s0 = s1; - } 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$parseidentifier() { - var s0, s1, s2, s3; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 61) { - s1 = peg$c9; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c10); } - } - if (s1 !== peg$FAILED) { - s2 = []; - if (peg$c11.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c12); } - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - if (peg$c11.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c12); } - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 61) { - s3 = peg$c9; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c10); } - } - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c13(s2); - s0 = s1; - } 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$parsevalue() { - var s0, s1, s2; - - s0 = peg$currPos; - s1 = []; - if (peg$c14.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c15); } - } - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - if (peg$c14.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c15); } - } - } - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c16(s1); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (peg$c17.test(input.charAt(peg$currPos))) { - s1 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c18); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c19(s1); - } - s0 = s1; - } - - return s0; - } - - function peg$parseend() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - s1 = peg$parsefatal(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c20(s1); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parsetrap(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c21(s1); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c22) { - s1 = peg$c22; - peg$currPos += 5; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c23); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c24) { - s3 = peg$c24; - peg$currPos += 5; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c25); } - } - if (s3 !== peg$FAILED) { - s4 = []; - if (peg$c26.test(input.charAt(peg$currPos))) { - s5 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c27); } - } - if (s5 !== peg$FAILED) { - while (s5 !== peg$FAILED) { - s4.push(s5); - if (peg$c26.test(input.charAt(peg$currPos))) { - s5 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c27); } - } - } - } else { - s4 = peg$FAILED; - } - if (s4 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c28(s4); - 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; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c22) { - s1 = peg$c22; - peg$currPos += 5; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c23); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - s3 = peg$parsetag(); - if (s3 !== peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c24) { - s4 = peg$c24; - peg$currPos += 5; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c25); } - } - if (s4 !== peg$FAILED) { - s5 = peg$parsens(); - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c29(s3, s5); - 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.substr(peg$currPos, 5) === peg$c22) { - s1 = peg$c22; - peg$currPos += 5; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c23); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - s3 = peg$parsetag(); - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c30(s3); - s0 = s1; - } 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.substr(peg$currPos, 5) === peg$c22) { - s1 = peg$c22; - peg$currPos += 5; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c23); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c31(); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parsetag(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c32(s1); - } - s0 = s1; - } - } - } - } - } - } - - return s0; - } - - function peg$parsetag() { - var s0, s1, s2, s3; - - s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c33) { - s1 = peg$c33; - peg$currPos += 5; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c34); } - } - if (s1 !== peg$FAILED) { - s2 = []; - if (peg$c35.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c36); } - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - if (peg$c35.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c36); } - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s3 = peg$parses(); - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c13(s2); - s0 = s1; - } 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$parsetrap() { - var s0, s1, s2, s3, s4, s5, s6; - - s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c37) { - s1 = peg$c37; - peg$currPos += 5; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c38); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - s3 = peg$parsetag(); - if (s3 !== peg$FAILED) { - s4 = peg$parses(); - if (s4 !== peg$FAILED) { - s5 = []; - s6 = peg$parsedata(); - if (s6 !== peg$FAILED) { - while (s6 !== peg$FAILED) { - s5.push(s6); - s6 = peg$parsedata(); - } - } else { - s5 = peg$FAILED; - } - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c39(s3, s5); - 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.substr(peg$currPos, 5) === peg$c37) { - s1 = peg$c37; - peg$currPos += 5; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c38); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$parsedata(); - if (s4 !== peg$FAILED) { - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parsedata(); - } - } else { - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c40(s3); - s0 = s1; - } 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$parsefatal() { - var s0, s1, s2, s3; - - s0 = peg$currPos; - if (input.substr(peg$currPos, 6) === peg$c41) { - s1 = peg$c41; - peg$currPos += 6; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c42); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parses(); - if (s2 !== peg$FAILED) { - s3 = peg$parsevalue(); - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c43(s3); - s0 = s1; - } 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$parses() { - var s0, s1, s2; - - s0 = peg$currPos; - s1 = []; - if (peg$c44.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c45); } - } - while (s2 !== peg$FAILED) { - s1.push(s2); - if (peg$c44.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c45); } - } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c46(); - } - s0 = s1; - - return s0; - } - - function peg$parsens() { - var s0, s1; - - s0 = []; - if (peg$c47.test(input.charAt(peg$currPos))) { - s1 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } - } - if (s1 !== peg$FAILED) { - while (s1 !== peg$FAILED) { - s0.push(s1); - if (peg$c47.test(input.charAt(peg$currPos))) { - s1 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } - } - } - } else { - s0 = peg$FAILED; - } - - return s0; - } - - function peg$parsenull() { - var s0; - - if (peg$c49.test(input.charAt(peg$currPos))) { - s0 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c50); } - } - - return s0; - } - - function peg$parsecolon() { - var s0; - - if (peg$c51.test(input.charAt(peg$currPos))) { - s0 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s0 = 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 - }; + "use strict"; + + function peg$subclass(child, parent) { + function ctor() { this.constructor = child; } + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + } + + function peg$SyntaxError(message, expected, found, location) { + this.message = message; + this.expected = expected; + this.found = found; + this.location = location; + this.name = "SyntaxError"; + + if (typeof Error.captureStackTrace === "function") { + Error.captureStackTrace(this, peg$SyntaxError); + } + } + + peg$subclass(peg$SyntaxError, Error); + + peg$SyntaxError.buildMessage = function(expected, found) { + var DESCRIBE_EXPECTATION_FNS = { + literal: function(expectation) { + return "\"" + literalEscape(expectation.text) + "\""; + }, + + "class": function(expectation) { + var escapedParts = "", + i; + + for (i = 0; i < expectation.parts.length; i++) { + escapedParts += expectation.parts[i] instanceof Array + ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) + : classEscape(expectation.parts[i]); + } + + return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; + }, + + any: function(expectation) { + return "any character"; + }, + + end: function(expectation) { + return "end of input"; + }, + + other: function(expectation) { + return expectation.description; + } + }; + + function hex(ch) { + return ch.charCodeAt(0).toString(16).toUpperCase(); + } + + function literalEscape(s) { + return s + .replace(/\\/g, '\\\\') + .replace(/"/g, '\\"') + .replace(/\0/g, '\\0') + .replace(/\t/g, '\\t') + .replace(/\n/g, '\\n') + .replace(/\r/g, '\\r') + .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) + .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); + } + + function classEscape(s) { + return s + .replace(/\\/g, '\\\\') + .replace(/\]/g, '\\]') + .replace(/\^/g, '\\^') + .replace(/-/g, '\\-') + .replace(/\0/g, '\\0') + .replace(/\t/g, '\\t') + .replace(/\n/g, '\\n') + .replace(/\r/g, '\\r') + .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) + .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); + } + + function describeExpectation(expectation) { + return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); + } + + function describeExpected(expected) { + var descriptions = new Array(expected.length), + i, j; + + for (i = 0; i < expected.length; i++) { + descriptions[i] = describeExpectation(expected[i]); + } + + descriptions.sort(); + + if (descriptions.length > 0) { + for (i = 1, j = 1; i < descriptions.length; i++) { + if (descriptions[i - 1] !== descriptions[i]) { + descriptions[j] = descriptions[i]; + j++; + } + } + descriptions.length = j; + } + + switch (descriptions.length) { + case 1: + return descriptions[0]; + + case 2: + return descriptions[0] + " or " + descriptions[1]; + + default: + return descriptions.slice(0, -1).join(", ") + + ", or " + + descriptions[descriptions.length - 1]; + } + } + + function describeFound(found) { + return found ? "\"" + literalEscape(found) + "\"" : "end of input"; + } + + return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; + }; + + function peg$parse(input, options) { + options = options !== void 0 ? options : {}; + + var peg$FAILED = {}, + + peg$startRuleFunctions = { start: peg$parsestart }, + peg$startRuleFunction = peg$parsestart, + + peg$c0 = function(p) { return p }, + peg$c1 = function(tag, data) { return {type: "data", data:data, tag:tag} }, + peg$c2 = function(tag) { return {type: "re", tag:tag} }, + peg$c3 = function(data, tag) { return {type: "data", data:data, tag:tag} }, + peg$c4 = function(data) { return {type: "data", data:data} }, + peg$c5 = function() { return {type: "re"} }, + peg$c6 = function(e) {return e}, + peg$c7 = "!re", + peg$c8 = peg$literalExpectation("!re", false), + peg$c9 = function() { return ""}, + peg$c10 = function(id, value) { return {field:id, value:value}}, + peg$c11 = "=", + peg$c12 = peg$literalExpectation("=", false), + peg$c13 = /^[.a-z\-0-9]/, + peg$c14 = peg$classExpectation([".", ["a", "z"], "-", ["0", "9"]], false, false), + peg$c15 = function(id) {return id.join('')}, + peg$c16 = /^[^\r\n\0]/, + peg$c17 = peg$classExpectation(["\r", "\n", "\0"], true, false), + peg$c18 = function(v) {return v.join('')}, + peg$c19 = /^[\r\n\0]/, + peg$c20 = peg$classExpectation(["\r", "\n", "\0"], false, false), + peg$c21 = function(v) {return ''}, + peg$c22 = function(f) {return {type: "fatal", data:f } }, + peg$c23 = function(t) {return t}, + peg$c24 = "!done", + peg$c25 = peg$literalExpectation("!done", false), + peg$c26 = "=ret=", + peg$c27 = peg$literalExpectation("=ret=", false), + peg$c28 = /^[a-z0-9]/, + peg$c29 = peg$classExpectation([["a", "z"], ["0", "9"]], false, false), + peg$c30 = function(ret) {return {type: "done_ret", data:ret.join('')}}, + peg$c31 = function(tag, ret) {return {type: "done_ret", tag: tag, data:ret.join('')}}, + peg$c32 = function(tag) {return {type: "done_tag", tag:tag}}, + peg$c33 = function() {return {type: "done" }}, + peg$c34 = function(tag) {return {type: "tag", tag:tag }}, + peg$c35 = ".tag=", + peg$c36 = peg$literalExpectation(".tag=", false), + peg$c37 = /^[a-zA-Z_\-0-9]/, + peg$c38 = peg$classExpectation([["a", "z"], ["A", "Z"], "_", "-", ["0", "9"]], false, false), + peg$c39 = /^[0-9]/, + peg$c40 = peg$classExpectation([["0", "9"]], false, false), + peg$c41 = function(id, subid) {return id.join('')+":"+subid.join('')}, + peg$c42 = "!trap", + peg$c43 = peg$literalExpectation("!trap", false), + peg$c44 = function(tag, d) { return {type:"trap", tag:tag, data:d} }, + peg$c45 = function(d) { return {type:"trap", data:d} }, + peg$c46 = "!fatal", + peg$c47 = peg$literalExpectation("!fatal", false), + peg$c48 = function(v) {return v}, + peg$c49 = /^[ \t\r\n\f\0x00]/, + peg$c50 = peg$classExpectation([" ", "\t", "\r", "\n", "\f", "\0", "x", "0", "0"], false, false), + peg$c51 = function() {return ""}, + peg$c52 = /^[^ \t\r\n\f\0x00]/, + peg$c53 = peg$classExpectation([" ", "\t", "\r", "\n", "\f", "\0", "x", "0", "0"], true, false), + peg$c54 = /^[\0x00]/, + peg$c55 = peg$classExpectation(["\0", "x", "0", "0"], false, false), + peg$c56 = /^[:]/, + peg$c57 = peg$classExpectation([":"], 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 peg$SyntaxError(message, null, null, location); + } + + function peg$buildStructuredError(expected, found, location) { + return new peg$SyntaxError( + peg$SyntaxError.buildMessage(expected, found), + expected, + found, + location + ); + } + + function peg$parsestart() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + s1 = peg$parses(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parsepacket(); + if (s3 !== peg$FAILED) { + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parsepacket(); + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c0(s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + if (s0 === peg$FAILED) { + s0 = peg$parsenull(); + } + + return s0; + } + + function peg$parsepacket() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + s1 = peg$parsere(); + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = peg$parsetag(); + if (s3 !== peg$FAILED) { + s4 = []; + s5 = peg$parsedata(); + if (s5 !== peg$FAILED) { + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parsedata(); + } + } else { + s4 = peg$FAILED; + } + if (s4 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c1(s3, s4); + 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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parsere(); + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = peg$parsetag(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c2(s3); + s0 = s1; + } 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 = peg$parsere(); + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = []; + s4 = peg$parsedata(); + if (s4 !== peg$FAILED) { + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parsedata(); + } + } else { + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + s4 = peg$parsetag(); + if (s4 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c3(s3, s4); + 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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parsere(); + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = []; + s4 = peg$parsedata(); + if (s4 !== peg$FAILED) { + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parsedata(); + } + } else { + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c4(s3); + s0 = s1; + } 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 = peg$parsere(); + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c5(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseend(); + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c6(s1); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } + } + } + } + } + + return s0; + } + + function peg$parsere() { + var s0, s1; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 3) === peg$c7) { + s1 = peg$c7; + peg$currPos += 3; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c8); } + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c9(); + } + s0 = s1; + + return s0; + } + + function peg$parsedata() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + s1 = peg$parseidentifier(); + if (s1 !== peg$FAILED) { + s2 = peg$parsevalue(); + if (s2 !== peg$FAILED) { + s3 = peg$parses(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c10(s1, s2); + s0 = s1; + } 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$parseidentifier() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 61) { + s1 = peg$c11; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c12); } + } + if (s1 !== peg$FAILED) { + s2 = []; + if (peg$c13.test(input.charAt(peg$currPos))) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c14); } + } + if (s3 !== peg$FAILED) { + while (s3 !== peg$FAILED) { + s2.push(s3); + if (peg$c13.test(input.charAt(peg$currPos))) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c14); } + } + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 61) { + s3 = peg$c11; + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c12); } + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c15(s2); + s0 = s1; + } 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$parsevalue() { + var s0, s1, s2; + + s0 = peg$currPos; + s1 = []; + if (peg$c16.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c17); } + } + if (s2 !== peg$FAILED) { + while (s2 !== peg$FAILED) { + s1.push(s2); + if (peg$c16.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c17); } + } + } + } else { + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c18(s1); + } + s0 = s1; + if (s0 === peg$FAILED) { + s0 = peg$currPos; + if (peg$c19.test(input.charAt(peg$currPos))) { + s1 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c20); } + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c21(s1); + } + s0 = s1; + } + + return s0; + } + + function peg$parseend() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + s1 = peg$parsefatal(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c22(s1); + } + s0 = s1; + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parsetrap(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c23(s1); + } + s0 = s1; + if (s0 === peg$FAILED) { + s0 = peg$currPos; + if (input.substr(peg$currPos, 5) === peg$c24) { + s1 = peg$c24; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c25); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + if (input.substr(peg$currPos, 5) === peg$c26) { + s3 = peg$c26; + peg$currPos += 5; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c27); } + } + if (s3 !== peg$FAILED) { + s4 = []; + if (peg$c28.test(input.charAt(peg$currPos))) { + s5 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c29); } + } + if (s5 !== peg$FAILED) { + while (s5 !== peg$FAILED) { + s4.push(s5); + if (peg$c28.test(input.charAt(peg$currPos))) { + s5 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c29); } + } + } + } else { + s4 = peg$FAILED; + } + if (s4 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c30(s4); + 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; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + if (input.substr(peg$currPos, 5) === peg$c24) { + s1 = peg$c24; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c25); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = peg$parsetag(); + if (s3 !== peg$FAILED) { + if (input.substr(peg$currPos, 5) === peg$c26) { + s4 = peg$c26; + peg$currPos += 5; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c27); } + } + if (s4 !== peg$FAILED) { + s5 = peg$parsens(); + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c31(s3, s5); + 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.substr(peg$currPos, 5) === peg$c24) { + s1 = peg$c24; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c25); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = peg$parsetag(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c32(s3); + s0 = s1; + } 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.substr(peg$currPos, 5) === peg$c24) { + s1 = peg$c24; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c25); } + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c33(); + } + s0 = s1; + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parsetag(); + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c34(s1); + } + s0 = s1; + } + } + } + } + } + } + + return s0; + } + + function peg$parsetag() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 5) === peg$c35) { + s1 = peg$c35; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c36); } + } + if (s1 !== peg$FAILED) { + s2 = []; + 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) { + while (s3 !== peg$FAILED) { + s2.push(s3); + 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); } + } + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + s3 = peg$parsecolon(); + if (s3 !== peg$FAILED) { + s4 = []; + if (peg$c39.test(input.charAt(peg$currPos))) { + s5 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c40); } + } + if (s5 !== peg$FAILED) { + while (s5 !== peg$FAILED) { + s4.push(s5); + if (peg$c39.test(input.charAt(peg$currPos))) { + s5 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c40); } + } + } + } else { + s4 = peg$FAILED; + } + if (s4 !== peg$FAILED) { + s5 = peg$parses(); + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c41(s2, s4); + 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.substr(peg$currPos, 5) === peg$c35) { + s1 = peg$c35; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c36); } + } + if (s1 !== peg$FAILED) { + s2 = []; + 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) { + while (s3 !== peg$FAILED) { + s2.push(s3); + 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); } + } + } + } else { + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + s3 = peg$parses(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c15(s2); + s0 = s1; + } 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$parsetrap() { + var s0, s1, s2, s3, s4, s5, s6; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 5) === peg$c42) { + s1 = peg$c42; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c43); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = peg$parsetag(); + if (s3 !== peg$FAILED) { + s4 = peg$parses(); + if (s4 !== peg$FAILED) { + s5 = []; + s6 = peg$parsedata(); + if (s6 !== peg$FAILED) { + while (s6 !== peg$FAILED) { + s5.push(s6); + s6 = peg$parsedata(); + } + } else { + s5 = peg$FAILED; + } + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c44(s3, s5); + 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.substr(peg$currPos, 5) === peg$c42) { + s1 = peg$c42; + peg$currPos += 5; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c43); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = []; + s4 = peg$parsedata(); + if (s4 !== peg$FAILED) { + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parsedata(); + } + } else { + s3 = peg$FAILED; + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c45(s3); + s0 = s1; + } 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$parsefatal() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 6) === peg$c46) { + s1 = peg$c46; + peg$currPos += 6; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c47); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parses(); + if (s2 !== peg$FAILED) { + s3 = peg$parsevalue(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c48(s3); + s0 = s1; + } 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$parses() { + var s0, s1, s2; + + s0 = peg$currPos; + s1 = []; + if (peg$c49.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c50); } + } + while (s2 !== peg$FAILED) { + s1.push(s2); + if (peg$c49.test(input.charAt(peg$currPos))) { + s2 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c50); } + } + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c51(); + } + s0 = s1; + + return s0; + } + + function peg$parsens() { + var s0, s1; + + s0 = []; + if (peg$c52.test(input.charAt(peg$currPos))) { + s1 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c53); } + } + if (s1 !== peg$FAILED) { + while (s1 !== peg$FAILED) { + s0.push(s1); + if (peg$c52.test(input.charAt(peg$currPos))) { + s1 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c53); } + } + } + } else { + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parsenull() { + var s0; + + if (peg$c54.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c55); } + } + + return s0; + } + + function peg$parsecolon() { + var s0; + + if (peg$c56.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c57); } + } + + 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 + }; })(); From 289d6300c6e293a01884aef8b0be5eabdf9a5b6f Mon Sep 17 00:00:00 2001 From: Brandon Myers Date: Wed, 25 Oct 2017 18:19:53 -0500 Subject: [PATCH 2/2] Update version. --- .npmignore | 9 +++++++-- package.json | 5 ++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.npmignore b/.npmignore index b834a45..aab8808 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,12 @@ -node_modules npm-debug.log +.vscode examples -test +node_modules src +test webpack.config.babel.js .babelrc +.eslintrc.json +.npmignore +constants.js +jsconfig.json diff --git a/package.json b/package.json index 805e463..284a1c4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mikronode", "description": "Mikrotik API implemented in Node", - "version": "2.3.4", + "version": "2.3.5", "author": "Brandon Myers ", "scripts": { "build": "webpack --color --progress", @@ -39,8 +39,6 @@ "babel-preset-stage-1": "^6.5.0", "babel-register": "^6.24.1", "chai": "^3.5.0", - "change-emitter": "^0.1.2", - "core-decorators": "^0.12.3", "mocha": ">=1.7.4", "simple-assign": "^0.1.0", "uglify-js": ">=1.2.5", @@ -48,6 +46,7 @@ "webpack-dev-server": "^1.15.0" }, "dependencies": { + "core-decorators": "^0.12.3", "rxjs": "^5.3.0" }, "main": "dist/mikronode.js",