From 00dd6e81f32cff6ebe3b2c3b14200bd8f83e7ce5 Mon Sep 17 00:00:00 2001 From: Sungwon Lee Date: Thu, 12 Jan 2012 18:50:08 +0900 Subject: [PATCH] add dust template engine to support .dust files --- lib/jasmine/headless.rb | 2 + lib/jasmine/headless/dust_cache.rb | 30 + lib/jasmine/headless/dust_template.rb | 41 + lib/jasmine/headless/files_list.rb | 4 + .../javascripts/dust-full-for-compile.js | 3209 +++++++++++++++++ 5 files changed, 3286 insertions(+) create mode 100644 lib/jasmine/headless/dust_cache.rb create mode 100644 lib/jasmine/headless/dust_template.rb create mode 100644 vendor/assets/javascripts/dust-full-for-compile.js diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index 0a60efa..cb2dba7 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -8,6 +8,7 @@ module Jasmine autoload :CommandLine, 'jasmine/headless/command_line' autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache' + autoload :DustCache, 'jasmine/headless/dust_cache' autoload :SpecFileAnalyzer, 'jasmine/headless/spec_file_analyzer' autoload :CacheableAction, 'jasmine/headless/cacheable_action' autoload :VERSION, 'jasmine/headless/version' @@ -23,6 +24,7 @@ module Jasmine autoload :FileChecker, 'jasmine/headless/file_checker' autoload :CoffeeTemplate, 'jasmine/headless/coffee_template' + autoload :DustTemplate, 'jasmine/headless/dust_template' autoload :JSTemplate, 'jasmine/headless/js_template' autoload :JSTTemplate, 'jasmine/headless/jst_template' autoload :CSSTemplate, 'jasmine/headless/css_template' diff --git a/lib/jasmine/headless/dust_cache.rb b/lib/jasmine/headless/dust_cache.rb new file mode 100644 index 0000000..e0c20f3 --- /dev/null +++ b/lib/jasmine/headless/dust_cache.rb @@ -0,0 +1,30 @@ +require 'execjs' +require 'digest/sha1' +require 'fileutils' + +module Jasmine + module Headless + + class DustCache < CacheableAction + + class << self + def cache_type + "dust" + end + end + + def action + @path ||= File.expand_path('../../../../vendor/assets/javascripts/dust-full-for-compile.js', __FILE__) + @contents ||= File.read(@path) + @context ||= ExecJS.compile(@contents) + + template_root = DustTemplate.template_root + template_root = template_root + '/' if template_root[ template_root.length - 1 ].chr != '/' + template_name = file.split(template_root).last.split('.',2).first + @context.call("dust.compile", File.read(file), template_name) + end + end + end +end + + diff --git a/lib/jasmine/headless/dust_template.rb b/lib/jasmine/headless/dust_template.rb new file mode 100644 index 0000000..8c615d5 --- /dev/null +++ b/lib/jasmine/headless/dust_template.rb @@ -0,0 +1,41 @@ +require 'tilt/template' +require 'execjs' + +module Jasmine::Headless + class DustTemplate < Tilt::Template + include Jasmine::Headless::FileChecker + + class << self + def template_root=(root) + @template_root = root + end + def template_root + @template_root || "app/assets/javascripts/templates/" + end + end + + self.default_mime_type = 'application/javascript' + + def prepare; end + + def evaluate(scope, locals, &block) + if bad_format?(file) + alert_bad_format(file) + return '' + end + begin + cache = Jasmine::Headless::DustCache.new(file) + source = cache.handle + if cache.cached? + %{ + } + else + %{} + end + rescue StandardError => e + puts "[%s] Error in compiling file: %s" % [ 'coffeescript'.color(:red), file.color(:yellow) ] + raise e + end + end + end +end diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index eef115a..573df49 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -66,6 +66,7 @@ module Jasmine::Headless register_engine '.js', Jasmine::Headless::JSTemplate register_engine '.css', Jasmine::Headless::CSSTemplate register_engine '.jst', Jasmine::Headless::JSTTemplate + register_engine '.dust', Jasmine::Headless::DustTemplate end end @@ -224,6 +225,9 @@ module Jasmine::Headless add_files(@searches[type] = data.flatten, type, send(SEARCH_ROOTS[type])) end end + + # config dust template + Jasmine::Headless::DustTemplate.template_root = @config['template_dir'] end def add_files(patterns, type, dirs) diff --git a/vendor/assets/javascripts/dust-full-for-compile.js b/vendor/assets/javascripts/dust-full-for-compile.js new file mode 100644 index 0000000..bf3d20b --- /dev/null +++ b/vendor/assets/javascripts/dust-full-for-compile.js @@ -0,0 +1,3209 @@ +// +// 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);