From 7f9aeac9268b4e9431b49cdd857765b219149528 Mon Sep 17 00:00:00 2001 From: Prayrit Jain Date: Tue, 1 Oct 2013 15:55:28 -0700 Subject: [PATCH] Revert "Merge pull request #279 from prashn64/master" This reverts commit d34e117fafbec1d41d0c8d041694cd02af6a3b4c, reversing changes made to 41ed48cd0ec47ee44ec9b43625b9c255ff00f78d. --- Makefile | 26 +- dist/dust-core-2.1.0.js | 687 ---- dist/dust-core-debug-2.1.0.js | 807 ----- dist/dust-full-2.1.0.js | 3663 --------------------- dist/dust-full-debug-2.1.0.js | 3783 ---------------------- lib/dust.js | 204 +- package.json | 2 +- test/core.js | 24 +- test/jasmine-test/spec/coreTests.js | 87 - test/jasmine-test/spec/renderTestSpec.js | 60 +- utils/debug_strip.js | 9 - utils/minifier.js | 2 +- 12 files changed, 45 insertions(+), 9309 deletions(-) delete mode 100644 dist/dust-core-2.1.0.js delete mode 100644 dist/dust-core-debug-2.1.0.js delete mode 100644 dist/dust-full-2.1.0.js delete mode 100644 dist/dust-full-debug-2.1.0.js delete mode 100644 utils/debug_strip.js diff --git a/Makefile b/Makefile index 44499d0f..1abc176c 100644 --- a/Makefile +++ b/Makefile @@ -40,13 +40,9 @@ parser: SRC = lib VERSION = ${shell cat package.json | grep version | grep -o '[0-9]\.[0-9]\.[0-9]\+'} CORE = dist/dust-core-${VERSION}.js -CORE_DEBUG = dist/dust-core-debug-${VERSION}.js CORE_MIN = dist/dust-core-${VERSION}.min.js -CORE_DEBUG_MIN = dist/dust-core-debug-${VERSION}.min.js FULL = dist/dust-full-${VERSION}.js -FULL_DEBUG = dist/dust-full-debug-${VERSION}.js FULL_MIN = dist/dust-full-${VERSION}.min.js -FULL_DEBUG_MIN = dist/dust-full-debug-${VERSION}.min.js define HEADER // @@ -64,34 +60,24 @@ export HEADER #TODO: REMOVE THE HELPERS IN THE NEXT RELEASE dust: @@mkdir -p dist - @@touch ${CORE_DEBUG} - @@echo "$$HEADER" > ${CORE_DEBUG} - @@cat ${SRC}/dust.js >> ${CORE_DEBUG} - @@echo ${CORE_DEBUG} built - - node utils/debug_strip ${CORE_DEBUG} ${CORE} + @@touch ${CORE} + @@echo "$$HEADER" > ${CORE} + @@cat ${SRC}/dust.js >> ${CORE} @@echo ${CORE} built - @@touch ${FULL_DEBUG} - @@echo "$$HEADER" > ${FULL_DEBUG} + @@touch ${FULL} + @@echo "$$HEADER" > ${FULL} @@cat ${SRC}/dust.js\ ${SRC}/compiler.js\ - ${SRC}/parser.js >> ${FULL_DEBUG} - @@echo ${FULL_DEBUG} built - - node utils/debug_strip ${FULL_DEBUG} ${FULL} + ${SRC}/parser.js >> ${FULL} @@echo ${FULL} built min: dust @@echo minifying... @@echo "$$HEADER" > ${CORE_MIN} - @@echo "$$HEADER" > ${CORE_DEBUG_MIN} @@echo "$$HEADER" > ${FULL_MIN} - @@echo "$$HEADER" > ${FULL_DEBUG_MIN} node utils/minifier ${CORE} ${CORE_MIN} - node utils/minifier ${CORE_DEBUG} ${CORE_DEBUG_MIN} node utils/minifier ${FULL} ${FULL_MIN} - node utils/minifier ${FULL_DEBUG} ${FULL_DEBUG_MIN} clean: git rm dist/* diff --git a/dist/dust-core-2.1.0.js b/dist/dust-core-2.1.0.js deleted file mode 100644 index f4d08c7c..00000000 --- a/dist/dust-core-2.1.0.js +++ /dev/null @@ -1,687 +0,0 @@ -// -// Dust - Asynchronous Templating v2.1.0 -// 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, - loadedChunk = dust.load(name, chunk, Context.wrap(context, name)); - loadedChunk.end(); -}; - -dust.stream = function(name, context) { - var stream = new Stream(); - dust.nextTick(function() { - var loadedChunk = dust.load(name, stream.head, Context.wrap(context, name)); - loadedChunk.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() { - if(typeof tmpl === '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 then we have a partial match - // and do not continue to search for the rest of the path. - // Note: a falsey value at the end of a matched path also comes here. - // This returns the value or undefined if we just have a partial match. - if (i > 1) return ctx; - 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) { - var context = new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - return Context.wrap(context); - } -}; - -Context.prototype.rebase = function(head) { - var context = new Context(new Stack(head), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - return Context.wrap(context); - } -}; - -Context.prototype.current = function() { - return this.stack.head; -}; - -Context.prototype.getBlock = function(key, chk, ctx) { - if (typeof key === "function") { - var tempChk = new Chunk(); - key = key(tempChk, this).data.join(""); - } - - 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, this.templateName); - } - return this; -}; - -function Stack(head, tail, idx, len) { - this.tail = tail; - this.isObject = !dust.isArray(head) && head && typeof head === "object"; - if(head != null) { - this.head = head; - } - else { - this.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 if (dust.isArray(handler)) { - 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]) { - if(callback) { - 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 - 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-core-debug-2.1.0.js b/dist/dust-core-debug-2.1.0.js deleted file mode 100644 index a3c1947b..00000000 --- a/dist/dust-core-debug-2.1.0.js +++ /dev/null @@ -1,807 +0,0 @@ -// -// Dust - Asynchronous Templating v2.1.0 -// 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) { -/* DEBUG */ - -var Log = {}; - -Log.queue = []; - -Log.readQueue = function() { return Log.queue; }; - -Log.clearQueue = function() { Log.queue = []; }; - -Log.addMessage = function(message, type) { - type = type || 'INFO'; - Log.queue.push({message: message, type: type}); -}; - -if(!dust) { - Log.addMessage('dust is not defined', 'ERROR'); - return; -} - -/* ENDDEBUG */ -dust.helpers = {}; - -dust.cache = {}; - -dust.register = function(name, tmpl) { - if (!name) { - /* DEBUG */ Log.addMessage('template name is undefined', 'WARN'); /* ENDDEBUG */ - return; - } - /* DEBUG */ - if(typeof tmpl !== 'function') { - Log.addMessage('template [' + name + '] cannot be resolved to a Dust function', 'WARN'); - } - /* ENDDEBUG */ - dust.cache[name] = tmpl; -}; - -dust.render = function(name, context, callback) { - var chunk = new Stub(callback).head, - loadedChunk = dust.load(name, chunk, Context.wrap(context, name)); - /* DEBUG */ - // Also include dust errors in the logs - if(loadedChunk.error && loadedChunk.error.message) { - Log.addMessage(loadedChunk.error.message, 'ERROR'); - } - /* ENDDEBUG */ - loadedChunk.end(); -}; - -dust.stream = function(name, context) { - var stream = new Stream(); - dust.nextTick(function() { - var loadedChunk = dust.load(name, stream.head, Context.wrap(context, name)); - /* DEBUG */ - // Also include dust errors in the logs - if(loadedChunk.error && loadedChunk.error.message) { - Log.addMessage(loadedChunk.error.message, 'ERROR'); - } - /* ENDDEBUG */ - loadedChunk.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() { - if(typeof tmpl === 'function') { - tmpl(master.head, Context.wrap(context, name)).end(); - } - /* DEBUG */ - else { - Log.addMessage('template [' + name + '] cannot be resolved to a dust function', 'WARN'); - } - /* ENDDEBUG */ - }); - 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 then we have a partial match - // and do not continue to search for the rest of the path. - // Note: a falsey value at the end of a matched path also comes here. - // This returns the value or undefined if we just have a partial match. - if (i > 1) return ctx; - 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) { - var context = new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - /* DEBUG */ Log.addMessage('Head [' + head + '] could not be resolved to a context for the template [' + this.templateName + ']', 'WARN'); /* ENDDEBUG */ - return Context.wrap(context); - } -}; - -Context.prototype.rebase = function(head) { - var context = new Context(new Stack(head), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - /* DEBUG */ Log.addMessage('Head [' + head + '] could not be resolved to a context for the template [' + this.templateName + ']', 'WARN'); /* ENDDEBUG */ - return Context.wrap(context); - } -}; - -Context.prototype.current = function() { - return this.stack.head; -}; - -Context.prototype.getBlock = function(key, chk, ctx) { - if (typeof key === "function") { - var tempChk = new Chunk(); - key = key(tempChk, this).data.join(""); - } - - var blocks = this.blocks; - - if (!blocks) { - /* DEBUG */ Log.addMessage('no blocks defined for function getBlock', 'DEBUG'); /* ENDDEBUG */ - 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, this.templateName); - } - return this; -}; - -function Stack(head, tail, idx, len) { - this.tail = tail; - this.isObject = !dust.isArray(head) && head && typeof head === "object"; - if(head != null) { - this.head = head; - } - else { - /* DEBUG */ Log.addMessage('head was undefined. Defaulting to {}', 'DEBUG'); /* ENDDEBUG */ - this.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; - /* DEBUG */var messages = [];/* ENDDEBUG */ - - while (chunk) { - /* DEBUG */ - chunk.setLog(Log.readQueue()); - Log.clearQueue(); - messages = messages.concat(chunk.log); - /* ENDDEBUG */ - if (chunk.flushable) { - this.out += chunk.data.join(""); //ie7 perf - } else if (chunk.error) { - this.callback(chunk.error/* DEBUG */, null, log/* ENDDEBUG */); - /* DEBUG */ Log.addMessage('chunk error [' + chunk.error + '] thrown. Ceasing to render this template.', 'WARN'); /* ENDDEBUG */ - this.flush = function() {}; - return; - } else { - return; - } - chunk = chunk.next; - this.head = chunk; - } - this.callback(null, this.out/* DEBUG */, messages/* ENDDEBUG */); -}; - -function Stream() { - this.head = new Chunk(this); -} - -Stream.prototype.flush = function() { - var chunk = this.head; - /* DEBUG */var messages = []/* ENDDEBUG */ - - while(chunk) { - /* DEBUG */ - chunk.setLog(Log.readQueue()); - Log.clearQueue(); - messages = messages.concat(chunk.log); - /* ENDDEBUG */ - if (chunk.flushable) { - this.emit('data', chunk.data.join("")); //ie7 perf - /* DEBUG */ - this.emit('log', messages); - /* ENDDEBUG */ - } else if (chunk.error) { - this.emit('error', chunk.error); - /* DEBUG */ - Log.addMessage('chunk error [' + chunk.error + '] thrown. Ceasing to render this template.', 'WARN'); - this.emit('log', messages); - /* ENDDEBUG */ - this.flush = function() {}; - return; - } else { - return; - } - chunk = chunk.next; - this.head = chunk; - } - this.emit('end'); -}; - -Stream.prototype.emit = function(type, data) { - if (!this.events) { - /* DEBUG */ Log.addMessage('no events to emit', 'INFO'); /* ENDDEBUG */ - return false; - } - var handler = this.events[type]; - if (!handler) { - /* DEBUG */ Log.addMessage('Event type [' + type + '] does not exist', 'WARN'); /* ENDDEBUG */ - return false; - } - if (typeof handler == 'function') { - handler(data); - } else if (dust.isArray(handler)) { - var listeners = handler.slice(0); - for (var i = 0, l = listeners.length; i < l; i++) { - listeners[i](data); - } - } - /* DEBUG */ - else { - Log.addMessage('handler [' + handler + '] is not of a type that is handled by emit', 'DEBUG'); - } - /* ENDDEBUG */ -}; - -Stream.prototype.on = function(type, callback) { - if (!this.events) { - this.events = {}; - } - if (!this.events[type]) { - /* DEBUG */ Log.addMessage('event type [' + type + '] does not exist. using just the specified callback.', 'WARN'); /* ENDDEBUG */ - if(callback) { - this.events[type] = callback; - } - /* DEBUG */ - else { - Log.addMessage('callback for type [' + type + '] does not exist. listener not registered.', 'WARN'); - } - /* ENDDEBUG */ - } 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); - })/* DEBUG */.on("log", function(logs) { - stream.log(logs); - })/* ENDDEBUG */; - 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 { - /* DEBUG */ Log.addMessage('reference for element was not found.', 'INFO'); /* ENDDEBUG */ - 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 - 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.1.0.js b/dist/dust-full-2.1.0.js deleted file mode 100644 index bb41d32b..00000000 --- a/dist/dust-full-2.1.0.js +++ /dev/null @@ -1,3663 +0,0 @@ -// -// Dust - Asynchronous Templating v2.1.0 -// 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, - loadedChunk = dust.load(name, chunk, Context.wrap(context, name)); - loadedChunk.end(); -}; - -dust.stream = function(name, context) { - var stream = new Stream(); - dust.nextTick(function() { - var loadedChunk = dust.load(name, stream.head, Context.wrap(context, name)); - loadedChunk.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() { - if(typeof tmpl === '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 then we have a partial match - // and do not continue to search for the rest of the path. - // Note: a falsey value at the end of a matched path also comes here. - // This returns the value or undefined if we just have a partial match. - if (i > 1) return ctx; - 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) { - var context = new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - return Context.wrap(context); - } -}; - -Context.prototype.rebase = function(head) { - var context = new Context(new Stack(head), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - return Context.wrap(context); - } -}; - -Context.prototype.current = function() { - return this.stack.head; -}; - -Context.prototype.getBlock = function(key, chk, ctx) { - if (typeof key === "function") { - var tempChk = new Chunk(); - key = key(tempChk, this).data.join(""); - } - - 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, this.templateName); - } - return this; -}; - -function Stack(head, tail, idx, len) { - this.tail = tail; - this.isObject = !dust.isArray(head) && head && typeof head === "object"; - if(head != null) { - this.head = head; - } - else { - this.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 if (dust.isArray(handler)) { - 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]) { - if(callback) { - 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 - 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/dist/dust-full-debug-2.1.0.js b/dist/dust-full-debug-2.1.0.js deleted file mode 100644 index 32f8b921..00000000 --- a/dist/dust-full-debug-2.1.0.js +++ /dev/null @@ -1,3783 +0,0 @@ -// -// Dust - Asynchronous Templating v2.1.0 -// 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) { -/* DEBUG */ - -var Log = {}; - -Log.queue = []; - -Log.readQueue = function() { return Log.queue; }; - -Log.clearQueue = function() { Log.queue = []; }; - -Log.addMessage = function(message, type) { - type = type || 'INFO'; - Log.queue.push({message: message, type: type}); -}; - -if(!dust) { - Log.addMessage('dust is not defined', 'ERROR'); - return; -} - -/* ENDDEBUG */ -dust.helpers = {}; - -dust.cache = {}; - -dust.register = function(name, tmpl) { - if (!name) { - /* DEBUG */ Log.addMessage('template name is undefined', 'WARN'); /* ENDDEBUG */ - return; - } - /* DEBUG */ - if(typeof tmpl !== 'function') { - Log.addMessage('template [' + name + '] cannot be resolved to a Dust function', 'WARN'); - } - /* ENDDEBUG */ - dust.cache[name] = tmpl; -}; - -dust.render = function(name, context, callback) { - var chunk = new Stub(callback).head, - loadedChunk = dust.load(name, chunk, Context.wrap(context, name)); - /* DEBUG */ - // Also include dust errors in the logs - if(loadedChunk.error && loadedChunk.error.message) { - Log.addMessage(loadedChunk.error.message, 'ERROR'); - } - /* ENDDEBUG */ - loadedChunk.end(); -}; - -dust.stream = function(name, context) { - var stream = new Stream(); - dust.nextTick(function() { - var loadedChunk = dust.load(name, stream.head, Context.wrap(context, name)); - /* DEBUG */ - // Also include dust errors in the logs - if(loadedChunk.error && loadedChunk.error.message) { - Log.addMessage(loadedChunk.error.message, 'ERROR'); - } - /* ENDDEBUG */ - loadedChunk.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() { - if(typeof tmpl === 'function') { - tmpl(master.head, Context.wrap(context, name)).end(); - } - /* DEBUG */ - else { - Log.addMessage('template [' + name + '] cannot be resolved to a dust function', 'WARN'); - } - /* ENDDEBUG */ - }); - 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 then we have a partial match - // and do not continue to search for the rest of the path. - // Note: a falsey value at the end of a matched path also comes here. - // This returns the value or undefined if we just have a partial match. - if (i > 1) return ctx; - 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) { - var context = new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - /* DEBUG */ Log.addMessage('Head [' + head + '] could not be resolved to a context for the template [' + this.templateName + ']', 'WARN'); /* ENDDEBUG */ - return Context.wrap(context); - } -}; - -Context.prototype.rebase = function(head) { - var context = new Context(new Stack(head), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - /* DEBUG */ Log.addMessage('Head [' + head + '] could not be resolved to a context for the template [' + this.templateName + ']', 'WARN'); /* ENDDEBUG */ - return Context.wrap(context); - } -}; - -Context.prototype.current = function() { - return this.stack.head; -}; - -Context.prototype.getBlock = function(key, chk, ctx) { - if (typeof key === "function") { - var tempChk = new Chunk(); - key = key(tempChk, this).data.join(""); - } - - var blocks = this.blocks; - - if (!blocks) { - /* DEBUG */ Log.addMessage('no blocks defined for function getBlock', 'DEBUG'); /* ENDDEBUG */ - 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, this.templateName); - } - return this; -}; - -function Stack(head, tail, idx, len) { - this.tail = tail; - this.isObject = !dust.isArray(head) && head && typeof head === "object"; - if(head != null) { - this.head = head; - } - else { - /* DEBUG */ Log.addMessage('head was undefined. Defaulting to {}', 'DEBUG'); /* ENDDEBUG */ - this.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; - /* DEBUG */var messages = [];/* ENDDEBUG */ - - while (chunk) { - /* DEBUG */ - chunk.setLog(Log.readQueue()); - Log.clearQueue(); - messages = messages.concat(chunk.log); - /* ENDDEBUG */ - if (chunk.flushable) { - this.out += chunk.data.join(""); //ie7 perf - } else if (chunk.error) { - this.callback(chunk.error/* DEBUG */, null, log/* ENDDEBUG */); - /* DEBUG */ Log.addMessage('chunk error [' + chunk.error + '] thrown. Ceasing to render this template.', 'WARN'); /* ENDDEBUG */ - this.flush = function() {}; - return; - } else { - return; - } - chunk = chunk.next; - this.head = chunk; - } - this.callback(null, this.out/* DEBUG */, messages/* ENDDEBUG */); -}; - -function Stream() { - this.head = new Chunk(this); -} - -Stream.prototype.flush = function() { - var chunk = this.head; - /* DEBUG */var messages = []/* ENDDEBUG */ - - while(chunk) { - /* DEBUG */ - chunk.setLog(Log.readQueue()); - Log.clearQueue(); - messages = messages.concat(chunk.log); - /* ENDDEBUG */ - if (chunk.flushable) { - this.emit('data', chunk.data.join("")); //ie7 perf - /* DEBUG */ - this.emit('log', messages); - /* ENDDEBUG */ - } else if (chunk.error) { - this.emit('error', chunk.error); - /* DEBUG */ - Log.addMessage('chunk error [' + chunk.error + '] thrown. Ceasing to render this template.', 'WARN'); - this.emit('log', messages); - /* ENDDEBUG */ - this.flush = function() {}; - return; - } else { - return; - } - chunk = chunk.next; - this.head = chunk; - } - this.emit('end'); -}; - -Stream.prototype.emit = function(type, data) { - if (!this.events) { - /* DEBUG */ Log.addMessage('no events to emit', 'INFO'); /* ENDDEBUG */ - return false; - } - var handler = this.events[type]; - if (!handler) { - /* DEBUG */ Log.addMessage('Event type [' + type + '] does not exist', 'WARN'); /* ENDDEBUG */ - return false; - } - if (typeof handler == 'function') { - handler(data); - } else if (dust.isArray(handler)) { - var listeners = handler.slice(0); - for (var i = 0, l = listeners.length; i < l; i++) { - listeners[i](data); - } - } - /* DEBUG */ - else { - Log.addMessage('handler [' + handler + '] is not of a type that is handled by emit', 'DEBUG'); - } - /* ENDDEBUG */ -}; - -Stream.prototype.on = function(type, callback) { - if (!this.events) { - this.events = {}; - } - if (!this.events[type]) { - /* DEBUG */ Log.addMessage('event type [' + type + '] does not exist. using just the specified callback.', 'WARN'); /* ENDDEBUG */ - if(callback) { - this.events[type] = callback; - } - /* DEBUG */ - else { - Log.addMessage('callback for type [' + type + '] does not exist. listener not registered.', 'WARN'); - } - /* ENDDEBUG */ - } 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); - })/* DEBUG */.on("log", function(logs) { - stream.log(logs); - })/* ENDDEBUG */; - 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 { - /* DEBUG */ Log.addMessage('reference for element was not found.', 'INFO'); /* ENDDEBUG */ - 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 - 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/dust.js b/lib/dust.js index 8dc0564b..bed85166 100755 --- a/lib/dust.js +++ b/lib/dust.js @@ -7,67 +7,25 @@ function getGlobal(){ } (function(dust) { -/* DEBUG */ -var Log = {}; - -Log.queue = []; - -Log.readQueue = function() { return Log.queue; }; - -Log.clearQueue = function() { Log.queue = []; }; - -Log.addMessage = function(message, type) { - type = type || 'INFO'; - Log.queue.push({message: message, type: type}); -}; - -if(!dust) { - Log.addMessage('dust is not defined', 'ERROR'); - return; -} - -/* ENDDEBUG */ dust.helpers = {}; dust.cache = {}; dust.register = function(name, tmpl) { - if (!name) { - /* DEBUG */ Log.addMessage('template name is undefined', 'WARN'); /* ENDDEBUG */ - return; - } - /* DEBUG */ - if(typeof tmpl !== 'function') { - Log.addMessage('template [' + name + '] cannot be resolved to a Dust function', 'WARN'); - } - /* ENDDEBUG */ + if (!name) return; dust.cache[name] = tmpl; }; dust.render = function(name, context, callback) { - var chunk = new Stub(callback).head, - loadedChunk = dust.load(name, chunk, Context.wrap(context, name)); - /* DEBUG */ - // Also include dust errors in the logs - if(loadedChunk.error && loadedChunk.error.message) { - Log.addMessage(loadedChunk.error.message, 'ERROR'); - } - /* ENDDEBUG */ - loadedChunk.end(); + 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() { - var loadedChunk = dust.load(name, stream.head, Context.wrap(context, name)); - /* DEBUG */ - // Also include dust errors in the logs - if(loadedChunk.error && loadedChunk.error.message) { - Log.addMessage(loadedChunk.error.message, 'ERROR'); - } - /* ENDDEBUG */ - loadedChunk.end(); + dust.load(name, stream.head, Context.wrap(context, name)).end(); }); return stream; }; @@ -81,14 +39,7 @@ dust.compileFn = function(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(); - } - /* DEBUG */ - else { - Log.addMessage('template [' + name + '] cannot be resolved to a dust function', 'WARN'); - } - /* ENDDEBUG */ + tmpl(master.head, Context.wrap(context, name)).end(); }); return master; }; @@ -120,7 +71,7 @@ if (Array.isArray) { dust.isArray = Array.isArray; } else { dust.isArray = function(arr) { - return Object.prototype.toString.call(arr) === "[object Array]"; + return Object.prototype.toString.call(arr) == "[object Array]"; }; } @@ -147,16 +98,11 @@ dust.filter = function(string, auto, filters) { var name = filters[i]; if (name === "s") { auto = null; - /* DEBUG */ Log.addMessage('using unescape filter on [' + string + ']', 'DEBUG'); /* ENDDEBUG */ } + // fail silently for invalid filters else if (typeof dust.filters[name] === 'function') { string = dust.filters[name](string); } - /* DEBUG */ - else { - Log.addMessage('invalid filter [' + name + ']', 'WARN'); - } - /* ENDDEBUG */ } } // by default always apply the h filter, unless asked to unescape with |s @@ -171,8 +117,8 @@ dust.filters = { j: function(value) { return dust.escapeJs(value); }, u: encodeURI, uc: encodeURIComponent, - js: function(value) { if (!JSON) {/* DEBUG */ Log.addMessage('JSON is undefined. JSON stringify has not been used on [' + value + ']', 'WARN'); /* ENDDEBUG */return value; } return JSON.stringify(value); }, - jp: function(value) { if (!JSON) {/* DEBUG */ Log.addMessage('JSON is undefined. JSON parse has not been used on [' + value + ']', 'WARN'); /* ENDDEBUG */return value; } return JSON.parse(value); } + js: function(value) { if (!JSON) { return value; } return JSON.stringify(value); }, + jp: function(value) { if (!JSON) { return value; } return JSON.parse(value); } }; function Context(stack, global, blocks, templateName) { @@ -198,43 +144,22 @@ Context.prototype.get = function(key) { while(ctx) { if (ctx.isObject) { - if(ctx.head) { - value = ctx.head[key]; - } - /* DEBUG */ - else { - Log.addMessage('context head is undefined for[' + key + ']', 'WARN'); - } - /* ENDDEBUG */ + value = ctx.head[key]; if (!(value === undefined)) { return value; } } - /* DEBUG */ - else { - Log.addMessage('current context is not an object. Cannot find value for [{' + key + '}]', 'DEBUG'); - } - Log.addMessage('Looking for [{' + key + '}] up the context stack', 'DEBUG'); - /* ENDDEBUG */ ctx = ctx.tail; } - /* DEBUG */ Log.addMessage('Looking for [{' + key + '}] in the globals', 'DEBUG'); /* ENDDEBUG */ return this.global ? this.global[key] : undefined; }; //supports dot path resolution, function wrapped apply, and searching global paths Context.prototype.getPath = function(cur, down) { var ctx = this.stack, ctxThis, - len = down ? down.length : 0, - tail = cur ? undefined : this.stack.tail; - /* DEBUG */ - if(!down) { - Log.addMessage('array parameter in getPath is not defined', 'INFO'); - } - if(!dust.isArray(down)) { - Log.addMessage('array parameter in getPath is not an array', 'INFO'); - } - /* ENDDEBUG */ + len = down.length, + tail = cur ? undefined : this.stack.tail; + if (cur && len === 0) return ctx.head; ctx = ctx.head; var i = 0; @@ -272,25 +197,11 @@ Context.prototype.getPath = function(cur, down) { }; Context.prototype.push = function(head, idx, len) { - var context = new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - /* DEBUG */ Log.addMessage('Head [' + head + '] could not be resolved to a context for the template [' + this.templateName + ']', 'WARN'); /* ENDDEBUG */ - return Context.wrap(context); - } + return new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks, this.templateName); }; Context.prototype.rebase = function(head) { - var context = new Context(new Stack(head), this.global, this.blocks, this.templateName); - if(context) { - return context; - } - else { - /* DEBUG */ Log.addMessage('Head [' + head + '] could not be resolved to a context for the template [' + this.templateName + ']', 'WARN'); /* ENDDEBUG */ - return Context.wrap(context); - } + return new Context(new Stack(head), this.global, this.blocks, this.templateName); }; Context.prototype.current = function() { @@ -305,10 +216,7 @@ Context.prototype.getBlock = function(key, chk, ctx) { var blocks = this.blocks; - if (!blocks) { - /* DEBUG */ Log.addMessage('no blocks defined for function getBlock', 'DEBUG'); /* ENDDEBUG */ - return; - } + if (!blocks) return; var len = blocks.length, fn; while (len--) { fn = blocks[len][key]; @@ -334,13 +242,7 @@ Context.prototype.shiftBlocks = function(locals) { function Stack(head, tail, idx, len) { this.tail = tail; this.isObject = !dust.isArray(head) && head && typeof head === "object"; - if(head != null) { - this.head = head; - } - else { - /* DEBUG */ Log.addMessage('head was undefined. Defaulting to {}', 'DEBUG'); /* ENDDEBUG */ - this.head = {}; - } + this.head = head; this.index = idx; this.of = len; } @@ -353,19 +255,12 @@ function Stub(callback) { Stub.prototype.flush = function() { var chunk = this.head; - /* DEBUG */var messages = [];/* ENDDEBUG */ while (chunk) { - /* DEBUG */ - chunk.setLog(Log.readQueue()); - Log.clearQueue(); - messages = messages.concat(chunk.log); - /* ENDDEBUG */ if (chunk.flushable) { this.out += chunk.data.join(""); //ie7 perf } else if (chunk.error) { - this.callback(chunk.error/* DEBUG */, null, log/* ENDDEBUG */); - /* DEBUG */ Log.addMessage('chunk error [' + chunk.error + '] thrown. Ceasing to render this template.', 'WARN'); /* ENDDEBUG */ + this.callback(chunk.error); this.flush = function() {}; return; } else { @@ -374,7 +269,7 @@ Stub.prototype.flush = function() { chunk = chunk.next; this.head = chunk; } - this.callback(null, this.out/* DEBUG */, messages/* ENDDEBUG */); + this.callback(null, this.out); }; function Stream() { @@ -383,25 +278,12 @@ function Stream() { Stream.prototype.flush = function() { var chunk = this.head; - /* DEBUG */var messages = []/* ENDDEBUG */ while(chunk) { - /* DEBUG */ - chunk.setLog(Log.readQueue()); - Log.clearQueue(); - messages = messages.concat(chunk.log); - /* ENDDEBUG */ if (chunk.flushable) { this.emit('data', chunk.data.join("")); //ie7 perf - /* DEBUG */ - this.emit('log', messages); - /* ENDDEBUG */ } else if (chunk.error) { this.emit('error', chunk.error); - /* DEBUG */ - Log.addMessage('chunk error [' + chunk.error + '] thrown. Ceasing to render this template.', 'WARN'); - this.emit('log', messages); - /* ENDDEBUG */ this.flush = function() {}; return; } else { @@ -414,28 +296,17 @@ Stream.prototype.flush = function() { }; Stream.prototype.emit = function(type, data) { - if (!this.events) { - /* DEBUG */ Log.addMessage('no events to emit', 'INFO'); /* ENDDEBUG */ - return false; - } + if (!this.events) return false; var handler = this.events[type]; - if (!handler) { - /* DEBUG */ Log.addMessage('Event type [' + type + '] does not exist', 'WARN'); /* ENDDEBUG */ - return false; - } + if (!handler) return false; if (typeof handler == 'function') { handler(data); - } else if (dust.isArray(handler)) { + } else { var listeners = handler.slice(0); for (var i = 0, l = listeners.length; i < l; i++) { listeners[i](data); } } - /* DEBUG */ - else { - Log.addMessage('handler [' + handler + '] is not of a type that is handled by emit', 'DEBUG'); - } - /* ENDDEBUG */ }; Stream.prototype.on = function(type, callback) { @@ -443,15 +314,7 @@ Stream.prototype.on = function(type, callback) { this.events = {}; } if (!this.events[type]) { - /* DEBUG */ Log.addMessage('event type [' + type + '] does not exist. using just the specified callback.', 'WARN'); /* ENDDEBUG */ - if(callback) { - this.events[type] = callback; - } - /* DEBUG */ - else { - Log.addMessage('callback for type [' + type + '] does not exist. listener not registered.', 'WARN'); - } - /* ENDDEBUG */ + this.events[type] = callback; } else if(typeof this.events[type] === 'function') { this.events[type] = [this.events[type], callback]; } else { @@ -467,9 +330,7 @@ Stream.prototype.pipe = function(stream) { stream.end(); }).on("error", function(err) { stream.error(err); - })/* DEBUG */.on("log", function(logs) { - stream.log(logs); - })/* ENDDEBUG */; + }); return this; }; @@ -543,7 +404,6 @@ Chunk.prototype.reference = function(elem, context, auto, filters) { if (!dust.isEmpty(elem)) { return this.write(dust.filter(elem, auto, filters)); } else { - /* DEBUG */ Log.addMessage('reference for element was not found.', 'INFO'); /* ENDDEBUG */ return this; } }; @@ -578,7 +438,9 @@ Chunk.prototype.section = function(elem, context, bodies, params) { if (len > 0) { // any custom helper can blow up the stack // and store a flattened context, guard defensively - context.stack.head['$len'] = len; + if(context.stack.head) { + context.stack.head['$len'] = len; + } for (var i=0; i