diff --git a/dist/dust-core-2.0.2.js b/dist/dust-core-2.0.2.js new file mode 100644 index 00000000..23912be6 --- /dev/null +++ b/dist/dust-core-2.0.2.js @@ -0,0 +1,660 @@ +// +// Dust - Asynchronous Templating v2.0.2 +// http://akdubya.github.com/dustjs +// +// Copyright (c) 2010, Aleksander Williams +// Released under the MIT License. +// + +var dust = {}; + +function getGlobal(){ + return (function(){ + return this.dust; + }).call(null); +} + +(function(dust) { + +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; + dust.load(name, chunk, Context.wrap(context, name)).end(); +}; + +dust.stream = function(name, context) { + var stream = new Stream(); + dust.nextTick(function() { + dust.load(name, stream.head, Context.wrap(context, name)).end(); + }); + 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() { + tmpl(master.head, Context.wrap(context, name)).end(); + }); + 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 1) return undefined; + if (tail){ + ctx = tail.head; + tail = tail.tail; + i=0; + } else if (!cur) { + //finally search this.global. we set cur to true to halt after + ctx = this.global; + cur = true; + i=0; + } + } + } + if (typeof ctx == 'function'){ + //wrap to preserve context 'this' see #174 + return function(){ + return ctx.apply(ctxThis,arguments); + }; + } + else { + return ctx; + } +}; + +Context.prototype.push = function(head, idx, len) { + return new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks); +}; + +Context.prototype.rebase = function(head) { + return new Context(new Stack(head), this.global, this.blocks); +}; + +Context.prototype.current = function() { + return this.stack.head; +}; + +Context.prototype.getBlock = function(key, chk, ctx) { + if (typeof key === "function") { + key = key(chk, ctx).data.join(""); + chk.data = []; //ie7 perf + } + + var blocks = this.blocks; + + if (!blocks) return; + var len = blocks.length, fn; + while (len--) { + fn = blocks[len][key]; + if (fn) return fn; + } +}; + +Context.prototype.shiftBlocks = function(locals) { + var blocks = this.blocks, + newBlocks; + + if (locals) { + if (!blocks) { + newBlocks = [locals]; + } else { + newBlocks = blocks.concat([locals]); + } + return new Context(this.stack, this.global, newBlocks); + } + return this; +}; + +function Stack(head, tail, idx, len) { + this.tail = tail; + this.isObject = !dust.isArray(head) && head && typeof head === "object"; + this.head = head; + this.index = idx; + this.of = len; +} + +function Stub(callback) { + this.head = new Chunk(this); + this.callback = callback; + this.out = ''; +} + +Stub.prototype.flush = function() { + var chunk = this.head; + + while (chunk) { + if (chunk.flushable) { + this.out += chunk.data.join(""); //ie7 perf + } else if (chunk.error) { + this.callback(chunk.error); + this.flush = function() {}; + return; + } else { + return; + } + chunk = chunk.next; + this.head = chunk; + } + this.callback(null, this.out); +}; + +function Stream() { + this.head = new Chunk(this); +} + +Stream.prototype.flush = function() { + var chunk = this.head; + + while(chunk) { + if (chunk.flushable) { + this.emit('data', chunk.data.join("")); //ie7 perf + } else if (chunk.error) { + this.emit('error', chunk.error); + this.flush = function() {}; + return; + } else { + return; + } + chunk = chunk.next; + this.head = chunk; + } + this.emit('end'); +}; + +Stream.prototype.emit = function(type, data) { + if (!this.events) return false; + var handler = this.events[type]; + if (!handler) return false; + if (typeof handler == 'function') { + handler(data); + } else { + var listeners = handler.slice(0); + for (var i = 0, l = listeners.length; i < l; i++) { + listeners[i](data); + } + } +}; + +Stream.prototype.on = function(type, callback) { + if (!this.events) { + this.events = {}; + } + if (!this.events[type]) { + this.events[type] = callback; + } else if(typeof this.events[type] === 'function') { + this.events[type] = [this.events[type], callback]; + } else { + this.events[type].push(callback); + } + return this; +}; + +Stream.prototype.pipe = function(stream) { + this.on("data", function(data) { + stream.write(data, "utf8"); + }).on("end", function() { + stream.end(); + }).on("error", function(err) { + stream.error(err); + }); + return this; +}; + +function Chunk(root, next, taps) { + this.root = root; + this.next = next; + this.data = []; //ie7 perf + this.flushable = false; + this.taps = taps; +} + +Chunk.prototype.write = function(data) { + var taps = this.taps; + + if (taps) { + data = taps.go(data); + } + this.data.push(data); + return this; +}; + +Chunk.prototype.end = function(data) { + if (data) { + this.write(data); + } + this.flushable = true; + this.root.flush(); + return this; +}; + +Chunk.prototype.map = function(callback) { + var cursor = new Chunk(this.root, this.next, this.taps), + branch = new Chunk(this.root, cursor, this.taps); + + this.next = branch; + this.flushable = true; + callback(branch); + return cursor; +}; + +Chunk.prototype.tap = function(tap) { + var taps = this.taps; + + if (taps) { + this.taps = taps.push(tap); + } else { + this.taps = new Tap(tap); + } + return this; +}; + +Chunk.prototype.untap = function() { + this.taps = this.taps.tail; + return this; +}; + +Chunk.prototype.render = function(body, context) { + return body(this, context); +}; + +Chunk.prototype.reference = function(elem, context, auto, filters) { + if (typeof elem === "function") { + elem.isFunction = true; + // Changed the function calling to use apply with the current context to make sure + // that "this" is wat we expect it to be inside the function + elem = elem.apply(context.current(), [this, context, null, {auto: auto, filters: filters}]); + if (elem instanceof Chunk) { + return elem; + } + } + if (!dust.isEmpty(elem)) { + return this.write(dust.filter(elem, auto, filters)); + } else { + return this; + } +}; + +Chunk.prototype.section = function(elem, context, bodies, params) { + // anonymous functions + if (typeof elem === "function") { + elem = elem.apply(context.current(), [this, context, bodies, params]); + // functions that return chunks are assumed to have handled the body and/or have modified the chunk + // use that return value as the current chunk and go to the next method in the chain + if (elem instanceof Chunk) { + return elem; + } + } + var body = bodies.block, + skip = bodies['else']; + + // a.k.a Inline parameters in the Dust documentations + if (params) { + context = context.push(params); + } + + /* + Dust's default behavior is to enumerate over the array elem, passing each object in the array to the block. + When elem resolves to a value or object instead of an array, Dust sets the current context to the value + and renders the block one time. + */ + //non empty array is truthy, empty array is falsy + if (dust.isArray(elem)) { + if (body) { + var len = elem.length, chunk = this; + if (len > 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; +} diff --git a/dist/dust-full-2.0.2.js b/dist/dust-full-2.0.2.js new file mode 100644 index 00000000..cc2add7a --- /dev/null +++ b/dist/dust-full-2.0.2.js @@ -0,0 +1,3636 @@ +// +// Dust - Asynchronous Templating v2.0.2 +// http://akdubya.github.com/dustjs +// +// Copyright (c) 2010, Aleksander Williams +// Released under the MIT License. +// + +var dust = {}; + +function getGlobal(){ + return (function(){ + return this.dust; + }).call(null); +} + +(function(dust) { + +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; + dust.load(name, chunk, Context.wrap(context, name)).end(); +}; + +dust.stream = function(name, context) { + var stream = new Stream(); + dust.nextTick(function() { + dust.load(name, stream.head, Context.wrap(context, name)).end(); + }); + 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() { + tmpl(master.head, Context.wrap(context, name)).end(); + }); + 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 1) return undefined; + if (tail){ + ctx = tail.head; + tail = tail.tail; + i=0; + } else if (!cur) { + //finally search this.global. we set cur to true to halt after + ctx = this.global; + cur = true; + i=0; + } + } + } + if (typeof ctx == 'function'){ + //wrap to preserve context 'this' see #174 + return function(){ + return ctx.apply(ctxThis,arguments); + }; + } + else { + return ctx; + } +}; + +Context.prototype.push = function(head, idx, len) { + return new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks); +}; + +Context.prototype.rebase = function(head) { + return new Context(new Stack(head), this.global, this.blocks); +}; + +Context.prototype.current = function() { + return this.stack.head; +}; + +Context.prototype.getBlock = function(key, chk, ctx) { + if (typeof key === "function") { + key = key(chk, ctx).data.join(""); + chk.data = []; //ie7 perf + } + + var blocks = this.blocks; + + if (!blocks) return; + var len = blocks.length, fn; + while (len--) { + fn = blocks[len][key]; + if (fn) return fn; + } +}; + +Context.prototype.shiftBlocks = function(locals) { + var blocks = this.blocks, + newBlocks; + + if (locals) { + if (!blocks) { + newBlocks = [locals]; + } else { + newBlocks = blocks.concat([locals]); + } + return new Context(this.stack, this.global, newBlocks); + } + return this; +}; + +function Stack(head, tail, idx, len) { + this.tail = tail; + this.isObject = !dust.isArray(head) && head && typeof head === "object"; + this.head = head; + this.index = idx; + this.of = len; +} + +function Stub(callback) { + this.head = new Chunk(this); + this.callback = callback; + this.out = ''; +} + +Stub.prototype.flush = function() { + var chunk = this.head; + + while (chunk) { + if (chunk.flushable) { + this.out += chunk.data.join(""); //ie7 perf + } else if (chunk.error) { + this.callback(chunk.error); + this.flush = function() {}; + return; + } else { + return; + } + chunk = chunk.next; + this.head = chunk; + } + this.callback(null, this.out); +}; + +function Stream() { + this.head = new Chunk(this); +} + +Stream.prototype.flush = function() { + var chunk = this.head; + + while(chunk) { + if (chunk.flushable) { + this.emit('data', chunk.data.join("")); //ie7 perf + } else if (chunk.error) { + this.emit('error', chunk.error); + this.flush = function() {}; + return; + } else { + return; + } + chunk = chunk.next; + this.head = chunk; + } + this.emit('end'); +}; + +Stream.prototype.emit = function(type, data) { + if (!this.events) return false; + var handler = this.events[type]; + if (!handler) return false; + if (typeof handler == 'function') { + handler(data); + } else { + var listeners = handler.slice(0); + for (var i = 0, l = listeners.length; i < l; i++) { + listeners[i](data); + } + } +}; + +Stream.prototype.on = function(type, callback) { + if (!this.events) { + this.events = {}; + } + if (!this.events[type]) { + this.events[type] = callback; + } else if(typeof this.events[type] === 'function') { + this.events[type] = [this.events[type], callback]; + } else { + this.events[type].push(callback); + } + return this; +}; + +Stream.prototype.pipe = function(stream) { + this.on("data", function(data) { + stream.write(data, "utf8"); + }).on("end", function() { + stream.end(); + }).on("error", function(err) { + stream.error(err); + }); + return this; +}; + +function Chunk(root, next, taps) { + this.root = root; + this.next = next; + this.data = []; //ie7 perf + this.flushable = false; + this.taps = taps; +} + +Chunk.prototype.write = function(data) { + var taps = this.taps; + + if (taps) { + data = taps.go(data); + } + this.data.push(data); + return this; +}; + +Chunk.prototype.end = function(data) { + if (data) { + this.write(data); + } + this.flushable = true; + this.root.flush(); + return this; +}; + +Chunk.prototype.map = function(callback) { + var cursor = new Chunk(this.root, this.next, this.taps), + branch = new Chunk(this.root, cursor, this.taps); + + this.next = branch; + this.flushable = true; + callback(branch); + return cursor; +}; + +Chunk.prototype.tap = function(tap) { + var taps = this.taps; + + if (taps) { + this.taps = taps.push(tap); + } else { + this.taps = new Tap(tap); + } + return this; +}; + +Chunk.prototype.untap = function() { + this.taps = this.taps.tail; + return this; +}; + +Chunk.prototype.render = function(body, context) { + return body(this, context); +}; + +Chunk.prototype.reference = function(elem, context, auto, filters) { + if (typeof elem === "function") { + elem.isFunction = true; + // Changed the function calling to use apply with the current context to make sure + // that "this" is wat we expect it to be inside the function + elem = elem.apply(context.current(), [this, context, null, {auto: auto, filters: filters}]); + if (elem instanceof Chunk) { + return elem; + } + } + if (!dust.isEmpty(elem)) { + return this.write(dust.filter(elem, auto, filters)); + } else { + return this; + } +}; + +Chunk.prototype.section = function(elem, context, bodies, params) { + // anonymous functions + if (typeof elem === "function") { + elem = elem.apply(context.current(), [this, context, bodies, params]); + // functions that return chunks are assumed to have handled the body and/or have modified the chunk + // use that return value as the current chunk and go to the next method in the chain + if (elem instanceof Chunk) { + return elem; + } + } + var body = bodies.block, + skip = bodies['else']; + + // a.k.a Inline parameters in the Dust documentations + if (params) { + context = context.push(params); + } + + /* + Dust's default behavior is to enumerate over the array elem, passing each object in the array to the block. + When elem resolves to a value or object instead of an array, Dust sets the current context to the value + and renders the block one time. + */ + //non empty array is truthy, empty array is falsy + if (dust.isArray(elem)) { + if (body) { + var len = elem.length, chunk = this; + if (len > 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; + if (!context) context = 'h'; + compiler.auto = (context === 's') ? '' : context; + var out = compileParts(compiler, bodies.block); + compiler.auto = old; + return out; + } +}; + +function visit(context, node) { + var out = [node[0]]; + for (var 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()); \ No newline at end of file diff --git a/lib/parser.js b/lib/parser.js index d3ca968d..9d6b1357 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -256,7 +256,7 @@ var parser = (function(){ 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 })(pos0.offset, pos0.line, pos0.column, result0[0], result0[3], result0[4], result0[5]); + 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); @@ -1725,7 +1725,7 @@ var parser = (function(){ pos0 = clone(pos); result0 = parse_literal(); if (result0 !== null) { - result0 = (function(offset, line, column, l) { return ["buffer", l].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0); + result0 = (function(offset, line, column, l) { return ["buffer", l] })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { pos = clone(pos0); @@ -1761,7 +1761,7 @@ var parser = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, e, w) { return ["format", e, w.join('')] })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); + 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); diff --git a/package.json b/package.json index a54a2af3..2e8ecda2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dustjs-linkedin", - "version": "2.0.1", + "version": "2.0.2", "author": "Aleksander Williams", "description": "Asynchronous templates for the browser and node.js ( LinkedIn fork )", "contributors": [