dust-rails 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,76 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dust-rails
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Hoseong Hwang
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-03 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rails
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70304932773940 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">"
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 3
31
- - 1
32
- - 0
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
33
21
  version: 3.1.0
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: tilt
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70304932773940
25
+ - !ruby/object:Gem::Dependency
26
+ name: tilt
27
+ requirement: &70304932773400 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
48
33
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: execjs
52
34
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70304932773400
36
+ - !ruby/object:Gem::Dependency
37
+ name: execjs
38
+ requirement: &70304932772780 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
62
44
  type: :runtime
63
- version_requirements: *id003
64
- description: This gem makes you dust.js easy to use with rails.
65
- email:
45
+ prerelease: false
46
+ version_requirements: *70304932772780
47
+ description: This gem makes it easy to use dust.js with rails.
48
+ email:
66
49
  - thefron@wafflestudio.com
67
50
  executables: []
68
-
69
51
  extensions: []
70
-
71
52
  extra_rdoc_files: []
72
-
73
- files:
53
+ files:
74
54
  - .gitignore
75
55
  - Gemfile
76
56
  - Gemfile.lock
@@ -83,42 +63,30 @@ files:
83
63
  - lib/dust-rails/rails/railtie.rb
84
64
  - lib/dust-rails/version.rb
85
65
  - vendor/assets/javascripts/dust-core.js
86
- - vendor/assets/javascripts/dust-core.min.js
87
- - vendor/assets/javascripts/dust-full-for-compile.js
88
66
  - vendor/assets/javascripts/dust-full.js
89
- - vendor/assets/javascripts/dust-full.min.js
67
+ - vendor/dustjs/lib/dust.js
90
68
  homepage: https://github.com/thefron/dust-rails
91
69
  licenses: []
92
-
93
70
  post_install_message:
94
71
  rdoc_options: []
95
-
96
- require_paths:
72
+ require_paths:
97
73
  - lib
98
- required_ruby_version: !ruby/object:Gem::Requirement
74
+ required_ruby_version: !ruby/object:Gem::Requirement
99
75
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
107
- required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
81
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
116
86
  requirements: []
117
-
118
87
  rubyforge_project: dust-rails
119
- rubygems_version: 1.8.10
88
+ rubygems_version: 1.8.15
120
89
  signing_key:
121
90
  specification_version: 3
122
91
  summary: Use dust.js with rails
123
92
  test_files: []
