diff --git a/lib/dust-rails/rails/dust_template.rb b/lib/dust-rails/rails/dust_template.rb index 56d5a79..1f1b4fd 100644 --- a/lib/dust-rails/rails/dust_template.rb +++ b/lib/dust-rails/rails/dust_template.rb @@ -6,7 +6,7 @@ module Rails module Source def self.path - @path ||= File.expand_path('../../../../vendor/assets/javascripts/dust-full-for-compile.js', __FILE__) + @path ||= File.expand_path('../../../../vendor/dustjs/lib/dust.js', __FILE__) end def self.contents diff --git a/vendor/assets/javascripts/dust-core.js b/vendor/assets/javascripts/dust-core.js index 04a0cd2..26019bd 100644 --- a/vendor/assets/javascripts/dust-core.js +++ b/vendor/assets/javascripts/dust-core.js @@ -1,5 +1,5 @@ // -// Dust - Asynchronous Templating v0.3.0 +// Dust - Asynchronous Templating v1.0.0 // http://akdubya.github.com/dustjs // // Copyright (c) 2010, Aleksander Williams @@ -8,6 +8,12 @@ var dust = {}; +function getGlobal(){ + return (function(){ + return this.dust; + }).call(null); +} + (function(dust) { dust.cache = {}; @@ -75,9 +81,15 @@ if (Array.isArray) { }; } -dust.nextTick = function(callback) { - setTimeout(callback, 0); -} +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; @@ -106,8 +118,10 @@ dust.filters = { h: function(value) { return dust.escapeHtml(value); }, j: function(value) { return dust.escapeJs(value); }, u: encodeURI, - uc: encodeURIComponent -} + uc: encodeURIComponent, + 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) { this.stack = stack; @@ -117,14 +131,14 @@ function Context(stack, global, blocks) { dust.makeBase = function(global) { return new Context(new Stack(), global); -} +}; Context.wrap = function(context) { if (context instanceof Context) { return context; } return new Context(new Stack(context)); -} +}; Context.prototype.get = function(key) { var ctx = this.stack, value; @@ -146,7 +160,6 @@ Context.prototype.getPath = function(cur, down) { len = down.length; if (cur && len === 0) return ctx.head; - if (!ctx.isObject) return undefined; ctx = ctx.head; var i = 0; while(ctx && i < len) { @@ -168,7 +181,12 @@ Context.prototype.current = function() { return this.stack.head; }; -Context.prototype.getBlock = function(key) { +Context.prototype.getBlock = function(key, chk, ctx) { + if (typeof key === "function") { + key = key(chk, ctx).data; + chk.data = ""; + } + var blocks = this.blocks; if (!blocks) return; @@ -177,7 +195,7 @@ Context.prototype.getBlock = function(key) { fn = blocks[len][key]; if (fn) return fn; } -} +}; Context.prototype.shiftBlocks = function(locals) { var blocks = this.blocks; @@ -191,7 +209,7 @@ Context.prototype.shiftBlocks = function(locals) { return new Context(this.stack, this.global, newBlocks); } return this; -} +}; function Stack(head, tail, idx, len) { this.tail = tail; @@ -224,7 +242,7 @@ Stub.prototype.flush = function() { this.head = chunk; } this.callback(null, this.out); -} +}; function Stream() { this.head = new Chunk(this); @@ -247,23 +265,46 @@ Stream.prototype.flush = function() { this.head = chunk; } this.emit('end'); -} +}; Stream.prototype.emit = function(type, data) { - var events = this.events; - - if (events && events[type]) { - events[type](data); + if (!this.events) return false; + var handler = this.events[type]; + if (!handler) return false; + if (typeof handler == 'function') { + handler(data); + } else { + var listeners = handler.slice(0); + for (var i = 0, l = listeners.length; i < l; i++) { + listeners[i](data); + } } -} +}; Stream.prototype.on = function(type, callback) { if (!this.events) { this.events = {}; } - this.events[type] = callback; + if (!this.events[type]) { + this.events[type] = callback; + } else if(typeof this.events[type] === 'function') { + this.events[type] = [this.events[type], callback]; + } else { + this.events[type].push(callback); + } return this; -} +}; + +Stream.prototype.pipe = function(stream) { + this.on("data", function(data) { + stream.write(data, "utf8"); + }).on("end", function() { + stream.end(); + }).on("error", function(err) { + stream.error(err); + }); + return this; +}; function Chunk(root, next, taps) { this.root = root; @@ -281,7 +322,7 @@ Chunk.prototype.write = function(data) { } this.data += data; return this; -} +}; Chunk.prototype.end = function(data) { if (data) { @@ -290,7 +331,7 @@ Chunk.prototype.end = function(data) { this.flushable = true; this.root.flush(); return this; -} +}; Chunk.prototype.map = function(callback) { var cursor = new Chunk(this.root, this.next, this.taps), @@ -300,7 +341,7 @@ Chunk.prototype.map = function(callback) { this.flushable = true; callback(branch); return cursor; -} +}; Chunk.prototype.tap = function(tap) { var taps = this.taps; @@ -311,20 +352,22 @@ Chunk.prototype.tap = function(tap) { 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 = elem(this, context, null, {auto: auto, filters: filters}); + elem.isReference = 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; } @@ -338,7 +381,7 @@ Chunk.prototype.reference = function(elem, context, auto, filters) { Chunk.prototype.section = function(elem, context, bodies, params) { if (typeof elem === "function") { - elem = elem(this, context, bodies, params); + elem = elem.apply(context.current(), [this, context, bodies, params]); if (elem instanceof Chunk) { return elem; } @@ -354,15 +397,26 @@ Chunk.prototype.section = function(elem, context, bodies, params) { if (dust.isArray(elem)) { if (body) { var len = elem.length, chunk = this; + context.stack.head['$len'] = len; for (var i=0; i\"]/), +var HCHARS = new RegExp(/[&<>\"\']/), AMP = /&/g, LT = //g, - QUOT = /\"/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,'"'); + return s.replace(AMP,'&').replace(LT,'<').replace(GT,'>').replace(QUOT,'"').replace(SQUOT, '''); } return s; }; @@ -515,8 +567,201 @@ dust.escapeJs = function(s) { })(dust); if (typeof exports !== "undefined") { + //TODO: Remove the helpers from dust core in the next release. + dust.helpers = require("./dust-helpers").helpers; if (typeof process !== "undefined") { require('./server')(dust); } module.exports = dust; } +(function(dust){ + +/* make a safe version of console if it is not available + * currently supporting: + * _console.log + * */ +var _console = (typeof console !== 'undefined')? console: { + log: function(){ + /* a noop*/ + } +}; + +function isSelect(context) { + var value = context.current(); + return typeof value === "object" && value.isSelect === true; +} + +function filter(chunk, context, bodies, params, filter) { + var params = params || {}, + actual, + expected; + if (params.key) { + actual = helpers.tap(params.key, chunk, context); + } else if (isSelect(context)) { + actual = context.current().selectKey; + if (context.current().isResolved) { + filter = function() { return false; }; + } + } else { + throw "No key specified for filter and no key found in context from select statement"; + } + expected = helpers.tap(params.value, chunk, context); + if (filter(expected, coerce(actual, params.type, context))) { + if (isSelect(context)) { + context.current().isResolved = true; + } + return chunk.render(bodies.block, context); + } else if (bodies['else']) { + return chunk.render(bodies['else'], context); + } + + return chunk.write(''); +} + +function coerce (value, type, context) { + if (value) { + switch (type || typeof(value)) { + case 'number': return +value; + case 'string': return String(value); + case 'boolean': return Boolean(value); + case 'date': return new Date(value); + case 'context': return context.get(value); + } + } + + return value; +} + +var helpers = { + + sep: function(chunk, context, bodies) { + if (context.stack.index === context.stack.of - 1) { + return chunk; + } + return bodies.block(chunk, context); + }, + + idx: function(chunk, context, bodies) { + return bodies.block(chunk, context.push(context.stack.index)); + }, + + contextDump: function(chunk, context, bodies) { + _console.log(JSON.stringify(context.stack)); + return chunk; + }, + + // Utility helping to resolve dust references in the given chunk + tap: function( input, chunk, context ){ + // return given input if there is no dust reference to resolve + var output = input; + // dust compiles a string to function, if there are references + if( typeof input === "function"){ + if( ( typeof input.isReference !== "undefined" ) && ( input.isReference === true ) ){ // just a plain function, not a dust `body` function + output = input(); + } else { + output = ''; + chunk.tap(function(data){ + output += data; + return ''; + }).render(input, context).untap(); + if( output === '' ){ + output = false; + } + } + } + return output; + }, + + /** + if helper + @param cond, either a string literal value or a dust reference + a string literal value, is enclosed in double quotes, e.g. cond="2>3" + a dust reference is also enclosed in double quotes, e.g. cond="'{val}'' > 3" + cond argument should evaluate to a valid javascript expression + **/ + + "if": function( chunk, context, bodies, params ){ + if( params && params.cond ){ + var cond = params.cond; + cond = this.tap(cond, chunk, context); + // eval expressions with given dust references + if( eval( cond ) ){ + return chunk.render( bodies.block, context ); + } + if( bodies['else'] ){ + return chunk.render( bodies['else'], context ); + } + } + // no condition + else { + _console.log( "No condition given in the if helper!" ); + } + return chunk; + }, + + /** + select/eq/lt/lte/gt/gte/default helper + @param key, either a string literal value or a dust reference + a string literal value, is enclosed in double quotes, e.g. key="foo" + a dust reference may or may not be enclosed in double quotes, e.g. key="{val}" and key=val are both valid + @param type (optiona), supported types are number, boolean, string, date, context, defaults to string + **/ + select: function(chunk, context, bodies, params) { + if( params && params.key){ + // returns given input as output, if the input is not a dust reference, else does a context lookup + var key = this.tap(params.key, chunk, context); + return chunk.render(bodies.block, context.push({ isSelect: true, isResolved: false, selectKey: key })); + } + // no key + else { + _console.log( "No key given in the select helper!" ); + } + return chunk; + }, + + eq: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; }); + }, + + lt: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; }); + }, + + lte: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; }); + }, + + gt: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual > expected; }); + }, + + gte: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual >= expected; }); + }, + + "default": function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return true; }); + }, + size: function( chunk, context, bodies, params ) { + var subject = params.subject; + var value = 0; + if (!subject) { //undefined, "", 0 + value = 0; + } else if(dust.isArray(subject)) { //array + value = subject.length; + } else if (!isNaN(subject)) { //numeric values + value = subject; + } else if (Object(subject) === subject) { //object test + var nr = 0; + for(var k in subject) if(Object.hasOwnProperty.call(subject,k)) nr++; + value = nr; + } else { + value = (subject + '').length; //any other value (strings etc.) + } + return chunk.write(value); + } +}; + +dust.helpers = helpers; + +})(typeof exports !== 'undefined' ? exports : getGlobal()); diff --git a/vendor/assets/javascripts/dust-core.min.js b/vendor/assets/javascripts/dust-core.min.js deleted file mode 100644 index cab380b..0000000 --- a/vendor/assets/javascripts/dust-core.min.js +++ /dev/null @@ -1,21 +0,0 @@ -// -// Dust - Asynchronous Templating v0.3.0 -// http://akdubya.github.com/dustjs -// -// Copyright (c) 2010, Aleksander Williams -// Released under the MIT License. -// - -var dust={}; -(function(d){function h(a,b,c){this.stack=a;this.global=b;this.blocks=c}function k(a,b,c,e){this.tail=b;this.isObject=!d.isArray(a)&&a&&typeof a==="object";this.head=a;this.index=c;this.of=e}function l(a){this.head=new f(this);this.callback=a;this.out=""}function j(){this.head=new f(this)}function f(a,b,c){this.root=a;this.next=b;this.data="";this.flushable=false;this.taps=c}function m(a,b){this.head=a;this.tail=b}d.cache={};d.register=function(a,b){if(a)d.cache[a]=b};d.render=function(a,b,c){c=(new l(c)).head; -d.load(a,c,h.wrap(b)).end()};d.stream=function(a,b){var c=new j;d.nextTick(function(){d.load(a,c.head,h.wrap(b)).end()});return c};d.renderSource=function(a,b,c){return d.compileFn(a)(b,c)};d.compileFn=function(a,b){var c=d.loadSource(d.compile(a,b));return function(e,g){var i=g?new l(g):new j;d.nextTick(function(){c(i.head,h.wrap(e)).end()});return i}};d.load=function(a,b,c){var e=d.cache[a];if(e)return e(b,c);else{if(d.onLoad)return b.map(function(g){d.onLoad(a,function(i,n){if(i)return g.setError(i); -d.cache[a]||d.loadSource(d.compile(n,a));d.cache[a](g,c).end()})});return b.setError(Error("Template Not Found: "+a))}};d.loadSource=function(a){return eval(a)};d.isArray=Array.isArray?Array.isArray:function(a){return Object.prototype.toString.call(a)=="[object Array]"};d.nextTick=function(a){setTimeout(a,0)};d.isEmpty=function(a){if(d.isArray(a)&&!a.length)return true;if(a===0)return false;return!a};d.filter=function(a,b,c){if(c)for(var e=0,g=c.length;e\"]/),p=/&/g,q=//g,s=/\"/g;d.escapeHtml=function(a){if(typeof a==="string"){if(!o.test(a))return a;return a.replace(p,"&").replace(q,"<").replace(r,">").replace(s,""")}return a}; -var t=/\\/g,u=/\r/g,v=/\u2028/g,w=/\u2029/g,x=/\n/g,y=/\f/g,z=/'/g,A=/"/g,B=/\t/g;d.escapeJs=function(a){if(typeof a==="string")return a.replace(t,"\\\\").replace(A,'\\"').replace(z,"\\'").replace(u,"\\r").replace(v,"\\u2028").replace(w,"\\u2029").replace(x,"\\n").replace(y,"\\f").replace(B,"\\t");return a}})(dust);if(typeof exports!=="undefined"){typeof process!=="undefined"&&require("./server")(dust);module.exports=dust}; diff --git a/vendor/assets/javascripts/dust-full-for-compile.js b/vendor/assets/javascripts/dust-full-for-compile.js deleted file mode 100644 index bf3d20b..0000000 --- a/vendor/assets/javascripts/dust-full-for-compile.js +++ /dev/null @@ -1,3209 +0,0 @@ -// -// Dust - Asynchronous Templating v0.3.0 -// http://akdubya.github.com/dustjs -// -// Copyright (c) 2010, Aleksander Williams -// Released under the MIT License. -// - -var dust = {}; - -(function(dust) { - -dust.cache = {}; - -dust.register = function(name, tmpl) { - if (!name) return; - dust.cache[name] = tmpl; -}; - -dust.render = function(name, context, callback) { - var chunk = new Stub(callback).head; - dust.load(name, chunk, Context.wrap(context)).end(); -}; - -dust.stream = function(name, context) { - var stream = new Stream(); - dust.nextTick(function() { - dust.load(name, stream.head, Context.wrap(context)).end(); - }); - return stream; -}; - -dust.renderSource = function(source, context, callback) { - return dust.compileFn(source)(context, callback); -}; - -dust.compileFn = function(source, name) { - var tmpl = dust.loadSource(dust.compile(source, name)); - return function(context, callback) { - var master = callback ? new Stub(callback) : new Stream(); - dust.nextTick(function() { - tmpl(master.head, Context.wrap(context)).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(callback) { - setTimeout(callback, 0); -} - -dust.isEmpty = function(value) { - if (dust.isArray(value) && !value.length) return true; - if (value === 0) return false; - return (!value); -}; - -dust.filter = function(string, auto, filters) { - if (filters) { - for (var i=0, len=filters.length; i\"]/), - AMP = /&/g, - LT = //g, - QUOT = /\"/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,'"'); - } - return s; -}; - -var BS = /\\/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(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; -} -(function(dust) { - -dust.compile = function(source, name) { - var ast = filterAST(dust.parse(source)); - return compile(ast, name); -}; - -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 -} - -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 rightmostMatchFailuresPos) { - rightmostMatchFailuresPos = pos; - rightmostMatchFailuresExpected = []; - } - - rightmostMatchFailuresExpected.push(failure); - } - - function parse_body() { - var cacheKey = "body" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var result1 = []; - var result2 = parse_part(); - while (result2 !== null) { - result1.push(result2); - var result2 = parse_part(); - } - var result0 = result1 !== null - ? (function(p) { return ["body"].concat(p) })(result1) - : null; - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_part() { - var cacheKey = "part" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var result6 = parse_comment(); - if (result6 !== null) { - var result0 = result6; - } else { - var result5 = parse_section(); - if (result5 !== null) { - var result0 = result5; - } else { - var result4 = parse_partial(); - if (result4 !== null) { - var result0 = result4; - } else { - var result3 = parse_special(); - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_reference(); - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_buffer(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; - }; - } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_section() { - var cacheKey = "section" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos1 = pos; - var result8 = parse_sec_tag_start(); - if (result8 !== null) { - var result9 = parse_rd(); - if (result9 !== null) { - var result10 = parse_body(); - if (result10 !== null) { - var result11 = parse_bodies(); - if (result11 !== null) { - var result12 = parse_end_tag(); - if (result12 !== null) { - var result13 = (function() {return result8[1].text === result12.text})() ? '' : null; - if (result13 !== null) { - var result7 = [result8, result9, result10, result11, result12, result13]; - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - var result6 = result7 !== null - ? (function(t, b, e, n) { e.push(["param", ["literal", "block"], b]); t.push(e); return t })(result7[0], result7[2], result7[3], result7[4]) - : null; - if (result6 !== null) { - var result0 = result6; - } else { - var savedPos0 = pos; - var result3 = parse_sec_tag_start(); - if (result3 !== null) { - if (input.substr(pos, 1) === "/") { - var result4 = "/"; - pos += 1; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("\"/\""); - } - } - if (result4 !== null) { - var result5 = parse_rd(); - if (result5 !== null) { - var result2 = [result3, result4, result5]; - } else { - var result2 = null; - pos = savedPos0; - } - } else { - var result2 = null; - pos = savedPos0; - } - } else { - var result2 = null; - pos = savedPos0; - } - var result1 = result2 !== null - ? (function(t) { t.push(["bodies"]); return t })(result2[0]) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("section"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_sec_tag_start() { - var cacheKey = "sec_tag_start" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - if (input.substr(pos).match(/^[#?^<+@%]/) !== null) { - var result3 = input.charAt(pos); - pos++; - } else { - var result3 = null; - if (reportMatchFailures) { - matchFailed("[#?^<+@%]"); - } - } - if (result3 !== null) { - var result4 = parse_identifier(); - if (result4 !== null) { - var result5 = parse_context(); - if (result5 !== null) { - var result6 = parse_params(); - if (result6 !== null) { - var result1 = [result2, result3, result4, result5, result6]; - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(t, n, c, p) { return [t, n, c, p] })(result1[1], result1[2], result1[3], result1[4]) - : null; - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_end_tag() { - var cacheKey = "end_tag" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - if (input.substr(pos, 1) === "/") { - var result3 = "/"; - pos += 1; - } else { - var result3 = null; - if (reportMatchFailures) { - matchFailed("\"/\""); - } - } - if (result3 !== null) { - var result4 = parse_identifier(); - if (result4 !== null) { - var result5 = parse_rd(); - if (result5 !== null) { - var result1 = [result2, result3, result4, result5]; - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(n) { return n })(result1[2]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("end tag"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_context() { - var cacheKey = "context" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var savedPos0 = pos; - if (input.substr(pos, 1) === ":") { - var result4 = ":"; - pos += 1; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("\":\""); - } - } - if (result4 !== null) { - var result5 = parse_identifier(); - if (result5 !== null) { - var result3 = [result4, result5]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(n) {return n})(result3[1]) - : null; - var result1 = result2 !== null ? result2 : ''; - var result0 = result1 !== null - ? (function(n) { return n ? ["context", n] : ["context"] })(result1) - : null; - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_params() { - var cacheKey = "params" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var result1 = []; - var savedPos0 = pos; - var result4 = parse_ws(); - if (result4 !== null) { - var result5 = parse_key(); - if (result5 !== null) { - if (input.substr(pos, 1) === "=") { - var result6 = "="; - pos += 1; - } else { - var result6 = null; - if (reportMatchFailures) { - matchFailed("\"=\""); - } - } - if (result6 !== null) { - var result9 = parse_identifier(); - if (result9 !== null) { - var result7 = result9; - } else { - var result8 = parse_inline(); - if (result8 !== null) { - var result7 = result8; - } else { - var result7 = null;; - }; - } - if (result7 !== null) { - var result3 = [result4, result5, result6, result7]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(k, v) {return ["param", ["literal", k], v]})(result3[1], result3[3]) - : null; - while (result2 !== null) { - result1.push(result2); - var savedPos0 = pos; - var result4 = parse_ws(); - if (result4 !== null) { - var result5 = parse_key(); - if (result5 !== null) { - if (input.substr(pos, 1) === "=") { - var result6 = "="; - pos += 1; - } else { - var result6 = null; - if (reportMatchFailures) { - matchFailed("\"=\""); - } - } - if (result6 !== null) { - var result9 = parse_identifier(); - if (result9 !== null) { - var result7 = result9; - } else { - var result8 = parse_inline(); - if (result8 !== null) { - var result7 = result8; - } else { - var result7 = null;; - }; - } - if (result7 !== null) { - var result3 = [result4, result5, result6, result7]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(k, v) {return ["param", ["literal", k], v]})(result3[1], result3[3]) - : null; - } - var result0 = result1 !== null - ? (function(p) { return ["params"].concat(p) })(result1) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("params"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_bodies() { - var cacheKey = "bodies" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var result1 = []; - var savedPos0 = pos; - var result4 = parse_ld(); - if (result4 !== null) { - if (input.substr(pos, 1) === ":") { - var result5 = ":"; - pos += 1; - } else { - var result5 = null; - if (reportMatchFailures) { - matchFailed("\":\""); - } - } - if (result5 !== null) { - var result6 = parse_key(); - if (result6 !== null) { - var result7 = parse_rd(); - if (result7 !== null) { - var result8 = parse_body(); - if (result8 !== null) { - var result3 = [result4, result5, result6, result7, result8]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(k, v) {return ["param", ["literal", k], v]})(result3[2], result3[4]) - : null; - while (result2 !== null) { - result1.push(result2); - var savedPos0 = pos; - var result4 = parse_ld(); - if (result4 !== null) { - if (input.substr(pos, 1) === ":") { - var result5 = ":"; - pos += 1; - } else { - var result5 = null; - if (reportMatchFailures) { - matchFailed("\":\""); - } - } - if (result5 !== null) { - var result6 = parse_key(); - if (result6 !== null) { - var result7 = parse_rd(); - if (result7 !== null) { - var result8 = parse_body(); - if (result8 !== null) { - var result3 = [result4, result5, result6, result7, result8]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(k, v) {return ["param", ["literal", k], v]})(result3[2], result3[4]) - : null; - } - var result0 = result1 !== null - ? (function(p) { return ["bodies"].concat(p) })(result1) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("bodies"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_reference() { - var cacheKey = "reference" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - var result3 = parse_identifier(); - if (result3 !== null) { - var result4 = parse_filters(); - if (result4 !== null) { - var result5 = parse_rd(); - if (result5 !== null) { - var result1 = [result2, result3, result4, result5]; - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(n, f) { return ["reference", n, f] })(result1[1], result1[2]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("reference"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_partial() { - var cacheKey = "partial" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - if (input.substr(pos, 1) === ">") { - var result3 = ">"; - pos += 1; - } else { - var result3 = null; - if (reportMatchFailures) { - matchFailed("\">\""); - } - } - if (result3 !== null) { - var result10 = parse_key(); - var result9 = result10 !== null - ? (function(k) {return ["literal", k]})(result10) - : null; - if (result9 !== null) { - var result4 = result9; - } else { - var result8 = parse_inline(); - if (result8 !== null) { - var result4 = result8; - } else { - var result4 = null;; - }; - } - if (result4 !== null) { - var result5 = parse_context(); - if (result5 !== null) { - if (input.substr(pos, 1) === "/") { - var result6 = "/"; - pos += 1; - } else { - var result6 = null; - if (reportMatchFailures) { - matchFailed("\"/\""); - } - } - if (result6 !== null) { - var result7 = parse_rd(); - if (result7 !== null) { - var result1 = [result2, result3, result4, result5, result6, result7]; - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(n, c) { return ["partial", n, c] })(result1[2], result1[3]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("partial"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_filters() { - var cacheKey = "filters" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var result1 = []; - var savedPos0 = pos; - if (input.substr(pos, 1) === "|") { - var result4 = "|"; - pos += 1; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("\"|\""); - } - } - if (result4 !== null) { - var result5 = parse_key(); - if (result5 !== null) { - var result3 = [result4, result5]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(n) {return n})(result3[1]) - : null; - while (result2 !== null) { - result1.push(result2); - var savedPos0 = pos; - if (input.substr(pos, 1) === "|") { - var result4 = "|"; - pos += 1; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("\"|\""); - } - } - if (result4 !== null) { - var result5 = parse_key(); - if (result5 !== null) { - var result3 = [result4, result5]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(n) {return n})(result3[1]) - : null; - } - var result0 = result1 !== null - ? (function(f) { return ["filters"].concat(f) })(result1) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("filters"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_special() { - var cacheKey = "special" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - if (input.substr(pos, 1) === "~") { - var result3 = "~"; - pos += 1; - } else { - var result3 = null; - if (reportMatchFailures) { - matchFailed("\"~\""); - } - } - if (result3 !== null) { - var result4 = parse_key(); - if (result4 !== null) { - var result5 = parse_rd(); - if (result5 !== null) { - var result1 = [result2, result3, result4, result5]; - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(k) { return ["special", k] })(result1[2]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("special"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_identifier() { - var cacheKey = "identifier" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var result4 = parse_path(); - var result3 = result4 !== null - ? (function(p) { return wrap(["path"].concat(p), cacheKey) })(result4) - : null; - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_key(); - var result1 = result2 !== null - ? (function(k) { return wrap(["key", k], cacheKey) })(result2) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("identifier"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_path() { - var cacheKey = "path" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result11 = parse_key(); - var result5 = result11 !== null ? result11 : ''; - if (result5 !== null) { - var savedPos1 = pos; - if (input.substr(pos, 1) === ".") { - var result9 = "."; - pos += 1; - } else { - var result9 = null; - if (reportMatchFailures) { - matchFailed("\".\""); - } - } - if (result9 !== null) { - var result10 = parse_key(); - if (result10 !== null) { - var result8 = [result9, result10]; - } else { - var result8 = null; - pos = savedPos1; - } - } else { - var result8 = null; - pos = savedPos1; - } - var result7 = result8 !== null - ? (function(k) {return k})(result8[1]) - : null; - if (result7 !== null) { - var result6 = []; - while (result7 !== null) { - result6.push(result7); - var savedPos1 = pos; - if (input.substr(pos, 1) === ".") { - var result9 = "."; - pos += 1; - } else { - var result9 = null; - if (reportMatchFailures) { - matchFailed("\".\""); - } - } - if (result9 !== null) { - var result10 = parse_key(); - if (result10 !== null) { - var result8 = [result9, result10]; - } else { - var result8 = null; - pos = savedPos1; - } - } else { - var result8 = null; - pos = savedPos1; - } - var result7 = result8 !== null - ? (function(k) {return k})(result8[1]) - : null; - } - } else { - var result6 = null; - } - if (result6 !== null) { - var result4 = [result5, result6]; - } else { - var result4 = null; - pos = savedPos0; - } - } else { - var result4 = null; - pos = savedPos0; - } - var result3 = result4 !== null - ? (function(k, d) { - if (k) { d.unshift(k); return [false, d]; } - return [true, d]; - })(result4[0], result4[1]) - : null; - if (result3 !== null) { - var result0 = result3; - } else { - if (input.substr(pos, 1) === ".") { - var result2 = "."; - pos += 1; - } else { - var result2 = null; - if (reportMatchFailures) { - matchFailed("\".\""); - } - } - var result1 = result2 !== null - ? (function() { return [true, []] })() - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("path"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_key() { - var cacheKey = "key" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - if (input.substr(pos).match(/^[a-zA-Z_$]/) !== null) { - var result2 = input.charAt(pos); - pos++; - } else { - var result2 = null; - if (reportMatchFailures) { - matchFailed("[a-zA-Z_$]"); - } - } - if (result2 !== null) { - var result3 = []; - if (input.substr(pos).match(/^[0-9a-zA-Z_$]/) !== null) { - var result4 = input.charAt(pos); - pos++; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("[0-9a-zA-Z_$]"); - } - } - while (result4 !== null) { - result3.push(result4); - if (input.substr(pos).match(/^[0-9a-zA-Z_$]/) !== null) { - var result4 = input.charAt(pos); - pos++; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("[0-9a-zA-Z_$]"); - } - } - } - if (result3 !== null) { - var result1 = [result2, result3]; - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(h, t) { return h + t.join('') })(result1[0], result1[1]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("key"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_inline() { - var cacheKey = "inline" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos2 = pos; - if (input.substr(pos, 1) === "\"") { - var result14 = "\""; - pos += 1; - } else { - var result14 = null; - if (reportMatchFailures) { - matchFailed("\"\\\"\""); - } - } - if (result14 !== null) { - if (input.substr(pos, 1) === "\"") { - var result15 = "\""; - pos += 1; - } else { - var result15 = null; - if (reportMatchFailures) { - matchFailed("\"\\\"\""); - } - } - if (result15 !== null) { - var result13 = [result14, result15]; - } else { - var result13 = null; - pos = savedPos2; - } - } else { - var result13 = null; - pos = savedPos2; - } - var result12 = result13 !== null - ? (function() { return ["literal", ""] })() - : null; - if (result12 !== null) { - var result0 = result12; - } else { - var savedPos1 = pos; - if (input.substr(pos, 1) === "\"") { - var result9 = "\""; - pos += 1; - } else { - var result9 = null; - if (reportMatchFailures) { - matchFailed("\"\\\"\""); - } - } - if (result9 !== null) { - var result10 = parse_literal(); - if (result10 !== null) { - if (input.substr(pos, 1) === "\"") { - var result11 = "\""; - pos += 1; - } else { - var result11 = null; - if (reportMatchFailures) { - matchFailed("\"\\\"\""); - } - } - if (result11 !== null) { - var result8 = [result9, result10, result11]; - } else { - var result8 = null; - pos = savedPos1; - } - } else { - var result8 = null; - pos = savedPos1; - } - } else { - var result8 = null; - pos = savedPos1; - } - var result7 = result8 !== null - ? (function(l) { return ["literal", l] })(result8[1]) - : null; - if (result7 !== null) { - var result0 = result7; - } else { - var savedPos0 = pos; - if (input.substr(pos, 1) === "\"") { - var result3 = "\""; - pos += 1; - } else { - var result3 = null; - if (reportMatchFailures) { - matchFailed("\"\\\"\""); - } - } - if (result3 !== null) { - var result6 = parse_inline_part(); - if (result6 !== null) { - var result4 = []; - while (result6 !== null) { - result4.push(result6); - var result6 = parse_inline_part(); - } - } else { - var result4 = null; - } - if (result4 !== null) { - if (input.substr(pos, 1) === "\"") { - var result5 = "\""; - pos += 1; - } else { - var result5 = null; - if (reportMatchFailures) { - matchFailed("\"\\\"\""); - } - } - if (result5 !== null) { - var result2 = [result3, result4, result5]; - } else { - var result2 = null; - pos = savedPos0; - } - } else { - var result2 = null; - pos = savedPos0; - } - } else { - var result2 = null; - pos = savedPos0; - } - var result1 = result2 !== null - ? (function(p) { return ["body"].concat(p) })(result2[1]) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("inline"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_inline_part() { - var cacheKey = "inline_part" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var result4 = parse_special(); - if (result4 !== null) { - var result0 = result4; - } else { - var result3 = parse_reference(); - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_literal(); - var result1 = result2 !== null - ? (function(l) { return ["buffer", l] })(result2) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_buffer() { - var cacheKey = "buffer" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos4 = pos; - var result14 = parse_eol(); - if (result14 !== null) { - var result15 = []; - var result16 = parse_ws(); - while (result16 !== null) { - result15.push(result16); - var result16 = parse_ws(); - } - if (result15 !== null) { - var result13 = [result14, result15]; - } else { - var result13 = null; - pos = savedPos4; - } - } else { - var result13 = null; - pos = savedPos4; - } - var result12 = result13 !== null - ? (function(e, w) { return ["format", e, w.join('')] })(result13[0], result13[1]) - : null; - if (result12 !== null) { - var result0 = result12; - } else { - var savedPos0 = pos; - var savedPos3 = pos; - var savedReportMatchFailuresVar2 = reportMatchFailures; - reportMatchFailures = false; - var result11 = parse_tag(); - reportMatchFailures = savedReportMatchFailuresVar2; - if (result11 === null) { - var result5 = ''; - } else { - var result5 = null; - pos = savedPos3; - } - if (result5 !== null) { - var savedPos2 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result10 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result10 === null) { - var result6 = ''; - } else { - var result6 = null; - pos = savedPos2; - } - if (result6 !== null) { - var savedPos1 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result9 = parse_comment(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result7 = ''; - } else { - var result7 = null; - pos = savedPos1; - } - if (result7 !== null) { - if (input.length > pos) { - var result8 = input.charAt(pos); - pos++; - } else { - var result8 = null; - if (reportMatchFailures) { - matchFailed('any character'); - } - } - if (result8 !== null) { - var result4 = [result5, result6, result7, result8]; - } else { - var result4 = null; - pos = savedPos0; - } - } else { - var result4 = null; - pos = savedPos0; - } - } else { - var result4 = null; - pos = savedPos0; - } - } else { - var result4 = null; - pos = savedPos0; - } - var result3 = result4 !== null - ? (function(c) {return c})(result4[3]) - : null; - if (result3 !== null) { - var result2 = []; - while (result3 !== null) { - result2.push(result3); - var savedPos0 = pos; - var savedPos3 = pos; - var savedReportMatchFailuresVar2 = reportMatchFailures; - reportMatchFailures = false; - var result11 = parse_tag(); - reportMatchFailures = savedReportMatchFailuresVar2; - if (result11 === null) { - var result5 = ''; - } else { - var result5 = null; - pos = savedPos3; - } - if (result5 !== null) { - var savedPos2 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result10 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result10 === null) { - var result6 = ''; - } else { - var result6 = null; - pos = savedPos2; - } - if (result6 !== null) { - var savedPos1 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result9 = parse_comment(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result7 = ''; - } else { - var result7 = null; - pos = savedPos1; - } - if (result7 !== null) { - if (input.length > pos) { - var result8 = input.charAt(pos); - pos++; - } else { - var result8 = null; - if (reportMatchFailures) { - matchFailed('any character'); - } - } - if (result8 !== null) { - var result4 = [result5, result6, result7, result8]; - } else { - var result4 = null; - pos = savedPos0; - } - } else { - var result4 = null; - pos = savedPos0; - } - } else { - var result4 = null; - pos = savedPos0; - } - } else { - var result4 = null; - pos = savedPos0; - } - var result3 = result4 !== null - ? (function(c) {return c})(result4[3]) - : null; - } - } else { - var result2 = null; - } - var result1 = result2 !== null - ? (function(b) { return ["buffer", b.join('')] })(result2) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("buffer"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_literal() { - var cacheKey = "literal" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var savedPos2 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result10 = parse_tag(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result10 === null) { - var result4 = ''; - } else { - var result4 = null; - pos = savedPos2; - } - if (result4 !== null) { - var savedPos1 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result9 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result5 = ''; - } else { - var result5 = null; - pos = savedPos1; - } - if (result5 !== null) { - var result8 = parse_esc(); - if (result8 !== null) { - var result6 = result8; - } else { - if (input.substr(pos).match(/^[^"]/) !== null) { - var result7 = input.charAt(pos); - pos++; - } else { - var result7 = null; - if (reportMatchFailures) { - matchFailed("[^\"]"); - } - } - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; - } - if (result6 !== null) { - var result3 = [result4, result5, result6]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(c) {return c})(result3[2]) - : null; - if (result2 !== null) { - var result1 = []; - while (result2 !== null) { - result1.push(result2); - var savedPos0 = pos; - var savedPos2 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result10 = parse_tag(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result10 === null) { - var result4 = ''; - } else { - var result4 = null; - pos = savedPos2; - } - if (result4 !== null) { - var savedPos1 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result9 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result5 = ''; - } else { - var result5 = null; - pos = savedPos1; - } - if (result5 !== null) { - var result8 = parse_esc(); - if (result8 !== null) { - var result6 = result8; - } else { - if (input.substr(pos).match(/^[^"]/) !== null) { - var result7 = input.charAt(pos); - pos++; - } else { - var result7 = null; - if (reportMatchFailures) { - matchFailed("[^\"]"); - } - } - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; - } - if (result6 !== null) { - var result3 = [result4, result5, result6]; - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(c) {return c})(result3[2]) - : null; - } - } else { - var result1 = null; - } - var result0 = result1 !== null - ? (function(b) { return b.join('') })(result1) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("literal"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_esc() { - var cacheKey = "esc" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - if (input.substr(pos, 2) === "\\\"") { - var result1 = "\\\""; - pos += 2; - } else { - var result1 = null; - if (reportMatchFailures) { - matchFailed("\"\\\\\\\"\""); - } - } - var result0 = result1 !== null - ? (function() { return '"' })() - : null; - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_comment() { - var cacheKey = "comment" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - if (input.substr(pos, 2) === "{!") { - var result2 = "{!"; - pos += 2; - } else { - var result2 = null; - if (reportMatchFailures) { - matchFailed("\"{!\""); - } - } - if (result2 !== null) { - var result3 = []; - var savedPos1 = pos; - var savedPos2 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - if (input.substr(pos, 2) === "!}") { - var result9 = "!}"; - pos += 2; - } else { - var result9 = null; - if (reportMatchFailures) { - matchFailed("\"!}\""); - } - } - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result7 = ''; - } else { - var result7 = null; - pos = savedPos2; - } - if (result7 !== null) { - if (input.length > pos) { - var result8 = input.charAt(pos); - pos++; - } else { - var result8 = null; - if (reportMatchFailures) { - matchFailed('any character'); - } - } - if (result8 !== null) { - var result6 = [result7, result8]; - } else { - var result6 = null; - pos = savedPos1; - } - } else { - var result6 = null; - pos = savedPos1; - } - var result5 = result6 !== null - ? (function(c) {return c})(result6[1]) - : null; - while (result5 !== null) { - result3.push(result5); - var savedPos1 = pos; - var savedPos2 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - if (input.substr(pos, 2) === "!}") { - var result9 = "!}"; - pos += 2; - } else { - var result9 = null; - if (reportMatchFailures) { - matchFailed("\"!}\""); - } - } - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result7 = ''; - } else { - var result7 = null; - pos = savedPos2; - } - if (result7 !== null) { - if (input.length > pos) { - var result8 = input.charAt(pos); - pos++; - } else { - var result8 = null; - if (reportMatchFailures) { - matchFailed('any character'); - } - } - if (result8 !== null) { - var result6 = [result7, result8]; - } else { - var result6 = null; - pos = savedPos1; - } - } else { - var result6 = null; - pos = savedPos1; - } - var result5 = result6 !== null - ? (function(c) {return c})(result6[1]) - : null; - } - if (result3 !== null) { - if (input.substr(pos, 2) === "!}") { - var result4 = "!}"; - pos += 2; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("\"!}\""); - } - } - if (result4 !== null) { - var result1 = [result2, result3, result4]; - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(c) { return ["comment", c.join('')] })(result1[1]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { - matchFailed("comment"); - } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_tag() { - var cacheKey = "tag" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var savedPos0 = pos; - var result3 = parse_ld(); - if (result3 !== null) { - if (input.substr(pos).match(/^[#?^><+%:@\/~%]/) !== null) { - var result4 = input.charAt(pos); - pos++; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("[#?^><+%:@\\/~%]"); - } - } - if (result4 !== null) { - var savedPos1 = pos; - var savedPos3 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result12 = parse_rd(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result12 === null) { - var result8 = ''; - } else { - var result8 = null; - pos = savedPos3; - } - if (result8 !== null) { - var savedPos2 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result11 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result11 === null) { - var result9 = ''; - } else { - var result9 = null; - pos = savedPos2; - } - if (result9 !== null) { - if (input.length > pos) { - var result10 = input.charAt(pos); - pos++; - } else { - var result10 = null; - if (reportMatchFailures) { - matchFailed('any character'); - } - } - if (result10 !== null) { - var result7 = [result8, result9, result10]; - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - if (result7 !== null) { - var result5 = []; - while (result7 !== null) { - result5.push(result7); - var savedPos1 = pos; - var savedPos3 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result12 = parse_rd(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result12 === null) { - var result8 = ''; - } else { - var result8 = null; - pos = savedPos3; - } - if (result8 !== null) { - var savedPos2 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result11 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result11 === null) { - var result9 = ''; - } else { - var result9 = null; - pos = savedPos2; - } - if (result9 !== null) { - if (input.length > pos) { - var result10 = input.charAt(pos); - pos++; - } else { - var result10 = null; - if (reportMatchFailures) { - matchFailed('any character'); - } - } - if (result10 !== null) { - var result7 = [result8, result9, result10]; - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - } else { - var result7 = null; - pos = savedPos1; - } - } - } else { - var result5 = null; - } - if (result5 !== null) { - var result6 = parse_rd(); - if (result6 !== null) { - var result2 = [result3, result4, result5, result6]; - } else { - var result2 = null; - pos = savedPos0; - } - } else { - var result2 = null; - pos = savedPos0; - } - } else { - var result2 = null; - pos = savedPos0; - } - } else { - var result2 = null; - pos = savedPos0; - } - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_reference(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_ld() { - var cacheKey = "ld" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - if (input.substr(pos, 1) === "{") { - var result0 = "{"; - pos += 1; - } else { - var result0 = null; - if (reportMatchFailures) { - matchFailed("\"{\""); - } - } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_rd() { - var cacheKey = "rd" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - if (input.substr(pos, 1) === "}") { - var result0 = "}"; - pos += 1; - } else { - var result0 = null; - if (reportMatchFailures) { - matchFailed("\"}\""); - } - } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_eol() { - var cacheKey = "eol" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - if (input.substr(pos, 1) === "\n") { - var result5 = "\n"; - pos += 1; - } else { - var result5 = null; - if (reportMatchFailures) { - matchFailed("\"\\n\""); - } - } - if (result5 !== null) { - var result0 = result5; - } else { - if (input.substr(pos, 2) === "\r\n") { - var result4 = "\r\n"; - pos += 2; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("\"\\r\\n\""); - } - } - if (result4 !== null) { - var result0 = result4; - } else { - if (input.substr(pos, 1) === "\r") { - var result3 = "\r"; - pos += 1; - } else { - var result3 = null; - if (reportMatchFailures) { - matchFailed("\"\\r\""); - } - } - if (result3 !== null) { - var result0 = result3; - } else { - if (input.substr(pos, 1) === "\u2028") { - var result2 = "\u2028"; - pos += 1; - } else { - var result2 = null; - if (reportMatchFailures) { - matchFailed("\"\\u2028\""); - } - } - if (result2 !== null) { - var result0 = result2; - } else { - if (input.substr(pos, 1) === "\u2029") { - var result1 = "\u2029"; - pos += 1; - } else { - var result1 = null; - if (reportMatchFailures) { - matchFailed("\"\\u2029\""); - } - } - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; - } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function parse_ws() { - var cacheKey = "ws" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - if (input.substr(pos).match(/^[ \xA0\uFEFF]/) !== null) { - var result0 = input.charAt(pos); - pos++; - } else { - var result0 = null; - if (reportMatchFailures) { - matchFailed("[ \\xA0\\uFEFF]"); - } - } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; - return result0; - } - - function buildErrorMessage() { - function buildExpected(failuresExpected) { - failuresExpected.sort(); - - var lastFailure = null; - var failuresExpectedUnique = []; - for (var i = 0; i < failuresExpected.length; i++) { - if (failuresExpected[i] !== lastFailure) { - failuresExpectedUnique.push(failuresExpected[i]); - lastFailure = failuresExpected[i]; - } - } - - switch (failuresExpectedUnique.length) { - case 0: - return 'end of input'; - case 1: - return failuresExpectedUnique[0]; - default: - return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ') - + ' or ' - + failuresExpectedUnique[failuresExpectedUnique.length - 1]; - } - } - - var expected = buildExpected(rightmostMatchFailuresExpected); - var actualPos = Math.max(pos, rightmostMatchFailuresPos); - var actual = actualPos < input.length - ? quote(input.charAt(actualPos)) - : 'end of input'; - - return 'Expected ' + expected + ' but ' + actual + ' found.'; - } - - function computeErrorPosition() { - /* - * The first idea was to use |String.split| to break the input up to the - * error position along newlines and derive the line and column from - * there. However IE's |split| implementation is so broken that it was - * enough to prevent it. - */ - - var line = 1; - var column = 1; - var seenCR = false; - - for (var i = 0; i < rightmostMatchFailuresPos; i++) { - var ch = input.charAt(i); - if (ch === '\n') { - if (!seenCR) { line++; } - column = 1; - seenCR = false; - } else if (ch === '\r' | ch === '\u2028' || ch === '\u2029') { - line++; - column = 1; - seenCR = true; - } else { - column++; - seenCR = false; - } - } - - return { line: line, column: column }; - } - - - - function wrap(node, ck) { - - node['text'] = input.substring(ck.split('@')[1], pos); - - return node; - - } - - - - var result = parse_body(); - - /* - * The parser is now in one of the following three states: - * - * 1. The parser successfully parsed the whole input. - * - * - |result !== null| - * - |pos === input.length| - * - |rightmostMatchFailuresExpected| may or may not contain something - * - * 2. The parser successfully parsed only a part of the input. - * - * - |result !== null| - * - |pos < input.length| - * - |rightmostMatchFailuresExpected| may or may not contain something - * - * 3. The parser did not successfully parse any part of the input. - * - * - |result === null| - * - |pos === 0| - * - |rightmostMatchFailuresExpected| contains at least one failure - * - * All code following this comment (including called functions) must - * handle these states. - */ - if (result === null || pos !== input.length) { - var errorPosition = computeErrorPosition(); - throw new SyntaxError( - buildErrorMessage(), - 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(message, line, column) { - this.name = 'SyntaxError'; - this.message = message; - this.line = line; - this.column = column; - }; - - result.SyntaxError.prototype = Error.prototype; - - return result; -})(); - -dust.parse = parser.parse; - -})(typeof exports !== 'undefined' ? exports : dust); diff --git a/vendor/assets/javascripts/dust-full.js b/vendor/assets/javascripts/dust-full.js index 6d7bdae..ee22e96 100644 --- a/vendor/assets/javascripts/dust-full.js +++ b/vendor/assets/javascripts/dust-full.js @@ -1,5 +1,5 @@ // -// Dust - Asynchronous Templating v0.3.0 +// Dust - Asynchronous Templating v1.0.0 // http://akdubya.github.com/dustjs // // Copyright (c) 2010, Aleksander Williams @@ -8,6 +8,12 @@ var dust = {}; +function getGlobal(){ + return (function(){ + return this.dust; + }).call(null); +} + (function(dust) { dust.cache = {}; @@ -75,9 +81,15 @@ if (Array.isArray) { }; } -dust.nextTick = function(callback) { - setTimeout(callback, 0); -} +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; @@ -106,8 +118,10 @@ dust.filters = { h: function(value) { return dust.escapeHtml(value); }, j: function(value) { return dust.escapeJs(value); }, u: encodeURI, - uc: encodeURIComponent -} + uc: encodeURIComponent, + 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) { this.stack = stack; @@ -117,14 +131,14 @@ function Context(stack, global, blocks) { dust.makeBase = function(global) { return new Context(new Stack(), global); -} +}; Context.wrap = function(context) { if (context instanceof Context) { return context; } return new Context(new Stack(context)); -} +}; Context.prototype.get = function(key) { var ctx = this.stack, value; @@ -146,7 +160,6 @@ Context.prototype.getPath = function(cur, down) { len = down.length; if (cur && len === 0) return ctx.head; - if (!ctx.isObject) return undefined; ctx = ctx.head; var i = 0; while(ctx && i < len) { @@ -168,7 +181,12 @@ Context.prototype.current = function() { return this.stack.head; }; -Context.prototype.getBlock = function(key) { +Context.prototype.getBlock = function(key, chk, ctx) { + if (typeof key === "function") { + key = key(chk, ctx).data; + chk.data = ""; + } + var blocks = this.blocks; if (!blocks) return; @@ -177,7 +195,7 @@ Context.prototype.getBlock = function(key) { fn = blocks[len][key]; if (fn) return fn; } -} +}; Context.prototype.shiftBlocks = function(locals) { var blocks = this.blocks; @@ -191,7 +209,7 @@ Context.prototype.shiftBlocks = function(locals) { return new Context(this.stack, this.global, newBlocks); } return this; -} +}; function Stack(head, tail, idx, len) { this.tail = tail; @@ -224,7 +242,7 @@ Stub.prototype.flush = function() { this.head = chunk; } this.callback(null, this.out); -} +}; function Stream() { this.head = new Chunk(this); @@ -247,23 +265,46 @@ Stream.prototype.flush = function() { this.head = chunk; } this.emit('end'); -} +}; Stream.prototype.emit = function(type, data) { - var events = this.events; - - if (events && events[type]) { - events[type](data); + if (!this.events) return false; + var handler = this.events[type]; + if (!handler) return false; + if (typeof handler == 'function') { + handler(data); + } else { + var listeners = handler.slice(0); + for (var i = 0, l = listeners.length; i < l; i++) { + listeners[i](data); + } } -} +}; Stream.prototype.on = function(type, callback) { if (!this.events) { this.events = {}; } - this.events[type] = callback; + if (!this.events[type]) { + this.events[type] = callback; + } else if(typeof this.events[type] === 'function') { + this.events[type] = [this.events[type], callback]; + } else { + this.events[type].push(callback); + } return this; -} +}; + +Stream.prototype.pipe = function(stream) { + this.on("data", function(data) { + stream.write(data, "utf8"); + }).on("end", function() { + stream.end(); + }).on("error", function(err) { + stream.error(err); + }); + return this; +}; function Chunk(root, next, taps) { this.root = root; @@ -281,7 +322,7 @@ Chunk.prototype.write = function(data) { } this.data += data; return this; -} +}; Chunk.prototype.end = function(data) { if (data) { @@ -290,7 +331,7 @@ Chunk.prototype.end = function(data) { this.flushable = true; this.root.flush(); return this; -} +}; Chunk.prototype.map = function(callback) { var cursor = new Chunk(this.root, this.next, this.taps), @@ -300,7 +341,7 @@ Chunk.prototype.map = function(callback) { this.flushable = true; callback(branch); return cursor; -} +}; Chunk.prototype.tap = function(tap) { var taps = this.taps; @@ -311,20 +352,22 @@ Chunk.prototype.tap = function(tap) { 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 = elem(this, context, null, {auto: auto, filters: filters}); + elem.isReference = 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; } @@ -338,7 +381,7 @@ Chunk.prototype.reference = function(elem, context, auto, filters) { Chunk.prototype.section = function(elem, context, bodies, params) { if (typeof elem === "function") { - elem = elem(this, context, bodies, params); + elem = elem.apply(context.current(), [this, context, bodies, params]); if (elem instanceof Chunk) { return elem; } @@ -354,15 +397,26 @@ Chunk.prototype.section = function(elem, context, bodies, params) { if (dust.isArray(elem)) { if (body) { var len = elem.length, chunk = this; + context.stack.head['$len'] = len; for (var i=0; i\"]/), +var HCHARS = new RegExp(/[&<>\"\']/), AMP = /&/g, LT = //g, - QUOT = /\"/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,'"'); + return s.replace(AMP,'&').replace(LT,'<').replace(GT,'>').replace(QUOT,'"').replace(SQUOT, '''); } return s; }; @@ -515,16 +567,216 @@ dust.escapeJs = function(s) { })(dust); if (typeof exports !== "undefined") { + //TODO: Remove the helpers from dust core in the next release. + dust.helpers = require("./dust-helpers").helpers; if (typeof process !== "undefined") { require('./server')(dust); } module.exports = dust; } +(function(dust){ + +/* make a safe version of console if it is not available + * currently supporting: + * _console.log + * */ +var _console = (typeof console !== 'undefined')? console: { + log: function(){ + /* a noop*/ + } +}; + +function isSelect(context) { + var value = context.current(); + return typeof value === "object" && value.isSelect === true; +} + +function filter(chunk, context, bodies, params, filter) { + var params = params || {}, + actual, + expected; + if (params.key) { + actual = helpers.tap(params.key, chunk, context); + } else if (isSelect(context)) { + actual = context.current().selectKey; + if (context.current().isResolved) { + filter = function() { return false; }; + } + } else { + throw "No key specified for filter and no key found in context from select statement"; + } + expected = helpers.tap(params.value, chunk, context); + if (filter(expected, coerce(actual, params.type, context))) { + if (isSelect(context)) { + context.current().isResolved = true; + } + return chunk.render(bodies.block, context); + } else if (bodies['else']) { + return chunk.render(bodies['else'], context); + } + + return chunk.write(''); +} + +function coerce (value, type, context) { + if (value) { + switch (type || typeof(value)) { + case 'number': return +value; + case 'string': return String(value); + case 'boolean': return Boolean(value); + case 'date': return new Date(value); + case 'context': return context.get(value); + } + } + + return value; +} + +var helpers = { + + sep: function(chunk, context, bodies) { + if (context.stack.index === context.stack.of - 1) { + return chunk; + } + return bodies.block(chunk, context); + }, + + idx: function(chunk, context, bodies) { + return bodies.block(chunk, context.push(context.stack.index)); + }, + + contextDump: function(chunk, context, bodies) { + _console.log(JSON.stringify(context.stack)); + return chunk; + }, + + // Utility helping to resolve dust references in the given chunk + tap: function( input, chunk, context ){ + // return given input if there is no dust reference to resolve + var output = input; + // dust compiles a string to function, if there are references + if( typeof input === "function"){ + if( ( typeof input.isReference !== "undefined" ) && ( input.isReference === true ) ){ // just a plain function, not a dust `body` function + output = input(); + } else { + output = ''; + chunk.tap(function(data){ + output += data; + return ''; + }).render(input, context).untap(); + if( output === '' ){ + output = false; + } + } + } + return output; + }, + + /** + if helper + @param cond, either a string literal value or a dust reference + a string literal value, is enclosed in double quotes, e.g. cond="2>3" + a dust reference is also enclosed in double quotes, e.g. cond="'{val}'' > 3" + cond argument should evaluate to a valid javascript expression + **/ + + "if": function( chunk, context, bodies, params ){ + if( params && params.cond ){ + var cond = params.cond; + cond = this.tap(cond, chunk, context); + // eval expressions with given dust references + if( eval( cond ) ){ + return chunk.render( bodies.block, context ); + } + if( bodies['else'] ){ + return chunk.render( bodies['else'], context ); + } + } + // no condition + else { + _console.log( "No condition given in the if helper!" ); + } + return chunk; + }, + + /** + select/eq/lt/lte/gt/gte/default helper + @param key, either a string literal value or a dust reference + a string literal value, is enclosed in double quotes, e.g. key="foo" + a dust reference may or may not be enclosed in double quotes, e.g. key="{val}" and key=val are both valid + @param type (optiona), supported types are number, boolean, string, date, context, defaults to string + **/ + select: function(chunk, context, bodies, params) { + if( params && params.key){ + // returns given input as output, if the input is not a dust reference, else does a context lookup + var key = this.tap(params.key, chunk, context); + return chunk.render(bodies.block, context.push({ isSelect: true, isResolved: false, selectKey: key })); + } + // no key + else { + _console.log( "No key given in the select helper!" ); + } + return chunk; + }, + + eq: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; }); + }, + + lt: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; }); + }, + + lte: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; }); + }, + + gt: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual > expected; }); + }, + + gte: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual >= expected; }); + }, + + "default": function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return true; }); + }, + size: function( chunk, context, bodies, params ) { + var subject = params.subject; + var value = 0; + if (!subject) { //undefined, "", 0 + value = 0; + } else if(dust.isArray(subject)) { //array + value = subject.length; + } else if (!isNaN(subject)) { //numeric values + value = subject; + } else if (Object(subject) === subject) { //object test + var nr = 0; + for(var k in subject) if(Object.hasOwnProperty.call(subject,k)) nr++; + value = nr; + } else { + value = (subject + '').length; //any other value (strings etc.) + } + return chunk.write(value); + } +}; + +dust.helpers = helpers; + +})(typeof exports !== 'undefined' ? exports : getGlobal()); (function(dust) { dust.compile = function(source, name) { - var ast = filterAST(dust.parse(source)); - return compile(ast, 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) { @@ -639,7 +891,7 @@ function compileBlocks(context) { blocks = context.blocks; for (var name in blocks) { - out.push(name + ":" + blocks[name]); + out.push("'" + name + "':" + blocks[name]); } if (out.length) { context.blocks = "ctx=ctx.shiftBlocks(blocks);"; @@ -718,12 +970,20 @@ dust.nodes = { }, "+": function(context, node) { - return ".block(ctx.getBlock(" + if(typeof(node[1].text) === "undefined" && typeof(node[4]) === "undefined"){ + return ".block(ctx.getBlock(" + + dust.compileNode(context, node[1]) + + ",chk, ctx)," + dust.compileNode(context, node[2]) + ", {}," + + dust.compileNode(context, node[3]) + + ")"; + }else { + return ".block(ctx.getBlock(" + escape(node[1].text) + ")," + dust.compileNode(context, node[2]) + "," + dust.compileNode(context, node[4]) + "," + dust.compileNode(context, node[3]) + ")"; + } }, "@": function(context, node) { @@ -762,7 +1022,8 @@ dust.nodes = { partial: function(context, node) { return ".partial(" + dust.compileNode(context, node[1]) - + "," + dust.compileNode(context, node[2]) + ")"; + + "," + dust.compileNode(context, node[2]) + + "," + dust.compileNode(context, node[3]) + ")"; }, context: function(context, node) { @@ -838,11 +1099,38 @@ var escape = (typeof JSON === "undefined") ? function(str) { return "\"" + dust.escapeJs(str) + "\"" } : JSON.stringify; -})(typeof exports !== 'undefined' ? exports : window.dust); +})(typeof exports !== 'undefined' ? exports : getGlobal()); (function(dust){ var parser = (function(){ - /* Generated by PEG.js (http://pegjs.majda.cz/). */ + /* + * Generated by PEG.js 0.7.0. + * + * http://pegjs.majda.cz/ + */ + + function quote(s) { + /* + * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a + * string literal except for the closing quote character, backslash, + * carriage return, line separator, paragraph separator, and line feed. + * Any character may appear in the form of an escape sequence. + * + * For portability, we also escape escape all control and non-ASCII + * characters. Note that "\0" and "\v" escape sequences are not used + * because JSHint does not like the first and IE the second. + */ + return '"' + s + .replace(/\\/g, '\\\\') // backslash + .replace(/"/g, '\\"') // closing quote character + .replace(/\x08/g, '\\b') // backspace + .replace(/\t/g, '\\t') // horizontal tab + .replace(/\n/g, '\\n') // line feed + .replace(/\f/g, '\\f') // form feed + .replace(/\r/g, '\\r') // carriage return + .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + + '"'; + } var result = { /* @@ -851,12 +1139,53 @@ var parser = (function(){ * which the parser was generated (see |PEG.buildParser|). If the parsing is * unsuccessful, throws |PEG.parser.SyntaxError| describing the error. */ - parse: function(input) { - var pos = 0; - var reportMatchFailures = true; - var rightmostMatchFailuresPos = 0; - var rightmostMatchFailuresExpected = []; - var cache = {}; + parse: function(input, startRule) { + var parseFunctions = { + "body": parse_body, + "part": parse_part, + "section": parse_section, + "sec_tag_start": parse_sec_tag_start, + "end_tag": parse_end_tag, + "context": parse_context, + "params": parse_params, + "bodies": parse_bodies, + "reference": parse_reference, + "partial": parse_partial, + "filters": parse_filters, + "special": parse_special, + "identifier": parse_identifier, + "number": parse_number, + "frac": parse_frac, + "integer": parse_integer, + "path": parse_path, + "key": parse_key, + "array": parse_array, + "array_part": parse_array_part, + "inline": parse_inline, + "inline_part": parse_inline_part, + "buffer": parse_buffer, + "literal": parse_literal, + "esc": parse_esc, + "comment": parse_comment, + "tag": parse_tag, + "ld": parse_ld, + "rd": parse_rd, + "eol": parse_eol, + "ws": parse_ws + }; + + if (startRule !== undefined) { + if (parseFunctions[startRule] === undefined) { + throw new Error("Invalid rule name: " + quote(startRule) + "."); + } + } else { + startRule = "body"; + } + + var pos = { offset: 0, line: 1, column: 1, seenCR: false }; + var reportFailures = 0; + var rightmostFailuresPos = { offset: 0, line: 1, column: 1, seenCR: false }; + var rightmostFailuresExpected = []; function padLeft(input, padding, length) { var result = input; @@ -871,2284 +1200,2398 @@ var parser = (function(){ function escape(ch) { var charCode = ch.charCodeAt(0); + var escapeChar; + var length; - if (charCode < 0xFF) { - var escapeChar = 'x'; - var length = 2; + if (charCode <= 0xFF) { + escapeChar = 'x'; + length = 2; } else { - var escapeChar = 'u'; - var length = 4; + escapeChar = 'u'; + length = 4; } return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); } - function quote(s) { - /* - * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a - * string literal except for the closing quote character, backslash, - * carriage return, line separator, paragraph separator, and line feed. - * Any character may appear in the form of an escape sequence. - */ - return '"' + s - .replace(/\\/g, '\\\\') // backslash - .replace(/"/g, '\\"') // closing quote character - .replace(/\r/g, '\\r') // carriage return - .replace(/\n/g, '\\n') // line feed - .replace(/[\x80-\uFFFF]/g, escape) // non-ASCII characters - + '"'; + function clone(object) { + var result = {}; + for (var key in object) { + result[key] = object[key]; + } + return result; + } + + function advance(pos, n) { + var endOffset = pos.offset + n; + + for (var offset = pos.offset; offset < endOffset; offset++) { + var ch = input.charAt(offset); + if (ch === "\n") { + if (!pos.seenCR) { pos.line++; } + pos.column = 1; + pos.seenCR = false; + } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { + pos.line++; + pos.column = 1; + pos.seenCR = true; + } else { + pos.column++; + pos.seenCR = false; + } + } + + pos.offset += n; } function matchFailed(failure) { - if (pos < rightmostMatchFailuresPos) { + if (pos.offset < rightmostFailuresPos.offset) { return; } - if (pos > rightmostMatchFailuresPos) { - rightmostMatchFailuresPos = pos; - rightmostMatchFailuresExpected = []; + if (pos.offset > rightmostFailuresPos.offset) { + rightmostFailuresPos = clone(pos); + rightmostFailuresExpected = []; } - rightmostMatchFailuresExpected.push(failure); + rightmostFailuresExpected.push(failure); } function parse_body() { - var cacheKey = "body" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var result1 = []; - var result2 = parse_part(); - while (result2 !== null) { - result1.push(result2); - var result2 = parse_part(); - } - var result0 = result1 !== null - ? (function(p) { return ["body"].concat(p) })(result1) - : null; + var result0, result1; + var pos0; - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; + 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) })(pos0.offset, pos0.line, pos0.column, result0); + } + if (result0 === null) { + pos = clone(pos0); + } return result0; } function parse_part() { - var cacheKey = "part" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var result6 = parse_comment(); - if (result6 !== null) { - var result0 = result6; - } else { - var result5 = parse_section(); - if (result5 !== null) { - var result0 = result5; - } else { - var result4 = parse_partial(); - if (result4 !== null) { - var result0 = result4; - } else { - var result3 = parse_special(); - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_reference(); - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_buffer(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; - }; + 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(); + } + } + } + } } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_section() { - var cacheKey = "section" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos1 = pos; - var result8 = parse_sec_tag_start(); - if (result8 !== null) { - var result9 = parse_rd(); - if (result9 !== null) { - var result10 = parse_body(); - if (result10 !== null) { - var result11 = parse_bodies(); - if (result11 !== null) { - var result12 = parse_end_tag(); - if (result12 !== null) { - var result13 = (function() {return result8[1].text === result12.text})() ? '' : null; - if (result13 !== null) { - var result7 = [result8, result9, result10, result11, result12, result13]; + 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(); + if (result5 !== null) { + result6 = (function(offset, line, column, t, b, e, n) { return t[1].text === n.text;})(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 { - var result7 = null; - pos = savedPos1; + result0 = null; + pos = clone(pos1); } } else { - var result7 = null; - pos = savedPos1; + result0 = null; + pos = clone(pos1); } } else { - var result7 = null; - pos = savedPos1; + result0 = null; + pos = clone(pos1); } } else { - var result7 = null; - pos = savedPos1; + result0 = null; + pos = clone(pos1); } } else { - var result7 = null; - pos = savedPos1; + result0 = null; + pos = clone(pos1); } } else { - var result7 = null; - pos = savedPos1; - } - var result6 = result7 !== null - ? (function(t, b, e, n) { e.push(["param", ["literal", "block"], b]); t.push(e); return t })(result7[0], result7[2], result7[3], result7[4]) - : null; - if (result6 !== null) { - var result0 = result6; - } else { - var savedPos0 = pos; - var result3 = parse_sec_tag_start(); - if (result3 !== null) { - if (input.substr(pos, 1) === "/") { - var result4 = "/"; - pos += 1; - } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("\"/\""); - } + 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 })(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 (result4 !== null) { - var result5 = parse_rd(); - if (result5 !== null) { - var result2 = [result3, result4, result5]; + 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 { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); + } + if (result0 !== null) { + result0 = (function(offset, line, column, t) { t.push(["bodies"]); return t })(pos0.offset, pos0.line, pos0.column, result0[0]); + } + if (result0 === null) { + pos = clone(pos0); } - var result1 = result2 !== null - ? (function(t) { t.push(["bodies"]); return t })(result2[0]) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("section"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_sec_tag_start() { - var cacheKey = "sec_tag_start" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - if (input.substr(pos).match(/^[#?^<+@%]/) !== null) { - var result3 = input.charAt(pos); - pos++; + 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 { - var result3 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("[#?^<+@%]"); } } - if (result3 !== null) { - var result4 = parse_identifier(); - if (result4 !== null) { - var result5 = parse_context(); - if (result5 !== null) { - var result6 = parse_params(); - if (result6 !== null) { - var result1 = [result2, result3, result4, result5, result6]; + 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 { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + 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); } - var result0 = result1 !== null - ? (function(t, n, c, p) { return [t, n, c, p] })(result1[1], result1[2], result1[3], result1[4]) - : null; - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_end_tag() { - var cacheKey = "end_tag" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - if (input.substr(pos, 1) === "/") { - var result3 = "/"; - pos += 1; + 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 { - var result3 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("\"/\""); } } - if (result3 !== null) { - var result4 = parse_identifier(); - if (result4 !== null) { - var result5 = parse_rd(); - if (result5 !== null) { - var result1 = [result2, result3, result4, result5]; + 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 { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(n) { return n })(result1[2]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + 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"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_context() { - var cacheKey = "context" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var savedPos0 = pos; - if (input.substr(pos, 1) === ":") { - var result4 = ":"; - pos += 1; + 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 { - var result4 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\":\""); } } - if (result4 !== null) { - var result5 = parse_identifier(); - if (result5 !== null) { - var result3 = [result4, result5]; + if (result0 !== null) { + result1 = parse_identifier(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result3 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(n) {return n})(result3[1]) - : null; - var result1 = result2 !== null ? result2 : ''; - var result0 = result1 !== null - ? (function(n) { return n ? ["context", n] : ["context"] })(result1) - : null; - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; + 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 cacheKey = "params" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var result1 = []; - var savedPos0 = pos; - var result4 = parse_ws(); - if (result4 !== null) { - var result5 = parse_key(); - if (result5 !== null) { - if (input.substr(pos, 1) === "=") { - var result6 = "="; - pos += 1; - } else { - var result6 = null; - if (reportMatchFailures) { - matchFailed("\"=\""); + 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 (result6 !== null) { - var result9 = parse_identifier(); - if (result9 !== null) { - var result7 = result9; - } else { - var result8 = parse_inline(); - if (result8 !== null) { - var result7 = result8; - } else { - var result7 = null;; - }; + if (result3 !== null) { + result4 = parse_number(); + if (result4 === null) { + result4 = parse_identifier(); + if (result4 === null) { + result4 = parse_inline(); + } } - if (result7 !== null) { - var result3 = [result4, result5, result6, result7]; + if (result4 !== null) { + result1 = [result1, result2, result3, result4]; } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(k, v) {return ["param", ["literal", k], v]})(result3[1], result3[3]) - : null; - while (result2 !== null) { - result1.push(result2); - var savedPos0 = pos; - var result4 = parse_ws(); - if (result4 !== null) { - var result5 = parse_key(); - if (result5 !== null) { - if (input.substr(pos, 1) === "=") { - var result6 = "="; - pos += 1; + 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 { - var result6 = null; - if (reportMatchFailures) { + result3 = null; + if (reportFailures === 0) { matchFailed("\"=\""); } } - if (result6 !== null) { - var result9 = parse_identifier(); - if (result9 !== null) { - var result7 = result9; - } else { - var result8 = parse_inline(); - if (result8 !== null) { - var result7 = result8; - } else { - var result7 = null;; - }; + if (result3 !== null) { + result4 = parse_number(); + if (result4 === null) { + result4 = parse_identifier(); + if (result4 === null) { + result4 = parse_inline(); + } } - if (result7 !== null) { - var result3 = [result4, result5, result6, result7]; + if (result4 !== null) { + result1 = [result1, result2, result3, result4]; } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(k, v) {return ["param", ["literal", k], v]})(result3[1], result3[3]) - : null; - } - var result0 = result1 !== null - ? (function(p) { return ["params"].concat(p) })(result1) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + 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"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_bodies() { - var cacheKey = "bodies" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var result1 = []; - var savedPos0 = pos; - var result4 = parse_ld(); - if (result4 !== null) { - if (input.substr(pos, 1) === ":") { - var result5 = ":"; - pos += 1; + 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 { - var result5 = null; - if (reportMatchFailures) { + result2 = null; + if (reportFailures === 0) { matchFailed("\":\""); } } - if (result5 !== null) { - var result6 = parse_key(); - if (result6 !== null) { - var result7 = parse_rd(); - if (result7 !== null) { - var result8 = parse_body(); - if (result8 !== null) { - var result3 = [result4, result5, result6, result7, result8]; + 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 { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(k, v) {return ["param", ["literal", k], v]})(result3[2], result3[4]) - : null; - while (result2 !== null) { - result1.push(result2); - var savedPos0 = pos; - var result4 = parse_ld(); - if (result4 !== null) { - if (input.substr(pos, 1) === ":") { - var result5 = ":"; - pos += 1; + 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 { - var result5 = null; - if (reportMatchFailures) { + result2 = null; + if (reportFailures === 0) { matchFailed("\":\""); } } - if (result5 !== null) { - var result6 = parse_key(); - if (result6 !== null) { - var result7 = parse_rd(); - if (result7 !== null) { - var result8 = parse_body(); - if (result8 !== null) { - var result3 = [result4, result5, result6, result7, result8]; + 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 { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(k, v) {return ["param", ["literal", k], v]})(result3[2], result3[4]) - : null; - } - var result0 = result1 !== null - ? (function(p) { return ["bodies"].concat(p) })(result1) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + 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"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_reference() { - var cacheKey = "reference" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - var result3 = parse_identifier(); - if (result3 !== null) { - var result4 = parse_filters(); - if (result4 !== null) { - var result5 = parse_rd(); - if (result5 !== null) { - var result1 = [result2, result3, result4, result5]; + 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 { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(n, f) { return ["reference", n, f] })(result1[1], result1[2]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + result0 = null; + pos = clone(pos1); + } + if (result0 !== null) { + result0 = (function(offset, line, column, n, f) { return ["reference", n, f] })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); + } + if (result0 === null) { + pos = clone(pos0); + } + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("reference"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_partial() { - var cacheKey = "partial" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - if (input.substr(pos, 1) === ">") { - var result3 = ">"; - pos += 1; + var result0, result1, result2, result3, result4, result5, result6, result7; + 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 { - var result3 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("\">\""); } } - if (result3 !== null) { - var result10 = parse_key(); - var result9 = result10 !== null - ? (function(k) {return ["literal", k]})(result10) - : null; - if (result9 !== null) { - var result4 = result9; + if (result1 === null) { + if (input.charCodeAt(pos.offset) === 43) { + result1 = "+"; + advance(pos, 1); } else { - var result8 = parse_inline(); - if (result8 !== null) { - var result4 = result8; - } else { - var result4 = null;; - }; - } - if (result4 !== null) { - var result5 = parse_context(); - if (result5 !== null) { - if (input.substr(pos, 1) === "/") { - var result6 = "/"; - pos += 1; - } else { - var result6 = null; - if (reportMatchFailures) { - matchFailed("\"/\""); + result1 = null; + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + } + if (result1 !== null) { + pos2 = clone(pos); + result2 = parse_key(); + if (result2 !== null) { + result2 = (function(offset, line, column, k) {return ["literal", k]})(pos2.offset, pos2.line, pos2.column, result2); + } + if (result2 === null) { + pos = clone(pos2); + } + if (result2 === null) { + result2 = parse_inline(); + } + if (result2 !== null) { + result3 = parse_context(); + if (result3 !== null) { + result4 = parse_params(); + if (result4 !== null) { + result5 = []; + result6 = parse_ws(); + while (result6 !== null) { + result5.push(result6); + result6 = parse_ws(); } - } - if (result6 !== null) { - var result7 = parse_rd(); - if (result7 !== null) { - var result1 = [result2, result3, result4, result5, result6, result7]; + if (result5 !== null) { + if (input.charCodeAt(pos.offset) === 47) { + result6 = "/"; + advance(pos, 1); + } else { + result6 = null; + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + if (result6 !== null) { + result7 = parse_rd(); + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = clone(pos1); + } + } else { + result0 = null; + pos = clone(pos1); + } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(n, c) { return ["partial", n, c] })(result1[2], result1[3]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + 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] })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2], result0[3], result0[4]); + } + if (result0 === null) { + pos = clone(pos0); + } + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("partial"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_filters() { - var cacheKey = "filters" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var result1 = []; - var savedPos0 = pos; - if (input.substr(pos, 1) === "|") { - var result4 = "|"; - pos += 1; + 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 { - var result4 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("\"|\""); } } - if (result4 !== null) { - var result5 = parse_key(); - if (result5 !== null) { - var result3 = [result4, result5]; + if (result1 !== null) { + result2 = parse_key(); + if (result2 !== null) { + result1 = [result1, result2]; } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(n) {return n})(result3[1]) - : null; - while (result2 !== null) { - result1.push(result2); - var savedPos0 = pos; - if (input.substr(pos, 1) === "|") { - var result4 = "|"; - pos += 1; + 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 { - var result4 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("\"|\""); } } - if (result4 !== null) { - var result5 = parse_key(); - if (result5 !== null) { - var result3 = [result4, result5]; + if (result1 !== null) { + result2 = parse_key(); + if (result2 !== null) { + result1 = [result1, result2]; } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(n) {return n})(result3[1]) - : null; - } - var result0 = result1 !== null - ? (function(f) { return ["filters"].concat(f) })(result1) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + 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"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_special() { - var cacheKey = "special" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result2 = parse_ld(); - if (result2 !== null) { - if (input.substr(pos, 1) === "~") { - var result3 = "~"; - pos += 1; + 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 { - var result3 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("\"~\""); } } - if (result3 !== null) { - var result4 = parse_key(); - if (result4 !== null) { - var result5 = parse_rd(); - if (result5 !== null) { - var result1 = [result2, result3, result4, result5]; + if (result1 !== null) { + result2 = parse_key(); + if (result2 !== null) { + result3 = parse_rd(); + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(k) { return ["special", k] })(result1[2]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + result0 = null; + pos = clone(pos1); + } + if (result0 !== null) { + result0 = (function(offset, line, column, k) { return ["special", k] })(pos0.offset, pos0.line, pos0.column, result0[2]); + } + if (result0 === null) { + pos = clone(pos0); + } + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("special"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_identifier() { - var cacheKey = "identifier" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var result4 = parse_path(); - var result3 = result4 !== null - ? (function(p) { return wrap(["path"].concat(p), cacheKey) })(result4) - : null; - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_key(); - var result1 = result2 !== null - ? (function(k) { return wrap(["key", k], cacheKey) })(result2) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; + 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); + } } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("identifier"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } - function parse_path() { - var cacheKey = "path" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } + function parse_number() { + var result0; + var pos0; - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var result11 = parse_key(); - var result5 = result11 !== null ? result11 : ''; - if (result5 !== null) { - var savedPos1 = pos; - if (input.substr(pos, 1) === ".") { - var result9 = "."; - pos += 1; + reportFailures++; + pos0 = clone(pos); + result0 = parse_frac(); + 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_frac() { + 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 { - var result9 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("\".\""); } } - if (result9 !== null) { - var result10 = parse_key(); - if (result10 !== null) { - var result8 = [result9, result10]; + 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 { - var result8 = null; - pos = savedPos1; + result0 = null; + pos = clone(pos1); } } else { - var result8 = null; - pos = savedPos1; - } - var result7 = result8 !== null - ? (function(k) {return k})(result8[1]) - : null; - if (result7 !== null) { - var result6 = []; - while (result7 !== null) { - result6.push(result7); - var savedPos1 = pos; - if (input.substr(pos, 1) === ".") { - var result9 = "."; - pos += 1; - } else { - var result9 = null; - if (reportMatchFailures) { - matchFailed("\".\""); - } + 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("frac"); + } + 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]"); } - if (result9 !== null) { - var result10 = parse_key(); - if (result10 !== null) { - var result8 = [result9, result10]; - } else { - var result8 = null; - pos = savedPos1; - } - } else { - var result8 = null; - pos = savedPos1; + } + } + } 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(); } - var result7 = result8 !== null - ? (function(k) {return k})(result8[1]) - : null; } } else { - var result6 = null; + result1 = null; } - if (result6 !== null) { - var result4 = [result5, result6]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result4 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result4 = null; - pos = savedPos0; - } - var result3 = result4 !== null - ? (function(k, d) { - if (k) { d.unshift(k); return [false, d]; } - return [true, d]; - })(result4[0], result4[1]) - : null; - if (result3 !== null) { - var result0 = result3; - } else { - if (input.substr(pos, 1) === ".") { - var result2 = "."; - pos += 1; + 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]; + } + return [true, d]; + })(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 { - var result2 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\".\""); } } - var result1 = result2 !== null - ? (function() { return [true, []] })() - : null; - if (result1 !== null) { - var result0 = result1; + 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 { - var result0 = null;; - }; + result0 = null; + pos = clone(pos1); + } + if (result0 !== null) { + result0 = (function(offset, line, column, d) { + if (d.length > 0) { + return [true, d[0]]; + } + return [true, []] + })(pos0.offset, pos0.line, pos0.column, result0[1]); + } + if (result0 === null) { + pos = clone(pos0); + } } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("path"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_key() { - var cacheKey = "key" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - if (input.substr(pos).match(/^[a-zA-Z_$]/) !== null) { - var result2 = input.charAt(pos); - pos++; + 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 { - var result2 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("[a-zA-Z_$]"); } } - if (result2 !== null) { - var result3 = []; - if (input.substr(pos).match(/^[0-9a-zA-Z_$]/) !== null) { - var result4 = input.charAt(pos); - pos++; + if (result0 !== null) { + result1 = []; + if (/^[0-9a-zA-Z_$\-]/.test(input.charAt(pos.offset))) { + result2 = input.charAt(pos.offset); + advance(pos, 1); } else { - var result4 = null; - if (reportMatchFailures) { - matchFailed("[0-9a-zA-Z_$]"); + result2 = null; + if (reportFailures === 0) { + matchFailed("[0-9a-zA-Z_$\\-]"); } } - while (result4 !== null) { - result3.push(result4); - if (input.substr(pos).match(/^[0-9a-zA-Z_$]/) !== null) { - var result4 = input.charAt(pos); - pos++; + 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 { - var result4 = null; - if (reportMatchFailures) { - matchFailed("[0-9a-zA-Z_$]"); + result2 = null; + if (reportFailures === 0) { + matchFailed("[0-9a-zA-Z_$\\-]"); } } } - if (result3 !== null) { - var result1 = [result2, result3]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(h, t) { return h + t.join('') })(result1[0], result1[1]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + 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"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } - function parse_inline() { - var cacheKey = "inline" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; + function parse_array() { + 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) === 91) { + result0 = "["; + advance(pos, 1); + } else { + result0 = null; + if (reportFailures === 0) { + matchFailed("\"[\""); + } } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos2 = pos; - if (input.substr(pos, 1) === "\"") { - var result14 = "\""; - pos += 1; + if (result0 !== null) { + 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) { + if (input.charCodeAt(pos.offset) === 93) { + result2 = "]"; + advance(pos, 1); + } else { + result2 = null; + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + 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.join('')})(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 { - var result14 = null; - if (reportMatchFailures) { + 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 (result14 !== null) { - if (input.substr(pos, 1) === "\"") { - var result15 = "\""; - pos += 1; + if (result0 !== null) { + if (input.charCodeAt(pos.offset) === 34) { + result1 = "\""; + advance(pos, 1); } else { - var result15 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("\"\\\"\""); } } - if (result15 !== null) { - var result13 = [result14, result15]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result13 = null; - pos = savedPos2; + result0 = null; + pos = clone(pos1); } } else { - var result13 = null; - pos = savedPos2; - } - var result12 = result13 !== null - ? (function() { return ["literal", ""] })() - : null; - if (result12 !== null) { - var result0 = result12; - } else { - var savedPos1 = pos; - if (input.substr(pos, 1) === "\"") { - var result9 = "\""; - pos += 1; + result0 = null; + pos = clone(pos1); + } + if (result0 !== null) { + result0 = (function(offset, line, column) { return ["literal", ""] })(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 { - var result9 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"\\\"\""); } } - if (result9 !== null) { - var result10 = parse_literal(); - if (result10 !== null) { - if (input.substr(pos, 1) === "\"") { - var result11 = "\""; - pos += 1; + if (result0 !== null) { + result1 = parse_literal(); + if (result1 !== null) { + if (input.charCodeAt(pos.offset) === 34) { + result2 = "\""; + advance(pos, 1); } else { - var result11 = null; - if (reportMatchFailures) { + result2 = null; + if (reportFailures === 0) { matchFailed("\"\\\"\""); } } - if (result11 !== null) { - var result8 = [result9, result10, result11]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result8 = null; - pos = savedPos1; + result0 = null; + pos = clone(pos1); } } else { - var result8 = null; - pos = savedPos1; + result0 = null; + pos = clone(pos1); } } else { - var result8 = null; - pos = savedPos1; - } - var result7 = result8 !== null - ? (function(l) { return ["literal", l] })(result8[1]) - : null; - if (result7 !== null) { - var result0 = result7; - } else { - var savedPos0 = pos; - if (input.substr(pos, 1) === "\"") { - var result3 = "\""; - pos += 1; + result0 = null; + pos = clone(pos1); + } + if (result0 !== null) { + result0 = (function(offset, line, column, l) { return ["literal", l] })(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 { - var result3 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"\\\"\""); } } - if (result3 !== null) { - var result6 = parse_inline_part(); - if (result6 !== null) { - var result4 = []; - while (result6 !== null) { - result4.push(result6); - var result6 = parse_inline_part(); + if (result0 !== null) { + result2 = parse_inline_part(); + if (result2 !== null) { + result1 = []; + while (result2 !== null) { + result1.push(result2); + result2 = parse_inline_part(); } } else { - var result4 = null; + result1 = null; } - if (result4 !== null) { - if (input.substr(pos, 1) === "\"") { - var result5 = "\""; - pos += 1; + if (result1 !== null) { + if (input.charCodeAt(pos.offset) === 34) { + result2 = "\""; + advance(pos, 1); } else { - var result5 = null; - if (reportMatchFailures) { + result2 = null; + if (reportFailures === 0) { matchFailed("\"\\\"\""); } } - if (result5 !== null) { - var result2 = [result3, result4, result5]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } - var result1 = result2 !== null - ? (function(p) { return ["body"].concat(p) })(result2[1]) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; + if (result0 !== null) { + result0 = (function(offset, line, column, p) { return ["body"].concat(p) })(pos0.offset, pos0.line, pos0.column, result0[1]); + } + if (result0 === null) { + pos = clone(pos0); + } + } } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("inline"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_inline_part() { - var cacheKey = "inline_part" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var result4 = parse_special(); - if (result4 !== null) { - var result0 = result4; - } else { - var result3 = parse_reference(); - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_literal(); - var result1 = result2 !== null - ? (function(l) { return ["buffer", l] })(result2) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; + 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); + } + } } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_buffer() { - var cacheKey = "buffer" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos4 = pos; - var result14 = parse_eol(); - if (result14 !== null) { - var result15 = []; - var result16 = parse_ws(); - while (result16 !== null) { - result15.push(result16); - var result16 = parse_ws(); - } - if (result15 !== null) { - var result13 = [result14, result15]; + 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 { - var result13 = null; - pos = savedPos4; + result0 = null; + pos = clone(pos1); } } else { - var result13 = null; - pos = savedPos4; - } - var result12 = result13 !== null - ? (function(e, w) { return ["format", e, w.join('')] })(result13[0], result13[1]) - : null; - if (result12 !== null) { - var result0 = result12; - } else { - var savedPos0 = pos; - var savedPos3 = pos; - var savedReportMatchFailuresVar2 = reportMatchFailures; - reportMatchFailures = false; - var result11 = parse_tag(); - reportMatchFailures = savedReportMatchFailuresVar2; - if (result11 === null) { - var result5 = ''; + result0 = null; + pos = clone(pos1); + } + if (result0 !== null) { + result0 = (function(offset, line, column, e, w) { return ["format", e, w.join('')] })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); + } + 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 { - var result5 = null; - pos = savedPos3; - } - if (result5 !== null) { - var savedPos2 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result10 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result10 === null) { - var result6 = ''; + result1 = null; + pos = clone(pos3); + } + if (result1 !== null) { + pos3 = clone(pos); + reportFailures++; + result2 = parse_eol(); + reportFailures--; + if (result2 === null) { + result2 = ""; } else { - var result6 = null; - pos = savedPos2; - } - if (result6 !== null) { - var savedPos1 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result9 = parse_comment(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result7 = ''; + result2 = null; + pos = clone(pos3); + } + if (result2 !== null) { + pos3 = clone(pos); + reportFailures++; + result3 = parse_comment(); + reportFailures--; + if (result3 === null) { + result3 = ""; } else { - var result7 = null; - pos = savedPos1; + result3 = null; + pos = clone(pos3); } - if (result7 !== null) { - if (input.length > pos) { - var result8 = input.charAt(pos); - pos++; + if (result3 !== null) { + if (input.length > pos.offset) { + result4 = input.charAt(pos.offset); + advance(pos, 1); } else { - var result8 = null; - if (reportMatchFailures) { - matchFailed('any character'); + result4 = null; + if (reportFailures === 0) { + matchFailed("any character"); } } - if (result8 !== null) { - var result4 = [result5, result6, result7, result8]; + if (result4 !== null) { + result1 = [result1, result2, result3, result4]; } else { - var result4 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result4 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result4 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result4 = null; - pos = savedPos0; - } - var result3 = result4 !== null - ? (function(c) {return c})(result4[3]) - : null; - if (result3 !== null) { - var result2 = []; - while (result3 !== null) { - result2.push(result3); - var savedPos0 = pos; - var savedPos3 = pos; - var savedReportMatchFailuresVar2 = reportMatchFailures; - reportMatchFailures = false; - var result11 = parse_tag(); - reportMatchFailures = savedReportMatchFailuresVar2; - if (result11 === null) { - var result5 = ''; + 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 { - var result5 = null; - pos = savedPos3; + result1 = null; + pos = clone(pos3); } - if (result5 !== null) { - var savedPos2 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result10 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result10 === null) { - var result6 = ''; + if (result1 !== null) { + pos3 = clone(pos); + reportFailures++; + result2 = parse_eol(); + reportFailures--; + if (result2 === null) { + result2 = ""; } else { - var result6 = null; - pos = savedPos2; + result2 = null; + pos = clone(pos3); } - if (result6 !== null) { - var savedPos1 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result9 = parse_comment(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result7 = ''; + if (result2 !== null) { + pos3 = clone(pos); + reportFailures++; + result3 = parse_comment(); + reportFailures--; + if (result3 === null) { + result3 = ""; } else { - var result7 = null; - pos = savedPos1; + result3 = null; + pos = clone(pos3); } - if (result7 !== null) { - if (input.length > pos) { - var result8 = input.charAt(pos); - pos++; + if (result3 !== null) { + if (input.length > pos.offset) { + result4 = input.charAt(pos.offset); + advance(pos, 1); } else { - var result8 = null; - if (reportMatchFailures) { - matchFailed('any character'); + result4 = null; + if (reportFailures === 0) { + matchFailed("any character"); } } - if (result8 !== null) { - var result4 = [result5, result6, result7, result8]; + if (result4 !== null) { + result1 = [result1, result2, result3, result4]; } else { - var result4 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result4 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result4 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result4 = null; - pos = savedPos0; + 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); } - var result3 = result4 !== null - ? (function(c) {return c})(result4[3]) - : null; } } else { - var result2 = null; + result0 = null; + } + if (result0 !== null) { + result0 = (function(offset, line, column, b) { return ["buffer", b.join('')] })(pos0.offset, pos0.line, pos0.column, result0); + } + if (result0 === null) { + pos = clone(pos0); } - var result1 = result2 !== null - ? (function(b) { return ["buffer", b.join('')] })(result2) - : null; - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; } - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("buffer"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_literal() { - var cacheKey = "literal" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - var savedPos2 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result10 = parse_tag(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result10 === null) { - var result4 = ''; + 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 { - var result4 = null; - pos = savedPos2; - } - if (result4 !== null) { - var savedPos1 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result9 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result5 = ''; - } else { - var result5 = null; - pos = savedPos1; - } - if (result5 !== null) { - var result8 = parse_esc(); - if (result8 !== null) { - var result6 = result8; + 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 { - if (input.substr(pos).match(/^[^"]/) !== null) { - var result7 = input.charAt(pos); - pos++; - } else { - var result7 = null; - if (reportMatchFailures) { - matchFailed("[^\"]"); - } + result2 = null; + if (reportFailures === 0) { + matchFailed("[^\"]"); } - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; - } - if (result6 !== null) { - var result3 = [result4, result5, result6]; - } else { - var result3 = null; - pos = savedPos0; } + } + if (result2 !== null) { + result1 = [result1, result2]; } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; - } - var result2 = result3 !== null - ? (function(c) {return c})(result3[2]) - : null; - if (result2 !== null) { - var result1 = []; - while (result2 !== null) { - result1.push(result2); - var savedPos0 = pos; - var savedPos2 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result10 = parse_tag(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result10 === null) { - var result4 = ''; + 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 { - var result4 = null; - pos = savedPos2; - } - if (result4 !== null) { - var savedPos1 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result9 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result5 = ''; - } else { - var result5 = null; - pos = savedPos1; - } - if (result5 !== null) { - var result8 = parse_esc(); - if (result8 !== null) { - var result6 = result8; + 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 { - if (input.substr(pos).match(/^[^"]/) !== null) { - var result7 = input.charAt(pos); - pos++; - } else { - var result7 = null; - if (reportMatchFailures) { - matchFailed("[^\"]"); - } + result2 = null; + if (reportFailures === 0) { + matchFailed("[^\"]"); } - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; - } - if (result6 !== null) { - var result3 = [result4, result5, result6]; - } else { - var result3 = null; - pos = savedPos0; } + } + if (result2 !== null) { + result1 = [result1, result2]; } else { - var result3 = null; - pos = savedPos0; + result1 = null; + pos = clone(pos2); } } else { - var result3 = null; - pos = savedPos0; + 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); } - var result2 = result3 !== null - ? (function(c) {return c})(result3[2]) - : null; } } else { - var result1 = null; + result0 = null; } - var result0 = result1 !== null - ? (function(b) { return b.join('') })(result1) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && 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"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_esc() { - var cacheKey = "esc" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } + var result0; + var pos0; - - if (input.substr(pos, 2) === "\\\"") { - var result1 = "\\\""; - pos += 2; + pos0 = clone(pos); + if (input.substr(pos.offset, 2) === "\\\"") { + result0 = "\\\""; + advance(pos, 2); } else { - var result1 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"\\\\\\\"\""); } } - var result0 = result1 !== null - ? (function() { return '"' })() - : null; - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; + 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 cacheKey = "comment" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - var savedReportMatchFailures = reportMatchFailures; - reportMatchFailures = false; - var savedPos0 = pos; - if (input.substr(pos, 2) === "{!") { - var result2 = "{!"; - pos += 2; + 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 { - var result2 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"{!\""); } } - if (result2 !== null) { - var result3 = []; - var savedPos1 = pos; - var savedPos2 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - if (input.substr(pos, 2) === "!}") { - var result9 = "!}"; - pos += 2; + 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 { - var result9 = null; - if (reportMatchFailures) { + result2 = null; + if (reportFailures === 0) { matchFailed("\"!}\""); } } - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result7 = ''; + reportFailures--; + if (result2 === null) { + result2 = ""; } else { - var result7 = null; - pos = savedPos2; + result2 = null; + pos = clone(pos4); } - if (result7 !== null) { - if (input.length > pos) { - var result8 = input.charAt(pos); - pos++; + if (result2 !== null) { + if (input.length > pos.offset) { + result3 = input.charAt(pos.offset); + advance(pos, 1); } else { - var result8 = null; - if (reportMatchFailures) { - matchFailed('any character'); + result3 = null; + if (reportFailures === 0) { + matchFailed("any character"); } } - if (result8 !== null) { - var result6 = [result7, result8]; + if (result3 !== null) { + result2 = [result2, result3]; } else { - var result6 = null; - pos = savedPos1; + result2 = null; + pos = clone(pos3); } } else { - var result6 = null; - pos = savedPos1; - } - var result5 = result6 !== null - ? (function(c) {return c})(result6[1]) - : null; - while (result5 !== null) { - result3.push(result5); - var savedPos1 = pos; - var savedPos2 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - if (input.substr(pos, 2) === "!}") { - var result9 = "!}"; - pos += 2; + 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 { - var result9 = null; - if (reportMatchFailures) { + result2 = null; + if (reportFailures === 0) { matchFailed("\"!}\""); } } - reportMatchFailures = savedReportMatchFailuresVar0; - if (result9 === null) { - var result7 = ''; + reportFailures--; + if (result2 === null) { + result2 = ""; } else { - var result7 = null; - pos = savedPos2; + result2 = null; + pos = clone(pos4); } - if (result7 !== null) { - if (input.length > pos) { - var result8 = input.charAt(pos); - pos++; + if (result2 !== null) { + if (input.length > pos.offset) { + result3 = input.charAt(pos.offset); + advance(pos, 1); } else { - var result8 = null; - if (reportMatchFailures) { - matchFailed('any character'); + result3 = null; + if (reportFailures === 0) { + matchFailed("any character"); } } - if (result8 !== null) { - var result6 = [result7, result8]; + if (result3 !== null) { + result2 = [result2, result3]; } else { - var result6 = null; - pos = savedPos1; + result2 = null; + pos = clone(pos3); } } else { - var result6 = null; - pos = savedPos1; + 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); } - var result5 = result6 !== null - ? (function(c) {return c})(result6[1]) - : null; } - if (result3 !== null) { - if (input.substr(pos, 2) === "!}") { - var result4 = "!}"; - pos += 2; + if (result1 !== null) { + if (input.substr(pos.offset, 2) === "!}") { + result2 = "!}"; + advance(pos, 2); } else { - var result4 = null; - if (reportMatchFailures) { + result2 = null; + if (reportFailures === 0) { matchFailed("\"!}\""); } } - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos1); } } else { - var result1 = null; - pos = savedPos0; - } - var result0 = result1 !== null - ? (function(c) { return ["comment", c.join('')] })(result1[1]) - : null; - reportMatchFailures = savedReportMatchFailures; - if (reportMatchFailures && result0 === null) { + result0 = null; + pos = clone(pos1); + } + if (result0 !== null) { + result0 = (function(offset, line, column, c) { return ["comment", c.join('')] })(pos0.offset, pos0.line, pos0.column, result0[1]); + } + if (result0 === null) { + pos = clone(pos0); + } + reportFailures--; + if (reportFailures === 0 && result0 === null) { matchFailed("comment"); } - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_tag() { - var cacheKey = "tag" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - - - var savedPos0 = pos; - var result3 = parse_ld(); - if (result3 !== null) { - if (input.substr(pos).match(/^[#?^><+%:@\/~%]/) !== null) { - var result4 = input.charAt(pos); - pos++; + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1, pos2; + + pos0 = clone(pos); + result0 = parse_ld(); + if (result0 !== null) { + if (/^[#?^><+%:@\/~%]/.test(input.charAt(pos.offset))) { + result1 = input.charAt(pos.offset); + advance(pos, 1); } else { - var result4 = null; - if (reportMatchFailures) { + result1 = null; + if (reportFailures === 0) { matchFailed("[#?^><+%:@\\/~%]"); } } - if (result4 !== null) { - var savedPos1 = pos; - var savedPos3 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result12 = parse_rd(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result12 === null) { - var result8 = ''; - } else { - var result8 = null; - pos = savedPos3; - } - if (result8 !== null) { - var savedPos2 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result11 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result11 === null) { - var result9 = ''; + if (result1 !== null) { + result2 = []; + result3 = parse_ws(); + while (result3 !== null) { + result2.push(result3); + result3 = parse_ws(); + } + if (result2 !== null) { + pos1 = clone(pos); + pos2 = clone(pos); + reportFailures++; + result4 = parse_rd(); + reportFailures--; + if (result4 === null) { + result4 = ""; } else { - var result9 = null; - pos = savedPos2; + result4 = null; + pos = clone(pos2); } - if (result9 !== null) { - if (input.length > pos) { - var result10 = input.charAt(pos); - pos++; + if (result4 !== null) { + pos2 = clone(pos); + reportFailures++; + result5 = parse_eol(); + reportFailures--; + if (result5 === null) { + result5 = ""; } else { - var result10 = null; - if (reportMatchFailures) { - matchFailed('any character'); - } + result5 = null; + pos = clone(pos2); } - if (result10 !== null) { - var result7 = [result8, result9, result10]; + if (result5 !== null) { + if (input.length > pos.offset) { + result6 = input.charAt(pos.offset); + advance(pos, 1); + } else { + result6 = null; + if (reportFailures === 0) { + matchFailed("any character"); + } + } + if (result6 !== null) { + result4 = [result4, result5, result6]; + } else { + result4 = null; + pos = clone(pos1); + } } else { - var result7 = null; - pos = savedPos1; + result4 = null; + pos = clone(pos1); } } else { - var result7 = null; - pos = savedPos1; + result4 = null; + pos = clone(pos1); } - } else { - var result7 = null; - pos = savedPos1; - } - if (result7 !== null) { - var result5 = []; - while (result7 !== null) { - result5.push(result7); - var savedPos1 = pos; - var savedPos3 = pos; - var savedReportMatchFailuresVar1 = reportMatchFailures; - reportMatchFailures = false; - var result12 = parse_rd(); - reportMatchFailures = savedReportMatchFailuresVar1; - if (result12 === null) { - var result8 = ''; - } else { - var result8 = null; - pos = savedPos3; - } - if (result8 !== null) { - var savedPos2 = pos; - var savedReportMatchFailuresVar0 = reportMatchFailures; - reportMatchFailures = false; - var result11 = parse_eol(); - reportMatchFailures = savedReportMatchFailuresVar0; - if (result11 === null) { - var result9 = ''; + if (result4 !== null) { + result3 = []; + while (result4 !== null) { + result3.push(result4); + pos1 = clone(pos); + pos2 = clone(pos); + reportFailures++; + result4 = parse_rd(); + reportFailures--; + if (result4 === null) { + result4 = ""; } else { - var result9 = null; - pos = savedPos2; + result4 = null; + pos = clone(pos2); } - if (result9 !== null) { - if (input.length > pos) { - var result10 = input.charAt(pos); - pos++; + if (result4 !== null) { + pos2 = clone(pos); + reportFailures++; + result5 = parse_eol(); + reportFailures--; + if (result5 === null) { + result5 = ""; } else { - var result10 = null; - if (reportMatchFailures) { - matchFailed('any character'); - } + result5 = null; + pos = clone(pos2); } - if (result10 !== null) { - var result7 = [result8, result9, result10]; + if (result5 !== null) { + if (input.length > pos.offset) { + result6 = input.charAt(pos.offset); + advance(pos, 1); + } else { + result6 = null; + if (reportFailures === 0) { + matchFailed("any character"); + } + } + if (result6 !== null) { + result4 = [result4, result5, result6]; + } else { + result4 = null; + pos = clone(pos1); + } } else { - var result7 = null; - pos = savedPos1; + result4 = null; + pos = clone(pos1); } } else { - var result7 = null; - pos = savedPos1; + result4 = null; + pos = clone(pos1); } - } else { - var result7 = null; - pos = savedPos1; } + } else { + result3 = null; } - } else { - var result5 = null; - } - if (result5 !== null) { - var result6 = parse_rd(); - if (result6 !== null) { - var result2 = [result3, result4, result5, result6]; + 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(pos0); + } + } else { + result0 = null; + pos = clone(pos0); + } } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos0); } } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos0); } } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos0); } } else { - var result2 = null; - pos = savedPos0; + result0 = null; + pos = clone(pos0); } - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_reference(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; + if (result0 === null) { + result0 = parse_reference(); } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_ld() { - var cacheKey = "ld" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } + var result0; - - if (input.substr(pos, 1) === "{") { - var result0 = "{"; - pos += 1; + if (input.charCodeAt(pos.offset) === 123) { + result0 = "{"; + advance(pos, 1); } else { - var result0 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"{\""); } } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_rd() { - var cacheKey = "rd" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } + var result0; - - if (input.substr(pos, 1) === "}") { - var result0 = "}"; - pos += 1; + if (input.charCodeAt(pos.offset) === 125) { + result0 = "}"; + advance(pos, 1); } else { - var result0 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"}\""); } } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_eol() { - var cacheKey = "eol" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } + var result0; - - if (input.substr(pos, 1) === "\n") { - var result5 = "\n"; - pos += 1; + if (input.charCodeAt(pos.offset) === 10) { + result0 = "\n"; + advance(pos, 1); } else { - var result5 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"\\n\""); } } - if (result5 !== null) { - var result0 = result5; - } else { - if (input.substr(pos, 2) === "\r\n") { - var result4 = "\r\n"; - pos += 2; + if (result0 === null) { + if (input.substr(pos.offset, 2) === "\r\n") { + result0 = "\r\n"; + advance(pos, 2); } else { - var result4 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"\\r\\n\""); } } - if (result4 !== null) { - var result0 = result4; - } else { - if (input.substr(pos, 1) === "\r") { - var result3 = "\r"; - pos += 1; + if (result0 === null) { + if (input.charCodeAt(pos.offset) === 13) { + result0 = "\r"; + advance(pos, 1); } else { - var result3 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"\\r\""); } } - if (result3 !== null) { - var result0 = result3; - } else { - if (input.substr(pos, 1) === "\u2028") { - var result2 = "\u2028"; - pos += 1; + if (result0 === null) { + if (input.charCodeAt(pos.offset) === 8232) { + result0 = "\u2028"; + advance(pos, 1); } else { - var result2 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"\\u2028\""); } } - if (result2 !== null) { - var result0 = result2; - } else { - if (input.substr(pos, 1) === "\u2029") { - var result1 = "\u2029"; - pos += 1; + if (result0 === null) { + if (input.charCodeAt(pos.offset) === 8233) { + result0 = "\u2029"; + advance(pos, 1); } else { - var result1 = null; - if (reportMatchFailures) { + result0 = null; + if (reportFailures === 0) { matchFailed("\"\\u2029\""); } } - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; + } + } + } } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; return result0; } function parse_ws() { - var cacheKey = "ws" + '@' + pos; - var cachedResult = cache[cacheKey]; - if (cachedResult) { - pos = cachedResult.nextPos; - return cachedResult.result; - } - + var result0; - if (input.substr(pos).match(/^[ \xA0\uFEFF]/) !== null) { - var result0 = input.charAt(pos); - pos++; + if (/^[\t\x0B\f \xA0\uFEFF]/.test(input.charAt(pos.offset))) { + result0 = input.charAt(pos.offset); + advance(pos, 1); } else { - var result0 = null; - if (reportMatchFailures) { - matchFailed("[ \\xA0\\uFEFF]"); + result0 = null; + if (reportFailures === 0) { + matchFailed("[\\t\\x0B\\f \\xA0\\uFEFF]"); } } - - - - cache[cacheKey] = { - nextPos: pos, - result: result0 - }; + if (result0 === null) { + result0 = parse_eol(); + } return result0; } - function buildErrorMessage() { - function buildExpected(failuresExpected) { - failuresExpected.sort(); - - var lastFailure = null; - var failuresExpectedUnique = []; - for (var i = 0; i < failuresExpected.length; i++) { - if (failuresExpected[i] !== lastFailure) { - failuresExpectedUnique.push(failuresExpected[i]); - lastFailure = failuresExpected[i]; - } - } - - switch (failuresExpectedUnique.length) { - case 0: - return 'end of input'; - case 1: - return failuresExpectedUnique[0]; - default: - return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ') - + ' or ' - + failuresExpectedUnique[failuresExpectedUnique.length - 1]; - } - } - - var expected = buildExpected(rightmostMatchFailuresExpected); - var actualPos = Math.max(pos, rightmostMatchFailuresPos); - var actual = actualPos < input.length - ? quote(input.charAt(actualPos)) - : 'end of input'; - - return 'Expected ' + expected + ' but ' + actual + ' found.'; - } - function computeErrorPosition() { - /* - * The first idea was to use |String.split| to break the input up to the - * error position along newlines and derive the line and column from - * there. However IE's |split| implementation is so broken that it was - * enough to prevent it. - */ - - var line = 1; - var column = 1; - var seenCR = false; - - for (var i = 0; i < rightmostMatchFailuresPos; i++) { - var ch = input.charAt(i); - if (ch === '\n') { - if (!seenCR) { line++; } - column = 1; - seenCR = false; - } else if (ch === '\r' | ch === '\u2028' || ch === '\u2029') { - line++; - column = 1; - seenCR = true; - } else { - column++; - seenCR = false; + 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 { line: line, column: column }; + return cleanExpected; } - function wrap(node, ck) { - - node['text'] = input.substring(ck.split('@')[1], pos); - - return node; - - } - - - - var result = parse_body(); + var result = parseFunctions[startRule](); /* * The parser is now in one of the following three states: @@ -3156,28 +3599,33 @@ var parser = (function(){ * 1. The parser successfully parsed the whole input. * * - |result !== null| - * - |pos === input.length| - * - |rightmostMatchFailuresExpected| may or may not contain something + * - |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 < input.length| - * - |rightmostMatchFailuresExpected| may or may not contain something + * - |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 === 0| - * - |rightmostMatchFailuresExpected| contains at least one failure + * - |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 !== input.length) { - var errorPosition = computeErrorPosition(); - throw new SyntaxError( - buildErrorMessage(), + 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 ); @@ -3192,9 +3640,33 @@ var parser = (function(){ /* Thrown when a parser encounters a syntax error. */ - result.SyntaxError = function(message, line, column) { - this.name = 'SyntaxError'; - this.message = message; + 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; }; @@ -3206,4 +3678,4 @@ var parser = (function(){ dust.parse = parser.parse; -})(typeof exports !== 'undefined' ? exports : window.dust); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : getGlobal()); \ No newline at end of file diff --git a/vendor/assets/javascripts/dust-full.min.js b/vendor/assets/javascripts/dust-full.min.js deleted file mode 100644 index ba21d94..0000000 --- a/vendor/assets/javascripts/dust-full.min.js +++ /dev/null @@ -1,61 +0,0 @@ -// -// Dust - Asynchronous Templating v0.3.0 -// http://akdubya.github.com/dustjs -// -// Copyright (c) 2010, Aleksander Williams -// Released under the MIT License. -// - -var dust={}; -(function(o){function z(e,k,l){this.stack=e;this.global=k;this.blocks=l}function H(e,k,l,x){this.tail=k;this.isObject=!o.isArray(e)&&e&&typeof e==="object";this.head=e;this.index=l;this.of=x}function p(e){this.head=new B(this);this.callback=e;this.out=""}function J(){this.head=new B(this)}function B(e,k,l){this.root=e;this.next=k;this.data="";this.flushable=false;this.taps=l}function r(e,k){this.head=e;this.tail=k}o.cache={};o.register=function(e,k){if(e)o.cache[e]=k};o.render=function(e,k,l){l=(new p(l)).head; -o.load(e,l,z.wrap(k)).end()};o.stream=function(e,k){var l=new J;o.nextTick(function(){o.load(e,l.head,z.wrap(k)).end()});return l};o.renderSource=function(e,k,l){return o.compileFn(e)(k,l)};o.compileFn=function(e,k){var l=o.loadSource(o.compile(e,k));return function(x,C){var E=C?new p(C):new J;o.nextTick(function(){l(E.head,z.wrap(x)).end()});return E}};o.load=function(e,k,l){var x=o.cache[e];if(x)return x(k,l);else{if(o.onLoad)return k.map(function(C){o.onLoad(e,function(E,M){if(E)return C.setError(E); -o.cache[e]||o.loadSource(o.compile(M,e));o.cache[e](C,l).end()})});return k.setError(Error("Template Not Found: "+e))}};o.loadSource=function(e){return eval(e)};o.isArray=Array.isArray?Array.isArray:function(e){return Object.prototype.toString.call(e)=="[object Array]"};o.nextTick=function(e){setTimeout(e,0)};o.isEmpty=function(e){if(o.isArray(e)&&!e.length)return true;if(e===0)return false;return!e};o.filter=function(e,k,l){if(l)for(var x=0,C=l.length;x\"]/),q=/&/g,j=//g,t=/\"/g;o.escapeHtml=function(e){if(typeof e==="string"){if(!K.test(e))return e;return e.replace(q,"&").replace(j,"<").replace(w,">").replace(t,""")}return e}; -var y=/\\/g,A=/\r/g,F=/\u2028/g,L=/\u2029/g,N=/\n/g,V=/\f/g,I=/'/g,Q=/"/g,T=/\t/g;o.escapeJs=function(e){if(typeof e==="string")return e.replace(y,"\\\\").replace(Q,'\\"').replace(I,"\\'").replace(A,"\\r").replace(F,"\\u2028").replace(L,"\\u2029").replace(N,"\\n").replace(V,"\\f").replace(T,"\\t");return e}})(dust);if(typeof exports!=="undefined"){typeof process!=="undefined"&&require("./server")(dust);module.exports=dust} -(function(o){function z(q,j){for(var w=[j[0]],t=1,y=j.length;tR){R=a;W=[]}W.push(n)}}function K(){var n="body@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=[];for(var c= -q();c!==null;){b.push(c);c=q()}b=b!==null?["body"].concat(b):null;v[n]={nextPos:a,result:b};return b}function q(){var n="part@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=l();if(b!==null)b=b;else{b=j();if(b!==null)b=b;else{b="partial@"+a;var c=v[b];if(c){a=c.nextPos;b=c.result}else{c=h;h=false;var d=a,g=C();if(g!==null){if(p.substr(a,1)===">"){var f=">";a+=1}else{f=null;h&&r('">"')}if(f!==null){var i=I();i=i!==null?["literal",i]:null;if(i!==null)i=i;else{i=Q();i=i!==null?i:null}if(i!==null){var m= -y();if(m!==null){if(p.substr(a,1)==="/"){var s="/";a+=1}else{s=null;h&&r('"/"')}if(s!==null){var u=E();if(u!==null)g=[g,f,i,m,s,u];else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}d=g!==null?["partial",g[2],g[3]]:null;(h=c)&&d===null&&r("partial");v[b]={nextPos:a,result:d};b=d}if(b!==null)b=b;else{b=L();if(b!==null)b=b;else{b=F();if(b!==null)b=b;else{b="buffer@"+a;if(c=v[b]){a=c.nextPos;b=c.result}else{c=h;h=false;d=a;g=M();if(g!==null){f=[];for(i= -U();i!==null;){f.push(i);i=U()}if(f!==null)g=[g,f];else{g=null;a=d}}else{g=null;a=d}d=g!==null?["format",g[0],g[1].join("")]:null;if(d!==null)d=d;else{i=g=a;f=h;h=false;m=x();h=f;if(m===null)f="";else{f=null;a=i}if(f!==null){m=a;i=h;h=false;s=M();h=i;if(s===null)i="";else{i=null;a=m}if(i!==null){m=a;s=h;h=false;u=l();h=s;if(u===null)s="";else{s=null;a=m}if(s!==null){if(p.length>a){m=p.charAt(a);a++}else{m=null;h&&r("any character")}if(m!==null)f=[f,i,s,m];else{f=null;a=g}}else{f=null;a=g}}else{f= -null;a=g}}else{f=null;a=g}g=f!==null?f[3]:null;if(g!==null)for(d=[];g!==null;){d.push(g);i=g=a;f=h;h=false;m=x();h=f;if(m===null)f="";else{f=null;a=i}if(f!==null){m=a;i=h;h=false;s=M();h=i;if(s===null)i="";else{i=null;a=m}if(i!==null){m=a;s=h;h=false;u=l();h=s;if(u===null)s="";else{s=null;a=m}if(s!==null){if(p.length>a){m=p.charAt(a);a++}else{m=null;h&&r("any character")}if(m!==null)f=[f,i,s,m];else{f=null;a=g}}else{f=null;a=g}}else{f=null;a=g}}else{f=null;a=g}g=f!==null?f[3]:null}else d=null;d=d!== -null?["buffer",d.join("")]:null;d=d!==null?d:null}(h=c)&&d===null&&r("buffer");v[b]={nextPos:a,result:d};b=d}b=b!==null?b:null}}}}}v[n]={nextPos:a,result:b};return b}function j(){var n="section@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a,d=w();if(d!==null){var g=E();if(g!==null){var f=K();if(f!==null){var i=A();if(i!==null){var m=t();if(m!==null){var s=d[1].text===m.text?"":null;if(s!==null)d=[d,g,f,i,m,s];else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}}else{d= -null;a=c}}else{d=null;a=c}c=d!==null?function(u,D,O){O.push(["param",["literal","block"],D]);u.push(O);return u}(d[0],d[2],d[3],d[4]):null;if(c!==null)c=c;else{c=a;d=w();if(d!==null){if(p.substr(a,1)==="/"){g="/";a+=1}else{g=null;h&&r('"/"')}if(g!==null){f=E();if(f!==null)d=[d,g,f];else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}c=d!==null?function(u){u.push(["bodies"]);return u}(d[0]):null;c=c!==null?c:null}(h=b)&&c===null&&r("section");v[n]={nextPos:a,result:c};return c}function w(){var n="sec_tag_start@"+ -a,b=v[n];if(b){a=b.nextPos;return b.result}b=a;var c=C();if(c!==null){if(p.substr(a).match(/^[#?^<+@%]/)!==null){var d=p.charAt(a);a++}else{d=null;h&&r("[#?^<+@%]")}if(d!==null){var g=N();if(g!==null){var f=y();if(f!==null){var i;i="params@"+a;var m=v[i];if(m){a=m.nextPos;i=m.result}else{m=h;h=false;var s=[],u=a,D=U();if(D!==null){var O=I();if(O!==null){if(p.substr(a,1)==="="){var P="=";a+=1}else{P=null;h&&r('"="')}if(P!==null){var G=N();if(G!==null)G=G;else{G=Q();G=G!==null?G:null}if(G!==null)D= -[D,O,P,G];else{D=null;a=u}}else{D=null;a=u}}else{D=null;a=u}}else{D=null;a=u}for(u=D!==null?["param",["literal",D[1]],D[3]]:null;u!==null;){s.push(u);u=a;D=U();if(D!==null){O=I();if(O!==null){if(p.substr(a,1)==="="){P="=";a+=1}else{P=null;h&&r('"="')}if(P!==null){G=N();if(G!==null)G=G;else{G=Q();G=G!==null?G:null}if(G!==null)D=[D,O,P,G];else{D=null;a=u}}else{D=null;a=u}}else{D=null;a=u}}else{D=null;a=u}u=D!==null?["param",["literal",D[1]],D[3]]:null}s=s!==null?["params"].concat(s):null;(h=m)&&s=== -null&&r("params");v[i]={nextPos:a,result:s};i=s}if(i!==null)c=[c,d,g,f,i];else{c=null;a=b}}else{c=null;a=b}}else{c=null;a=b}}else{c=null;a=b}}else{c=null;a=b}b=c!==null?[c[1],c[2],c[3],c[4]]:null;v[n]={nextPos:a,result:b};return b}function t(){var n="end_tag@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a,d=C();if(d!==null){if(p.substr(a,1)==="/"){var g="/";a+=1}else{g=null;h&&r('"/"')}if(g!==null){var f=N();if(f!==null){var i=E();if(i!==null)d=[d,g,f,i];else{d=null;a=c}}else{d=null; -a=c}}else{d=null;a=c}}else{d=null;a=c}c=d!==null?d[2]:null;(h=b)&&c===null&&r("end tag");v[n]={nextPos:a,result:c};return c}function y(){var n="context@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=a;if(p.substr(a,1)===":"){var c=":";a+=1}else{c=null;h&&r('":"')}if(c!==null){var d=N();if(d!==null)c=[c,d];else{c=null;a=b}}else{c=null;a=b}b=c!==null?c[1]:null;b=b!==null?b:"";b=b!==null?b?["context",b]:["context"]:null;v[n]={nextPos:a,result:b};return b}function A(){var n="bodies@"+a,b=v[n];if(b){a= -b.nextPos;return b.result}b=h;h=false;var c=[],d=a,g=C();if(g!==null){if(p.substr(a,1)===":"){var f=":";a+=1}else{f=null;h&&r('":"')}if(f!==null){var i=I();if(i!==null){var m=E();if(m!==null){var s=K();if(s!==null)g=[g,f,i,m,s];else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}for(d=g!==null?["param",["literal",g[2]],g[4]]:null;d!==null;){c.push(d);d=a;g=C();if(g!==null){if(p.substr(a,1)===":"){f=":";a+=1}else{f=null;h&&r('":"')}if(f!==null){i=I();if(i!==null){m= -E();if(m!==null){s=K();if(s!==null)g=[g,f,i,m,s];else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}}else{g=null;a=d}d=g!==null?["param",["literal",g[2]],g[4]]:null}c=c!==null?["bodies"].concat(c):null;(h=b)&&c===null&&r("bodies");v[n]={nextPos:a,result:c};return c}function F(){var n="reference@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a,d=C();if(d!==null){var g=N();if(g!==null){var f;f="filters@"+a;var i=v[f];if(i){a=i.nextPos;f=i.result}else{i=h;h=false;var m= -[],s=a;if(p.substr(a,1)==="|"){var u="|";a+=1}else{u=null;h&&r('"|"')}if(u!==null){var D=I();if(D!==null)u=[u,D];else{u=null;a=s}}else{u=null;a=s}for(s=u!==null?u[1]:null;s!==null;){m.push(s);s=a;if(p.substr(a,1)==="|"){u="|";a+=1}else{u=null;h&&r('"|"')}if(u!==null){D=I();if(D!==null)u=[u,D];else{u=null;a=s}}else{u=null;a=s}s=u!==null?u[1]:null}m=m!==null?["filters"].concat(m):null;(h=i)&&m===null&&r("filters");v[f]={nextPos:a,result:m};f=m}if(f!==null){i=E();if(i!==null)d=[d,g,f,i];else{d=null; -a=c}}else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}c=d!==null?["reference",d[1],d[2]]:null;(h=b)&&c===null&&r("reference");v[n]={nextPos:a,result:c};return c}function L(){var n="special@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a,d=C();if(d!==null){if(p.substr(a,1)==="~"){var g="~";a+=1}else{g=null;h&&r('"~"')}if(g!==null){var f=I();if(f!==null){var i=E();if(i!==null)d=[d,g,f,i];else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}c=d!==null?["special",d[2]]: -null;(h=b)&&c===null&&r("special");v[n]={nextPos:a,result:c};return c}function N(){var n="identifier@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=V();c=c!==null?X(["path"].concat(c),n):null;if(c!==null)c=c;else{c=I();c=c!==null?X(["key",c],n):null;c=c!==null?c:null}(h=b)&&c===null&&r("identifier");v[n]={nextPos:a,result:c};return c}function V(){var n="path@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a,d=I();d=d!==null?d:"";if(d!==null){var g=a;if(p.substr(a,1)=== -"."){var f=".";a+=1}else{f=null;h&&r('"."')}if(f!==null){var i=I();if(i!==null)f=[f,i];else{f=null;a=g}}else{f=null;a=g}g=f!==null?f[1]:null;if(g!==null)for(var m=[];g!==null;){m.push(g);g=a;if(p.substr(a,1)==="."){f=".";a+=1}else{f=null;h&&r('"."')}if(f!==null){i=I();if(i!==null)f=[f,i];else{f=null;a=g}}else{f=null;a=g}g=f!==null?f[1]:null}else m=null;if(m!==null)d=[d,m];else{d=null;a=c}}else{d=null;a=c}c=d!==null?function(s,u){if(s){u.unshift(s);return[false,u]}return[true,u]}(d[0],d[1]):null;if(c!== -null)c=c;else{if(p.substr(a,1)==="."){c=".";a+=1}else{c=null;h&&r('"."')}c=c!==null?[true,[]]:null;c=c!==null?c:null}(h=b)&&c===null&&r("path");v[n]={nextPos:a,result:c};return c}function I(){var n="key@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a;if(p.substr(a).match(/^[a-zA-Z_$]/)!==null){var d=p.charAt(a);a++}else{d=null;h&&r("[a-zA-Z_$]")}if(d!==null){var g=[];if(p.substr(a).match(/^[0-9a-zA-Z_$]/)!==null){var f=p.charAt(a);a++}else{f=null;h&&r("[0-9a-zA-Z_$]")}for(;f!==null;){g.push(f); -if(p.substr(a).match(/^[0-9a-zA-Z_$]/)!==null){f=p.charAt(a);a++}else{f=null;h&&r("[0-9a-zA-Z_$]")}}if(g!==null)d=[d,g];else{d=null;a=c}}else{d=null;a=c}c=d!==null?d[0]+d[1].join(""):null;(h=b)&&c===null&&r("key");v[n]={nextPos:a,result:c};return c}function Q(){var n="inline@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a;if(p.substr(a,1)==='"'){var d='"';a+=1}else{d=null;h&&r('"\\""')}if(d!==null){if(p.substr(a,1)==='"'){var g='"';a+=1}else{g=null;h&&r('"\\""')}if(g!==null)d=[d, -g];else{d=null;a=c}}else{d=null;a=c}c=d!==null?["literal",""]:null;if(c!==null)c=c;else{c=a;if(p.substr(a,1)==='"'){d='"';a+=1}else{d=null;h&&r('"\\""')}if(d!==null){g=e();if(g!==null){if(p.substr(a,1)==='"'){var f='"';a+=1}else{f=null;h&&r('"\\""')}if(f!==null)d=[d,g,f];else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}c=d!==null?["literal",d[1]]:null;if(c!==null)c=c;else{c=a;if(p.substr(a,1)==='"'){d='"';a+=1}else{d=null;h&&r('"\\""')}if(d!==null){f=T();if(f!==null)for(g=[];f!==null;){g.push(f); -f=T()}else g=null;if(g!==null){if(p.substr(a,1)==='"'){f='"';a+=1}else{f=null;h&&r('"\\""')}if(f!==null)d=[d,g,f];else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}c=d!==null?["body"].concat(d[1]):null;c=c!==null?c:null}}(h=b)&&c===null&&r("inline");v[n]={nextPos:a,result:c};return c}function T(){var n="inline_part@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=L();if(b!==null)b=b;else{b=F();if(b!==null)b=b;else{b=e();b=b!==null?["buffer",b]:null;b=b!==null?b:null}}v[n]={nextPos:a,result:b};return b} -function e(){var n="literal@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a,d=a,g=h;h=false;var f=x();h=g;if(f===null)g="";else{g=null;a=d}if(g!==null){f=a;d=h;h=false;var i=M();h=d;if(i===null)d="";else{d=null;a=f}if(d!==null){f=k();if(f!==null)f=f;else{if(p.substr(a).match(/^[^"]/)!==null){f=p.charAt(a);a++}else{f=null;h&&r('[^"]')}f=f!==null?f:null}if(f!==null)g=[g,d,f];else{g=null;a=c}}else{g=null;a=c}}else{g=null;a=c}c=g!==null?g[2]:null;if(c!==null)for(var m=[];c!==null;){m.push(c); -d=c=a;g=h;h=false;f=x();h=g;if(f===null)g="";else{g=null;a=d}if(g!==null){f=a;d=h;h=false;i=M();h=d;if(i===null)d="";else{d=null;a=f}if(d!==null){f=k();if(f!==null)f=f;else{if(p.substr(a).match(/^[^"]/)!==null){f=p.charAt(a);a++}else{f=null;h&&r('[^"]')}f=f!==null?f:null}if(f!==null)g=[g,d,f];else{g=null;a=c}}else{g=null;a=c}}else{g=null;a=c}c=g!==null?g[2]:null}else m=null;m=m!==null?m.join(""):null;(h=b)&&m===null&&r("literal");v[n]={nextPos:a,result:m};return m}function k(){var n="esc@"+a,b=v[n]; -if(b){a=b.nextPos;return b.result}if(p.substr(a,2)==='\\"'){b='\\"';a+=2}else{b=null;h&&r('"\\\\\\""')}b=b!==null?'"':null;v[n]={nextPos:a,result:b};return b}function l(){var n="comment@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=h;h=false;var c=a;if(p.substr(a,2)==="{!"){var d="{!";a+=2}else{d=null;h&&r('"{!"')}if(d!==null){var g=[],f=a,i=a,m=h;h=false;if(p.substr(a,2)==="!}"){var s="!}";a+=2}else{s=null;h&&r('"!}"')}h=m;if(s===null)m="";else{m=null;a=i}if(m!==null){if(p.length>a){i=p.charAt(a); -a++}else{i=null;h&&r("any character")}if(i!==null)i=[m,i];else{i=null;a=f}}else{i=null;a=f}for(f=i!==null?i[1]:null;f!==null;){g.push(f);i=f=a;m=h;h=false;if(p.substr(a,2)==="!}"){s="!}";a+=2}else{s=null;h&&r('"!}"')}h=m;if(s===null)m="";else{m=null;a=i}if(m!==null){if(p.length>a){i=p.charAt(a);a++}else{i=null;h&&r("any character")}if(i!==null)i=[m,i];else{i=null;a=f}}else{i=null;a=f}f=i!==null?i[1]:null}if(g!==null){if(p.substr(a,2)==="!}"){f="!}";a+=2}else{f=null;h&&r('"!}"')}if(f!==null)d=[d,g, -f];else{d=null;a=c}}else{d=null;a=c}}else{d=null;a=c}c=d!==null?["comment",d[1].join("")]:null;(h=b)&&c===null&&r("comment");v[n]={nextPos:a,result:c};return c}function x(){var n="tag@"+a,b=v[n];if(b){a=b.nextPos;return b.result}b=a;var c=C();if(c!==null){if(p.substr(a).match(/^[#?^><+%:@\/~%]/)!==null){var d=p.charAt(a);a++}else{d=null;h&&r("[#?^><+%:@\\/~%]")}if(d!==null){var g=a,f=a,i=h;h=false;var m=E();h=i;if(m===null)i="";else{i=null;a=f}if(i!==null){f=a;m=h;h=false;var s=M();h=m;if(s===null)m= -"";else{m=null;a=f}if(m!==null){if(p.length>a){f=p.charAt(a);a++}else{f=null;h&&r("any character")}if(f!==null)i=[i,m,f];else{i=null;a=g}}else{i=null;a=g}}else{i=null;a=g}if(i!==null)for(var u=[];i!==null;){u.push(i);f=g=a;i=h;h=false;m=E();h=i;if(m===null)i="";else{i=null;a=f}if(i!==null){f=a;m=h;h=false;s=M();h=m;if(s===null)m="";else{m=null;a=f}if(m!==null){if(p.length>a){f=p.charAt(a);a++}else{f=null;h&&r("any character")}if(f!==null)i=[i,m,f];else{i=null;a=g}}else{i=null;a=g}}else{i=null;a=g}}else u= -null;if(u!==null){g=E();if(g!==null)c=[c,d,u,g];else{c=null;a=b}}else{c=null;a=b}}else{c=null;a=b}}else{c=null;a=b}if(c!==null)b=c;else{b=F();b=b!==null?b:null}v[n]={nextPos:a,result:b};return b}function C(){var n="ld@"+a,b=v[n];if(b){a=b.nextPos;return b.result}if(p.substr(a,1)==="{"){b="{";a+=1}else{b=null;h&&r('"{"')}v[n]={nextPos:a,result:b};return b}function E(){var n="rd@"+a,b=v[n];if(b){a=b.nextPos;return b.result}if(p.substr(a,1)==="}"){b="}";a+=1}else{b=null;h&&r('"}"')}v[n]={nextPos:a,result:b}; -return b}function M(){var n="eol@"+a,b=v[n];if(b){a=b.nextPos;return b.result}if(p.substr(a,1)==="\n"){b="\n";a+=1}else{b=null;h&&r('"\\n"')}if(b!==null)b=b;else{if(p.substr(a,2)==="\r\n"){b="\r\n";a+=2}else{b=null;h&&r('"\\r\\n"')}if(b!==null)b=b;else{if(p.substr(a,1)==="\r"){b="\r";a+=1}else{b=null;h&&r('"\\r"')}if(b!==null)b=b;else{if(p.substr(a,1)==="\u2028"){b="\u2028";a+=1}else{b=null;h&&r('"\\u2028"')}if(b!==null)b=b;else{if(p.substr(a,1)==="\u2029"){b="\u2029";a+=1}else{b=null;h&&r('"\\u2029"')}b= -b!==null?b:null}}}}v[n]={nextPos:a,result:b};return b}function U(){var n="ws@"+a,b=v[n];if(b){a=b.nextPos;return b.result}if(p.substr(a).match(/^[\t\u000b\u000c \xA0\uFEFF]/)!==null){b=p.charAt(a);a++}else{b=null;h&&r("[\t\u000b\u000c \\xA0\\uFEFF]")}v[n]={nextPos:a,result:b};return b}function Y(){var n=function(c){c.sort();for(var d=null,g=[],f=0;f\"\']/), + 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, + 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(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") { + //TODO: Remove the helpers from dust core in the next release. + dust.helpers = require("./dust-helpers").helpers; + if (typeof process !== "undefined") { + require('./server')(dust); + } + module.exports = dust; +} +(function(dust){ + +/* make a safe version of console if it is not available + * currently supporting: + * _console.log + * */ +var _console = (typeof console !== 'undefined')? console: { + log: function(){ + /* a noop*/ + } +}; + +function isSelect(context) { + var value = context.current(); + return typeof value === "object" && value.isSelect === true; +} + +function filter(chunk, context, bodies, params, filter) { + var params = params || {}, + actual, + expected; + if (params.key) { + actual = helpers.tap(params.key, chunk, context); + } else if (isSelect(context)) { + actual = context.current().selectKey; + if (context.current().isResolved) { + filter = function() { return false; }; + } + } else { + throw "No key specified for filter and no key found in context from select statement"; + } + expected = helpers.tap(params.value, chunk, context); + if (filter(expected, coerce(actual, params.type, context))) { + if (isSelect(context)) { + context.current().isResolved = true; + } + return chunk.render(bodies.block, context); + } else if (bodies['else']) { + return chunk.render(bodies['else'], context); + } + + return chunk.write(''); +} + +function coerce (value, type, context) { + if (value) { + switch (type || typeof(value)) { + case 'number': return +value; + case 'string': return String(value); + case 'boolean': return Boolean(value); + case 'date': return new Date(value); + case 'context': return context.get(value); + } + } + + return value; +} + +var helpers = { + + sep: function(chunk, context, bodies) { + if (context.stack.index === context.stack.of - 1) { + return chunk; + } + return bodies.block(chunk, context); + }, + + idx: function(chunk, context, bodies) { + return bodies.block(chunk, context.push(context.stack.index)); + }, + + contextDump: function(chunk, context, bodies) { + _console.log(JSON.stringify(context.stack)); + return chunk; + }, + + // Utility helping to resolve dust references in the given chunk + tap: function( input, chunk, context ){ + // return given input if there is no dust reference to resolve + var output = input; + // dust compiles a string to function, if there are references + if( typeof input === "function"){ + if( ( typeof input.isReference !== "undefined" ) && ( input.isReference === true ) ){ // just a plain function, not a dust `body` function + output = input(); + } else { + output = ''; + chunk.tap(function(data){ + output += data; + return ''; + }).render(input, context).untap(); + if( output === '' ){ + output = false; + } + } + } + return output; + }, + + /** + if helper + @param cond, either a string literal value or a dust reference + a string literal value, is enclosed in double quotes, e.g. cond="2>3" + a dust reference is also enclosed in double quotes, e.g. cond="'{val}'' > 3" + cond argument should evaluate to a valid javascript expression + **/ + + "if": function( chunk, context, bodies, params ){ + if( params && params.cond ){ + var cond = params.cond; + cond = this.tap(cond, chunk, context); + // eval expressions with given dust references + if( eval( cond ) ){ + return chunk.render( bodies.block, context ); + } + if( bodies['else'] ){ + return chunk.render( bodies['else'], context ); + } + } + // no condition + else { + _console.log( "No condition given in the if helper!" ); + } + return chunk; + }, + + /** + select/eq/lt/lte/gt/gte/default helper + @param key, either a string literal value or a dust reference + a string literal value, is enclosed in double quotes, e.g. key="foo" + a dust reference may or may not be enclosed in double quotes, e.g. key="{val}" and key=val are both valid + @param type (optiona), supported types are number, boolean, string, date, context, defaults to string + **/ + select: function(chunk, context, bodies, params) { + if( params && params.key){ + // returns given input as output, if the input is not a dust reference, else does a context lookup + var key = this.tap(params.key, chunk, context); + return chunk.render(bodies.block, context.push({ isSelect: true, isResolved: false, selectKey: key })); + } + // no key + else { + _console.log( "No key given in the select helper!" ); + } + return chunk; + }, + + eq: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; }); + }, + + lt: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; }); + }, + + lte: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; }); + }, + + gt: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual > expected; }); + }, + + gte: function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return actual >= expected; }); + }, + + "default": function(chunk, context, bodies, params) { + return filter(chunk, context, bodies, params, function(expected, actual) { return true; }); + }, + size: function( chunk, context, bodies, params ) { + var subject = params.subject; + var value = 0; + if (!subject) { //undefined, "", 0 + value = 0; + } else if(dust.isArray(subject)) { //array + value = subject.length; + } else if (!isNaN(subject)) { //numeric values + value = subject; + } else if (Object(subject) === subject) { //object test + var nr = 0; + for(var k in subject) if(Object.hasOwnProperty.call(subject,k)) nr++; + value = nr; + } else { + value = (subject + '').length; //any other value (strings etc.) + } + return chunk.write(value); + } +}; + +dust.helpers = helpers; + +})(typeof exports !== 'undefined' ? exports : dust); +(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 +} + +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) })(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(); + if (result5 !== null) { + result6 = (function(offset, line, column, t, b, e, n) { return t[1].text === n.text;})(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 })(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 })(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] })(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; + 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) { + pos2 = clone(pos); + result2 = parse_key(); + if (result2 !== null) { + result2 = (function(offset, line, column, k) {return ["literal", k]})(pos2.offset, pos2.line, pos2.column, result2); + } + if (result2 === null) { + pos = clone(pos2); + } + if (result2 === null) { + result2 = parse_inline(); + } + if (result2 !== null) { + result3 = parse_context(); + if (result3 !== null) { + result4 = parse_params(); + if (result4 !== null) { + result5 = []; + result6 = parse_ws(); + while (result6 !== null) { + result5.push(result6); + result6 = parse_ws(); + } + if (result5 !== null) { + if (input.charCodeAt(pos.offset) === 47) { + result6 = "/"; + advance(pos, 1); + } else { + result6 = null; + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + if (result6 !== null) { + result7 = parse_rd(); + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } 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] })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2], result0[3], result0[4]); + } + 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] })(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_frac(); + 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_frac() { + 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("frac"); + } + 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]; + } + return [true, d]; + })(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]]; + } + return [true, []] + })(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; + + reportFailures++; + pos0 = clone(pos); + pos1 = clone(pos); + pos2 = clone(pos); + pos3 = clone(pos); + if (input.charCodeAt(pos.offset) === 91) { + result0 = "["; + advance(pos, 1); + } else { + result0 = null; + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + if (result0 !== null) { + 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) { + if (input.charCodeAt(pos.offset) === 93) { + result2 = "]"; + advance(pos, 1); + } else { + result2 = null; + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + 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.join('')})(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", ""] })(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] })(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) })(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('')] })(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_eol(); + reportFailures--; + if (result2 === null) { + result2 = ""; + } else { + result2 = null; + pos = clone(pos3); + } + if (result2 !== null) { + pos3 = clone(pos); + reportFailures++; + result3 = parse_comment(); + 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_eol(); + reportFailures--; + if (result2 === null) { + result2 = ""; + } else { + result2 = null; + pos = clone(pos3); + } + if (result2 !== null) { + pos3 = clone(pos); + reportFailures++; + result3 = parse_comment(); + 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('')] })(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('')] })(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; + var pos0, pos1, pos2; + + pos0 = 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) { + pos1 = clone(pos); + pos2 = clone(pos); + reportFailures++; + result4 = parse_rd(); + reportFailures--; + if (result4 === null) { + result4 = ""; + } else { + result4 = null; + pos = clone(pos2); + } + if (result4 !== null) { + pos2 = clone(pos); + reportFailures++; + result5 = parse_eol(); + reportFailures--; + if (result5 === null) { + result5 = ""; + } else { + result5 = null; + pos = clone(pos2); + } + if (result5 !== null) { + if (input.length > pos.offset) { + result6 = input.charAt(pos.offset); + advance(pos, 1); + } else { + result6 = null; + if (reportFailures === 0) { + matchFailed("any character"); + } + } + if (result6 !== null) { + result4 = [result4, result5, result6]; + } else { + result4 = null; + pos = clone(pos1); + } + } else { + result4 = null; + pos = clone(pos1); + } + } else { + result4 = null; + pos = clone(pos1); + } + if (result4 !== null) { + result3 = []; + while (result4 !== null) { + result3.push(result4); + pos1 = clone(pos); + pos2 = clone(pos); + reportFailures++; + result4 = parse_rd(); + reportFailures--; + if (result4 === null) { + result4 = ""; + } else { + result4 = null; + pos = clone(pos2); + } + if (result4 !== null) { + pos2 = clone(pos); + reportFailures++; + result5 = parse_eol(); + reportFailures--; + if (result5 === null) { + result5 = ""; + } else { + result5 = null; + pos = clone(pos2); + } + if (result5 !== null) { + if (input.length > pos.offset) { + result6 = input.charAt(pos.offset); + advance(pos, 1); + } else { + result6 = null; + if (reportFailures === 0) { + matchFailed("any character"); + } + } + if (result6 !== null) { + result4 = [result4, result5, result6]; + } else { + result4 = null; + pos = clone(pos1); + } + } else { + result4 = null; + pos = clone(pos1); + } + } else { + result4 = null; + pos = clone(pos1); + } + } + } else { + result3 = null; + } + 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(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_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 : dust);