/* Copyright (c) 2013-2015 Richard Rodger, MIT License, https://github.com/rjrodger/jsonic */ "use strict"; /* TODO: if number fails, assume it's just a string, might be an identifier of some kindTODO: upgrade to pegjs 0.8 */ ;(function() { var root = this var previous_jsonic = root.jsonic var has_require = typeof require !== 'undefined' var jsonic = root.jsonic = function(src) { if( Object.prototype.toString.call(src) !== '[object String]' ) { if( !Object.prototype.toString.call(src).match(/\[object (Object|Array)\]/) ) { //throw new Error( "Not an object, array or string: "+src ) return ''+src; } else return src; } src = src.trim(); if( '{' != src[0] && '[' != src[0] ) { src = '{'+src+'}'; } return jsonic_parser.parse( src ); } jsonic.noConflict = function() { root.jsonic = previous_jsonic; return jsonic; } var jsonic_parser = (function() { /* * Generated by PEG.js 0.8.0. * * http://pegjs.majda.cz/ */ function peg$subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); } function SyntaxError(message, expected, found, offset, line, column) { this.message = message; this.expected = expected; this.found = found; this.offset = offset; this.line = line; this.column = column; this.name = "SyntaxError"; } peg$subclass(SyntaxError, Error); function parse(input) { var options = arguments.length > 1 ? arguments[1] : {}, peg$FAILED = {}, peg$startRuleFunctions = { start: peg$parsestart }, peg$startRuleFunction = peg$parsestart, peg$c0 = peg$FAILED, peg$c1 = function(object) { return object; }, peg$c2 = function(array) { return array; }, peg$c3 = "{", peg$c4 = { type: "literal", value: "{", description: "\"{\"" }, peg$c5 = "}", peg$c6 = { type: "literal", value: "}", description: "\"}\"" }, peg$c7 = function() { return {}; }, peg$c8 = function(members) { return members; }, peg$c9 = null, peg$c10 = ",", peg$c11 = { type: "literal", value: ",", description: "\",\"" }, peg$c12 = [], peg$c13 = function(head, tail) { var result = {}; if( head ) { result[head[0]] = fixNull(head[1]); } for (var i = 0; i < tail.length; i++) { result[tail[i][2][0]] = fixNull(tail[i][2][1]); } return result; }, peg$c14 = ":", peg$c15 = { type: "literal", value: ":", description: "\":\"" }, peg$c16 = function(name, value) { return [name, value]; }, peg$c17 = "[", peg$c18 = { type: "literal", value: "[", description: "\"[\"" }, peg$c19 = "]", peg$c20 = { type: "literal", value: "]", description: "\"]\"" }, peg$c21 = function() { return []; }, peg$c22 = function(elements) { return elements; }, peg$c23 = function(head, tail) { var result = []; if( typeof head !== 'undefined' && head !== null ) { result.push( fixNull(head) ) } for (var i = 0; i < tail.length; i++) { result.push(fixNull(tail[i][2])); } return result; }, peg$c24 = "true", peg$c25 = { type: "literal", value: "true", description: "\"true\"" }, peg$c26 = function() { return true; }, peg$c27 = "false", peg$c28 = { type: "literal", value: "false", description: "\"false\"" }, peg$c29 = function() { return false; }, peg$c30 = "null", peg$c31 = { type: "literal", value: "null", description: "\"null\"" }, peg$c32 = function() { return null_; }, peg$c33 = function(lit) { return lit.join('').trim() }, peg$c34 = { type: "other", description: "double-quote string" }, peg$c35 = "\"", peg$c36 = { type: "literal", value: "\"", description: "\"\\\"\"" }, peg$c37 = function() { return ""; }, peg$c38 = function(chars) { return chars; }, peg$c39 = { type: "other", description: "single-quote string" }, peg$c40 = "'", peg$c41 = { type: "literal", value: "'", description: "\"'\"" }, peg$c42 = function(chars) { return chars.join(""); }, peg$c43 = /^[^"\\\0-\x1F]/, peg$c44 = { type: "class", value: "[^\"\\\\\\0-\\x1F]", description: "[^\"\\\\\\0-\\x1F]" }, peg$c45 = "\\\"", peg$c46 = { type: "literal", value: "\\\"", description: "\"\\\\\\\"\"" }, peg$c47 = function() { return '"'; }, peg$c48 = "\\\\", peg$c49 = { type: "literal", value: "\\\\", description: "\"\\\\\\\\\"" }, peg$c50 = function() { return "\\"; }, peg$c51 = "\\/", peg$c52 = { type: "literal", value: "\\/", description: "\"\\\\/\"" }, peg$c53 = function() { return "/"; }, peg$c54 = "\\b", peg$c55 = { type: "literal", value: "\\b", description: "\"\\\\b\"" }, peg$c56 = function() { return "\b"; }, peg$c57 = "\\f", peg$c58 = { type: "literal", value: "\\f", description: "\"\\\\f\"" }, peg$c59 = function() { return "\f"; }, peg$c60 = "\\n", peg$c61 = { type: "literal", value: "\\n", description: "\"\\\\n\"" }, peg$c62 = function() { return "\n"; }, peg$c63 = "\\r", peg$c64 = { type: "literal", value: "\\r", description: "\"\\\\r\"" }, peg$c65 = function() { return "\r"; }, peg$c66 = "\\t", peg$c67 = { type: "literal", value: "\\t", description: "\"\\\\t\"" }, peg$c68 = function() { return "\t"; }, peg$c69 = "\\u", peg$c70 = { type: "literal", value: "\\u", description: "\"\\\\u\"" }, peg$c71 = function(h1, h2, h3, h4) { return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4)); }, peg$c72 = /^[^'\\\0-\x1F]/, peg$c73 = { type: "class", value: "[^'\\\\\\0-\\x1F]", description: "[^'\\\\\\0-\\x1F]" }, peg$c74 = "\\'", peg$c75 = { type: "literal", value: "\\'", description: "\"\\\\'\"" }, peg$c76 = function() { return '\''; }, peg$c77 = { type: "other", description: "key" }, peg$c78 = /^[a-zA-Z0-9_$\-]/, peg$c79 = { type: "class", value: "[a-zA-Z0-9_$\\-]", description: "[a-zA-Z0-9_$\\-]" }, peg$c80 = function(chars) { return chars.join('') }, peg$c81 = /^[^,}\]]/, peg$c82 = { type: "class", value: "[^,}\\]]", description: "[^,}\\]]" }, peg$c83 = { type: "other", description: "number" }, peg$c84 = function(int_, frac, exp, suffix) { return 0 === suffix.length ? parseFloat(int_ + frac + exp) : (int_ + frac + exp + suffix.join('')).trim(); }, peg$c85 = function(int_, frac, suffix) { return 0 === suffix.length ? parseFloat(int_ + frac) : (int_ + frac + suffix.join('')).trim(); }, peg$c86 = function(int_, exp, suffix) { return 0 === suffix.length ? parseFloat(int_ + exp) : (int_ + exp + suffix.join('')).trim(); }, peg$c87 = function(int_, suffix) { return 0 === suffix.length ? parseFloat(int_) : (int_ + suffix.join('')).trim(); }, peg$c88 = function(digit19, digits) { return digit19 + digits; }, peg$c89 = "-", peg$c90 = { type: "literal", value: "-", description: "\"-\"" }, peg$c91 = function(digit19, digits) { return "-" + digit19 + digits; }, peg$c92 = function(digit) { return "-" + digit; }, peg$c93 = ".", peg$c94 = { type: "literal", value: ".", description: "\".\"" }, peg$c95 = function(digits) { return "." + digits; }, peg$c96 = function(e, digits) { return e + digits; }, peg$c97 = function(digits) { return digits.join(""); }, peg$c98 = /^[eE]/, peg$c99 = { type: "class", value: "[eE]", description: "[eE]" }, peg$c100 = /^[+\-]/, peg$c101 = { type: "class", value: "[+\\-]", description: "[+\\-]" }, peg$c102 = function(e, sign) { return e + (sign?sign:''); }, peg$c103 = /^[0-9]/, peg$c104 = { type: "class", value: "[0-9]", description: "[0-9]" }, peg$c105 = /^[1-9]/, peg$c106 = { type: "class", value: "[1-9]", description: "[1-9]" }, peg$c107 = /^[0-9a-fA-F]/, peg$c108 = { type: "class", value: "[0-9a-fA-F]", description: "[0-9a-fA-F]" }, peg$c109 = { type: "other", description: "whitespace" }, peg$c110 = /^[ \t\n\r]/, peg$c111 = { type: "class", value: "[ \\t\\n\\r]", description: "[ \\t\\n\\r]" }, peg$currPos = 0, peg$reportedPos = 0, peg$cachedPos = 0, peg$cachedPosDetails = { 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$startRuleFunctions)) { throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; } function text() { return input.substring(peg$reportedPos, peg$currPos); } function offset() { return peg$reportedPos; } function line() { return peg$computePosDetails(peg$reportedPos).line; } function column() { return peg$computePosDetails(peg$reportedPos).column; } function expected(description) { throw peg$buildException( null, [{ type: "other", description: description }], peg$reportedPos ); } function error(message) { throw peg$buildException(message, null, peg$reportedPos); } function peg$computePosDetails(pos) { function advance(details, startPos, endPos) { var p, ch; for (p = startPos; p < endPos; p++) { 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; } } } if (peg$cachedPos !== pos) { if (peg$cachedPos > pos) { peg$cachedPos = 0; peg$cachedPosDetails = { line: 1, column: 1, seenCR: false }; } advance(peg$cachedPosDetails, peg$cachedPos, pos); peg$cachedPos = pos; } return peg$cachedPosDetails; } 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, pos) { 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(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); }) .replace(/[\u1080-\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."; } var posDetails = peg$computePosDetails(pos), found = pos < input.length ? input.charAt(pos) : null; if (expected !== null) { cleanupExpected(expected); } return new SyntaxError( message !== null ? message : buildMessage(expected, found), expected, found, pos, posDetails.line, posDetails.column ); } function peg$parsestart() { var s0, s1, s2; s0 = peg$currPos; s1 = peg$parse_(); if (s1 !== peg$FAILED) { s2 = peg$parseobject(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c1(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parse_(); if (s1 !== peg$FAILED) { s2 = peg$parsearray(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c2(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } return s0; } function peg$parseobject() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 123) { s1 = peg$c3; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { s3 = peg$c5; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c6); } } if (s3 !== peg$FAILED) { s4 = peg$parse_(); if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c7(); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 123) { s1 = peg$c3; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { s3 = peg$parsemembers(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { s4 = peg$c5; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c6); } } if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c8(s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } return s0; } function peg$parsemembers() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s1 = peg$c10; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s1 === peg$FAILED) { s1 = peg$c9; } if (s1 !== peg$FAILED) { s2 = peg$parsepair(); if (s2 === peg$FAILED) { s2 = peg$c9; } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c10; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s5 !== peg$FAILED) { s6 = peg$parse_(); if (s6 !== peg$FAILED) { s7 = peg$parsepair(); if (s7 !== peg$FAILED) { s5 = [s5, s6, s7]; s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c10; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s5 !== peg$FAILED) { s6 = peg$parse_(); if (s6 !== peg$FAILED) { s7 = peg$parsepair(); if (s7 !== peg$FAILED) { s5 = [s5, s6, s7]; s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s4 = peg$c10; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s4 === peg$FAILED) { s4 = peg$c9; } if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c13(s2, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parsepair() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$parsekey(); if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 58) { s3 = peg$c14; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c15); } } if (s3 !== peg$FAILED) { s4 = peg$parse_(); if (s4 !== peg$FAILED) { s5 = peg$parsevalue(); if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c16(s1, s5); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parsearray() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { s1 = peg$c17; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { s3 = peg$c19; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c20); } } if (s3 !== peg$FAILED) { s4 = peg$parse_(); if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c21(); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { s1 = peg$c17; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { s3 = peg$parseelements(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { s4 = peg$c19; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c20); } } if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c22(s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } return s0; } function peg$parseelements() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s1 = peg$c10; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s1 === peg$FAILED) { s1 = peg$c9; } if (s1 !== peg$FAILED) { s2 = peg$parsevalue(); if (s2 === peg$FAILED) { s2 = peg$c9; } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c10; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s5 !== peg$FAILED) { s6 = peg$parse_(); if (s6 !== peg$FAILED) { s7 = peg$parsevalue(); if (s7 !== peg$FAILED) { s5 = [s5, s6, s7]; s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c10; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s5 !== peg$FAILED) { s6 = peg$parse_(); if (s6 !== peg$FAILED) { s7 = peg$parsevalue(); if (s7 !== peg$FAILED) { s5 = [s5, s6, s7]; s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s4 = peg$c10; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s4 === peg$FAILED) { s4 = peg$c9; } if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c23(s2, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parsevalue() { var s0, s1, s2; s0 = peg$parsestring(); if (s0 === peg$FAILED) { s0 = peg$parsesingle(); if (s0 === peg$FAILED) { s0 = peg$parseobject(); if (s0 === peg$FAILED) { s0 = peg$parsearray(); if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 4) === peg$c24) { s1 = peg$c24; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c25); } } if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c26(); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 5) === peg$c27) { s1 = peg$c27; peg$currPos += 5; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c29(); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 4) === peg$c30) { s1 = peg$c30; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c31); } } if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c32(); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$parsenumber(); if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseliteral(); if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c33(s1); } s0 = s1; } } } } } } } } return s0; } function peg$parsestring() { var s0, s1, s2, s3, s4; peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { s1 = peg$c35; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { s2 = peg$c35; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c37(); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { s1 = peg$c35; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s1 !== peg$FAILED) { s2 = peg$parsechars(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { s3 = peg$c35; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s3 !== peg$FAILED) { s4 = peg$parse_(); if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c38(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c34); } } return s0; } function peg$parsesingle() { var s0, s1, s2, s3, s4; peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 39) { s1 = peg$c40; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { s2 = peg$c40; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c37(); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 39) { s1 = peg$c40; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s1 !== peg$FAILED) { s2 = peg$parseschars(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { s3 = peg$c40; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s3 !== peg$FAILED) { s4 = peg$parse_(); if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c38(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } return s0; } function peg$parsechars() { var s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parsechar(); if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsechar(); } } else { s1 = peg$c0; } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c42(s1); } s0 = s1; return s0; } function peg$parsechar() { var s0, s1, s2, s3, s4, s5; if (peg$c43.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c44); } } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c45) { s1 = peg$c45; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c47(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c48) { s1 = peg$c48; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c49); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c50(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c51) { s1 = peg$c51; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c53(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c54) { s1 = peg$c54; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c55); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c56(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c57) { s1 = peg$c57; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c58); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c59(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c60) { s1 = peg$c60; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c61); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c62(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c63) { s1 = peg$c63; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c64); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c65(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c66) { s1 = peg$c66; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c67); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c68(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c69) { s1 = peg$c69; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s1 !== peg$FAILED) { s2 = peg$parsehexDigit(); if (s2 !== peg$FAILED) { s3 = peg$parsehexDigit(); if (s3 !== peg$FAILED) { s4 = peg$parsehexDigit(); if (s4 !== peg$FAILED) { s5 = peg$parsehexDigit(); if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c71(s2, s3, s4, s5); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } } } } } } } } } return s0; } function peg$parseschars() { var s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parseschar(); if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseschar(); } } else { s1 = peg$c0; } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c42(s1); } s0 = s1; return s0; } function peg$parseschar() { var s0, s1, s2, s3, s4, s5; if (peg$c72.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c73); } } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c74) { s1 = peg$c74; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c75); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c76(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c48) { s1 = peg$c48; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c49); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c50(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c51) { s1 = peg$c51; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c53(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c54) { s1 = peg$c54; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c55); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c56(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c57) { s1 = peg$c57; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c58); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c59(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c60) { s1 = peg$c60; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c61); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c62(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c63) { s1 = peg$c63; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c64); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c65(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c66) { s1 = peg$c66; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c67); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c68(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c69) { s1 = peg$c69; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s1 !== peg$FAILED) { s2 = peg$parsehexDigit(); if (s2 !== peg$FAILED) { s3 = peg$parsehexDigit(); if (s3 !== peg$FAILED) { s4 = peg$parsehexDigit(); if (s4 !== peg$FAILED) { s5 = peg$parsehexDigit(); if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c71(s2, s3, s4, s5); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } } } } } } } } } return s0; } function peg$parsekey() { var s0, s1, s2; peg$silentFails++; s0 = peg$parsestring(); if (s0 === peg$FAILED) { s0 = peg$parsesingle(); if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; if (peg$c78.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c79); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); if (peg$c78.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c79); } } } } else { s1 = peg$c0; } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c80(s1); } s0 = s1; } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c77); } } return s0; } function peg$parseliteral() { var s0, s1; s0 = []; s1 = peg$parselitchar(); if (s1 !== peg$FAILED) { while (s1 !== peg$FAILED) { s0.push(s1); s1 = peg$parselitchar(); } } else { s0 = peg$c0; } return s0; } function peg$parselitchar() { var s0; if (peg$c81.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c82); } } return s0; } function peg$parsenumber() { var s0, s1, s2, s3, s4, s5, s6; peg$silentFails++; s0 = peg$currPos; s1 = peg$parseint(); if (s1 !== peg$FAILED) { s2 = peg$parsefrac(); if (s2 !== peg$FAILED) { s3 = peg$parseexp(); if (s3 !== peg$FAILED) { s4 = peg$parse_(); if (s4 !== peg$FAILED) { s5 = []; s6 = peg$parselitchar(); while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$parselitchar(); } if (s5 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c84(s1, s2, s3, s5); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseint(); if (s1 !== peg$FAILED) { s2 = peg$parsefrac(); if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parselitchar(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parselitchar(); } if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c85(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseint(); if (s1 !== peg$FAILED) { s2 = peg$parseexp(); if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parselitchar(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parselitchar(); } if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c86(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseint(); if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parselitchar(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parselitchar(); } if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c87(s1, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c83); } } return s0; } function peg$parseint() { var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parsedigit19(); if (s1 !== peg$FAILED) { s2 = peg$parsedigits(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c88(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$parsedigit(); if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { s1 = peg$c89; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s1 !== peg$FAILED) { s2 = peg$parsedigit19(); if (s2 !== peg$FAILED) { s3 = peg$parsedigits(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c91(s2, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { s1 = peg$c89; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c90); } } if (s1 !== peg$FAILED) { s2 = peg$parsedigit(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c92(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } } } return s0; } function peg$parsefrac() { var s0, s1, s2; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 46) { s1 = peg$c93; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c94); } } if (s1 !== peg$FAILED) { s2 = peg$parsedigits(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c95(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parseexp() { var s0, s1, s2; s0 = peg$currPos; s1 = peg$parsee(); if (s1 !== peg$FAILED) { s2 = peg$parsedigits(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c96(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parsedigits() { var s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parsedigit(); if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsedigit(); } } else { s1 = peg$c0; } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c97(s1); } s0 = s1; return s0; } function peg$parsee() { var s0, s1, s2; s0 = peg$currPos; if (peg$c98.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c99); } } if (s1 !== peg$FAILED) { if (peg$c100.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c101); } } if (s2 === peg$FAILED) { s2 = peg$c9; } if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c102(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parsedigit() { var s0; if (peg$c103.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c104); } } return s0; } function peg$parsedigit19() { var s0; if (peg$c105.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c106); } } return s0; } function peg$parsehexDigit() { var s0; if (peg$c107.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c108); } } return s0; } function peg$parse_() { var s0, s1; peg$silentFails++; s0 = []; s1 = peg$parsewhitespace(); while (s1 !== peg$FAILED) { s0.push(s1); s1 = peg$parsewhitespace(); } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c109); } } return s0; } function peg$parsewhitespace() { var s0; if (peg$c110.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c111); } } return s0; } /* * We can't return |null| in the |value| rule because that would mean parse * failure. So we return a special object instead and convert it to |null| * later. */ var null_ = new Object; function fixNull(value) { return value === null_ ? null : value; } 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({ type: "end", description: "end of input" }); } throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos); } } return { SyntaxError: SyntaxError, parse: parse }; })(); function stringify( val, opts, depth ) { depth++ if( null == val ) return 'null'; var type = Object.prototype.toString.call(val).charAt(8); if( 'F' === type && !opts.showfunc ) return null; // WARNING: output may not be jsonically parsable! if( opts.custom ) { if( val.hasOwnProperty('toString') ) { return val.toString() } else if( val.hasOwnProperty('inspect') ) { return val.inspect() } } var out, i = 0, j, k; if( 'N' === type ) { return isNaN(val) ? 'null' : val.toString(); } else if( 'O' === type ) { out = [] if( depth <= opts.depth ) { j = 0 for( i in val ) { if( j >= opts.maxitems ) break; var pass = true for( k = 0; k < opts.exclude.length && pass; k++ ) { pass = !~i.indexOf(opts.exclude[k]) } pass = pass && !opts.omit[i] var str = stringify(val[i],opts,depth) if( null != str && pass ) { var n = i.match(/^[a-zA-Z0-9_$]+$/) ? i : JSON.stringify(i) out.push( n+':'+str ) j++ } } } return '{'+out.join(',')+'}' } else if( 'A' === type ) { out = [] if( depth <= opts.depth ) { for( ; i < val.length && i < opts.maxitems; i++ ) { var str = stringify(val[i],opts,depth) if( null != str ) { out.push( str ) } } } return '['+out.join(',')+']' } else { var valstr = val.toString(); if( ~" \"'\r\n\t,}]".indexOf(valstr[0]) || !~valstr.match(/,}]/) || ~" \r\n\t".indexOf(valstr[valstr.length-1])) { valstr = "'"+valstr.replace(/'/g,"\\'")+"'" } return valstr; } } jsonic.stringify = function( val, callopts ) { try { var callopts = callopts || {}; var opts = {}; opts.showfunc = callopts.showfunc || callopts.f || false; opts.custom = callopts.custom || callopts.c || false; opts.depth = callopts.depth || callopts.d || 3; opts.maxitems = callopts.maxitems || callopts.mi || 11; opts.maxchars = callopts.maxchars || callopts.mc || 111; opts.exclude = callopts.exclude || callopts.x || ['$']; var omit = callopts.omit || callopts.o || []; opts.omit = {} for( var i = 0; i < omit.length; i++ ) { opts.omit[omit[i]] = true; } var str = stringify( val, opts, 0 ); str = null == str ? '' : str.substring(0,opts.maxchars); return str; } catch( e ) { return 'ERROR: jsonic.stringify: '+e+' input was: '+JSON.stringify( val ) } } if( typeof exports !== 'undefined' ) { if( typeof module !== 'undefined' && module.exports ) { exports = module.exports = jsonic } exports.jsonic = jsonic } else { root.jsonic = jsonic } }).call(this);