124
-
@@ -1,21 +0,0 @@
1
- //
2
- // Dust - Asynchronous Templating v0.3.0
3
- // http://akdubya.github.com/dustjs
4
- //
5
- // Copyright (c) 2010, Aleksander Williams
6
- // Released under the MIT License.
7
- //
8
-
9
- var dust={};
10
- (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;
11
- 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);
12
- 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<g;e++){var i=c[e];if(i==="s")b=null;else a=
13
- d.filters[i](a)}if(b)a=d.filters[b](a);return a};d.filters={h:function(a){return d.escapeHtml(a)},j:function(a){return d.escapeJs(a)},u:encodeURI,uc:encodeURIComponent};d.makeBase=function(a){return new h(new k,a)};h.wrap=function(a){if(a instanceof h)return a;return new h(new k(a))};h.prototype.get=function(a){for(var b=this.stack,c;b;){if(b.isObject){c=b.head[a];if(c!==undefined)return c}b=b.tail}return this.global?this.global[a]:undefined};h.prototype.getPath=function(a,b){var c=this.stack,e=b.length;
14
- if(a&&e===0)return c.head;if(c.isObject){c=c.head;for(var g=0;c&&g<e;){c=c[b[g]];g++}return c}};h.prototype.push=function(a,b,c){return new h(new k(a,this.stack,b,c),this.global,this.blocks)};h.prototype.rebase=function(a){return new h(new k(a),this.global,this.blocks)};h.prototype.current=function(){return this.stack.head};h.prototype.getBlock=function(a){var b=this.blocks;if(b)for(var c=b.length,e;c--;)if(e=b[c][a])return e};h.prototype.shiftBlocks=function(a){var b=this.blocks;if(a){newBlocks=
15
- b?b.concat([a]):[a];return new h(this.stack,this.global,newBlocks)}return this};l.prototype.flush=function(){for(var a=this.head;a;){if(a.flushable)this.out+=a.data;else{if(a.error){this.callback(a.error);this.flush=function(){}}return}this.head=a=a.next}this.callback(null,this.out)};j.prototype.flush=function(){for(var a=this.head;a;){if(a.flushable)this.emit("data",a.data);else{if(a.error){this.emit("error",a.error);this.flush=function(){}}return}this.head=a=a.next}this.emit("end")};j.prototype.emit=
16
- function(a,b){var c=this.events;c&&c[a]&&c[a](b)};j.prototype.on=function(a,b){if(!this.events)this.events={};this.events[a]=b;return this};f.prototype.write=function(a){var b=this.taps;if(b)a=b.go(a);this.data+=a;return this};f.prototype.end=function(a){a&&this.write(a);this.flushable=true;this.root.flush();return this};f.prototype.map=function(a){var b=new f(this.root,this.next,this.taps),c=new f(this.root,b,this.taps);this.next=c;this.flushable=true;a(c);return b};f.prototype.tap=function(a){var b=
17
- this.taps;this.taps=b?b.push(a):new m(a);return this};f.prototype.untap=function(){this.taps=this.taps.tail;return this};f.prototype.render=function(a,b){return a(this,b)};f.prototype.reference=function(a,b,c,e){if(typeof a==="function"){a=a(this,b,null,{auto:c,filters:e});if(a instanceof f)return a}return d.isEmpty(a)?this:this.write(d.filter(a,c,e))};f.prototype.section=function(a,b,c,e){if(typeof a==="function"){a=a(this,b,c,e);if(a instanceof f)return a}var g=c.block;c=c["else"];if(e)b=b.push(e);
18
- if(d.isArray(a)){if(g){e=a.length;c=this;for(var i=0;i<e;i++)c=g(c,b.push(a[i],i,e));return c}}else if(a===true){if(g)return g(this,b)}else if(a||a===0){if(g)return g(this,b.push(a))}else if(c)return c(this,b);return this};f.prototype.exists=function(a,b,c){var e=c.block;c=c["else"];if(d.isEmpty(a)){if(c)return c(this,b)}else if(e)return e(this,b);return this};f.prototype.notexists=function(a,b,c){var e=c.block;c=c["else"];if(d.isEmpty(a)){if(e)return e(this,b)}else if(c)return c(this,b);return this};
19
- f.prototype.block=function(a,b,c){c=c.block;if(a)c=a;if(c)return c(this,b);return this};f.prototype.partial=function(a,b){if(typeof a==="function")return this.capture(a,b,function(c,e){d.load(c,e,b).end()});return d.load(a,this,b)};f.prototype.helper=function(a,b,c,e){return d.helpers[a](this,b,c,e)};f.prototype.capture=function(a,b,c){return this.map(function(e){var g=new l(function(i,n){i?e.setError(i):c(n,e)});a(g.head,b).end()})};f.prototype.setError=function(a){this.error=a;this.root.flush();
20
- return this};d.helpers={sep:function(a,b,c){if(b.stack.index===b.stack.of-1)return a;return c.block(a,b)},idx:function(a,b,c){return c.block(a,b.push(b.stack.index))}};m.prototype.push=function(a){return new m(a,this)};m.prototype.go=function(a){for(var b=this;b;){a=b.head(a);b=b.tail}return a};var o=RegExp(/[&<>\"]/),p=/&/g,q=/</g,r=/>/g,s=/\"/g;d.escapeHtml=function(a){if(typeof a==="string"){if(!o.test(a))return a;return a.replace(p,"&amp;").replace(q,"&lt;").replace(r,"&gt;").replace(s,"&quot;")}return a};
21
- 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};
@@ -1,3209 +0,0 @@
1
- //
2
- // Dust - Asynchronous Templating v0.3.0
3
- // http://akdubya.github.com/dustjs
4
- //
5
- // Copyright (c) 2010, Aleksander Williams
6
- // Released under the MIT License.
7
- //
8
-
9
- var dust = {};
10
-
11
- (function(dust) {
12
-
13
- dust.cache = {};
14
-
15
- dust.register = function(name, tmpl) {
16
- if (!name) return;
17
- dust.cache[name] = tmpl;
18
- };
19
-
20
- dust.render = function(name, context, callback) {
21
- var chunk = new Stub(callback).head;
22
- dust.load(name, chunk, Context.wrap(context)).end();
23
- };
24
-
25
- dust.stream = function(name, context) {
26
- var stream = new Stream();
27
- dust.nextTick(function() {
28
- dust.load(name, stream.head, Context.wrap(context)).end();
29
- });
30
- return stream;
31
- };
32
-
33
- dust.renderSource = function(source, context, callback) {
34
- return dust.compileFn(source)(context, callback);
35
- };
36
-
37
- dust.compileFn = function(source, name) {
38
- var tmpl = dust.loadSource(dust.compile(source, name));
39
- return function(context, callback) {
40
- var master = callback ? new Stub(callback) : new Stream();
41
- dust.nextTick(function() {
42
- tmpl(master.head, Context.wrap(context)).end();
43
- });
44
- return master;
45
- }
46
- };
47
-
48
- dust.load = function(name, chunk, context) {
49
- var tmpl = dust.cache[name];
50
- if (tmpl) {
51
- return tmpl(chunk, context);
52
- } else {
53
- if (dust.onLoad) {
54
- return chunk.map(function(chunk) {
55
- dust.onLoad(name, function(err, src) {
56
- if (err) return chunk.setError(err);
57
- if (!dust.cache[name]) dust.loadSource(dust.compile(src, name));
58
- dust.cache[name](chunk, context).end();
59
- });
60
- });
61
- }
62
- return chunk.setError(new Error("Template Not Found: " + name));
63
- }
64
- };
65
-
66
- dust.loadSource = function(source, path) {
67
- return eval(source);
68
- };
69
-
70
- if (Array.isArray) {
71
- dust.isArray = Array.isArray;
72
- } else {
73
- dust.isArray = function(arr) {
74
- return Object.prototype.toString.call(arr) == "[object Array]";
75
- };
76
- }
77
-
78
- dust.nextTick = function(callback) {
79
- setTimeout(callback, 0);
80
- }
81
-
82
- dust.isEmpty = function(value) {
83
- if (dust.isArray(value) && !value.length) return true;
84
- if (value === 0) return false;
85
- return (!value);
86
- };
87
-
88
- dust.filter = function(string, auto, filters) {
89
- if (filters) {
90
- for (var i=0, len=filters.length; i<len; i++) {
91
- var name = filters[i];
92
- if (name === "s") {
93
- auto = null;
94
- } else {
95
- string = dust.filters[name](string);
96
- }
97
- }
98
- }
99
- if (auto) {
100
- string = dust.filters[auto](string);
101
- }
102
- return string;
103
- };
104
-
105
- dust.filters = {
106
- h: function(value) { return dust.escapeHtml(value); },
107
- j: function(value) { return dust.escapeJs(value); },
108
- u: encodeURI,
109
- uc: encodeURIComponent
110
- }
111
-
112
- function Context(stack, global, blocks) {
113
- this.stack = stack;
114
- this.global = global;
115
- this.blocks = blocks;
116
- }
117
-
118
- dust.makeBase = function(global) {
119
- return new Context(new Stack(), global);
120
- }
121
-
122
- Context.wrap = function(context) {
123
- if (context instanceof Context) {
124
- return context;
125
- }
126
- return new Context(new Stack(context));
127
- }
128
-
129
- Context.prototype.get = function(key) {
130
- var ctx = this.stack, value;
131
-
132
- while(ctx) {
133
- if (ctx.isObject) {
134
- value = ctx.head[key];
135
- if (!(value === undefined)) {
136
- return value;
137
- }
138
- }
139
- ctx = ctx.tail;
140
- }
141
- return this.global ? this.global[key] : undefined;
142
- };
143
-
144
- Context.prototype.getPath = function(cur, down) {
145
- var ctx = this.stack,
146
- len = down.length;
147
-
148
- if (cur && len === 0) return ctx.head;
149
- if (!ctx.isObject) return undefined;
150
- ctx = ctx.head;
151
- var i = 0;
152
- while(ctx && i < len) {
153
- ctx = ctx[down[i]];
154
- i++;
155
- }
156
- return ctx;
157
- };
158
-
159
- Context.prototype.push = function(head, idx, len) {
160
- return new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks);
161
- };
162
-
163
- Context.prototype.rebase = function(head) {
164
- return new Context(new Stack(head), this.global, this.blocks);
165
- };
166
-
167
- Context.prototype.current = function() {
168
- return this.stack.head;
169
- };
170
-
171
- Context.prototype.getBlock = function(key) {
172
- var blocks = this.blocks;
173
-
174
- if (!blocks) return;
175
- var len = blocks.length, fn;
176
- while (len--) {
177
- fn = blocks[len][key];
178
- if (fn) return fn;
179
- }
180
- }
181
-
182
- Context.prototype.shiftBlocks = function(locals) {
183
- var blocks = this.blocks;
184
-
185
- if (locals) {
186
- if (!blocks) {
187
- newBlocks = [locals];
188
- } else {
189
- newBlocks = blocks.concat([locals]);
190
- }
191
- return new Context(this.stack, this.global, newBlocks);
192
- }
193
- return this;
194
- }
195
-
196
- function Stack(head, tail, idx, len) {
197
- this.tail = tail;
198
- this.isObject = !dust.isArray(head) && head && typeof head === "object";
199
- this.head = head;
200
- this.index = idx;
201
- this.of = len;
202
- }
203
-
204
- function Stub(callback) {
205
- this.head = new Chunk(this);
206
- this.callback = callback;
207
- this.out = '';
208
- }
209
-
210
- Stub.prototype.flush = function() {
211
- var chunk = this.head;
212
-
213
- while (chunk) {
214
- if (chunk.flushable) {
215
- this.out += chunk.data;
216
- } else if (chunk.error) {
217
- this.callback(chunk.error);
218
- this.flush = function() {};
219
- return;
220
- } else {
221
- return;
222
- }
223
- chunk = chunk.next;
224
- this.head = chunk;
225
- }
226
- this.callback(null, this.out);
227
- }
228
-
229
- function Stream() {
230
- this.head = new Chunk(this);
231
- }
232
-
233
- Stream.prototype.flush = function() {
234
- var chunk = this.head;
235
-
236
- while(chunk) {
237
- if (chunk.flushable) {
238
- this.emit('data', chunk.data);
239
- } else if (chunk.error) {
240
- this.emit('error', chunk.error);
241
- this.flush = function() {};
242
- return;
243
- } else {
244
- return;
245
- }
246
- chunk = chunk.next;
247
- this.head = chunk;
248
- }
249
- this.emit('end');
250
- }
251
-
252
- Stream.prototype.emit = function(type, data) {
253
- var events = this.events;
254
-
255
- if (events && events[type]) {
256
- events[type](data);
257
- }
258
- }
259
-
260
- Stream.prototype.on = function(type, callback) {
261
- if (!this.events) {
262
- this.events = {};
263
- }
264
- this.events[type] = callback;
265
- return this;
266
- }
267
-
268
- function Chunk(root, next, taps) {
269
- this.root = root;
270
- this.next = next;
271
- this.data = '';
272
- this.flushable = false;
273
- this.taps = taps;
274
- }
275
-
276
- Chunk.prototype.write = function(data) {
277
- var taps = this.taps;
278
-
279
- if (taps) {
280
- data = taps.go(data);
281
- }
282
- this.data += data;
283
- return this;
284
- }
285
-
286
- Chunk.prototype.end = function(data) {
287
- if (data) {
288
- this.write(data);
289
- }
290
- this.flushable = true;
291
- this.root.flush();
292
- return this;
293
- }
294
-
295
- Chunk.prototype.map = function(callback) {
296
- var cursor = new Chunk(this.root, this.next, this.taps),
297
- branch = new Chunk(this.root, cursor, this.taps);
298
-
299
- this.next = branch;
300
- this.flushable = true;
301
- callback(branch);
302
- return cursor;
303
- }
304
-
305
- Chunk.prototype.tap = function(tap) {
306
- var taps = this.taps;
307
-
308
- if (taps) {
309
- this.taps = taps.push(tap);
310
- } else {
311
- this.taps = new Tap(tap);
312
- }
313
- return this;
314
- }
315
-
316
- Chunk.prototype.untap = function() {
317
- this.taps = this.taps.tail;
318
- return this;
319
- }
320
-
321
- Chunk.prototype.render = function(body, context) {
322
- return body(this, context);
323
- }
324
-
325
- Chunk.prototype.reference = function(elem, context, auto, filters) {
326
- if (typeof elem === "function") {
327
- elem = elem(this, context, null, {auto: auto, filters: filters});
328
- if (elem instanceof Chunk) {
329
- return elem;
330
- }
331
- }
332
- if (!dust.isEmpty(elem)) {
333
- return this.write(dust.filter(elem, auto, filters));
334
- } else {
335
- return this;
336
- }
337
- };
338
-
339
- Chunk.prototype.section = function(elem, context, bodies, params) {
340
- if (typeof elem === "function") {
341
- elem = elem(this, context, bodies, params);
342
- if (elem instanceof Chunk) {
343
- return elem;
344
- }
345
- }
346
-
347
- var body = bodies.block,
348
- skip = bodies['else'];
349
-
350
- if (params) {
351
- context = context.push(params);
352
- }
353
-
354
- if (dust.isArray(elem)) {
355
- if (body) {
356
- var len = elem.length, chunk = this;
357
- for (var i=0; i<len; i++) {
358
- chunk = body(chunk, context.push(elem[i], i, len));
359
- }
360
- return chunk;
361
- }
362
- } else if (elem === true) {
363
- if (body) return body(this, context);
364
- } else if (elem || elem === 0) {
365
- if (body) return body(this, context.push(elem));
366
- } else if (skip) {
367
- return skip(this, context);
368
- }
369
- return this;
370
- };
371
-
372
- Chunk.prototype.exists = function(elem, context, bodies) {
373
- var body = bodies.block,
374
- skip = bodies['else'];
375
-
376
- if (!dust.isEmpty(elem)) {
377
- if (body) return body(this, context);
378
- } else if (skip) {
379
- return skip(this, context);
380
- }
381
- return this;
382
- }
383
-
384
- Chunk.prototype.notexists = function(elem, context, bodies) {
385
- var body = bodies.block,
386
- skip = bodies['else'];
387
-
388
- if (dust.isEmpty(elem)) {
389
- if (body) return body(this, context);
390
- } else if (skip) {
391
- return skip(this, context);
392
- }
393
- return this;
394
- }
395
-
396
- Chunk.prototype.block = function(elem, context, bodies) {
397
- var body = bodies.block;
398
-
399
- if (elem) {
400
- body = elem;
401
- }
402
-
403
- if (body) {
404
- return body(this, context);
405
- }
406
- return this;
407
- };
408
-
409
- Chunk.prototype.partial = function(elem, context) {
410
- if (typeof elem === "function") {
411
- return this.capture(elem, context, function(name, chunk) {
412
- dust.load(name, chunk, context).end();
413
- });
414
- }
415
- return dust.load(elem, this, context);
416
- };
417
-
418
- Chunk.prototype.helper = function(name, context, bodies, params) {
419
- return dust.helpers[name](this, context, bodies, params);
420
- };
421
-
422
- Chunk.prototype.capture = function(body, context, callback) {
423
- return this.map(function(chunk) {
424
- var stub = new Stub(function(err, out) {
425
- if (err) {
426
- chunk.setError(err);
427
- } else {
428
- callback(out, chunk);
429
- }
430
- });
431
- body(stub.head, context).end();
432
- });
433
- };
434
-
435
- Chunk.prototype.setError = function(err) {
436
- this.error = err;
437
- this.root.flush();
438
- return this;
439
- };
440
-
441
- dust.helpers = {
442
- sep: function(chunk, context, bodies) {
443
- if (context.stack.index === context.stack.of - 1) {
444
- return chunk;
445
- }
446
- return bodies.block(chunk, context);
447
- },
448
-
449
- idx: function(chunk, context, bodies) {
450
- return bodies.block(chunk, context.push(context.stack.index));
451
- }
452
- }
453
-
454
- function Tap(head, tail) {
455
- this.head = head;
456
- this.tail = tail;
457
- }
458
-
459
- Tap.prototype.push = function(tap) {
460
- return new Tap(tap, this);
461
- };
462
-
463
- Tap.prototype.go = function(value) {
464
- var tap = this;
465
-
466
- while(tap) {
467
- value = tap.head(value);
468
- tap = tap.tail;
469
- }
470
- return value;
471
- };
472
-
473
- var HCHARS = new RegExp(/[&<>\"]/),
474
- AMP = /&/g,
475
- LT = /</g,
476
- GT = />/g,
477
- QUOT = /\"/g;
478
-
479
- dust.escapeHtml = function(s) {
480
- if (typeof s === "string") {
481
- if (!HCHARS.test(s)) {
482
- return s;
483
- }
484
- return s.replace(AMP,'&amp;').replace(LT,'&lt;').replace(GT,'&gt;').replace(QUOT,'&quot;');
485
- }
486
- return s;
487
- };
488
-
489
- var BS = /\\/g,
490
- CR = /\r/g,
491
- LS = /\u2028/g,
492
- PS = /\u2029/g,
493
- NL = /\n/g,
494
- LF = /\f/g,
495
- SQ = /'/g,
496
- DQ = /"/g,
497
- TB = /\t/g;
498
-
499
- dust.escapeJs = function(s) {
500
- if (typeof s === "string") {
501
- return s
502
- .replace(BS, '\\\\')
503
- .replace(DQ, '\\"')
504
- .replace(SQ, "\\'")
505
- .replace(CR, '\\r')
506
- .replace(LS, '\\u2028')
507
- .replace(PS, '\\u2029')
508
- .replace(NL, '\\n')
509
- .replace(LF, '\\f')
510
- .replace(TB, "\\t");
511
- }
512
- return s;
513
- };
514
-
515
- })(dust);
516
-
517
- if (typeof exports !== "undefined") {
518
- if (typeof process !== "undefined") {
519
- require('./server')(dust);
520
- }
521
- module.exports = dust;
522
- }
523
- (function(dust) {
524
-
525
- dust.compile = function(source, name) {
526
- var ast = filterAST(dust.parse(source));
527
- return compile(ast, name);
528
- };
529
-
530
- function filterAST(ast) {
531
- var context = {};
532
- return dust.filterNode(context, ast);
533
- }
534
-
535
- dust.filterNode = function(context, node) {
536
- return dust.optimizers[node[0]](context, node);
537
- }
538
-
539
- dust.optimizers = {
540
- body: compactBuffers,
541
- buffer: noop,
542
- special: convertSpecial,
543
- format: nullify, // TODO: convert format
544
- reference: visit,
545
- "#": visit,
546
- "?": visit,
547
- "^": visit,
548
- "<": visit,
549
- "+": visit,
550
- "@": visit,
551
- "%": visit,
552
- partial: visit,
553
- context: visit,
554
- params: visit,
555
- bodies: visit,
556
- param: visit,
557
- filters: noop,
558
- key: noop,
559
- path: noop,
560
- literal: noop,
561
- comment: nullify
562
- }
563
-
564
- dust.pragmas = {
565
- esc: function(compiler, context, bodies, params) {
566
- var old = compiler.auto;
567
- if (!context) context = 'h';
568
- compiler.auto = (context === 's') ? '' : context;
569
- var out = compileParts(compiler, bodies.block);
570
- compiler.auto = old;
571
- return out;
572
- }
573
- }
574
-
575
- function visit(context, node) {
576
- var out = [node[0]];
577
- for (var i=1, len=node.length; i<len; i++) {
578
- var res = dust.filterNode(context, node[i]);
579
- if (res) out.push(res);
580
- }
581
- return out;
582
- }
583
-
584
- // Compacts consecutive buffer nodes into a single node
585
- function compactBuffers(context, node) {
586
- var out = [node[0]], memo;
587
- for (var i=1, len=node.length; i<len; i++) {
588
- var res = dust.filterNode(context, node[i]);
589
- if (res) {
590
- if (res[0] === 'buffer') {
591
- if (memo) {
592
- memo[1] += res[1];
593
- } else {
594
- memo = res;
595
- out.push(res);
596
- }
597
- } else {
598
- memo = null;
599
- out.push(res);
600
- }
601
- }
602
- }
603
- return out;
604
- }
605
-
606
- var specialChars = {
607
- "s": " ",
608
- "n": "\n",
609
- "r": "\r",
610
- "lb": "{",
611
- "rb": "}"
612
- };
613
-
614
- function convertSpecial(context, node) { return ['buffer', specialChars[node[1]]] }
615
- function noop(context, node) { return node }
616
- function nullify(){}
617
-
618
- function compile(ast, name) {
619
- var context = {
620
- name: name,
621
- bodies: [],
622
- blocks: {},
623
- index: 0,
624
- auto: "h"
625
- }
626
-
627
- return "(function(){dust.register("
628
- + (name ? "\"" + name + "\"" : "null") + ","
629
- + dust.compileNode(context, ast)
630
- + ");"
631
- + compileBlocks(context)
632
- + compileBodies(context)
633
- + "return body_0;"
634
- + "})();";
635
- }
636
-
637
- function compileBlocks(context) {
638
- var out = [],
639
- blocks = context.blocks;
640
-
641
- for (var name in blocks) {
642
- out.push(name + ":" + blocks[name]);
643
- }
644
- if (out.length) {
645
- context.blocks = "ctx=ctx.shiftBlocks(blocks);";
646
- return "var blocks={" + out.join(',') + "};";
647
- }
648
- return context.blocks = "";
649
- }
650
-
651
- function compileBodies(context) {
652
- var out = [],
653
- bodies = context.bodies,
654
- blx = context.blocks;
655
-
656
- for (var i=0, len=bodies.length; i<len; i++) {
657
- out[i] = "function body_" + i + "(chk,ctx){"
658
- + blx + "return chk" + bodies[i] + ";}";
659
- }
660
- return out.join('');
661
- }
662
-
663
- function compileParts(context, body) {
664
- var parts = '';
665
- for (var i=1, len=body.length; i<len; i++) {
666
- parts += dust.compileNode(context, body[i]);
667
- }
668
- return parts;
669
- }
670
-
671
- dust.compileNode = function(context, node) {
672
- return dust.nodes[node[0]](context, node);
673
- }
674
-
675
- dust.nodes = {
676
- body: function(context, node) {
677
- var id = context.index++, name = "body_" + id;
678
- context.bodies[id] = compileParts(context, node);
679
- return name;
680
- },
681
-
682
- buffer: function(context, node) {
683
- return ".write(" + escape(node[1]) + ")";
684
- },
685
-
686
- format: function(context, node) {
687
- return ".write(" + escape(node[1] + node[2]) + ")";
688
- },
689
-
690
- reference: function(context, node) {
691
- return ".reference(" + dust.compileNode(context, node[1])
692
- + ",ctx," + dust.compileNode(context, node[2]) + ")";
693
- },
694
-
695
- "#": function(context, node) {
696
- return compileSection(context, node, "section");
697
- },
698
-
699
- "?": function(context, node) {
700
- return compileSection(context, node, "exists");
701
- },
702
-
703
- "^": function(context, node) {
704
- return compileSection(context, node, "notexists");
705
- },
706
-
707
- "<": function(context, node) {
708
- var bodies = node[4];
709
- for (var i=1, len=bodies.length; i<len; i++) {
710
- var param = bodies[i],
711
- type = param[1][1];
712
- if (type === "block") {
713
- context.blocks[node[1].text] = dust.compileNode(context, param[2]);
714
- return '';
715
- }
716
- }
717
- return '';
718
- },
719
-
720
- "+": function(context, node) {
721
- return ".block(ctx.getBlock("
722
- + escape(node[1].text)
723
- + ")," + dust.compileNode(context, node[2]) + ","
724
- + dust.compileNode(context, node[4]) + ","
725
- + dust.compileNode(context, node[3])
726
- + ")";
727
- },
728
-
729
- "@": function(context, node) {
730
- return ".helper("
731
- + escape(node[1].text)
732
- + "," + dust.compileNode(context, node[2]) + ","
733
- + dust.compileNode(context, node[4]) + ","
734
- + dust.compileNode(context, node[3])
735
- + ")";
736
- },
737
-
738
- "%": function(context, node) {
739
- // TODO: Move these hacks into pragma precompiler
740
- var name = node[1][1];
741
- if (!dust.pragmas[name]) return '';
742
-
743
- var rawBodies = node[4];
744
- var bodies = {};
745
- for (var i=1, len=rawBodies.length; i<len; i++) {
746
- var b = rawBodies[i];
747
- bodies[b[1][1]] = b[2];
748
- }
749
-
750
- var rawParams = node[3];
751
- var params = {};
752
- for (var i=1, len=rawParams.length; i<len; i++) {
753
- var p = rawParams[i];
754
- params[p[1][1]] = p[2][1];
755
- }
756
-
757
- var ctx = node[2][1] ? node[2][1].text : null;
758
-
759
- return dust.pragmas[name](context, ctx, bodies, params);
760
- },
761
-
762
- partial: function(context, node) {
763
- return ".partial("
764
- + dust.compileNode(context, node[1])
765
- + "," + dust.compileNode(context, node[2]) + ")";
766
- },
767
-
768
- context: function(context, node) {
769
- if (node[1]) {
770
- return "ctx.rebase(" + dust.compileNode(context, node[1]) + ")";
771
- }
772
- return "ctx";
773
- },
774
-
775
- params: function(context, node) {
776
- var out = [];
777
- for (var i=1, len=node.length; i<len; i++) {
778
- out.push(dust.compileNode(context, node[i]));
779
- }
780
- if (out.length) {
781
- return "{" + out.join(',') + "}";
782
- }
783
- return "null";
784
- },
785
-
786
- bodies: function(context, node) {
787
- var out = [];
788
- for (var i=1, len=node.length; i<len; i++) {
789
- out.push(dust.compileNode(context, node[i]));
790
- }
791
- return "{" + out.join(',') + "}";
792
- },
793
-
794
- param: function(context, node) {
795
- return dust.compileNode(context, node[1]) + ":" + dust.compileNode(context, node[2]);
796
- },
797
-
798
- filters: function(context, node) {
799
- var list = [];
800
- for (var i=1, len=node.length; i<len; i++) {
801
- var filter = node[i];
802
- list.push("\"" + filter + "\"");
803
- }
804
- return "\"" + context.auto + "\""
805
- + (list.length ? ",[" + list.join(',') + "]" : '');
806
- },
807
-
808
- key: function(context, node) {
809
- return "ctx.get(\"" + node[1] + "\")";
810
- },
811
-
812
- path: function(context, node) {
813
- var current = node[1],
814
- keys = node[2],
815
- list = [];
816
-
817
- for (var i=0,len=keys.length; i<len; i++) {
818
- list.push("\"" + keys[i] + "\"");
819
- }
820
- return "ctx.getPath(" + current + ",[" + list.join(',') + "])";
821
- },
822
-
823
- literal: function(context, node) {
824
- return escape(node[1]);
825
- }
826
- }
827
-
828
- function compileSection(context, node, cmd) {
829
- return "." + cmd + "("
830
- + dust.compileNode(context, node[1])
831
- + "," + dust.compileNode(context, node[2]) + ","
832
- + dust.compileNode(context, node[4]) + ","
833
- + dust.compileNode(context, node[3])
834
- + ")";
835
- }
836
-
837
- var escape = (typeof JSON === "undefined")
838
- ? function(str) { return "\"" + dust.escapeJs(str) + "\"" }
839
- : JSON.stringify;
840
-
841
- })(typeof exports !== 'undefined' ? exports : dust);
842
- (function(dust){
843
-
844
- var parser = (function(){
845
- /* Generated by PEG.js (http://pegjs.majda.cz/). */
846
-
847
- var result = {
848
- /*
849
- * Parses the input with a generated parser. If the parsing is successfull,
850
- * returns a value explicitly or implicitly specified by the grammar from
851
- * which the parser was generated (see |PEG.buildParser|). If the parsing is
852
- * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
853
- */
854
- parse: function(input) {
855
- var pos = 0;
856
- var reportMatchFailures = true;
857
- var rightmostMatchFailuresPos = 0;
858
- var rightmostMatchFailuresExpected = [];
859
- var cache = {};
860
-
861
- function padLeft(input, padding, length) {
862
- var result = input;
863
-
864
- var padLength = length - input.length;
865
- for (var i = 0; i < padLength; i++) {
866
- result = padding + result;
867
- }
868
-
869
- return result;
870
- }
871
-
872
- function escape(ch) {
873
- var charCode = ch.charCodeAt(0);
874
-
875
- if (charCode < 0xFF) {
876
- var escapeChar = 'x';
877
- var length = 2;
878
- } else {
879
- var escapeChar = 'u';
880
- var length = 4;
881
- }
882
-
883
- return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
884
- }
885
-
886
- function quote(s) {
887
- /*
888
- * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
889
- * string literal except for the closing quote character, backslash,
890
- * carriage return, line separator, paragraph separator, and line feed.
891
- * Any character may appear in the form of an escape sequence.
892
- */
893
- return '"' + s
894
- .replace(/\\/g, '\\\\') // backslash
895
- .replace(/"/g, '\\"') // closing quote character
896
- .replace(/\r/g, '\\r') // carriage return
897
- .replace(/\n/g, '\\n') // line feed
898
- .replace(/[\x80-\uFFFF]/g, escape) // non-ASCII characters
899
- + '"';
900
- }
901
-
902
- function matchFailed(failure) {
903
- if (pos < rightmostMatchFailuresPos) {
904
- return;
905
- }
906
-
907
- if (pos > rightmostMatchFailuresPos) {
908
- rightmostMatchFailuresPos = pos;
909
- rightmostMatchFailuresExpected = [];
910
- }
911
-
912
- rightmostMatchFailuresExpected.push(failure);
913
- }
914
-
915
- function parse_body() {
916
- var cacheKey = "body" + '@' + pos;
917
- var cachedResult = cache[cacheKey];
918
- if (cachedResult) {
919
- pos = cachedResult.nextPos;
920
- return cachedResult.result;
921
- }
922
-
923
-
924
- var result1 = [];
925
- var result2 = parse_part();
926
- while (result2 !== null) {
927
- result1.push(result2);
928
- var result2 = parse_part();
929
- }
930
- var result0 = result1 !== null
931
- ? (function(p) { return ["body"].concat(p) })(result1)
932
- : null;
933
-
934
-
935
-
936
- cache[cacheKey] = {
937
- nextPos: pos,
938
- result: result0
939
- };
940
- return result0;
941
- }
942
-
943
- function parse_part() {
944
- var cacheKey = "part" + '@' + pos;
945
- var cachedResult = cache[cacheKey];
946
- if (cachedResult) {
947
- pos = cachedResult.nextPos;
948
- return cachedResult.result;
949
- }
950
-
951
-
952
- var result6 = parse_comment();
953
- if (result6 !== null) {
954
- var result0 = result6;
955
- } else {
956
- var result5 = parse_section();
957
- if (result5 !== null) {
958
- var result0 = result5;
959
- } else {
960
- var result4 = parse_partial();
961
- if (result4 !== null) {
962
- var result0 = result4;
963
- } else {
964
- var result3 = parse_special();
965
- if (result3 !== null) {
966
- var result0 = result3;
967
- } else {
968
- var result2 = parse_reference();
969
- if (result2 !== null) {
970
- var result0 = result2;
971
- } else {
972
- var result1 = parse_buffer();
973
- if (result1 !== null) {
974
- var result0 = result1;
975
- } else {
976
- var result0 = null;;
977
- };
978
- };
979
- };
980
- };
981
- };
982
- }
983
-
984
-
985
-
986
- cache[cacheKey] = {
987
- nextPos: pos,
988
- result: result0
989
- };
990
- return result0;
991
- }
992
-
993
- function parse_section() {
994
- var cacheKey = "section" + '@' + pos;
995
- var cachedResult = cache[cacheKey];
996
- if (cachedResult) {
997
- pos = cachedResult.nextPos;
998
- return cachedResult.result;
999
- }
1000
-
1001
- var savedReportMatchFailures = reportMatchFailures;
1002
- reportMatchFailures = false;
1003
- var savedPos1 = pos;
1004
- var result8 = parse_sec_tag_start();
1005
- if (result8 !== null) {
1006
- var result9 = parse_rd();
1007
- if (result9 !== null) {
1008
- var result10 = parse_body();
1009
- if (result10 !== null) {
1010
- var result11 = parse_bodies();
1011
- if (result11 !== null) {
1012
- var result12 = parse_end_tag();
1013
- if (result12 !== null) {
1014
- var result13 = (function() {return result8[1].text === result12.text})() ? '' : null;
1015
- if (result13 !== null) {
1016
- var result7 = [result8, result9, result10, result11, result12, result13];
1017
- } else {
1018
- var result7 = null;
1019
- pos = savedPos1;
1020
- }
1021
- } else {
1022
- var result7 = null;
1023
- pos = savedPos1;
1024
- }
1025
- } else {
1026
- var result7 = null;
1027
- pos = savedPos1;
1028
- }
1029
- } else {
1030
- var result7 = null;
1031
- pos = savedPos1;
1032
- }
1033
- } else {
1034
- var result7 = null;
1035
- pos = savedPos1;
1036
- }
1037
- } else {
1038
- var result7 = null;
1039
- pos = savedPos1;
1040
- }
1041
- var result6 = result7 !== null
1042
- ? (function(t, b, e, n) { e.push(["param", ["literal", "block"], b]); t.push(e); return t })(result7[0], result7[2], result7[3], result7[4])
1043
- : null;
1044
- if (result6 !== null) {
1045
- var result0 = result6;
1046
- } else {
1047
- var savedPos0 = pos;
1048
- var result3 = parse_sec_tag_start();
1049
- if (result3 !== null) {
1050
- if (input.substr(pos, 1) === "/") {
1051
- var result4 = "/";
1052
- pos += 1;
1053
- } else {
1054
- var result4 = null;
1055
- if (reportMatchFailures) {
1056
- matchFailed("\"/\"");
1057
- }
1058
- }
1059
- if (result4 !== null) {
1060
- var result5 = parse_rd();
1061
- if (result5 !== null) {
1062
- var result2 = [result3, result4, result5];
1063
- } else {
1064
- var result2 = null;
1065
- pos = savedPos0;
1066
- }
1067
- } else {
1068
- var result2 = null;
1069
- pos = savedPos0;
1070
- }
1071
- } else {
1072
- var result2 = null;
1073
- pos = savedPos0;
1074
- }
1075
- var result1 = result2 !== null
1076
- ? (function(t) { t.push(["bodies"]); return t })(result2[0])
1077
- : null;
1078
- if (result1 !== null) {
1079
- var result0 = result1;
1080
- } else {
1081
- var result0 = null;;
1082
- };
1083
- }
1084
- reportMatchFailures = savedReportMatchFailures;
1085
- if (reportMatchFailures && result0 === null) {
1086
- matchFailed("section");
1087
- }
1088
-
1089
- cache[cacheKey] = {
1090
- nextPos: pos,
1091
- result: result0
1092
- };
1093
- return result0;
1094
- }
1095
-
1096
- function parse_sec_tag_start() {
1097
- var cacheKey = "sec_tag_start" + '@' + pos;
1098
- var cachedResult = cache[cacheKey];
1099
- if (cachedResult) {
1100
- pos = cachedResult.nextPos;
1101
- return cachedResult.result;
1102
- }
1103
-
1104
-
1105
- var savedPos0 = pos;
1106
- var result2 = parse_ld();
1107
- if (result2 !== null) {
1108
- if (input.substr(pos).match(/^[#?^<+@%]/) !== null) {
1109
- var result3 = input.charAt(pos);
1110
- pos++;
1111
- } else {
1112
- var result3 = null;
1113
- if (reportMatchFailures) {
1114
- matchFailed("[#?^<+@%]");
1115
- }
1116
- }
1117
- if (result3 !== null) {
1118
- var result4 = parse_identifier();
1119
- if (result4 !== null) {
1120
- var result5 = parse_context();
1121
- if (result5 !== null) {
1122
- var result6 = parse_params();
1123
- if (result6 !== null) {
1124
- var result1 = [result2, result3, result4, result5, result6];
1125
- } else {
1126
- var result1 = null;
1127
- pos = savedPos0;
1128
- }
1129
- } else {
1130
- var result1 = null;
1131
- pos = savedPos0;
1132
- }
1133
- } else {
1134
- var result1 = null;
1135
- pos = savedPos0;
1136
- }
1137
- } else {
1138
- var result1 = null;
1139
- pos = savedPos0;
1140
- }
1141
- } else {
1142
- var result1 = null;
1143
- pos = savedPos0;
1144
- }
1145
- var result0 = result1 !== null
1146
- ? (function(t, n, c, p) { return [t, n, c, p] })(result1[1], result1[2], result1[3], result1[4])
1147
- : null;
1148
-
1149
-
1150
-
1151
- cache[cacheKey] = {
1152
- nextPos: pos,
1153
- result: result0
1154
- };
1155
- return result0;
1156
- }
1157
-
1158
- function parse_end_tag() {
1159
- var cacheKey = "end_tag" + '@' + pos;
1160
- var cachedResult = cache[cacheKey];
1161
- if (cachedResult) {
1162
- pos = cachedResult.nextPos;
1163
- return cachedResult.result;
1164
- }
1165
-
1166
- var savedReportMatchFailures = reportMatchFailures;
1167
- reportMatchFailures = false;
1168
- var savedPos0 = pos;
1169
- var result2 = parse_ld();
1170
- if (result2 !== null) {
1171
- if (input.substr(pos, 1) === "/") {
1172
- var result3 = "/";
1173
- pos += 1;
1174
- } else {
1175
- var result3 = null;
1176
- if (reportMatchFailures) {
1177
- matchFailed("\"/\"");
1178
- }
1179
- }
1180
- if (result3 !== null) {
1181
- var result4 = parse_identifier();
1182
- if (result4 !== null) {
1183
- var result5 = parse_rd();
1184
- if (result5 !== null) {
1185
- var result1 = [result2, result3, result4, result5];
1186
- } else {
1187
- var result1 = null;
1188
- pos = savedPos0;
1189
- }
1190
- } else {
1191
- var result1 = null;
1192
- pos = savedPos0;
1193
- }
1194
- } else {
1195
- var result1 = null;
1196
- pos = savedPos0;
1197
- }
1198
- } else {
1199
- var result1 = null;
1200
- pos = savedPos0;
1201
- }
1202
- var result0 = result1 !== null
1203
- ? (function(n) { return n })(result1[2])
1204
- : null;
1205
- reportMatchFailures = savedReportMatchFailures;
1206
- if (reportMatchFailures && result0 === null) {
1207
- matchFailed("end tag");
1208
- }
1209
-
1210
- cache[cacheKey] = {
1211
- nextPos: pos,
1212
- result: result0
1213
- };
1214
- return result0;
1215
- }
1216
-
1217
- function parse_context() {
1218
- var cacheKey = "context" + '@' + pos;
1219
- var cachedResult = cache[cacheKey];
1220
- if (cachedResult) {
1221
- pos = cachedResult.nextPos;
1222
- return cachedResult.result;
1223
- }
1224
-
1225
-
1226
- var savedPos0 = pos;
1227
- if (input.substr(pos, 1) === ":") {
1228
- var result4 = ":";
1229
- pos += 1;
1230
- } else {
1231
- var result4 = null;
1232
- if (reportMatchFailures) {
1233
- matchFailed("\":\"");
1234
- }
1235
- }
1236
- if (result4 !== null) {
1237
- var result5 = parse_identifier();
1238
- if (result5 !== null) {
1239
- var result3 = [result4, result5];
1240
- } else {
1241
- var result3 = null;
1242
- pos = savedPos0;
1243
- }
1244
- } else {
1245
- var result3 = null;
1246
- pos = savedPos0;
1247
- }
1248
- var result2 = result3 !== null
1249
- ? (function(n) {return n})(result3[1])
1250
- : null;
1251
- var result1 = result2 !== null ? result2 : '';
1252
- var result0 = result1 !== null
1253
- ? (function(n) { return n ? ["context", n] : ["context"] })(result1)
1254
- : null;
1255
-
1256
-
1257
-
1258
- cache[cacheKey] = {
1259
- nextPos: pos,
1260
- result: result0
1261
- };
1262
- return result0;
1263
- }
1264
-
1265
- function parse_params() {
1266
- var cacheKey = "params" + '@' + pos;
1267
- var cachedResult = cache[cacheKey];
1268
- if (cachedResult) {
1269
- pos = cachedResult.nextPos;
1270
- return cachedResult.result;
1271
- }
1272
-
1273
- var savedReportMatchFailures = reportMatchFailures;
1274
- reportMatchFailures = false;
1275
- var result1 = [];
1276
- var savedPos0 = pos;
1277
- var result4 = parse_ws();
1278
- if (result4 !== null) {
1279
- var result5 = parse_key();
1280
- if (result5 !== null) {
1281
- if (input.substr(pos, 1) === "=") {
1282
- var result6 = "=";
1283
- pos += 1;
1284
- } else {
1285
- var result6 = null;
1286
- if (reportMatchFailures) {
1287
- matchFailed("\"=\"");
1288
- }
1289
- }
1290
- if (result6 !== null) {
1291
- var result9 = parse_identifier();
1292
- if (result9 !== null) {
1293
- var result7 = result9;
1294
- } else {
1295
- var result8 = parse_inline();
1296
- if (result8 !== null) {
1297
- var result7 = result8;
1298
- } else {
1299
- var result7 = null;;
1300
- };
1301
- }
1302
- if (result7 !== null) {
1303
- var result3 = [result4, result5, result6, result7];
1304
- } else {
1305
- var result3 = null;
1306
- pos = savedPos0;
1307
- }
1308
- } else {
1309
- var result3 = null;
1310
- pos = savedPos0;
1311
- }
1312
- } else {
1313
- var result3 = null;
1314
- pos = savedPos0;
1315
- }
1316
- } else {
1317
- var result3 = null;
1318
- pos = savedPos0;
1319
- }
1320
- var result2 = result3 !== null
1321
- ? (function(k, v) {return ["param", ["literal", k], v]})(result3[1], result3[3])
1322
- : null;
1323
- while (result2 !== null) {
1324
- result1.push(result2);
1325
- var savedPos0 = pos;
1326
- var result4 = parse_ws();
1327
- if (result4 !== null) {
1328
- var result5 = parse_key();
1329
- if (result5 !== null) {
1330
- if (input.substr(pos, 1) === "=") {
1331
- var result6 = "=";
1332
- pos += 1;
1333
- } else {
1334
- var result6 = null;
1335
- if (reportMatchFailures) {
1336
- matchFailed("\"=\"");
1337
- }
1338
- }
1339
- if (result6 !== null) {
1340
- var result9 = parse_identifier();
1341
- if (result9 !== null) {
1342
- var result7 = result9;
1343
- } else {
1344
- var result8 = parse_inline();
1345
- if (result8 !== null) {
1346
- var result7 = result8;
1347
- } else {
1348
- var result7 = null;;
1349
- };
1350
- }
1351
- if (result7 !== null) {
1352
- var result3 = [result4, result5, result6, result7];
1353
- } else {
1354
- var result3 = null;
1355
- pos = savedPos0;
1356
- }
1357
- } else {
1358
- var result3 = null;
1359
- pos = savedPos0;
1360
- }
1361
- } else {
1362
- var result3 = null;
1363
- pos = savedPos0;
1364
- }
1365
- } else {
1366
- var result3 = null;
1367
- pos = savedPos0;
1368
- }
1369
- var result2 = result3 !== null
1370
- ? (function(k, v) {return ["param", ["literal", k], v]})(result3[1], result3[3])
1371
- : null;
1372
- }
1373
- var result0 = result1 !== null
1374
- ? (function(p) { return ["params"].concat(p) })(result1)
1375
- : null;
1376
- reportMatchFailures = savedReportMatchFailures;
1377
- if (reportMatchFailures && result0 === null) {
1378
- matchFailed("params");
1379
- }
1380
-
1381
- cache[cacheKey] = {
1382
- nextPos: pos,
1383
- result: result0
1384
- };
1385
- return result0;
1386
- }
1387
-
1388
- function parse_bodies() {
1389
- var cacheKey = "bodies" + '@' + pos;
1390
- var cachedResult = cache[cacheKey];
1391
- if (cachedResult) {
1392
- pos = cachedResult.nextPos;
1393
- return cachedResult.result;
1394
- }
1395
-
1396
- var savedReportMatchFailures = reportMatchFailures;
1397
- reportMatchFailures = false;
1398
- var result1 = [];
1399
- var savedPos0 = pos;
1400
- var result4 = parse_ld();
1401
- if (result4 !== null) {
1402
- if (input.substr(pos, 1) === ":") {
1403
- var result5 = ":";
1404
- pos += 1;
1405
- } else {
1406
- var result5 = null;
1407
- if (reportMatchFailures) {
1408
- matchFailed("\":\"");
1409
- }
1410
- }
1411
- if (result5 !== null) {
1412
- var result6 = parse_key();
1413
- if (result6 !== null) {
1414
- var result7 = parse_rd();
1415
- if (result7 !== null) {
1416
- var result8 = parse_body();
1417
- if (result8 !== null) {
1418
- var result3 = [result4, result5, result6, result7, result8];
1419
- } else {
1420
- var result3 = null;
1421
- pos = savedPos0;
1422
- }
1423
- } else {
1424
- var result3 = null;
1425
- pos = savedPos0;
1426
- }
1427
- } else {
1428
- var result3 = null;
1429
- pos = savedPos0;
1430
- }
1431
- } else {
1432
- var result3 = null;
1433
- pos = savedPos0;
1434
- }
1435
- } else {
1436
- var result3 = null;
1437
- pos = savedPos0;
1438
- }
1439
- var result2 = result3 !== null
1440
- ? (function(k, v) {return ["param", ["literal", k], v]})(result3[2], result3[4])
1441
- : null;
1442
- while (result2 !== null) {
1443
- result1.push(result2);
1444
- var savedPos0 = pos;
1445
- var result4 = parse_ld();
1446
- if (result4 !== null) {
1447
- if (input.substr(pos, 1) === ":") {
1448
- var result5 = ":";
1449
- pos += 1;
1450
- } else {
1451
- var result5 = null;
1452
- if (reportMatchFailures) {
1453
- matchFailed("\":\"");
1454
- }
1455
- }
1456
- if (result5 !== null) {
1457
- var result6 = parse_key();
1458
- if (result6 !== null) {
1459
- var result7 = parse_rd();
1460
- if (result7 !== null) {
1461
- var result8 = parse_body();
1462
- if (result8 !== null) {
1463
- var result3 = [result4, result5, result6, result7, result8];
1464
- } else {
1465
- var result3 = null;
1466
- pos = savedPos0;
1467
- }
1468
- } else {
1469
- var result3 = null;
1470
- pos = savedPos0;
1471
- }
1472
- } else {
1473
- var result3 = null;
1474
- pos = savedPos0;
1475
- }
1476
- } else {
1477
- var result3 = null;
1478
- pos = savedPos0;
1479
- }
1480
- } else {
1481
- var result3 = null;
1482
- pos = savedPos0;
1483
- }
1484
- var result2 = result3 !== null
1485
- ? (function(k, v) {return ["param", ["literal", k], v]})(result3[2], result3[4])
1486
- : null;
1487
- }
1488
- var result0 = result1 !== null
1489
- ? (function(p) { return ["bodies"].concat(p) })(result1)
1490
- : null;
1491
- reportMatchFailures = savedReportMatchFailures;
1492
- if (reportMatchFailures && result0 === null) {
1493
- matchFailed("bodies");
1494
- }
1495
-
1496
- cache[cacheKey] = {
1497
- nextPos: pos,
1498
- result: result0
1499
- };
1500
- return result0;
1501
- }
1502
-
1503
- function parse_reference() {
1504
- var cacheKey = "reference" + '@' + pos;
1505
- var cachedResult = cache[cacheKey];
1506
- if (cachedResult) {
1507
- pos = cachedResult.nextPos;
1508
- return cachedResult.result;
1509
- }
1510
-
1511
- var savedReportMatchFailures = reportMatchFailures;
1512
- reportMatchFailures = false;
1513
- var savedPos0 = pos;
1514
- var result2 = parse_ld();
1515
- if (result2 !== null) {
1516
- var result3 = parse_identifier();
1517
- if (result3 !== null) {
1518
- var result4 = parse_filters();
1519
- if (result4 !== null) {
1520
- var result5 = parse_rd();
1521
- if (result5 !== null) {
1522
- var result1 = [result2, result3, result4, result5];
1523
- } else {
1524
- var result1 = null;
1525
- pos = savedPos0;
1526
- }
1527
- } else {
1528
- var result1 = null;
1529
- pos = savedPos0;
1530
- }
1531
- } else {
1532
- var result1 = null;
1533
- pos = savedPos0;
1534
- }
1535
- } else {
1536
- var result1 = null;
1537
- pos = savedPos0;
1538
- }
1539
- var result0 = result1 !== null
1540
- ? (function(n, f) { return ["reference", n, f] })(result1[1], result1[2])
1541
- : null;
1542
- reportMatchFailures = savedReportMatchFailures;
1543
- if (reportMatchFailures && result0 === null) {
1544
- matchFailed("reference");
1545
- }
1546
-
1547
- cache[cacheKey] = {
1548
- nextPos: pos,
1549
- result: result0
1550
- };
1551
- return result0;
1552
- }
1553
-
1554
- function parse_partial() {
1555
- var cacheKey = "partial" + '@' + pos;
1556
- var cachedResult = cache[cacheKey];
1557
- if (cachedResult) {
1558
- pos = cachedResult.nextPos;
1559
- return cachedResult.result;
1560
- }
1561
-
1562
- var savedReportMatchFailures = reportMatchFailures;
1563
- reportMatchFailures = false;
1564
- var savedPos0 = pos;
1565
- var result2 = parse_ld();
1566
- if (result2 !== null) {
1567
- if (input.substr(pos, 1) === ">") {
1568
- var result3 = ">";
1569
- pos += 1;
1570
- } else {
1571
- var result3 = null;
1572
- if (reportMatchFailures) {
1573
- matchFailed("\">\"");
1574
- }
1575
- }
1576
- if (result3 !== null) {
1577
- var result10 = parse_key();
1578
- var result9 = result10 !== null
1579
- ? (function(k) {return ["literal", k]})(result10)
1580
- : null;
1581
- if (result9 !== null) {
1582
- var result4 = result9;
1583
- } else {
1584
- var result8 = parse_inline();
1585
- if (result8 !== null) {
1586
- var result4 = result8;
1587
- } else {
1588
- var result4 = null;;
1589
- };
1590
- }
1591
- if (result4 !== null) {
1592
- var result5 = parse_context();
1593
- if (result5 !== null) {
1594
- if (input.substr(pos, 1) === "/") {
1595
- var result6 = "/";
1596
- pos += 1;
1597
- } else {
1598
- var result6 = null;
1599
- if (reportMatchFailures) {
1600
- matchFailed("\"/\"");
1601
- }
1602
- }
1603
- if (result6 !== null) {
1604
- var result7 = parse_rd();
1605
- if (result7 !== null) {
1606
- var result1 = [result2, result3, result4, result5, result6, result7];
1607
- } else {
1608
- var result1 = null;
1609
- pos = savedPos0;
1610
- }
1611
- } else {
1612
- var result1 = null;
1613
- pos = savedPos0;
1614
- }
1615
- } else {
1616
- var result1 = null;
1617
- pos = savedPos0;
1618
- }
1619
- } else {
1620
- var result1 = null;
1621
- pos = savedPos0;
1622
- }
1623
- } else {
1624
- var result1 = null;
1625
- pos = savedPos0;
1626
- }
1627
- } else {
1628
- var result1 = null;
1629
- pos = savedPos0;
1630
- }
1631
- var result0 = result1 !== null
1632
- ? (function(n, c) { return ["partial", n, c] })(result1[2], result1[3])
1633
- : null;
1634
- reportMatchFailures = savedReportMatchFailures;
1635
- if (reportMatchFailures && result0 === null) {
1636
- matchFailed("partial");
1637
- }
1638
-
1639
- cache[cacheKey] = {
1640
- nextPos: pos,
1641
- result: result0
1642
- };
1643
- return result0;
1644
- }
1645
-
1646
- function parse_filters() {
1647
- var cacheKey = "filters" + '@' + pos;
1648
- var cachedResult = cache[cacheKey];
1649
- if (cachedResult) {
1650
- pos = cachedResult.nextPos;
1651
- return cachedResult.result;
1652
- }
1653
-
1654
- var savedReportMatchFailures = reportMatchFailures;
1655
- reportMatchFailures = false;
1656
- var result1 = [];
1657
- var savedPos0 = pos;
1658
- if (input.substr(pos, 1) === "|") {
1659
- var result4 = "|";
1660
- pos += 1;
1661
- } else {
1662
- var result4 = null;
1663
- if (reportMatchFailures) {
1664
- matchFailed("\"|\"");
1665
- }
1666
- }
1667
- if (result4 !== null) {
1668
- var result5 = parse_key();
1669
- if (result5 !== null) {
1670
- var result3 = [result4, result5];
1671
- } else {
1672
- var result3 = null;
1673
- pos = savedPos0;
1674
- }
1675
- } else {
1676
- var result3 = null;
1677
- pos = savedPos0;
1678
- }
1679
- var result2 = result3 !== null
1680
- ? (function(n) {return n})(result3[1])
1681
- : null;
1682
- while (result2 !== null) {
1683
- result1.push(result2);
1684
- var savedPos0 = pos;
1685
- if (input.substr(pos, 1) === "|") {
1686
- var result4 = "|";
1687
- pos += 1;
1688
- } else {
1689
- var result4 = null;
1690
- if (reportMatchFailures) {
1691
- matchFailed("\"|\"");
1692
- }
1693
- }
1694
- if (result4 !== null) {
1695
- var result5 = parse_key();
1696
- if (result5 !== null) {
1697
- var result3 = [result4, result5];
1698
- } else {
1699
- var result3 = null;
1700
- pos = savedPos0;
1701
- }
1702
- } else {
1703
- var result3 = null;
1704
- pos = savedPos0;
1705
- }
1706
- var result2 = result3 !== null
1707
- ? (function(n) {return n})(result3[1])
1708
- : null;
1709
- }
1710
- var result0 = result1 !== null
1711
- ? (function(f) { return ["filters"].concat(f) })(result1)
1712
- : null;
1713
- reportMatchFailures = savedReportMatchFailures;
1714
- if (reportMatchFailures && result0 === null) {
1715
- matchFailed("filters");
1716
- }
1717
-
1718
- cache[cacheKey] = {
1719
- nextPos: pos,
1720
- result: result0
1721
- };
1722
- return result0;
1723
- }
1724
-
1725
- function parse_special() {
1726
- var cacheKey = "special" + '@' + pos;
1727
- var cachedResult = cache[cacheKey];
1728
- if (cachedResult) {
1729
- pos = cachedResult.nextPos;
1730
- return cachedResult.result;
1731
- }
1732
-
1733
- var savedReportMatchFailures = reportMatchFailures;
1734
- reportMatchFailures = false;
1735
- var savedPos0 = pos;
1736
- var result2 = parse_ld();
1737
- if (result2 !== null) {
1738
- if (input.substr(pos, 1) === "~") {
1739
- var result3 = "~";
1740
- pos += 1;
1741
- } else {
1742
- var result3 = null;
1743
- if (reportMatchFailures) {
1744
- matchFailed("\"~\"");
1745
- }
1746
- }
1747
- if (result3 !== null) {
1748
- var result4 = parse_key();
1749
- if (result4 !== null) {
1750
- var result5 = parse_rd();
1751
- if (result5 !== null) {
1752
- var result1 = [result2, result3, result4, result5];
1753
- } else {
1754
- var result1 = null;
1755
- pos = savedPos0;
1756
- }
1757
- } else {
1758
- var result1 = null;
1759
- pos = savedPos0;
1760
- }
1761
- } else {
1762
- var result1 = null;
1763
- pos = savedPos0;
1764
- }
1765
- } else {
1766
- var result1 = null;
1767
- pos = savedPos0;
1768
- }
1769
- var result0 = result1 !== null
1770
- ? (function(k) { return ["special", k] })(result1[2])
1771
- : null;
1772
- reportMatchFailures = savedReportMatchFailures;
1773
- if (reportMatchFailures && result0 === null) {
1774
- matchFailed("special");
1775
- }
1776
-
1777
- cache[cacheKey] = {
1778
- nextPos: pos,
1779
- result: result0
1780
- };
1781
- return result0;
1782
- }
1783
-
1784
- function parse_identifier() {
1785
- var cacheKey = "identifier" + '@' + pos;
1786
- var cachedResult = cache[cacheKey];
1787
- if (cachedResult) {
1788
- pos = cachedResult.nextPos;
1789
- return cachedResult.result;
1790
- }
1791
-
1792
- var savedReportMatchFailures = reportMatchFailures;
1793
- reportMatchFailures = false;
1794
- var result4 = parse_path();
1795
- var result3 = result4 !== null
1796
- ? (function(p) { return wrap(["path"].concat(p), cacheKey) })(result4)
1797
- : null;
1798
- if (result3 !== null) {
1799
- var result0 = result3;
1800
- } else {
1801
- var result2 = parse_key();
1802
- var result1 = result2 !== null
1803
- ? (function(k) { return wrap(["key", k], cacheKey) })(result2)
1804
- : null;
1805
- if (result1 !== null) {
1806
- var result0 = result1;
1807
- } else {
1808
- var result0 = null;;
1809
- };
1810
- }
1811
- reportMatchFailures = savedReportMatchFailures;
1812
- if (reportMatchFailures && result0 === null) {
1813
- matchFailed("identifier");
1814
- }
1815
-
1816
- cache[cacheKey] = {
1817
- nextPos: pos,
1818
- result: result0
1819
- };
1820
- return result0;
1821
- }
1822
-
1823
- function parse_path() {
1824
- var cacheKey = "path" + '@' + pos;
1825
- var cachedResult = cache[cacheKey];
1826
- if (cachedResult) {
1827
- pos = cachedResult.nextPos;
1828
- return cachedResult.result;
1829
- }
1830
-
1831
- var savedReportMatchFailures = reportMatchFailures;
1832
- reportMatchFailures = false;
1833
- var savedPos0 = pos;
1834
- var result11 = parse_key();
1835
- var result5 = result11 !== null ? result11 : '';
1836
- if (result5 !== null) {
1837
- var savedPos1 = pos;
1838
- if (input.substr(pos, 1) === ".") {
1839
- var result9 = ".";
1840
- pos += 1;
1841
- } else {
1842
- var result9 = null;
1843
- if (reportMatchFailures) {
1844
- matchFailed("\".\"");
1845
- }
1846
- }
1847
- if (result9 !== null) {
1848
- var result10 = parse_key();
1849
- if (result10 !== null) {
1850
- var result8 = [result9, result10];
1851
- } else {
1852
- var result8 = null;
1853
- pos = savedPos1;
1854
- }
1855
- } else {
1856
- var result8 = null;
1857
- pos = savedPos1;
1858
- }
1859
- var result7 = result8 !== null
1860
- ? (function(k) {return k})(result8[1])
1861
- : null;
1862
- if (result7 !== null) {
1863
- var result6 = [];
1864
- while (result7 !== null) {
1865
- result6.push(result7);
1866
- var savedPos1 = pos;
1867
- if (input.substr(pos, 1) === ".") {
1868
- var result9 = ".";
1869
- pos += 1;
1870
- } else {
1871
- var result9 = null;
1872
- if (reportMatchFailures) {
1873
- matchFailed("\".\"");
1874
- }
1875
- }
1876
- if (result9 !== null) {
1877
- var result10 = parse_key();
1878
- if (result10 !== null) {
1879
- var result8 = [result9, result10];
1880
- } else {
1881
- var result8 = null;
1882
- pos = savedPos1;
1883
- }
1884
- } else {
1885
- var result8 = null;
1886
- pos = savedPos1;
1887
- }
1888
- var result7 = result8 !== null
1889
- ? (function(k) {return k})(result8[1])
1890
- : null;
1891
- }
1892
- } else {
1893
- var result6 = null;
1894
- }
1895
- if (result6 !== null) {
1896
- var result4 = [result5, result6];
1897
- } else {
1898
- var result4 = null;
1899
- pos = savedPos0;
1900
- }
1901
- } else {
1902
- var result4 = null;
1903
- pos = savedPos0;
1904
- }
1905
- var result3 = result4 !== null
1906
- ? (function(k, d) {
1907
- if (k) { d.unshift(k); return [false, d]; }
1908
- return [true, d];
1909
- })(result4[0], result4[1])
1910
- : null;
1911
- if (result3 !== null) {
1912
- var result0 = result3;
1913
- } else {
1914
- if (input.substr(pos, 1) === ".") {
1915
- var result2 = ".";
1916
- pos += 1;
1917
- } else {
1918
- var result2 = null;
1919
- if (reportMatchFailures) {
1920
- matchFailed("\".\"");
1921
- }
1922
- }
1923
- var result1 = result2 !== null
1924
- ? (function() { return [true, []] })()
1925
- : null;
1926
- if (result1 !== null) {
1927
- var result0 = result1;
1928
- } else {
1929
- var result0 = null;;
1930
- };
1931
- }
1932
- reportMatchFailures = savedReportMatchFailures;
1933
- if (reportMatchFailures && result0 === null) {
1934
- matchFailed("path");
1935
- }
1936
-
1937
- cache[cacheKey] = {
1938
- nextPos: pos,
1939
- result: result0
1940
- };
1941
- return result0;
1942
- }
1943
-
1944
- function parse_key() {
1945
- var cacheKey = "key" + '@' + pos;
1946
- var cachedResult = cache[cacheKey];
1947
- if (cachedResult) {
1948
- pos = cachedResult.nextPos;
1949
- return cachedResult.result;
1950
- }
1951
-
1952
- var savedReportMatchFailures = reportMatchFailures;
1953
- reportMatchFailures = false;
1954
- var savedPos0 = pos;
1955
- if (input.substr(pos).match(/^[a-zA-Z_$]/) !== null) {
1956
- var result2 = input.charAt(pos);
1957
- pos++;
1958
- } else {
1959
- var result2 = null;
1960
- if (reportMatchFailures) {
1961
- matchFailed("[a-zA-Z_$]");
1962
- }
1963
- }
1964
- if (result2 !== null) {
1965
- var result3 = [];
1966
- if (input.substr(pos).match(/^[0-9a-zA-Z_$]/) !== null) {
1967
- var result4 = input.charAt(pos);
1968
- pos++;
1969
- } else {
1970
- var result4 = null;
1971
- if (reportMatchFailures) {
1972
- matchFailed("[0-9a-zA-Z_$]");
1973
- }
1974
- }
1975
- while (result4 !== null) {
1976
- result3.push(result4);
1977
- if (input.substr(pos).match(/^[0-9a-zA-Z_$]/) !== null) {
1978
- var result4 = input.charAt(pos);
1979
- pos++;
1980
- } else {
1981
- var result4 = null;
1982
- if (reportMatchFailures) {
1983
- matchFailed("[0-9a-zA-Z_$]");
1984
- }
1985
- }
1986
- }
1987
- if (result3 !== null) {
1988
- var result1 = [result2, result3];
1989
- } else {
1990
- var result1 = null;
1991
- pos = savedPos0;
1992
- }
1993
- } else {
1994
- var result1 = null;
1995
- pos = savedPos0;
1996
- }
1997
- var result0 = result1 !== null
1998
- ? (function(h, t) { return h + t.join('') })(result1[0], result1[1])
1999
- : null;
2000
- reportMatchFailures = savedReportMatchFailures;
2001
- if (reportMatchFailures && result0 === null) {
2002
- matchFailed("key");
2003
- }
2004
-
2005
- cache[cacheKey] = {
2006
- nextPos: pos,
2007
- result: result0
2008
- };
2009
- return result0;
2010
- }
2011
-
2012
- function parse_inline() {
2013
- var cacheKey = "inline" + '@' + pos;
2014
- var cachedResult = cache[cacheKey];
2015
- if (cachedResult) {
2016
- pos = cachedResult.nextPos;
2017
- return cachedResult.result;
2018
- }
2019
-
2020
- var savedReportMatchFailures = reportMatchFailures;
2021
- reportMatchFailures = false;
2022
- var savedPos2 = pos;
2023
- if (input.substr(pos, 1) === "\"") {
2024
- var result14 = "\"";
2025
- pos += 1;
2026
- } else {
2027
- var result14 = null;
2028
- if (reportMatchFailures) {
2029
- matchFailed("\"\\\"\"");
2030
- }
2031
- }
2032
- if (result14 !== null) {
2033
- if (input.substr(pos, 1) === "\"") {
2034
- var result15 = "\"";
2035
- pos += 1;
2036
- } else {
2037
- var result15 = null;
2038
- if (reportMatchFailures) {
2039
- matchFailed("\"\\\"\"");
2040
- }
2041
- }
2042
- if (result15 !== null) {
2043
- var result13 = [result14, result15];
2044
- } else {
2045
- var result13 = null;
2046
- pos = savedPos2;
2047
- }
2048
- } else {
2049
- var result13 = null;
2050
- pos = savedPos2;
2051
- }
2052
- var result12 = result13 !== null
2053
- ? (function() { return ["literal", ""] })()
2054
- : null;
2055
- if (result12 !== null) {
2056
- var result0 = result12;
2057
- } else {
2058
- var savedPos1 = pos;
2059
- if (input.substr(pos, 1) === "\"") {
2060
- var result9 = "\"";
2061
- pos += 1;
2062
- } else {
2063
- var result9 = null;
2064
- if (reportMatchFailures) {
2065
- matchFailed("\"\\\"\"");
2066
- }
2067
- }
2068
- if (result9 !== null) {
2069
- var result10 = parse_literal();
2070
- if (result10 !== null) {
2071
- if (input.substr(pos, 1) === "\"") {
2072
- var result11 = "\"";
2073
- pos += 1;
2074
- } else {
2075
- var result11 = null;
2076
- if (reportMatchFailures) {
2077
- matchFailed("\"\\\"\"");
2078
- }
2079
- }
2080
- if (result11 !== null) {
2081
- var result8 = [result9, result10, result11];
2082
- } else {
2083
- var result8 = null;
2084
- pos = savedPos1;
2085
- }
2086
- } else {
2087
- var result8 = null;
2088
- pos = savedPos1;
2089
- }
2090
- } else {
2091
- var result8 = null;
2092
- pos = savedPos1;
2093
- }
2094
- var result7 = result8 !== null
2095
- ? (function(l) { return ["literal", l] })(result8[1])
2096
- : null;
2097
- if (result7 !== null) {
2098
- var result0 = result7;
2099
- } else {
2100
- var savedPos0 = pos;
2101
- if (input.substr(pos, 1) === "\"") {
2102
- var result3 = "\"";
2103
- pos += 1;
2104
- } else {
2105
- var result3 = null;
2106
- if (reportMatchFailures) {
2107
- matchFailed("\"\\\"\"");
2108
- }
2109
- }
2110
- if (result3 !== null) {
2111
- var result6 = parse_inline_part();
2112
- if (result6 !== null) {
2113
- var result4 = [];
2114
- while (result6 !== null) {
2115
- result4.push(result6);
2116
- var result6 = parse_inline_part();
2117
- }
2118
- } else {
2119
- var result4 = null;
2120
- }
2121
- if (result4 !== null) {
2122
- if (input.substr(pos, 1) === "\"") {
2123
- var result5 = "\"";
2124
- pos += 1;
2125
- } else {
2126
- var result5 = null;
2127
- if (reportMatchFailures) {
2128
- matchFailed("\"\\\"\"");
2129
- }
2130
- }
2131
- if (result5 !== null) {
2132
- var result2 = [result3, result4, result5];
2133
- } else {
2134
- var result2 = null;
2135
- pos = savedPos0;
2136
- }
2137
- } else {
2138
- var result2 = null;
2139
- pos = savedPos0;
2140
- }
2141
- } else {
2142
- var result2 = null;
2143
- pos = savedPos0;
2144
- }
2145
- var result1 = result2 !== null
2146
- ? (function(p) { return ["body"].concat(p) })(result2[1])
2147
- : null;
2148
- if (result1 !== null) {
2149
- var result0 = result1;
2150
- } else {
2151
- var result0 = null;;
2152
- };
2153
- };
2154
- }
2155
- reportMatchFailures = savedReportMatchFailures;
2156
- if (reportMatchFailures && result0 === null) {
2157
- matchFailed("inline");
2158
- }
2159
-
2160
- cache[cacheKey] = {
2161
- nextPos: pos,
2162
- result: result0
2163
- };
2164
- return result0;
2165
- }
2166
-
2167
- function parse_inline_part() {
2168
- var cacheKey = "inline_part" + '@' + pos;
2169
- var cachedResult = cache[cacheKey];
2170
- if (cachedResult) {
2171
- pos = cachedResult.nextPos;
2172
- return cachedResult.result;
2173
- }
2174
-
2175
-
2176
- var result4 = parse_special();
2177
- if (result4 !== null) {
2178
- var result0 = result4;
2179
- } else {
2180
- var result3 = parse_reference();
2181
- if (result3 !== null) {
2182
- var result0 = result3;
2183
- } else {
2184
- var result2 = parse_literal();
2185
- var result1 = result2 !== null
2186
- ? (function(l) { return ["buffer", l] })(result2)
2187
- : null;
2188
- if (result1 !== null) {
2189
- var result0 = result1;
2190
- } else {
2191
- var result0 = null;;
2192
- };
2193
- };
2194
- }
2195
-
2196
-
2197
-
2198
- cache[cacheKey] = {
2199
- nextPos: pos,
2200
- result: result0
2201
- };
2202
- return result0;
2203
- }
2204
-
2205
- function parse_buffer() {
2206
- var cacheKey = "buffer" + '@' + pos;
2207
- var cachedResult = cache[cacheKey];
2208
- if (cachedResult) {
2209
- pos = cachedResult.nextPos;
2210
- return cachedResult.result;
2211
- }
2212
-
2213
- var savedReportMatchFailures = reportMatchFailures;
2214
- reportMatchFailures = false;
2215
- var savedPos4 = pos;
2216
- var result14 = parse_eol();
2217
- if (result14 !== null) {
2218
- var result15 = [];
2219
- var result16 = parse_ws();
2220
- while (result16 !== null) {
2221
- result15.push(result16);
2222
- var result16 = parse_ws();
2223
- }
2224
- if (result15 !== null) {
2225
- var result13 = [result14, result15];
2226
- } else {
2227
- var result13 = null;
2228
- pos = savedPos4;
2229
- }
2230
- } else {
2231
- var result13 = null;
2232
- pos = savedPos4;
2233
- }
2234
- var result12 = result13 !== null
2235
- ? (function(e, w) { return ["format", e, w.join('')] })(result13[0], result13[1])
2236
- : null;
2237
- if (result12 !== null) {
2238
- var result0 = result12;
2239
- } else {
2240
- var savedPos0 = pos;
2241
- var savedPos3 = pos;
2242
- var savedReportMatchFailuresVar2 = reportMatchFailures;
2243
- reportMatchFailures = false;
2244
- var result11 = parse_tag();
2245
- reportMatchFailures = savedReportMatchFailuresVar2;
2246
- if (result11 === null) {
2247
- var result5 = '';
2248
- } else {
2249
- var result5 = null;
2250
- pos = savedPos3;
2251
- }
2252
- if (result5 !== null) {
2253
- var savedPos2 = pos;
2254
- var savedReportMatchFailuresVar1 = reportMatchFailures;
2255
- reportMatchFailures = false;
2256
- var result10 = parse_eol();
2257
- reportMatchFailures = savedReportMatchFailuresVar1;
2258
- if (result10 === null) {
2259
- var result6 = '';
2260
- } else {
2261
- var result6 = null;
2262
- pos = savedPos2;
2263
- }
2264
- if (result6 !== null) {
2265
- var savedPos1 = pos;
2266
- var savedReportMatchFailuresVar0 = reportMatchFailures;
2267
- reportMatchFailures = false;
2268
- var result9 = parse_comment();
2269
- reportMatchFailures = savedReportMatchFailuresVar0;
2270
- if (result9 === null) {
2271
- var result7 = '';
2272
- } else {
2273
- var result7 = null;
2274
- pos = savedPos1;
2275
- }
2276
- if (result7 !== null) {
2277
- if (input.length > pos) {
2278
- var result8 = input.charAt(pos);
2279
- pos++;
2280
- } else {
2281
- var result8 = null;
2282
- if (reportMatchFailures) {
2283
- matchFailed('any character');
2284
- }
2285
- }
2286
- if (result8 !== null) {
2287
- var result4 = [result5, result6, result7, result8];
2288
- } else {
2289
- var result4 = null;
2290
- pos = savedPos0;
2291
- }
2292
- } else {
2293
- var result4 = null;
2294
- pos = savedPos0;
2295
- }
2296
- } else {
2297
- var result4 = null;
2298
- pos = savedPos0;
2299
- }
2300
- } else {
2301
- var result4 = null;
2302
- pos = savedPos0;
2303
- }
2304
- var result3 = result4 !== null
2305
- ? (function(c) {return c})(result4[3])
2306
- : null;
2307
- if (result3 !== null) {
2308
- var result2 = [];
2309
- while (result3 !== null) {
2310
- result2.push(result3);
2311
- var savedPos0 = pos;
2312
- var savedPos3 = pos;
2313
- var savedReportMatchFailuresVar2 = reportMatchFailures;
2314
- reportMatchFailures = false;
2315
- var result11 = parse_tag();
2316
- reportMatchFailures = savedReportMatchFailuresVar2;
2317
- if (result11 === null) {
2318
- var result5 = '';
2319
- } else {
2320
- var result5 = null;
2321
- pos = savedPos3;
2322
- }
2323
- if (result5 !== null) {
2324
- var savedPos2 = pos;
2325
- var savedReportMatchFailuresVar1 = reportMatchFailures;
2326
- reportMatchFailures = false;
2327
- var result10 = parse_eol();
2328
- reportMatchFailures = savedReportMatchFailuresVar1;
2329
- if (result10 === null) {
2330
- var result6 = '';
2331
- } else {
2332
- var result6 = null;
2333
- pos = savedPos2;
2334
- }
2335
- if (result6 !== null) {
2336
- var savedPos1 = pos;
2337
- var savedReportMatchFailuresVar0 = reportMatchFailures;
2338
- reportMatchFailures = false;
2339
- var result9 = parse_comment();
2340
- reportMatchFailures = savedReportMatchFailuresVar0;
2341
- if (result9 === null) {
2342
- var result7 = '';
2343
- } else {
2344
- var result7 = null;
2345
- pos = savedPos1;
2346
- }
2347
- if (result7 !== null) {
2348
- if (input.length > pos) {
2349
- var result8 = input.charAt(pos);
2350
- pos++;
2351
- } else {
2352
- var result8 = null;
2353
- if (reportMatchFailures) {
2354
- matchFailed('any character');
2355
- }
2356
- }
2357
- if (result8 !== null) {
2358
- var result4 = [result5, result6, result7, result8];
2359
- } else {
2360
- var result4 = null;
2361
- pos = savedPos0;
2362
- }
2363
- } else {
2364
- var result4 = null;
2365
- pos = savedPos0;
2366
- }
2367
- } else {
2368
- var result4 = null;
2369
- pos = savedPos0;
2370
- }
2371
- } else {
2372
- var result4 = null;
2373
- pos = savedPos0;
2374
- }
2375
- var result3 = result4 !== null
2376
- ? (function(c) {return c})(result4[3])
2377
- : null;
2378
- }
2379
- } else {
2380
- var result2 = null;
2381
- }
2382
- var result1 = result2 !== null
2383
- ? (function(b) { return ["buffer", b.join('')] })(result2)
2384
- : null;
2385
- if (result1 !== null) {
2386
- var result0 = result1;
2387
- } else {
2388
- var result0 = null;;
2389
- };
2390
- }
2391
- reportMatchFailures = savedReportMatchFailures;
2392
- if (reportMatchFailures && result0 === null) {
2393
- matchFailed("buffer");
2394
- }
2395
-
2396
- cache[cacheKey] = {
2397
- nextPos: pos,
2398
- result: result0
2399
- };
2400
- return result0;
2401
- }
2402
-
2403
- function parse_literal() {
2404
- var cacheKey = "literal" + '@' + pos;
2405
- var cachedResult = cache[cacheKey];
2406
- if (cachedResult) {
2407
- pos = cachedResult.nextPos;
2408
- return cachedResult.result;
2409
- }
2410
-
2411
- var savedReportMatchFailures = reportMatchFailures;
2412
- reportMatchFailures = false;
2413
- var savedPos0 = pos;
2414
- var savedPos2 = pos;
2415
- var savedReportMatchFailuresVar1 = reportMatchFailures;
2416
- reportMatchFailures = false;
2417
- var result10 = parse_tag();
2418
- reportMatchFailures = savedReportMatchFailuresVar1;
2419
- if (result10 === null) {
2420
- var result4 = '';
2421
- } else {
2422
- var result4 = null;
2423
- pos = savedPos2;
2424
- }
2425
- if (result4 !== null) {
2426
- var savedPos1 = pos;
2427
- var savedReportMatchFailuresVar0 = reportMatchFailures;
2428
- reportMatchFailures = false;
2429
- var result9 = parse_eol();
2430
- reportMatchFailures = savedReportMatchFailuresVar0;
2431
- if (result9 === null) {
2432
- var result5 = '';
2433
- } else {
2434
- var result5 = null;
2435
- pos = savedPos1;
2436
- }
2437
- if (result5 !== null) {
2438
- var result8 = parse_esc();
2439
- if (result8 !== null) {
2440
- var result6 = result8;
2441
- } else {
2442
- if (input.substr(pos).match(/^[^"]/) !== null) {
2443
- var result7 = input.charAt(pos);
2444
- pos++;
2445
- } else {
2446
- var result7 = null;
2447
- if (reportMatchFailures) {
2448
- matchFailed("[^\"]");
2449
- }
2450
- }
2451
- if (result7 !== null) {
2452
- var result6 = result7;
2453
- } else {
2454
- var result6 = null;;
2455
- };
2456
- }
2457
- if (result6 !== null) {
2458
- var result3 = [result4, result5, result6];
2459
- } else {
2460
- var result3 = null;
2461
- pos = savedPos0;
2462
- }
2463
- } else {
2464
- var result3 = null;
2465
- pos = savedPos0;
2466
- }
2467
- } else {
2468
- var result3 = null;
2469
- pos = savedPos0;
2470
- }
2471
- var result2 = result3 !== null
2472
- ? (function(c) {return c})(result3[2])
2473
- : null;
2474
- if (result2 !== null) {
2475
- var result1 = [];
2476
- while (result2 !== null) {
2477
- result1.push(result2);
2478
- var savedPos0 = pos;
2479
- var savedPos2 = pos;
2480
- var savedReportMatchFailuresVar1 = reportMatchFailures;
2481
- reportMatchFailures = false;
2482
- var result10 = parse_tag();
2483
- reportMatchFailures = savedReportMatchFailuresVar1;
2484
- if (result10 === null) {
2485
- var result4 = '';
2486
- } else {
2487
- var result4 = null;
2488
- pos = savedPos2;
2489
- }
2490
- if (result4 !== null) {
2491
- var savedPos1 = pos;
2492
- var savedReportMatchFailuresVar0 = reportMatchFailures;
2493
- reportMatchFailures = false;
2494
- var result9 = parse_eol();
2495
- reportMatchFailures = savedReportMatchFailuresVar0;
2496
- if (result9 === null) {
2497
- var result5 = '';
2498
- } else {
2499
- var result5 = null;
2500
- pos = savedPos1;
2501
- }
2502
- if (result5 !== null) {
2503
- var result8 = parse_esc();
2504
- if (result8 !== null) {
2505
- var result6 = result8;
2506
- } else {
2507
- if (input.substr(pos).match(/^[^"]/) !== null) {
2508
- var result7 = input.charAt(pos);
2509
- pos++;
2510
- } else {
2511
- var result7 = null;
2512
- if (reportMatchFailures) {
2513
- matchFailed("[^\"]");
2514
- }
2515
- }
2516
- if (result7 !== null) {
2517
- var result6 = result7;
2518
- } else {
2519
- var result6 = null;;
2520
- };
2521
- }
2522
- if (result6 !== null) {
2523
- var result3 = [result4, result5, result6];
2524
- } else {
2525
- var result3 = null;
2526
- pos = savedPos0;
2527
- }
2528
- } else {
2529
- var result3 = null;
2530
- pos = savedPos0;
2531
- }
2532
- } else {
2533
- var result3 = null;
2534
- pos = savedPos0;
2535
- }
2536
- var result2 = result3 !== null
2537
- ? (function(c) {return c})(result3[2])
2538
- : null;
2539
- }
2540
- } else {
2541
- var result1 = null;
2542
- }
2543
- var result0 = result1 !== null
2544
- ? (function(b) { return b.join('') })(result1)
2545
- : null;
2546
- reportMatchFailures = savedReportMatchFailures;
2547
- if (reportMatchFailures && result0 === null) {
2548
- matchFailed("literal");
2549
- }
2550
-
2551
- cache[cacheKey] = {
2552
- nextPos: pos,
2553
- result: result0
2554
- };
2555
- return result0;
2556
- }
2557
-
2558
- function parse_esc() {
2559
- var cacheKey = "esc" + '@' + pos;
2560
- var cachedResult = cache[cacheKey];
2561
- if (cachedResult) {
2562
- pos = cachedResult.nextPos;
2563
- return cachedResult.result;
2564
- }
2565
-
2566
-
2567
- if (input.substr(pos, 2) === "\\\"") {
2568
- var result1 = "\\\"";
2569
- pos += 2;
2570
- } else {
2571
- var result1 = null;
2572
- if (reportMatchFailures) {
2573
- matchFailed("\"\\\\\\\"\"");
2574
- }
2575
- }
2576
- var result0 = result1 !== null
2577
- ? (function() { return '"' })()
2578
- : null;
2579
-
2580
-
2581
-
2582
- cache[cacheKey] = {
2583
- nextPos: pos,
2584
- result: result0
2585
- };
2586
- return result0;
2587
- }
2588
-
2589
- function parse_comment() {
2590
- var cacheKey = "comment" + '@' + pos;
2591
- var cachedResult = cache[cacheKey];
2592
- if (cachedResult) {
2593
- pos = cachedResult.nextPos;
2594
- return cachedResult.result;
2595
- }
2596
-
2597
- var savedReportMatchFailures = reportMatchFailures;
2598
- reportMatchFailures = false;
2599
- var savedPos0 = pos;
2600
- if (input.substr(pos, 2) === "{!") {
2601
- var result2 = "{!";
2602
- pos += 2;
2603
- } else {
2604
- var result2 = null;
2605
- if (reportMatchFailures) {
2606
- matchFailed("\"{!\"");
2607
- }
2608
- }
2609
- if (result2 !== null) {
2610
- var result3 = [];
2611
- var savedPos1 = pos;
2612
- var savedPos2 = pos;
2613
- var savedReportMatchFailuresVar0 = reportMatchFailures;
2614
- reportMatchFailures = false;
2615
- if (input.substr(pos, 2) === "!}") {
2616
- var result9 = "!}";
2617
- pos += 2;
2618
- } else {
2619
- var result9 = null;
2620
- if (reportMatchFailures) {
2621
- matchFailed("\"!}\"");
2622
- }
2623
- }
2624
- reportMatchFailures = savedReportMatchFailuresVar0;
2625
- if (result9 === null) {
2626
- var result7 = '';
2627
- } else {
2628
- var result7 = null;
2629
- pos = savedPos2;
2630
- }
2631
- if (result7 !== null) {
2632
- if (input.length > pos) {
2633
- var result8 = input.charAt(pos);
2634
- pos++;
2635
- } else {
2636
- var result8 = null;
2637
- if (reportMatchFailures) {
2638
- matchFailed('any character');
2639
- }
2640
- }
2641
- if (result8 !== null) {
2642
- var result6 = [result7, result8];
2643
- } else {
2644
- var result6 = null;
2645
- pos = savedPos1;
2646
- }
2647
- } else {
2648
- var result6 = null;
2649
- pos = savedPos1;
2650
- }
2651
- var result5 = result6 !== null
2652
- ? (function(c) {return c})(result6[1])
2653
- : null;
2654
- while (result5 !== null) {
2655
- result3.push(result5);
2656
- var savedPos1 = pos;
2657
- var savedPos2 = pos;
2658
- var savedReportMatchFailuresVar0 = reportMatchFailures;
2659
- reportMatchFailures = false;
2660
- if (input.substr(pos, 2) === "!}") {
2661
- var result9 = "!}";
2662
- pos += 2;
2663
- } else {
2664
- var result9 = null;
2665
- if (reportMatchFailures) {
2666
- matchFailed("\"!}\"");
2667
- }
2668
- }
2669
- reportMatchFailures = savedReportMatchFailuresVar0;
2670
- if (result9 === null) {
2671
- var result7 = '';
2672
- } else {
2673
- var result7 = null;
2674
- pos = savedPos2;
2675
- }
2676
- if (result7 !== null) {
2677
- if (input.length > pos) {
2678
- var result8 = input.charAt(pos);
2679
- pos++;
2680
- } else {
2681
- var result8 = null;
2682
- if (reportMatchFailures) {
2683
- matchFailed('any character');
2684
- }
2685
- }
2686
- if (result8 !== null) {
2687
- var result6 = [result7, result8];
2688
- } else {
2689
- var result6 = null;
2690
- pos = savedPos1;
2691
- }
2692
- } else {
2693
- var result6 = null;
2694
- pos = savedPos1;
2695
- }
2696
- var result5 = result6 !== null
2697
- ? (function(c) {return c})(result6[1])
2698
- : null;
2699
- }
2700
- if (result3 !== null) {
2701
- if (input.substr(pos, 2) === "!}") {
2702
- var result4 = "!}";
2703
- pos += 2;
2704
- } else {
2705
- var result4 = null;
2706
- if (reportMatchFailures) {
2707
- matchFailed("\"!}\"");
2708
- }
2709
- }
2710
- if (result4 !== null) {
2711
- var result1 = [result2, result3, result4];
2712
- } else {
2713
- var result1 = null;
2714
- pos = savedPos0;
2715
- }
2716
- } else {
2717
- var result1 = null;
2718
- pos = savedPos0;
2719
- }
2720
- } else {
2721
- var result1 = null;
2722
- pos = savedPos0;
2723
- }
2724
- var result0 = result1 !== null
2725
- ? (function(c) { return ["comment", c.join('')] })(result1[1])
2726
- : null;
2727
- reportMatchFailures = savedReportMatchFailures;
2728
- if (reportMatchFailures && result0 === null) {
2729
- matchFailed("comment");
2730
- }
2731
-
2732
- cache[cacheKey] = {
2733
- nextPos: pos,
2734
- result: result0
2735
- };
2736
- return result0;
2737
- }
2738
-
2739
- function parse_tag() {
2740
- var cacheKey = "tag" + '@' + pos;
2741
- var cachedResult = cache[cacheKey];
2742
- if (cachedResult) {
2743
- pos = cachedResult.nextPos;
2744
- return cachedResult.result;
2745
- }
2746
-
2747
-
2748
- var savedPos0 = pos;
2749
- var result3 = parse_ld();
2750
- if (result3 !== null) {
2751
- if (input.substr(pos).match(/^[#?^><+%:@\/~%]/) !== null) {
2752
- var result4 = input.charAt(pos);
2753
- pos++;
2754
- } else {
2755
- var result4 = null;
2756
- if (reportMatchFailures) {
2757
- matchFailed("[#?^><+%:@\\/~%]");
2758
- }
2759
- }
2760
- if (result4 !== null) {
2761
- var savedPos1 = pos;
2762
- var savedPos3 = pos;
2763
- var savedReportMatchFailuresVar1 = reportMatchFailures;
2764
- reportMatchFailures = false;
2765
- var result12 = parse_rd();
2766
- reportMatchFailures = savedReportMatchFailuresVar1;
2767
- if (result12 === null) {
2768
- var result8 = '';
2769
- } else {
2770
- var result8 = null;
2771
- pos = savedPos3;
2772
- }
2773
- if (result8 !== null) {
2774
- var savedPos2 = pos;
2775
- var savedReportMatchFailuresVar0 = reportMatchFailures;
2776
- reportMatchFailures = false;
2777
- var result11 = parse_eol();
2778
- reportMatchFailures = savedReportMatchFailuresVar0;
2779
- if (result11 === null) {
2780
- var result9 = '';
2781
- } else {
2782
- var result9 = null;
2783
- pos = savedPos2;
2784
- }
2785
- if (result9 !== null) {
2786
- if (input.length > pos) {
2787
- var result10 = input.charAt(pos);
2788
- pos++;
2789
- } else {
2790
- var result10 = null;
2791
- if (reportMatchFailures) {
2792
- matchFailed('any character');
2793
- }
2794
- }
2795
- if (result10 !== null) {
2796
- var result7 = [result8, result9, result10];
2797
- } else {
2798
- var result7 = null;
2799
- pos = savedPos1;
2800
- }
2801
- } else {
2802
- var result7 = null;
2803
- pos = savedPos1;
2804
- }
2805
- } else {
2806
- var result7 = null;
2807
- pos = savedPos1;
2808
- }
2809
- if (result7 !== null) {
2810
- var result5 = [];
2811
- while (result7 !== null) {
2812
- result5.push(result7);
2813
- var savedPos1 = pos;
2814
- var savedPos3 = pos;
2815
- var savedReportMatchFailuresVar1 = reportMatchFailures;
2816
- reportMatchFailures = false;
2817
- var result12 = parse_rd();
2818
- reportMatchFailures = savedReportMatchFailuresVar1;
2819
- if (result12 === null) {
2820
- var result8 = '';
2821
- } else {
2822
- var result8 = null;
2823
- pos = savedPos3;
2824
- }
2825
- if (result8 !== null) {
2826
- var savedPos2 = pos;
2827
- var savedReportMatchFailuresVar0 = reportMatchFailures;
2828
- reportMatchFailures = false;
2829
- var result11 = parse_eol();
2830
- reportMatchFailures = savedReportMatchFailuresVar0;
2831
- if (result11 === null) {
2832
- var result9 = '';
2833
- } else {
2834
- var result9 = null;
2835
- pos = savedPos2;
2836
- }
2837
- if (result9 !== null) {
2838
- if (input.length > pos) {
2839
- var result10 = input.charAt(pos);
2840
- pos++;
2841
- } else {
2842
- var result10 = null;
2843
- if (reportMatchFailures) {
2844
- matchFailed('any character');
2845
- }
2846
- }
2847
- if (result10 !== null) {
2848
- var result7 = [result8, result9, result10];
2849
- } else {
2850
- var result7 = null;
2851
- pos = savedPos1;
2852
- }
2853
- } else {
2854
- var result7 = null;
2855
- pos = savedPos1;
2856
- }
2857
- } else {
2858
- var result7 = null;
2859
- pos = savedPos1;
2860
- }
2861
- }
2862
- } else {
2863
- var result5 = null;
2864
- }
2865
- if (result5 !== null) {
2866
- var result6 = parse_rd();
2867
- if (result6 !== null) {
2868
- var result2 = [result3, result4, result5, result6];
2869
- } else {
2870
- var result2 = null;
2871
- pos = savedPos0;
2872
- }
2873
- } else {
2874
- var result2 = null;
2875
- pos = savedPos0;
2876
- }
2877
- } else {
2878
- var result2 = null;
2879
- pos = savedPos0;
2880
- }
2881
- } else {
2882
- var result2 = null;
2883
- pos = savedPos0;
2884
- }
2885
- if (result2 !== null) {
2886
- var result0 = result2;
2887
- } else {
2888
- var result1 = parse_reference();
2889
- if (result1 !== null) {
2890
- var result0 = result1;
2891
- } else {
2892
- var result0 = null;;
2893
- };
2894
- }
2895
-
2896
-
2897
-
2898
- cache[cacheKey] = {
2899
- nextPos: pos,
2900
- result: result0
2901
- };
2902
- return result0;
2903
- }
2904
-
2905
- function parse_ld() {
2906
- var cacheKey = "ld" + '@' + pos;
2907
- var cachedResult = cache[cacheKey];
2908
- if (cachedResult) {
2909
- pos = cachedResult.nextPos;
2910
- return cachedResult.result;
2911
- }
2912
-
2913
-
2914
- if (input.substr(pos, 1) === "{") {
2915
- var result0 = "{";
2916
- pos += 1;
2917
- } else {
2918
- var result0 = null;
2919
- if (reportMatchFailures) {
2920
- matchFailed("\"{\"");
2921
- }
2922
- }
2923
-
2924
-
2925
-
2926
- cache[cacheKey] = {
2927
- nextPos: pos,
2928
- result: result0
2929
- };
2930
- return result0;
2931
- }
2932
-
2933
- function parse_rd() {
2934
- var cacheKey = "rd" + '@' + pos;
2935
- var cachedResult = cache[cacheKey];
2936
- if (cachedResult) {
2937
- pos = cachedResult.nextPos;
2938
- return cachedResult.result;
2939
- }
2940
-
2941
-
2942
- if (input.substr(pos, 1) === "}") {
2943
- var result0 = "}";
2944
- pos += 1;
2945
- } else {
2946
- var result0 = null;
2947
- if (reportMatchFailures) {
2948
- matchFailed("\"}\"");
2949
- }
2950
- }
2951
-
2952
-
2953
-
2954
- cache[cacheKey] = {
2955
- nextPos: pos,
2956
- result: result0
2957
- };
2958
- return result0;
2959
- }
2960
-
2961
- function parse_eol() {
2962
- var cacheKey = "eol" + '@' + pos;
2963
- var cachedResult = cache[cacheKey];
2964
- if (cachedResult) {
2965
- pos = cachedResult.nextPos;
2966
- return cachedResult.result;
2967
- }
2968
-
2969
-
2970
- if (input.substr(pos, 1) === "\n") {
2971
- var result5 = "\n";
2972
- pos += 1;
2973
- } else {
2974
- var result5 = null;
2975
- if (reportMatchFailures) {
2976
- matchFailed("\"\\n\"");
2977
- }
2978
- }
2979
- if (result5 !== null) {
2980
- var result0 = result5;
2981
- } else {
2982
- if (input.substr(pos, 2) === "\r\n") {
2983
- var result4 = "\r\n";
2984
- pos += 2;
2985
- } else {
2986
- var result4 = null;
2987
- if (reportMatchFailures) {
2988
- matchFailed("\"\\r\\n\"");
2989
- }
2990
- }
2991
- if (result4 !== null) {
2992
- var result0 = result4;
2993
- } else {
2994
- if (input.substr(pos, 1) === "\r") {
2995
- var result3 = "\r";
2996
- pos += 1;
2997
- } else {
2998
- var result3 = null;
2999
- if (reportMatchFailures) {
3000
- matchFailed("\"\\r\"");
3001
- }
3002
- }
3003
- if (result3 !== null) {
3004
- var result0 = result3;
3005
- } else {
3006
- if (input.substr(pos, 1) === "\u2028") {
3007
- var result2 = "\u2028";
3008
- pos += 1;
3009
- } else {
3010
- var result2 = null;
3011
- if (reportMatchFailures) {
3012
- matchFailed("\"\\u2028\"");
3013
- }
3014
- }
3015
- if (result2 !== null) {
3016
- var result0 = result2;
3017
- } else {
3018
- if (input.substr(pos, 1) === "\u2029") {
3019
- var result1 = "\u2029";
3020
- pos += 1;
3021
- } else {
3022
- var result1 = null;
3023
- if (reportMatchFailures) {
3024
- matchFailed("\"\\u2029\"");
3025
- }
3026
- }
3027
- if (result1 !== null) {
3028
- var result0 = result1;
3029
- } else {
3030
- var result0 = null;;
3031
- };
3032
- };
3033
- };
3034
- };
3035
- }
3036
-
3037
-
3038
-
3039
- cache[cacheKey] = {
3040
- nextPos: pos,
3041
- result: result0
3042
- };
3043
- return result0;
3044
- }
3045
-
3046
- function parse_ws() {
3047
- var cacheKey = "ws" + '@' + pos;
3048
- var cachedResult = cache[cacheKey];
3049
- if (cachedResult) {
3050
- pos = cachedResult.nextPos;
3051
- return cachedResult.result;
3052
- }
3053
-
3054
-
3055
- if (input.substr(pos).match(/^[ \xA0\uFEFF]/) !== null) {
3056
- var result0 = input.charAt(pos);
3057
- pos++;
3058
- } else {
3059
- var result0 = null;
3060
- if (reportMatchFailures) {
3061
- matchFailed("[ \\xA0\\uFEFF]");
3062
- }
3063
- }
3064
-
3065
-
3066
-
3067
- cache[cacheKey] = {
3068
- nextPos: pos,
3069
- result: result0
3070
- };
3071
- return result0;
3072
- }
3073
-
3074
- function buildErrorMessage() {
3075
- function buildExpected(failuresExpected) {
3076
- failuresExpected.sort();
3077
-
3078
- var lastFailure = null;
3079
- var failuresExpectedUnique = [];
3080
- for (var i = 0; i < failuresExpected.length; i++) {
3081
- if (failuresExpected[i] !== lastFailure) {
3082
- failuresExpectedUnique.push(failuresExpected[i]);
3083
- lastFailure = failuresExpected[i];
3084
- }
3085
- }
3086
-
3087
- switch (failuresExpectedUnique.length) {
3088
- case 0:
3089
- return 'end of input';
3090
- case 1:
3091
- return failuresExpectedUnique[0];
3092
- default:
3093
- return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ')
3094
- + ' or '
3095
- + failuresExpectedUnique[failuresExpectedUnique.length - 1];
3096
- }
3097
- }
3098
-
3099
- var expected = buildExpected(rightmostMatchFailuresExpected);
3100
- var actualPos = Math.max(pos, rightmostMatchFailuresPos);
3101
- var actual = actualPos < input.length
3102
- ? quote(input.charAt(actualPos))
3103
- : 'end of input';
3104
-
3105
- return 'Expected ' + expected + ' but ' + actual + ' found.';
3106
- }
3107
-
3108
- function computeErrorPosition() {
3109
- /*
3110
- * The first idea was to use |String.split| to break the input up to the
3111
- * error position along newlines and derive the line and column from
3112
- * there. However IE's |split| implementation is so broken that it was
3113
- * enough to prevent it.
3114
- */
3115
-
3116
- var line = 1;
3117
- var column = 1;
3118
- var seenCR = false;
3119
-
3120
- for (var i = 0; i < rightmostMatchFailuresPos; i++) {
3121
- var ch = input.charAt(i);
3122
- if (ch === '\n') {
3123
- if (!seenCR) { line++; }
3124
- column = 1;
3125
- seenCR = false;
3126
- } else if (ch === '\r' | ch === '\u2028' || ch === '\u2029') {
3127
- line++;
3128
- column = 1;
3129
- seenCR = true;
3130
- } else {
3131
- column++;
3132
- seenCR = false;
3133
- }
3134
- }
3135
-
3136
- return { line: line, column: column };
3137
- }
3138
-
3139
-
3140
-
3141
- function wrap(node, ck) {
3142
-
3143
- node['text'] = input.substring(ck.split('@')[1], pos);
3144
-
3145
- return node;
3146
-
3147
- }
3148
-
3149
-
3150
-
3151
- var result = parse_body();
3152
-
3153
- /*
3154
- * The parser is now in one of the following three states:
3155
- *
3156
- * 1. The parser successfully parsed the whole input.
3157
- *
3158
- * - |result !== null|
3159
- * - |pos === input.length|
3160
- * - |rightmostMatchFailuresExpected| may or may not contain something
3161
- *
3162
- * 2. The parser successfully parsed only a part of the input.
3163
- *
3164
- * - |result !== null|
3165
- * - |pos < input.length|
3166
- * - |rightmostMatchFailuresExpected| may or may not contain something
3167
- *
3168
- * 3. The parser did not successfully parse any part of the input.
3169
- *
3170
- * - |result === null|
3171
- * - |pos === 0|
3172
- * - |rightmostMatchFailuresExpected| contains at least one failure
3173
- *
3174
- * All code following this comment (including called functions) must
3175
- * handle these states.
3176
- */
3177
- if (result === null || pos !== input.length) {
3178
- var errorPosition = computeErrorPosition();
3179
- throw new SyntaxError(
3180
- buildErrorMessage(),
3181
- errorPosition.line,
3182
- errorPosition.column
3183
- );
3184
- }
3185
-
3186
- return result;
3187
- },
3188
-
3189
- /* Returns the parser source code. */
3190
- toSource: function() { return this._source; }
3191
- };
3192
-
3193
- /* Thrown when a parser encounters a syntax error. */
3194
-
3195
- result.SyntaxError = function(message, line, column) {
3196
- this.name = 'SyntaxError';
3197
- this.message = message;
3198
- this.line = line;
3199
- this.column = column;
3200
- };
3201
-
3202
- result.SyntaxError.prototype = Error.prototype;
3203
-
3204
- return result;
3205
- })();
3206
-
3207
- dust.parse = parser.parse;
3208
-
3209
- })(typeof exports !== 'undefined' ? exports : dust);