// // Dust - Asynchronous Templating v2.2.2 // http://akdubya.github.com/dustjs // // Copyright (c) 2010, Aleksander Williams // Released under the MIT License. // /*global console */ dust = {}; function getGlobal(){ return (function(){ return this.dust; }).call(null); } (function(dust) { if(!dust) { return; } var ERROR = 'ERROR', WARN = 'WARN', INFO = 'INFO', DEBUG = 'DEBUG', levels = [DEBUG, INFO, WARN, ERROR], logger = function() {}; dust.isDebug = false; dust.debugLevel = INFO; // Try to find the console logger in window scope (browsers) or top level scope (node.js) if (typeof window !== 'undefined' && window && window.console && window.console.log) { logger = window.console.log; } else if (typeof console !== 'undefined' && console && console.log) { logger = console.log; } /** * If dust.isDebug is true, Log dust debug statements, info statements, warning statements, and errors. * This default implementation will print to the console if it exists. * @param {String} message the message to print * @param {String} type the severity of the message(ERROR, WARN, INFO, or DEBUG) * @public */ dust.log = function(message, type) { var type = type || INFO; if(dust.isDebug && levels.indexOf(type) >= levels.indexOf(dust.debugLevel)) { if(!dust.logQueue) { dust.logQueue = []; } dust.logQueue.push({message: message, type: type}); logger.call(console || window.console, '[DUST ' + type + ']: ' + message); } }; /** * If debugging is turned on(dust.isDebug=true) log the error message and throw it. * Otherwise try to keep rendering. This is useful to fail hard in dev mode, but keep rendering in production. * @param {Error} error the error message to throw * @param {Object} chunk the chunk the error was thrown from * @public */ dust.onError = function(error, chunk) { dust.log(error.message || error, ERROR); if(dust.isDebug) { throw error; } else { return chunk; } }; dust.helpers = {}; dust.cache = {}; dust.register = function(name, tmpl) { if (!name) { return; } dust.cache[name] = tmpl; }; dust.render = function(name, context, callback) { var chunk = new Stub(callback).head; try { dust.load(name, chunk, Context.wrap(context, name)).end(); } catch (err) { dust.onError(err, chunk); } }; dust.stream = function(name, context) { var stream = new Stream(); dust.nextTick(function() { try { dust.load(name, stream.head, Context.wrap(context, name)).end(); } catch (err) { dust.onError(err, stream.head); } }); return stream; }; dust.renderSource = function(source, context, callback) { return dust.compileFn(source)(context, callback); }; dust.compileFn = function(source, name) { var tmpl = dust.loadSource(dust.compile(source, name)); return function(context, callback) { var master = callback ? new Stub(callback) : new Stream(); dust.nextTick(function() { if(typeof tmpl === 'function') { tmpl(master.head, Context.wrap(context, name)).end(); } else { dust.onError(new Error('Template [' + name + '] cannot be resolved to a Dust function')); } }); return master; }; }; dust.load = function(name, chunk, context) { var tmpl = dust.cache[name]; if (tmpl) { return tmpl(chunk, context); } else { if (dust.onLoad) { return chunk.map(function(chunk) { dust.onLoad(name, function(err, src) { if (err) { return chunk.setError(err); } if (!dust.cache[name]) { dust.loadSource(dust.compile(src, name)); } dust.cache[name](chunk, context).end(); }); }); } return chunk.setError(new Error('Template Not Found: ' + name)); } }; dust.loadSource = function(source, path) { return eval(source); }; if (Array.isArray) { dust.isArray = Array.isArray; } else { dust.isArray = function(arr) { return Object.prototype.toString.call(arr) === '[object Array]'; }; } dust.nextTick = (function() { if (typeof process !== 'undefined') { return process.nextTick; } else { return function(callback) { setTimeout(callback,0); }; } } )(); dust.isEmpty = function(value) { if (dust.isArray(value) && !value.length) { return true; } if (value === 0) { return false; } return (!value); }; // apply the filter chain and return the output string dust.filter = function(string, auto, filters) { if (filters) { for (var i=0, len=filters.length; i 0) { // any custom helper can blow up the stack // and store a flattened context, guard defensively if(context.stack.head) { context.stack.head['$len'] = len; } for (var i=0; i\"\']/), AMP = /&/g, LT = //g, QUOT = /\"/g, SQUOT = /\'/g; dust.escapeHtml = function(s) { if (typeof s === 'string') { if (!HCHARS.test(s)) { return s; } return s.replace(AMP,'&').replace(LT,'<').replace(GT,'>').replace(QUOT,'"').replace(SQUOT, '''); } return s; }; var BS = /\\/g, FS = /\//g, CR = /\r/g, LS = /\u2028/g, PS = /\u2029/g, NL = /\n/g, LF = /\f/g, SQ = /'/g, DQ = /"/g, TB = /\t/g; dust.escapeJs = function(s) { if (typeof s === 'string') { return s .replace(BS, '\\\\') .replace(FS, '\\/') .replace(DQ, '\\"') .replace(SQ, '\\\'') .replace(CR, '\\r') .replace(LS, '\\u2028') .replace(PS, '\\u2029') .replace(NL, '\\n') .replace(LF, '\\f') .replace(TB, '\\t'); } return s; }; })(dust); if (typeof exports !== 'undefined') { if (typeof process !== 'undefined') { require('./server')(dust); } module.exports = dust; } var dustCompiler = (function(dust) { dust.compile = function(source, name) { try { var ast = filterAST(dust.parse(source)); return compile(ast, name); } catch (err) { if (!err.line || !err.column) { throw err; } throw new SyntaxError(err.message + " At line : " + err.line + ", column : " + err.column); } }; function filterAST(ast) { var context = {}; return dust.filterNode(context, ast); }; dust.filterNode = function(context, node) { return dust.optimizers[node[0]](context, node); }; dust.optimizers = { body: compactBuffers, buffer: noop, special: convertSpecial, format: nullify, // TODO: convert format reference: visit, "#": visit, "?": visit, "^": visit, "<": visit, "+": visit, "@": visit, "%": visit, partial: visit, context: visit, params: visit, bodies: visit, param: visit, filters: noop, key: noop, path: noop, literal: noop, comment: nullify, line: nullify, col: nullify }; dust.pragmas = { esc: function(compiler, context, bodies, params) { var old = compiler.auto, out; if (!context) { context = 'h'; } compiler.auto = (context === 's') ? '' : context; out = compileParts(compiler, bodies.block); compiler.auto = old; return out; } }; function visit(context, node) { var out = [node[0]], i, len, res; for (i=1, len=node.length; i rightmostFailuresPos.offset) { rightmostFailuresPos = clone(pos); rightmostFailuresExpected = []; } rightmostFailuresExpected.push(failure); } function parse_body() { var result0, result1; var pos0; pos0 = clone(pos); result0 = []; result1 = parse_part(); while (result1 !== null) { result0.push(result1); result1 = parse_part(); } if (result0 !== null) { result0 = (function(offset, line, column, p) { return ["body"].concat(p).concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } return result0; } function parse_part() { var result0; result0 = parse_comment(); if (result0 === null) { result0 = parse_section(); if (result0 === null) { result0 = parse_partial(); if (result0 === null) { result0 = parse_special(); if (result0 === null) { result0 = parse_reference(); if (result0 === null) { result0 = parse_buffer(); } } } } } return result0; } function parse_section() { var result0, result1, result2, result3, result4, result5, result6; var pos0, pos1; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_sec_tag_start(); if (result0 !== null) { result1 = []; result2 = parse_ws(); while (result2 !== null) { result1.push(result2); result2 = parse_ws(); } if (result1 !== null) { result2 = parse_rd(); if (result2 !== null) { result3 = parse_body(); if (result3 !== null) { result4 = parse_bodies(); if (result4 !== null) { result5 = parse_end_tag(); result5 = result5 !== null ? result5 : ""; if (result5 !== null) { result6 = (function(offset, line, column, t, b, e, n) {if( (!n) || (t[1].text !== n.text) ) { throw new Error("Expected end tag for "+t[1].text+" but it was not found. At line : "+line+", column : " + column)} return true;})(pos.offset, pos.line, pos.column, result0, result3, result4, result5) ? "" : null; if (result6 !== null) { result0 = [result0, result1, result2, result3, result4, result5, result6]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, t, b, e, n) { e.push(["param", ["literal", "block"], b]); t.push(e); return t.concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[0], result0[3], result0[4], result0[5]); } if (result0 === null) { pos = clone(pos0); } if (result0 === null) { pos0 = clone(pos); pos1 = clone(pos); result0 = parse_sec_tag_start(); if (result0 !== null) { result1 = []; result2 = parse_ws(); while (result2 !== null) { result1.push(result2); result2 = parse_ws(); } if (result1 !== null) { if (input.charCodeAt(pos.offset) === 47) { result2 = "/"; advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("\"/\""); } } if (result2 !== null) { result3 = parse_rd(); if (result3 !== null) { result0 = [result0, result1, result2, result3]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, t) { t.push(["bodies"]); return t.concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[0]); } if (result0 === null) { pos = clone(pos0); } } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("section"); } return result0; } function parse_sec_tag_start() { var result0, result1, result2, result3, result4, result5; var pos0, pos1; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_ld(); if (result0 !== null) { if (/^[#?^<+@%]/.test(input.charAt(pos.offset))) { result1 = input.charAt(pos.offset); advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("[#?^<+@%]"); } } if (result1 !== null) { result2 = []; result3 = parse_ws(); while (result3 !== null) { result2.push(result3); result3 = parse_ws(); } if (result2 !== null) { result3 = parse_identifier(); if (result3 !== null) { result4 = parse_context(); if (result4 !== null) { result5 = parse_params(); if (result5 !== null) { result0 = [result0, result1, result2, result3, result4, result5]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, t, n, c, p) { return [t, n, c, p] })(pos0.offset, pos0.line, pos0.column, result0[1], result0[3], result0[4], result0[5]); } if (result0 === null) { pos = clone(pos0); } return result0; } function parse_end_tag() { var result0, result1, result2, result3, result4, result5; var pos0, pos1; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_ld(); if (result0 !== null) { if (input.charCodeAt(pos.offset) === 47) { result1 = "/"; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\"/\""); } } if (result1 !== null) { result2 = []; result3 = parse_ws(); while (result3 !== null) { result2.push(result3); result3 = parse_ws(); } if (result2 !== null) { result3 = parse_identifier(); if (result3 !== null) { result4 = []; result5 = parse_ws(); while (result5 !== null) { result4.push(result5); result5 = parse_ws(); } if (result4 !== null) { result5 = parse_rd(); if (result5 !== null) { result0 = [result0, result1, result2, result3, result4, result5]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, n) { return n })(pos0.offset, pos0.line, pos0.column, result0[3]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("end tag"); } return result0; } function parse_context() { var result0, result1; var pos0, pos1, pos2; pos0 = clone(pos); pos1 = clone(pos); pos2 = clone(pos); if (input.charCodeAt(pos.offset) === 58) { result0 = ":"; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\":\""); } } if (result0 !== null) { result1 = parse_identifier(); if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = clone(pos2); } } else { result0 = null; pos = clone(pos2); } if (result0 !== null) { result0 = (function(offset, line, column, n) {return n})(pos1.offset, pos1.line, pos1.column, result0[1]); } if (result0 === null) { pos = clone(pos1); } result0 = result0 !== null ? result0 : ""; if (result0 !== null) { result0 = (function(offset, line, column, n) { return n ? ["context", n] : ["context"] })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } return result0; } function parse_params() { var result0, result1, result2, result3, result4; var pos0, pos1, pos2; reportFailures++; pos0 = clone(pos); result0 = []; pos1 = clone(pos); pos2 = clone(pos); result2 = parse_ws(); if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); result2 = parse_ws(); } } else { result1 = null; } if (result1 !== null) { result2 = parse_key(); if (result2 !== null) { if (input.charCodeAt(pos.offset) === 61) { result3 = "="; advance(pos, 1); } else { result3 = null; if (reportFailures === 0) { matchFailed("\"=\""); } } if (result3 !== null) { result4 = parse_number(); if (result4 === null) { result4 = parse_identifier(); if (result4 === null) { result4 = parse_inline(); } } if (result4 !== null) { result1 = [result1, result2, result3, result4]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, k, v) {return ["param", ["literal", k], v]})(pos1.offset, pos1.line, pos1.column, result1[1], result1[3]); } if (result1 === null) { pos = clone(pos1); } while (result1 !== null) { result0.push(result1); pos1 = clone(pos); pos2 = clone(pos); result2 = parse_ws(); if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); result2 = parse_ws(); } } else { result1 = null; } if (result1 !== null) { result2 = parse_key(); if (result2 !== null) { if (input.charCodeAt(pos.offset) === 61) { result3 = "="; advance(pos, 1); } else { result3 = null; if (reportFailures === 0) { matchFailed("\"=\""); } } if (result3 !== null) { result4 = parse_number(); if (result4 === null) { result4 = parse_identifier(); if (result4 === null) { result4 = parse_inline(); } } if (result4 !== null) { result1 = [result1, result2, result3, result4]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, k, v) {return ["param", ["literal", k], v]})(pos1.offset, pos1.line, pos1.column, result1[1], result1[3]); } if (result1 === null) { pos = clone(pos1); } } if (result0 !== null) { result0 = (function(offset, line, column, p) { return ["params"].concat(p) })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("params"); } return result0; } function parse_bodies() { var result0, result1, result2, result3, result4, result5; var pos0, pos1, pos2; reportFailures++; pos0 = clone(pos); result0 = []; pos1 = clone(pos); pos2 = clone(pos); result1 = parse_ld(); if (result1 !== null) { if (input.charCodeAt(pos.offset) === 58) { result2 = ":"; advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("\":\""); } } if (result2 !== null) { result3 = parse_key(); if (result3 !== null) { result4 = parse_rd(); if (result4 !== null) { result5 = parse_body(); if (result5 !== null) { result1 = [result1, result2, result3, result4, result5]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, k, v) {return ["param", ["literal", k], v]})(pos1.offset, pos1.line, pos1.column, result1[2], result1[4]); } if (result1 === null) { pos = clone(pos1); } while (result1 !== null) { result0.push(result1); pos1 = clone(pos); pos2 = clone(pos); result1 = parse_ld(); if (result1 !== null) { if (input.charCodeAt(pos.offset) === 58) { result2 = ":"; advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("\":\""); } } if (result2 !== null) { result3 = parse_key(); if (result3 !== null) { result4 = parse_rd(); if (result4 !== null) { result5 = parse_body(); if (result5 !== null) { result1 = [result1, result2, result3, result4, result5]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, k, v) {return ["param", ["literal", k], v]})(pos1.offset, pos1.line, pos1.column, result1[2], result1[4]); } if (result1 === null) { pos = clone(pos1); } } if (result0 !== null) { result0 = (function(offset, line, column, p) { return ["bodies"].concat(p) })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("bodies"); } return result0; } function parse_reference() { var result0, result1, result2, result3; var pos0, pos1; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_ld(); if (result0 !== null) { result1 = parse_identifier(); if (result1 !== null) { result2 = parse_filters(); if (result2 !== null) { result3 = parse_rd(); if (result3 !== null) { result0 = [result0, result1, result2, result3]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, n, f) { return ["reference", n, f].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("reference"); } return result0; } function parse_partial() { var result0, result1, result2, result3, result4, result5, result6, result7, result8; var pos0, pos1, pos2; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_ld(); if (result0 !== null) { if (input.charCodeAt(pos.offset) === 62) { result1 = ">"; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\">\""); } } if (result1 === null) { if (input.charCodeAt(pos.offset) === 43) { result1 = "+"; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\"+\""); } } } if (result1 !== null) { result2 = []; result3 = parse_ws(); while (result3 !== null) { result2.push(result3); result3 = parse_ws(); } if (result2 !== null) { pos2 = clone(pos); result3 = parse_key(); if (result3 !== null) { result3 = (function(offset, line, column, k) {return ["literal", k]})(pos2.offset, pos2.line, pos2.column, result3); } if (result3 === null) { pos = clone(pos2); } if (result3 === null) { result3 = parse_inline(); } if (result3 !== null) { result4 = parse_context(); if (result4 !== null) { result5 = parse_params(); if (result5 !== null) { result6 = []; result7 = parse_ws(); while (result7 !== null) { result6.push(result7); result7 = parse_ws(); } if (result6 !== null) { if (input.charCodeAt(pos.offset) === 47) { result7 = "/"; advance(pos, 1); } else { result7 = null; if (reportFailures === 0) { matchFailed("\"/\""); } } if (result7 !== null) { result8 = parse_rd(); if (result8 !== null) { result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, s, n, c, p) { var key = (s ===">")? "partial" : s; return [key, n, c, p].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1], result0[3], result0[4], result0[5]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("partial"); } return result0; } function parse_filters() { var result0, result1, result2; var pos0, pos1, pos2; reportFailures++; pos0 = clone(pos); result0 = []; pos1 = clone(pos); pos2 = clone(pos); if (input.charCodeAt(pos.offset) === 124) { result1 = "|"; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\"|\""); } } if (result1 !== null) { result2 = parse_key(); if (result2 !== null) { result1 = [result1, result2]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, n) {return n})(pos1.offset, pos1.line, pos1.column, result1[1]); } if (result1 === null) { pos = clone(pos1); } while (result1 !== null) { result0.push(result1); pos1 = clone(pos); pos2 = clone(pos); if (input.charCodeAt(pos.offset) === 124) { result1 = "|"; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\"|\""); } } if (result1 !== null) { result2 = parse_key(); if (result2 !== null) { result1 = [result1, result2]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, n) {return n})(pos1.offset, pos1.line, pos1.column, result1[1]); } if (result1 === null) { pos = clone(pos1); } } if (result0 !== null) { result0 = (function(offset, line, column, f) { return ["filters"].concat(f) })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("filters"); } return result0; } function parse_special() { var result0, result1, result2, result3; var pos0, pos1; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_ld(); if (result0 !== null) { if (input.charCodeAt(pos.offset) === 126) { result1 = "~"; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\"~\""); } } if (result1 !== null) { result2 = parse_key(); if (result2 !== null) { result3 = parse_rd(); if (result3 !== null) { result0 = [result0, result1, result2, result3]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, k) { return ["special", k].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[2]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("special"); } return result0; } function parse_identifier() { var result0; var pos0; reportFailures++; pos0 = clone(pos); result0 = parse_path(); if (result0 !== null) { result0 = (function(offset, line, column, p) { var arr = ["path"].concat(p); arr.text = p[1].join('.'); return arr; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } if (result0 === null) { pos0 = clone(pos); result0 = parse_key(); if (result0 !== null) { result0 = (function(offset, line, column, k) { var arr = ["key", k]; arr.text = k; return arr; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("identifier"); } return result0; } function parse_number() { var result0; var pos0; reportFailures++; pos0 = clone(pos); result0 = parse_float(); if (result0 === null) { result0 = parse_integer(); } if (result0 !== null) { result0 = (function(offset, line, column, n) { return ['literal', n]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("number"); } return result0; } function parse_float() { var result0, result1, result2, result3; var pos0, pos1; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_integer(); if (result0 !== null) { if (input.charCodeAt(pos.offset) === 46) { result1 = "."; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\".\""); } } if (result1 !== null) { result3 = parse_integer(); if (result3 !== null) { result2 = []; while (result3 !== null) { result2.push(result3); result3 = parse_integer(); } } else { result2 = null; } if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, l, r) { return parseFloat(l + "." + r.join('')); })(pos0.offset, pos0.line, pos0.column, result0[0], result0[2]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("float"); } return result0; } function parse_integer() { var result0, result1; var pos0; reportFailures++; pos0 = clone(pos); if (/^[0-9]/.test(input.charAt(pos.offset))) { result1 = input.charAt(pos.offset); advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("[0-9]"); } } if (result1 !== null) { result0 = []; while (result1 !== null) { result0.push(result1); if (/^[0-9]/.test(input.charAt(pos.offset))) { result1 = input.charAt(pos.offset); advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("[0-9]"); } } } } else { result0 = null; } if (result0 !== null) { result0 = (function(offset, line, column, digits) { return parseInt(digits.join(""), 10); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("integer"); } return result0; } function parse_path() { var result0, result1, result2; var pos0, pos1; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_key(); result0 = result0 !== null ? result0 : ""; if (result0 !== null) { result2 = parse_array_part(); if (result2 === null) { result2 = parse_array(); } if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); result2 = parse_array_part(); if (result2 === null) { result2 = parse_array(); } } } else { result1 = null; } if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, k, d) { d = d[0]; if (k && d) { d.unshift(k); return [false, d].concat([['line', line], ['col', column]]); } return [true, d].concat([['line', line], ['col', column]]); })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { pos = clone(pos0); } if (result0 === null) { pos0 = clone(pos); pos1 = clone(pos); if (input.charCodeAt(pos.offset) === 46) { result0 = "."; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\".\""); } } if (result0 !== null) { result1 = []; result2 = parse_array_part(); if (result2 === null) { result2 = parse_array(); } while (result2 !== null) { result1.push(result2); result2 = parse_array_part(); if (result2 === null) { result2 = parse_array(); } } if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, d) { if (d.length > 0) { return [true, d[0]].concat([['line', line], ['col', column]]); } return [true, []].concat([['line', line], ['col', column]]); })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { pos = clone(pos0); } } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("path"); } return result0; } function parse_key() { var result0, result1, result2; var pos0, pos1; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); if (/^[a-zA-Z_$]/.test(input.charAt(pos.offset))) { result0 = input.charAt(pos.offset); advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("[a-zA-Z_$]"); } } if (result0 !== null) { result1 = []; if (/^[0-9a-zA-Z_$\-]/.test(input.charAt(pos.offset))) { result2 = input.charAt(pos.offset); advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("[0-9a-zA-Z_$\\-]"); } } while (result2 !== null) { result1.push(result2); if (/^[0-9a-zA-Z_$\-]/.test(input.charAt(pos.offset))) { result2 = input.charAt(pos.offset); advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("[0-9a-zA-Z_$\\-]"); } } } if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, h, t) { return h + t.join('') })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("key"); } return result0; } function parse_array() { var result0, result1, result2; var pos0, pos1, pos2, pos3, pos4; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); pos2 = clone(pos); pos3 = clone(pos); result0 = parse_lb(); if (result0 !== null) { pos4 = clone(pos); if (/^[0-9]/.test(input.charAt(pos.offset))) { result2 = input.charAt(pos.offset); advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("[0-9]"); } } if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); if (/^[0-9]/.test(input.charAt(pos.offset))) { result2 = input.charAt(pos.offset); advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("[0-9]"); } } } } else { result1 = null; } if (result1 !== null) { result1 = (function(offset, line, column, n) {return n.join('')})(pos4.offset, pos4.line, pos4.column, result1); } if (result1 === null) { pos = clone(pos4); } if (result1 === null) { result1 = parse_identifier(); } if (result1 !== null) { result2 = parse_rb(); if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = clone(pos3); } } else { result0 = null; pos = clone(pos3); } } else { result0 = null; pos = clone(pos3); } if (result0 !== null) { result0 = (function(offset, line, column, a) {return a; })(pos2.offset, pos2.line, pos2.column, result0[1]); } if (result0 === null) { pos = clone(pos2); } if (result0 !== null) { result1 = parse_array_part(); result1 = result1 !== null ? result1 : ""; if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, i, nk) { if(nk) { nk.unshift(i); } else {nk = [i] } return nk; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("array"); } return result0; } function parse_array_part() { var result0, result1, result2; var pos0, pos1, pos2, pos3; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); pos2 = clone(pos); pos3 = clone(pos); if (input.charCodeAt(pos.offset) === 46) { result1 = "."; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\".\""); } } if (result1 !== null) { result2 = parse_key(); if (result2 !== null) { result1 = [result1, result2]; } else { result1 = null; pos = clone(pos3); } } else { result1 = null; pos = clone(pos3); } if (result1 !== null) { result1 = (function(offset, line, column, k) {return k})(pos2.offset, pos2.line, pos2.column, result1[1]); } if (result1 === null) { pos = clone(pos2); } if (result1 !== null) { result0 = []; while (result1 !== null) { result0.push(result1); pos2 = clone(pos); pos3 = clone(pos); if (input.charCodeAt(pos.offset) === 46) { result1 = "."; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\".\""); } } if (result1 !== null) { result2 = parse_key(); if (result2 !== null) { result1 = [result1, result2]; } else { result1 = null; pos = clone(pos3); } } else { result1 = null; pos = clone(pos3); } if (result1 !== null) { result1 = (function(offset, line, column, k) {return k})(pos2.offset, pos2.line, pos2.column, result1[1]); } if (result1 === null) { pos = clone(pos2); } } } else { result0 = null; } if (result0 !== null) { result1 = parse_array(); result1 = result1 !== null ? result1 : ""; if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, d, a) { if (a) { return d.concat(a); } else { return d; } })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("array_part"); } return result0; } function parse_inline() { var result0, result1, result2; var pos0, pos1; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); if (input.charCodeAt(pos.offset) === 34) { result0 = "\""; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } if (result0 !== null) { if (input.charCodeAt(pos.offset) === 34) { result1 = "\""; advance(pos, 1); } else { result1 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column) { return ["literal", ""].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column); } if (result0 === null) { pos = clone(pos0); } if (result0 === null) { pos0 = clone(pos); pos1 = clone(pos); if (input.charCodeAt(pos.offset) === 34) { result0 = "\""; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } if (result0 !== null) { result1 = parse_literal(); if (result1 !== null) { if (input.charCodeAt(pos.offset) === 34) { result2 = "\""; advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, l) { return ["literal", l].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { pos = clone(pos0); } if (result0 === null) { pos0 = clone(pos); pos1 = clone(pos); if (input.charCodeAt(pos.offset) === 34) { result0 = "\""; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } if (result0 !== null) { result2 = parse_inline_part(); if (result2 !== null) { result1 = []; while (result2 !== null) { result1.push(result2); result2 = parse_inline_part(); } } else { result1 = null; } if (result1 !== null) { if (input.charCodeAt(pos.offset) === 34) { result2 = "\""; advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, p) { return ["body"].concat(p).concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { pos = clone(pos0); } } } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("inline"); } return result0; } function parse_inline_part() { var result0; var pos0; result0 = parse_special(); if (result0 === null) { result0 = parse_reference(); if (result0 === null) { pos0 = clone(pos); result0 = parse_literal(); if (result0 !== null) { result0 = (function(offset, line, column, l) { return ["buffer", l] })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } } } return result0; } function parse_buffer() { var result0, result1, result2, result3, result4; var pos0, pos1, pos2, pos3; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); result0 = parse_eol(); if (result0 !== null) { result1 = []; result2 = parse_ws(); while (result2 !== null) { result1.push(result2); result2 = parse_ws(); } if (result1 !== null) { result0 = [result0, result1]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, e, w) { return ["format", e, w.join('')].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { pos = clone(pos0); } if (result0 === null) { pos0 = clone(pos); pos1 = clone(pos); pos2 = clone(pos); pos3 = clone(pos); reportFailures++; result1 = parse_tag(); reportFailures--; if (result1 === null) { result1 = ""; } else { result1 = null; pos = clone(pos3); } if (result1 !== null) { pos3 = clone(pos); reportFailures++; result2 = parse_comment(); reportFailures--; if (result2 === null) { result2 = ""; } else { result2 = null; pos = clone(pos3); } if (result2 !== null) { pos3 = clone(pos); reportFailures++; result3 = parse_eol(); reportFailures--; if (result3 === null) { result3 = ""; } else { result3 = null; pos = clone(pos3); } if (result3 !== null) { if (input.length > pos.offset) { result4 = input.charAt(pos.offset); advance(pos, 1); } else { result4 = null; if (reportFailures === 0) { matchFailed("any character"); } } if (result4 !== null) { result1 = [result1, result2, result3, result4]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[3]); } if (result1 === null) { pos = clone(pos1); } if (result1 !== null) { result0 = []; while (result1 !== null) { result0.push(result1); pos1 = clone(pos); pos2 = clone(pos); pos3 = clone(pos); reportFailures++; result1 = parse_tag(); reportFailures--; if (result1 === null) { result1 = ""; } else { result1 = null; pos = clone(pos3); } if (result1 !== null) { pos3 = clone(pos); reportFailures++; result2 = parse_comment(); reportFailures--; if (result2 === null) { result2 = ""; } else { result2 = null; pos = clone(pos3); } if (result2 !== null) { pos3 = clone(pos); reportFailures++; result3 = parse_eol(); reportFailures--; if (result3 === null) { result3 = ""; } else { result3 = null; pos = clone(pos3); } if (result3 !== null) { if (input.length > pos.offset) { result4 = input.charAt(pos.offset); advance(pos, 1); } else { result4 = null; if (reportFailures === 0) { matchFailed("any character"); } } if (result4 !== null) { result1 = [result1, result2, result3, result4]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[3]); } if (result1 === null) { pos = clone(pos1); } } } else { result0 = null; } if (result0 !== null) { result0 = (function(offset, line, column, b) { return ["buffer", b.join('')].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("buffer"); } return result0; } function parse_literal() { var result0, result1, result2; var pos0, pos1, pos2, pos3; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); pos2 = clone(pos); pos3 = clone(pos); reportFailures++; result1 = parse_tag(); reportFailures--; if (result1 === null) { result1 = ""; } else { result1 = null; pos = clone(pos3); } if (result1 !== null) { result2 = parse_esc(); if (result2 === null) { if (/^[^"]/.test(input.charAt(pos.offset))) { result2 = input.charAt(pos.offset); advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("[^\"]"); } } } if (result2 !== null) { result1 = [result1, result2]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[1]); } if (result1 === null) { pos = clone(pos1); } if (result1 !== null) { result0 = []; while (result1 !== null) { result0.push(result1); pos1 = clone(pos); pos2 = clone(pos); pos3 = clone(pos); reportFailures++; result1 = parse_tag(); reportFailures--; if (result1 === null) { result1 = ""; } else { result1 = null; pos = clone(pos3); } if (result1 !== null) { result2 = parse_esc(); if (result2 === null) { if (/^[^"]/.test(input.charAt(pos.offset))) { result2 = input.charAt(pos.offset); advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("[^\"]"); } } } if (result2 !== null) { result1 = [result1, result2]; } else { result1 = null; pos = clone(pos2); } } else { result1 = null; pos = clone(pos2); } if (result1 !== null) { result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[1]); } if (result1 === null) { pos = clone(pos1); } } } else { result0 = null; } if (result0 !== null) { result0 = (function(offset, line, column, b) { return b.join('') })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("literal"); } return result0; } function parse_esc() { var result0; var pos0; pos0 = clone(pos); if (input.substr(pos.offset, 2) === "\\\"") { result0 = "\\\""; advance(pos, 2); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\\\\"\""); } } if (result0 !== null) { result0 = (function(offset, line, column) { return '"' })(pos0.offset, pos0.line, pos0.column); } if (result0 === null) { pos = clone(pos0); } return result0; } function parse_comment() { var result0, result1, result2, result3; var pos0, pos1, pos2, pos3, pos4; reportFailures++; pos0 = clone(pos); pos1 = clone(pos); if (input.substr(pos.offset, 2) === "{!") { result0 = "{!"; advance(pos, 2); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"{!\""); } } if (result0 !== null) { result1 = []; pos2 = clone(pos); pos3 = clone(pos); pos4 = clone(pos); reportFailures++; if (input.substr(pos.offset, 2) === "!}") { result2 = "!}"; advance(pos, 2); } else { result2 = null; if (reportFailures === 0) { matchFailed("\"!}\""); } } reportFailures--; if (result2 === null) { result2 = ""; } else { result2 = null; pos = clone(pos4); } if (result2 !== null) { if (input.length > pos.offset) { result3 = input.charAt(pos.offset); advance(pos, 1); } else { result3 = null; if (reportFailures === 0) { matchFailed("any character"); } } if (result3 !== null) { result2 = [result2, result3]; } else { result2 = null; pos = clone(pos3); } } else { result2 = null; pos = clone(pos3); } if (result2 !== null) { result2 = (function(offset, line, column, c) {return c})(pos2.offset, pos2.line, pos2.column, result2[1]); } if (result2 === null) { pos = clone(pos2); } while (result2 !== null) { result1.push(result2); pos2 = clone(pos); pos3 = clone(pos); pos4 = clone(pos); reportFailures++; if (input.substr(pos.offset, 2) === "!}") { result2 = "!}"; advance(pos, 2); } else { result2 = null; if (reportFailures === 0) { matchFailed("\"!}\""); } } reportFailures--; if (result2 === null) { result2 = ""; } else { result2 = null; pos = clone(pos4); } if (result2 !== null) { if (input.length > pos.offset) { result3 = input.charAt(pos.offset); advance(pos, 1); } else { result3 = null; if (reportFailures === 0) { matchFailed("any character"); } } if (result3 !== null) { result2 = [result2, result3]; } else { result2 = null; pos = clone(pos3); } } else { result2 = null; pos = clone(pos3); } if (result2 !== null) { result2 = (function(offset, line, column, c) {return c})(pos2.offset, pos2.line, pos2.column, result2[1]); } if (result2 === null) { pos = clone(pos2); } } if (result1 !== null) { if (input.substr(pos.offset, 2) === "!}") { result2 = "!}"; advance(pos, 2); } else { result2 = null; if (reportFailures === 0) { matchFailed("\"!}\""); } } if (result2 !== null) { result0 = [result0, result1, result2]; } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } } else { result0 = null; pos = clone(pos1); } if (result0 !== null) { result0 = (function(offset, line, column, c) { return ["comment", c.join('')].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { pos = clone(pos0); } reportFailures--; if (reportFailures === 0 && result0 === null) { matchFailed("comment"); } return result0; } function parse_tag() { var result0, result1, result2, result3, result4, result5, result6, result7; var pos0, pos1, pos2; pos0 = clone(pos); result0 = parse_ld(); if (result0 !== null) { result1 = []; result2 = parse_ws(); while (result2 !== null) { result1.push(result2); result2 = parse_ws(); } if (result1 !== null) { if (/^[#?^><+%:@\/~%]/.test(input.charAt(pos.offset))) { result2 = input.charAt(pos.offset); advance(pos, 1); } else { result2 = null; if (reportFailures === 0) { matchFailed("[#?^><+%:@\\/~%]"); } } if (result2 !== null) { result3 = []; result4 = parse_ws(); while (result4 !== null) { result3.push(result4); result4 = parse_ws(); } if (result3 !== null) { pos1 = clone(pos); pos2 = clone(pos); reportFailures++; result5 = parse_rd(); reportFailures--; if (result5 === null) { result5 = ""; } else { result5 = null; pos = clone(pos2); } if (result5 !== null) { pos2 = clone(pos); reportFailures++; result6 = parse_eol(); reportFailures--; if (result6 === null) { result6 = ""; } else { result6 = null; pos = clone(pos2); } if (result6 !== null) { if (input.length > pos.offset) { result7 = input.charAt(pos.offset); advance(pos, 1); } else { result7 = null; if (reportFailures === 0) { matchFailed("any character"); } } if (result7 !== null) { result5 = [result5, result6, result7]; } else { result5 = null; pos = clone(pos1); } } else { result5 = null; pos = clone(pos1); } } else { result5 = null; pos = clone(pos1); } if (result5 !== null) { result4 = []; while (result5 !== null) { result4.push(result5); pos1 = clone(pos); pos2 = clone(pos); reportFailures++; result5 = parse_rd(); reportFailures--; if (result5 === null) { result5 = ""; } else { result5 = null; pos = clone(pos2); } if (result5 !== null) { pos2 = clone(pos); reportFailures++; result6 = parse_eol(); reportFailures--; if (result6 === null) { result6 = ""; } else { result6 = null; pos = clone(pos2); } if (result6 !== null) { if (input.length > pos.offset) { result7 = input.charAt(pos.offset); advance(pos, 1); } else { result7 = null; if (reportFailures === 0) { matchFailed("any character"); } } if (result7 !== null) { result5 = [result5, result6, result7]; } else { result5 = null; pos = clone(pos1); } } else { result5 = null; pos = clone(pos1); } } else { result5 = null; pos = clone(pos1); } } } else { result4 = null; } if (result4 !== null) { result5 = []; result6 = parse_ws(); while (result6 !== null) { result5.push(result6); result6 = parse_ws(); } if (result5 !== null) { result6 = parse_rd(); if (result6 !== null) { result0 = [result0, result1, result2, result3, result4, result5, result6]; } else { result0 = null; pos = clone(pos0); } } else { result0 = null; pos = clone(pos0); } } else { result0 = null; pos = clone(pos0); } } else { result0 = null; pos = clone(pos0); } } else { result0 = null; pos = clone(pos0); } } else { result0 = null; pos = clone(pos0); } } else { result0 = null; pos = clone(pos0); } if (result0 === null) { result0 = parse_reference(); } return result0; } function parse_ld() { var result0; if (input.charCodeAt(pos.offset) === 123) { result0 = "{"; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"{\""); } } return result0; } function parse_rd() { var result0; if (input.charCodeAt(pos.offset) === 125) { result0 = "}"; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"}\""); } } return result0; } function parse_lb() { var result0; if (input.charCodeAt(pos.offset) === 91) { result0 = "["; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"[\""); } } return result0; } function parse_rb() { var result0; if (input.charCodeAt(pos.offset) === 93) { result0 = "]"; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"]\""); } } return result0; } function parse_eol() { var result0; if (input.charCodeAt(pos.offset) === 10) { result0 = "\n"; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\n\""); } } if (result0 === null) { if (input.substr(pos.offset, 2) === "\r\n") { result0 = "\r\n"; advance(pos, 2); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\r\\n\""); } } if (result0 === null) { if (input.charCodeAt(pos.offset) === 13) { result0 = "\r"; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\r\""); } } if (result0 === null) { if (input.charCodeAt(pos.offset) === 8232) { result0 = "\u2028"; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\u2028\""); } } if (result0 === null) { if (input.charCodeAt(pos.offset) === 8233) { result0 = "\u2029"; advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("\"\\u2029\""); } } } } } } return result0; } function parse_ws() { var result0; if (/^[\t\x0B\f \xA0\uFEFF]/.test(input.charAt(pos.offset))) { result0 = input.charAt(pos.offset); advance(pos, 1); } else { result0 = null; if (reportFailures === 0) { matchFailed("[\\t\\x0B\\f \\xA0\\uFEFF]"); } } if (result0 === null) { result0 = parse_eol(); } return result0; } function cleanupExpected(expected) { expected.sort(); var lastExpected = null; var cleanExpected = []; for (var i = 0; i < expected.length; i++) { if (expected[i] !== lastExpected) { cleanExpected.push(expected[i]); lastExpected = expected[i]; } } return cleanExpected; } var result = parseFunctions[startRule](); /* * The parser is now in one of the following three states: * * 1. The parser successfully parsed the whole input. * * - |result !== null| * - |pos.offset === input.length| * - |rightmostFailuresExpected| may or may not contain something * * 2. The parser successfully parsed only a part of the input. * * - |result !== null| * - |pos.offset < input.length| * - |rightmostFailuresExpected| may or may not contain something * * 3. The parser did not successfully parse any part of the input. * * - |result === null| * - |pos.offset === 0| * - |rightmostFailuresExpected| contains at least one failure * * All code following this comment (including called functions) must * handle these states. */ if (result === null || pos.offset !== input.length) { var offset = Math.max(pos.offset, rightmostFailuresPos.offset); var found = offset < input.length ? input.charAt(offset) : null; var errorPosition = pos.offset > rightmostFailuresPos.offset ? pos : rightmostFailuresPos; throw new parser.SyntaxError( cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column ); } return result; }, /* Returns the parser source code. */ toSource: function() { return this._source; } }; /* Thrown when a parser encounters a syntax error. */ result.SyntaxError = function(expected, found, offset, line, column) { function buildMessage(expected, found) { var expectedHumanized, foundHumanized; switch (expected.length) { case 0: expectedHumanized = "end of input"; break; case 1: expectedHumanized = expected[0]; break; default: expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1]; } foundHumanized = found ? quote(found) : "end of input"; return "Expected " + expectedHumanized + " but " + foundHumanized + " found."; } this.name = "SyntaxError"; this.expected = expected; this.found = found; this.message = buildMessage(expected, found); this.offset = offset; this.line = line; this.column = column; }; result.SyntaxError.prototype = Error.prototype; return result; })(); dust.parse = parser.parse; })(typeof exports !== 'undefined' ? exports : getGlobal());