marionette_dust 0.0.1

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.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +114 -0
  8. data/Rakefile +5 -0
  9. data/lib/generators/marionette_dust/common/templates/app.js +10 -0
  10. data/lib/generators/marionette_dust/common/templates/controller.js +3 -0
  11. data/lib/generators/marionette_dust/common/templates/entity.js +9 -0
  12. data/lib/generators/marionette_dust/common/templates/template.jst.dust +1 -0
  13. data/lib/generators/marionette_dust/common/templates/view.js +5 -0
  14. data/lib/generators/marionette_dust/helpers.rb +71 -0
  15. data/lib/generators/marionette_dust/install/install_generator.rb +58 -0
  16. data/lib/generators/marionette_dust/install/templates/app.js +20 -0
  17. data/lib/generators/marionette_dust/install/templates/app.js.coffee +16 -0
  18. data/lib/generators/marionette_dust/scaffold/scaffold_generator.rb +64 -0
  19. data/lib/generators/marionette_dust/submodule/submodule_generator.rb +52 -0
  20. data/lib/marionette_dust/engine.rb +3 -0
  21. data/lib/marionette_dust/version.rb +3 -0
  22. data/lib/marionette_dust.rb +6 -0
  23. data/marionette_dust.gemspec +23 -0
  24. data/vendor/assets/javascripts/marionette_dust/backbone.js +1581 -0
  25. data/vendor/assets/javascripts/marionette_dust/backbone.marionette.js +2385 -0
  26. data/vendor/assets/javascripts/marionette_dust/dust-full-2.1.0.js +3759 -0
  27. data/vendor/assets/javascripts/marionette_dust/dust-helpers-1.1.1.js +523 -0
  28. data/vendor/assets/javascripts/marionette_dust/index.js +7 -0
  29. data/vendor/assets/javascripts/marionette_dust/marionette_renderer.js +11 -0
  30. data/vendor/assets/javascripts/marionette_dust/template_loader.js +13 -0
  31. data/vendor/assets/javascripts/marionette_dust/underscore.js +1276 -0
  32. metadata +103 -0
@@ -0,0 +1,3759 @@
1
+ //
2
+ // Dust - Asynchronous Templating v2.1.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 getGlobal(){
12
+ return (function(){
13
+ return this.dust;
14
+ }).call(null);
15
+ }
16
+
17
+ (function(dust) {
18
+
19
+ if(!dust) {
20
+ return;
21
+ }
22
+ var ERROR = 'ERROR',
23
+ WARN = 'WARN',
24
+ INFO = 'INFO',
25
+ DEBUG = 'DEBUG',
26
+ levels = [DEBUG, INFO, WARN, ERROR],
27
+ logger = function() {};
28
+
29
+ dust.isDebug = false;
30
+ dust.debugLevel = INFO;
31
+
32
+ // Try to find the console logger in window scope (browsers) or top level scope (node.js)
33
+ if (typeof window !== 'undefined' && window && window.console && window.console.log) {
34
+ logger = window.console.log;
35
+ } else if (typeof console !== 'undefined' && console && console.log) {
36
+ logger = console.log;
37
+ }
38
+
39
+ /**
40
+ * If dust.isDebug is true, Log dust debug statements, info statements, warning statements, and errors.
41
+ * This default implementation will print to the console if it exists.
42
+ * @param {String} message the message to print
43
+ * @param {String} type the severity of the message(ERROR, WARN, INFO, or DEBUG)
44
+ * @public
45
+ */
46
+ dust.log = function(message, type) {
47
+ var type = type || INFO;
48
+ if(dust.isDebug && levels.indexOf(type) >= levels.indexOf(dust.debugLevel)) {
49
+ if(!dust.logQueue) {
50
+ dust.logQueue = [];
51
+ }
52
+ dust.logQueue.push({message: message, type: type});
53
+ logger.call(console || window.console, "[DUST " + type + "]: " + message);
54
+ }
55
+ };
56
+
57
+ /**
58
+ * If debugging is turned on(dust.isDebug=true) log the error message and throw it.
59
+ * Otherwise try to keep rendering. This is useful to fail hard in dev mode, but keep rendering in production.
60
+ * @param {Error} error the error message to throw
61
+ * @param {Object} chunk the chunk the error was thrown from
62
+ * @public
63
+ */
64
+ dust.onError = function(error, chunk) {
65
+ dust.log(error.message || error, ERROR);
66
+ if(dust.isDebug) {
67
+ throw error;
68
+ } else {
69
+ return chunk;
70
+ }
71
+ };
72
+
73
+ dust.helpers = {};
74
+
75
+ dust.cache = {};
76
+
77
+ dust.register = function(name, tmpl) {
78
+ if (!name) return;
79
+ dust.cache[name] = tmpl;
80
+ };
81
+
82
+ dust.render = function(name, context, callback) {
83
+ var chunk = new Stub(callback).head;
84
+ try {
85
+ dust.load(name, chunk, Context.wrap(context, name)).end();
86
+ } catch (err) {
87
+ dust.onError(err, chunk);
88
+ }
89
+ };
90
+
91
+ dust.stream = function(name, context) {
92
+ var stream = new Stream();
93
+ dust.nextTick(function() {
94
+ try {
95
+ dust.load(name, stream.head, Context.wrap(context, name)).end();
96
+ } catch (err) {
97
+ dust.onError(err, stream.head);
98
+ }
99
+ });
100
+ return stream;
101
+ };
102
+
103
+ dust.renderSource = function(source, context, callback) {
104
+ return dust.compileFn(source)(context, callback);
105
+ };
106
+
107
+ dust.compileFn = function(source, name) {
108
+ var tmpl = dust.loadSource(dust.compile(source, name));
109
+ return function(context, callback) {
110
+ var master = callback ? new Stub(callback) : new Stream();
111
+ dust.nextTick(function() {
112
+ if(typeof tmpl === 'function') {
113
+ tmpl(master.head, Context.wrap(context, name)).end();
114
+ }
115
+ else {
116
+ dust.onError(new Error('Template [' + name + '] cannot be resolved to a Dust function'));
117
+ }
118
+ });
119
+ return master;
120
+ };
121
+ };
122
+
123
+ dust.load = function(name, chunk, context) {
124
+ var tmpl = dust.cache[name];
125
+ if (tmpl) {
126
+ return tmpl(chunk, context);
127
+ } else {
128
+ if (dust.onLoad) {
129
+ return chunk.map(function(chunk) {
130
+ dust.onLoad(name, function(err, src) {
131
+ if (err) return chunk.setError(err);
132
+ if (!dust.cache[name]) dust.loadSource(dust.compile(src, name));
133
+ dust.cache[name](chunk, context).end();
134
+ });
135
+ });
136
+ }
137
+ return chunk.setError(new Error("Template Not Found: " + name));
138
+ }
139
+ };
140
+
141
+ dust.loadSource = function(source, path) {
142
+ return eval(source);
143
+ };
144
+
145
+ if (Array.isArray) {
146
+ dust.isArray = Array.isArray;
147
+ } else {
148
+ dust.isArray = function(arr) {
149
+ return Object.prototype.toString.call(arr) === "[object Array]";
150
+ };
151
+ }
152
+
153
+ dust.nextTick = (function() {
154
+ if (typeof process !== "undefined") {
155
+ return process.nextTick;
156
+ } else {
157
+ return function(callback) {
158
+ setTimeout(callback,0);
159
+ };
160
+ }
161
+ } )();
162
+
163
+ dust.isEmpty = function(value) {
164
+ if (dust.isArray(value) && !value.length) return true;
165
+ if (value === 0) return false;
166
+ return (!value);
167
+ };
168
+
169
+ // apply the filter chain and return the output string
170
+ dust.filter = function(string, auto, filters) {
171
+ if (filters) {
172
+ for (var i=0, len=filters.length; i<len; i++) {
173
+ var name = filters[i];
174
+ if (name === "s") {
175
+ auto = null;
176
+ dust.log('Using unescape filter on [' + string + ']', DEBUG);
177
+ }
178
+ else if (typeof dust.filters[name] === 'function') {
179
+ string = dust.filters[name](string);
180
+ }
181
+ else {
182
+ dust.onError(new Error('Invalid filter [' + name + ']'));
183
+ }
184
+ }
185
+ }
186
+ // by default always apply the h filter, unless asked to unescape with |s
187
+ if (auto) {
188
+ string = dust.filters[auto](string);
189
+ }
190
+ return string;
191
+ };
192
+
193
+ dust.filters = {
194
+ h: function(value) { return dust.escapeHtml(value); },
195
+ j: function(value) { return dust.escapeJs(value); },
196
+ u: encodeURI,
197
+ uc: encodeURIComponent,
198
+ js: function(value) {
199
+ if (!JSON) {
200
+ dust.log('JSON is undefined. JSON stringify has not been used on [' + value + ']', WARN);
201
+ return value;
202
+ } else {
203
+ return JSON.stringify(value);
204
+ }
205
+ },
206
+ jp: function(value) {
207
+ if (!JSON) {dust.log('JSON is undefined. JSON parse has not been used on [' + value + ']', WARN);
208
+ return value;
209
+ } else {
210
+ return JSON.parse(value);
211
+ }
212
+ }
213
+ };
214
+
215
+ function Context(stack, global, blocks, templateName) {
216
+ this.stack = stack;
217
+ this.global = global;
218
+ this.blocks = blocks;
219
+ this.templateName = templateName;
220
+ }
221
+
222
+ dust.makeBase = function(global) {
223
+ return new Context(new Stack(), global);
224
+ };
225
+
226
+ Context.wrap = function(context, name) {
227
+ if (context instanceof Context) {
228
+ return context;
229
+ }
230
+ return new Context(new Stack(context), {}, null, name);
231
+ };
232
+
233
+ Context.prototype.get = function(key) {
234
+ var ctx = this.stack, value, globalValue;
235
+ dust.log('Searching for reference [{' + key + '}] in template [' + this.templateName + ']', DEBUG);
236
+ while(ctx) {
237
+ if (ctx.isObject) {
238
+ value = ctx.head[key];
239
+ if (!(value === undefined)) {
240
+ return value;
241
+ }
242
+ }
243
+ ctx = ctx.tail;
244
+ }
245
+ globalValue = this.global ? this.global[key] : undefined;
246
+ if(typeof globalValue === 'undefined') {
247
+ dust.log('Cannot find the value for reference [{' + key + '}] in template [' + this.templateName + ']');
248
+ }
249
+ return globalValue;
250
+ };
251
+
252
+ //supports dot path resolution, function wrapped apply, and searching global paths
253
+ Context.prototype.getPath = function(cur, down) {
254
+ var ctx = this.stack, ctxThis,
255
+ len = down.length,
256
+ tail = cur ? undefined : this.stack.tail;
257
+
258
+ dust.log('Searching for reference [{' + down.join('.') + '}] in template [' + this.templateName + ']', DEBUG);
259
+ if (cur && len === 0) return ctx.head;
260
+ ctx = ctx.head;
261
+ var i = 0;
262
+ while(ctx && i < len) {
263
+ ctxThis = ctx;
264
+ ctx = ctx[down[i]];
265
+ i++;
266
+ while (!ctx && !cur){
267
+ // i is the count of number of path elements matched. If > 1 then we have a partial match
268
+ // and do not continue to search for the rest of the path.
269
+ // Note: a falsey value at the end of a matched path also comes here.
270
+ // This returns the value or undefined if we just have a partial match.
271
+ if (i > 1) return ctx;
272
+ if (tail){
273
+ ctx = tail.head;
274
+ tail = tail.tail;
275
+ i=0;
276
+ } else if (!cur) {
277
+ //finally search this.global. we set cur to true to halt after
278
+ ctx = this.global;
279
+ cur = true;
280
+ i=0;
281
+ }
282
+ }
283
+ }
284
+ if (typeof ctx == 'function'){
285
+ //wrap to preserve context 'this' see #174
286
+ return function(){
287
+ return ctx.apply(ctxThis,arguments);
288
+ };
289
+ }
290
+ else {
291
+ return ctx;
292
+ }
293
+ };
294
+
295
+ Context.prototype.push = function(head, idx, len) {
296
+ return new Context(new Stack(head, this.stack, idx, len), this.global, this.blocks, this.templateName);
297
+ };
298
+
299
+ Context.prototype.rebase = function(head) {
300
+ return new Context(new Stack(head), this.global, this.blocks, this.templateName);
301
+ };
302
+
303
+ Context.prototype.current = function() {
304
+ return this.stack.head;
305
+ };
306
+
307
+ Context.prototype.getBlock = function(key, chk, ctx) {
308
+ if (typeof key === "function") {
309
+ var tempChk = new Chunk();
310
+ key = key(tempChk, this).data.join("");
311
+ }
312
+
313
+ var blocks = this.blocks;
314
+
315
+ if (!blocks) {
316
+ dust.log('No blocks for context[{' + key + '}] in template [' + this.templateName + ']', DEBUG);
317
+ return;
318
+ }
319
+ var len = blocks.length, fn;
320
+ while (len--) {
321
+ fn = blocks[len][key];
322
+ if (fn) return fn;
323
+ }
324
+ };
325
+
326
+ Context.prototype.shiftBlocks = function(locals) {
327
+ var blocks = this.blocks,
328
+ newBlocks;
329
+
330
+ if (locals) {
331
+ if (!blocks) {
332
+ newBlocks = [locals];
333
+ } else {
334
+ newBlocks = blocks.concat([locals]);
335
+ }
336
+ return new Context(this.stack, this.global, newBlocks, this.templateName);
337
+ }
338
+ return this;
339
+ };
340
+
341
+ function Stack(head, tail, idx, len) {
342
+ this.tail = tail;
343
+ this.isObject = !dust.isArray(head) && head && typeof head === "object";
344
+ this.head = head;
345
+ this.index = idx;
346
+ this.of = len;
347
+ }
348
+
349
+ function Stub(callback) {
350
+ this.head = new Chunk(this);
351
+ this.callback = callback;
352
+ this.out = '';
353
+ }
354
+
355
+ Stub.prototype.flush = function() {
356
+ var chunk = this.head;
357
+
358
+ while (chunk) {
359
+ if (chunk.flushable) {
360
+ this.out += chunk.data.join(""); //ie7 perf
361
+ } else if (chunk.error) {
362
+ this.callback(chunk.error);
363
+ dust.onError(new Error('Chunk error [' + chunk.error + '] thrown. Ceasing to render this template.'));
364
+ this.flush = function() {};
365
+ return;
366
+ } else {
367
+ return;
368
+ }
369
+ chunk = chunk.next;
370
+ this.head = chunk;
371
+ }
372
+ this.callback(null, this.out);
373
+ };
374
+
375
+ function Stream() {
376
+ this.head = new Chunk(this);
377
+ }
378
+
379
+ Stream.prototype.flush = function() {
380
+ var chunk = this.head;
381
+
382
+ while(chunk) {
383
+ if (chunk.flushable) {
384
+ this.emit('data', chunk.data.join("")); //ie7 perf
385
+ } else if (chunk.error) {
386
+ this.emit('error', chunk.error);
387
+ dust.onError(new Error('Chunk error [' + chunk.error + '] thrown. Ceasing to render this template.'));
388
+ this.flush = function() {};
389
+ return;
390
+ } else {
391
+ return;
392
+ }
393
+ chunk = chunk.next;
394
+ this.head = chunk;
395
+ }
396
+ this.emit('end');
397
+ };
398
+
399
+ Stream.prototype.emit = function(type, data) {
400
+ if (!this.events) {
401
+ dust.log('No events to emit', INFO);
402
+ return false;
403
+ }
404
+ var handler = this.events[type];
405
+ if (!handler) {
406
+ dust.log('Event type [' + type + '] does not exist', WARN);
407
+ return false;
408
+ }
409
+ if (typeof handler === 'function') {
410
+ handler(data);
411
+ } else if (dust.isArray(handler)) {
412
+ var listeners = handler.slice(0);
413
+ for (var i = 0, l = listeners.length; i < l; i++) {
414
+ listeners[i](data);
415
+ }
416
+ } else {
417
+ dust.onError(new Error('Event Handler [' + handler + '] is not of a type that is handled by emit'));
418
+ }
419
+ };
420
+
421
+ Stream.prototype.on = function(type, callback) {
422
+ if (!this.events) {
423
+ this.events = {};
424
+ }
425
+ if (!this.events[type]) {
426
+ dust.log('Event type [' + type + '] does not exist. Using just the specified callback.', WARN);
427
+ if(callback) {
428
+ this.events[type] = callback;
429
+ } else {
430
+ dust.log('Callback for type [' + type + '] does not exist. Listener not registered.', WARN);
431
+ }
432
+ } else if(typeof this.events[type] === 'function') {
433
+ this.events[type] = [this.events[type], callback];
434
+ } else {
435
+ this.events[type].push(callback);
436
+ }
437
+ return this;
438
+ };
439
+
440
+ Stream.prototype.pipe = function(stream) {
441
+ this.on("data", function(data) {
442
+ try {
443
+ stream.write(data, "utf8");
444
+ } catch (err) {
445
+ dust.onError(err, stream.head);
446
+ }
447
+ }).on("end", function() {
448
+ try {
449
+ return stream.end();
450
+ } catch (err) {
451
+ dust.onError(err, stream.head);
452
+ }
453
+ }).on("error", function(err) {
454
+ stream.error(err);
455
+ });
456
+ return this;
457
+ };
458
+
459
+ function Chunk(root, next, taps) {
460
+ this.root = root;
461
+ this.next = next;
462
+ this.data = []; //ie7 perf
463
+ this.flushable = false;
464
+ this.taps = taps;
465
+ }
466
+
467
+ Chunk.prototype.write = function(data) {
468
+ var taps = this.taps;
469
+
470
+ if (taps) {
471
+ data = taps.go(data);
472
+ }
473
+ this.data.push(data);
474
+ return this;
475
+ };
476
+
477
+ Chunk.prototype.end = function(data) {
478
+ if (data) {
479
+ this.write(data);
480
+ }
481
+ this.flushable = true;
482
+ this.root.flush();
483
+ return this;
484
+ };
485
+
486
+ Chunk.prototype.map = function(callback) {
487
+ var cursor = new Chunk(this.root, this.next, this.taps),
488
+ branch = new Chunk(this.root, cursor, this.taps);
489
+
490
+ this.next = branch;
491
+ this.flushable = true;
492
+ callback(branch);
493
+ return cursor;
494
+ };
495
+
496
+ Chunk.prototype.tap = function(tap) {
497
+ var taps = this.taps;
498
+
499
+ if (taps) {
500
+ this.taps = taps.push(tap);
501
+ } else {
502
+ this.taps = new Tap(tap);
503
+ }
504
+ return this;
505
+ };
506
+
507
+ Chunk.prototype.untap = function() {
508
+ this.taps = this.taps.tail;
509
+ return this;
510
+ };
511
+
512
+ Chunk.prototype.render = function(body, context) {
513
+ return body(this, context);
514
+ };
515
+
516
+ Chunk.prototype.reference = function(elem, context, auto, filters) {
517
+ if (typeof elem === "function") {
518
+ elem.isFunction = true;
519
+ // Changed the function calling to use apply with the current context to make sure
520
+ // that "this" is wat we expect it to be inside the function
521
+ elem = elem.apply(context.current(), [this, context, null, {auto: auto, filters: filters}]);
522
+ if (elem instanceof Chunk) {
523
+ return elem;
524
+ }
525
+ }
526
+ if (!dust.isEmpty(elem)) {
527
+ return this.write(dust.filter(elem, auto, filters));
528
+ } else {
529
+ return this;
530
+ }
531
+ };
532
+
533
+ Chunk.prototype.section = function(elem, context, bodies, params) {
534
+ // anonymous functions
535
+ if (typeof elem === "function") {
536
+ elem = elem.apply(context.current(), [this, context, bodies, params]);
537
+ // functions that return chunks are assumed to have handled the body and/or have modified the chunk
538
+ // use that return value as the current chunk and go to the next method in the chain
539
+ if (elem instanceof Chunk) {
540
+ return elem;
541
+ }
542
+ }
543
+ var body = bodies.block,
544
+ skip = bodies['else'];
545
+
546
+ // a.k.a Inline parameters in the Dust documentations
547
+ if (params) {
548
+ context = context.push(params);
549
+ }
550
+
551
+ /*
552
+ Dust's default behavior is to enumerate over the array elem, passing each object in the array to the block.
553
+ When elem resolves to a value or object instead of an array, Dust sets the current context to the value
554
+ and renders the block one time.
555
+ */
556
+ //non empty array is truthy, empty array is falsy
557
+ if (dust.isArray(elem)) {
558
+ if (body) {
559
+ var len = elem.length, chunk = this;
560
+ if (len > 0) {
561
+ // any custom helper can blow up the stack
562
+ // and store a flattened context, guard defensively
563
+ if(context.stack.head) {
564
+ context.stack.head['$len'] = len;
565
+ }
566
+ for (var i=0; i<len; i++) {
567
+ if(context.stack.head) {
568
+ context.stack.head['$idx'] = i;
569
+ }
570
+ chunk = body(chunk, context.push(elem[i], i, len));
571
+ }
572
+ if(context.stack.head) {
573
+ context.stack.head['$idx'] = undefined;
574
+ context.stack.head['$len'] = undefined;
575
+ }
576
+ return chunk;
577
+ }
578
+ else if (skip) {
579
+ return skip(this, context);
580
+ }
581
+ }
582
+ }
583
+ // true is truthy but does not change context
584
+ else if (elem === true) {
585
+ if (body) {
586
+ return body(this, context);
587
+ }
588
+ }
589
+ // everything that evaluates to true are truthy ( e.g. Non-empty strings and Empty objects are truthy. )
590
+ // zero is truthy
591
+ // for anonymous functions that did not returns a chunk, truthiness is evaluated based on the return value
592
+ //
593
+ else if (elem || elem === 0) {
594
+ if (body) return body(this, context.push(elem));
595
+ // nonexistent, scalar false value, scalar empty string, null,
596
+ // undefined are all falsy
597
+ } else if (skip) {
598
+ return skip(this, context);
599
+ }
600
+ dust.log('Not rendering section (#) block in template [' + context.templateName + '], because above key was not found', DEBUG);
601
+ return this;
602
+ };
603
+
604
+ Chunk.prototype.exists = function(elem, context, bodies) {
605
+ var body = bodies.block,
606
+ skip = bodies['else'];
607
+
608
+ if (!dust.isEmpty(elem)) {
609
+ if (body) return body(this, context);
610
+ } else if (skip) {
611
+ return skip(this, context);
612
+ }
613
+ dust.log('Not rendering exists (?) block in template [' + context.templateName + '], because above key was not found', DEBUG);
614
+ return this;
615
+ };
616
+
617
+ Chunk.prototype.notexists = function(elem, context, bodies) {
618
+ var body = bodies.block,
619
+ skip = bodies['else'];
620
+
621
+ if (dust.isEmpty(elem)) {
622
+ if (body) return body(this, context);
623
+ } else if (skip) {
624
+ return skip(this, context);
625
+ }
626
+ dust.log('Not rendering not exists (^) block check in template [' + context.templateName + '], because above key was found', DEBUG);
627
+ return this;
628
+ };
629
+
630
+ Chunk.prototype.block = function(elem, context, bodies) {
631
+ var body = bodies.block;
632
+
633
+ if (elem) {
634
+ body = elem;
635
+ }
636
+
637
+ if (body) {
638
+ return body(this, context);
639
+ }
640
+ return this;
641
+ };
642
+
643
+ Chunk.prototype.partial = function(elem, context, params) {
644
+ var partialContext;
645
+ //put the params context second to match what section does. {.} matches the current context without parameters
646
+ // start with an empty context
647
+ partialContext = dust.makeBase(context.global);
648
+ partialContext.blocks = context.blocks;
649
+ if (context.stack && context.stack.tail){
650
+ // grab the stack(tail) off of the previous context if we have it
651
+ partialContext.stack = context.stack.tail;
652
+ }
653
+ if (params){
654
+ //put params on
655
+ partialContext = partialContext.push(params);
656
+ }
657
+ // templateName can be static (string) or dynamic (function)
658
+ // e.g. {>"static_template"/}
659
+ // {>"{dynamic_template}"/}
660
+ if (elem) {
661
+ partialContext.templateName = elem;
662
+ }
663
+
664
+ //reattach the head
665
+ partialContext = partialContext.push(context.stack.head);
666
+
667
+ var partialChunk;
668
+ if (typeof elem === "function") {
669
+ partialChunk = this.capture(elem, partialContext, function(name, chunk) {
670
+ dust.load(name, chunk, partialContext).end();
671
+ });
672
+ }
673
+ else {
674
+ partialChunk = dust.load(elem, this, partialContext);
675
+ }
676
+ return partialChunk;
677
+ };
678
+
679
+ Chunk.prototype.helper = function(name, context, bodies, params) {
680
+ var chunk = this;
681
+ // handle invalid helpers, similar to invalid filters
682
+ try {
683
+ if(dust.helpers[name]) {
684
+ return dust.helpers[name](chunk, context, bodies, params);
685
+ } else {
686
+ return dust.onError(new Error('Invalid helper [' + name + ']'), chunk);
687
+ }
688
+ } catch (err) {
689
+ return dust.onError(err, chunk);
690
+ }
691
+ };
692
+
693
+ Chunk.prototype.capture = function(body, context, callback) {
694
+ return this.map(function(chunk) {
695
+ var stub = new Stub(function(err, out) {
696
+ if (err) {
697
+ chunk.setError(err);
698
+ } else {
699
+ callback(out, chunk);
700
+ }
701
+ });
702
+ body(stub.head, context).end();
703
+ });
704
+ };
705
+
706
+ Chunk.prototype.setError = function(err) {
707
+ this.error = err;
708
+ this.root.flush();
709
+ return this;
710
+ };
711
+
712
+ function Tap(head, tail) {
713
+ this.head = head;
714
+ this.tail = tail;
715
+ }
716
+
717
+ Tap.prototype.push = function(tap) {
718
+ return new Tap(tap, this);
719
+ };
720
+
721
+ Tap.prototype.go = function(value) {
722
+ var tap = this;
723
+
724
+ while(tap) {
725
+ value = tap.head(value);
726
+ tap = tap.tail;
727
+ }
728
+ return value;
729
+ };
730
+
731
+ var HCHARS = new RegExp(/[&<>\"\']/),
732
+ AMP = /&/g,
733
+ LT = /</g,
734
+ GT = />/g,
735
+ QUOT = /\"/g,
736
+ SQUOT = /\'/g;
737
+
738
+ dust.escapeHtml = function(s) {
739
+ if (typeof s === "string") {
740
+ if (!HCHARS.test(s)) {
741
+ return s;
742
+ }
743
+ return s.replace(AMP,'&amp;').replace(LT,'&lt;').replace(GT,'&gt;').replace(QUOT,'&quot;').replace(SQUOT, '&#39;');
744
+ }
745
+ return s;
746
+ };
747
+
748
+ var BS = /\\/g,
749
+ FS = /\//g,
750
+ CR = /\r/g,
751
+ LS = /\u2028/g,
752
+ PS = /\u2029/g,
753
+ NL = /\n/g,
754
+ LF = /\f/g,
755
+ SQ = /'/g,
756
+ DQ = /"/g,
757
+ TB = /\t/g;
758
+
759
+ dust.escapeJs = function(s) {
760
+ if (typeof s === "string") {
761
+ return s
762
+ .replace(BS, '\\\\')
763
+ .replace(FS, '\\/')
764
+ .replace(DQ, '\\"')
765
+ .replace(SQ, "\\'")
766
+ .replace(CR, '\\r')
767
+ .replace(LS, '\\u2028')
768
+ .replace(PS, '\\u2029')
769
+ .replace(NL, '\\n')
770
+ .replace(LF, '\\f')
771
+ .replace(TB, "\\t");
772
+ }
773
+ return s;
774
+ };
775
+
776
+ })(dust);
777
+
778
+ if (typeof exports !== "undefined") {
779
+ if (typeof process !== "undefined") {
780
+ require('./server')(dust);
781
+ }
782
+ module.exports = dust;
783
+ }
784
+ var dustCompiler = (function(dust) {
785
+
786
+ dust.compile = function(source, name) {
787
+ try {
788
+ var ast = filterAST(dust.parse(source));
789
+ return compile(ast, name);
790
+ }
791
+ catch(err)
792
+ {
793
+ if(!err.line || !err.column) throw err;
794
+ throw new SyntaxError(err.message + " At line : " + err.line + ", column : " + err.column);
795
+ }
796
+ };
797
+
798
+ function filterAST(ast) {
799
+ var context = {};
800
+ return dust.filterNode(context, ast);
801
+ };
802
+
803
+ dust.filterNode = function(context, node) {
804
+ return dust.optimizers[node[0]](context, node);
805
+ };
806
+
807
+ dust.optimizers = {
808
+ body: compactBuffers,
809
+ buffer: noop,
810
+ special: convertSpecial,
811
+ format: nullify, // TODO: convert format
812
+ reference: visit,
813
+ "#": visit,
814
+ "?": visit,
815
+ "^": visit,
816
+ "<": visit,
817
+ "+": visit,
818
+ "@": visit,
819
+ "%": visit,
820
+ partial: visit,
821
+ context: visit,
822
+ params: visit,
823
+ bodies: visit,
824
+ param: visit,
825
+ filters: noop,
826
+ key: noop,
827
+ path: noop,
828
+ literal: noop,
829
+ comment: nullify,
830
+ line: nullify,
831
+ col: nullify
832
+ };
833
+
834
+ dust.pragmas = {
835
+ esc: function(compiler, context, bodies, params) {
836
+ var old = compiler.auto;
837
+ if (!context) context = 'h';
838
+ compiler.auto = (context === 's') ? '' : context;
839
+ var out = compileParts(compiler, bodies.block);
840
+ compiler.auto = old;
841
+ return out;
842
+ }
843
+ };
844
+
845
+ function visit(context, node) {
846
+ var out = [node[0]];
847
+ for (var i=1, len=node.length; i<len; i++) {
848
+ var res = dust.filterNode(context, node[i]);
849
+ if (res) out.push(res);
850
+ }
851
+ return out;
852
+ };
853
+
854
+ // Compacts consecutive buffer nodes into a single node
855
+ function compactBuffers(context, node) {
856
+ var out = [node[0]], memo;
857
+ for (var i=1, len=node.length; i<len; i++) {
858
+ var res = dust.filterNode(context, node[i]);
859
+ if (res) {
860
+ if (res[0] === 'buffer') {
861
+ if (memo) {
862
+ memo[1] += res[1];
863
+ } else {
864
+ memo = res;
865
+ out.push(res);
866
+ }
867
+ } else {
868
+ memo = null;
869
+ out.push(res);
870
+ }
871
+ }
872
+ }
873
+ return out;
874
+ };
875
+
876
+ var specialChars = {
877
+ "s": " ",
878
+ "n": "\n",
879
+ "r": "\r",
880
+ "lb": "{",
881
+ "rb": "}"
882
+ };
883
+
884
+ function convertSpecial(context, node) { return ['buffer', specialChars[node[1]]] };
885
+ function noop(context, node) { return node };
886
+ function nullify(){};
887
+
888
+ function compile(ast, name) {
889
+ var context = {
890
+ name: name,
891
+ bodies: [],
892
+ blocks: {},
893
+ index: 0,
894
+ auto: "h"
895
+ }
896
+
897
+ return "(function(){dust.register("
898
+ + (name ? "\"" + name + "\"" : "null") + ","
899
+ + dust.compileNode(context, ast)
900
+ + ");"
901
+ + compileBlocks(context)
902
+ + compileBodies(context)
903
+ + "return body_0;"
904
+ + "})();";
905
+ };
906
+
907
+ function compileBlocks(context) {
908
+ var out = [],
909
+ blocks = context.blocks;
910
+
911
+ for (var name in blocks) {
912
+ out.push("'" + name + "':" + blocks[name]);
913
+ }
914
+ if (out.length) {
915
+ context.blocks = "ctx=ctx.shiftBlocks(blocks);";
916
+ return "var blocks={" + out.join(',') + "};";
917
+ }
918
+ return context.blocks = "";
919
+ };
920
+
921
+ function compileBodies(context) {
922
+ var out = [],
923
+ bodies = context.bodies,
924
+ blx = context.blocks;
925
+
926
+ for (var i=0, len=bodies.length; i<len; i++) {
927
+ out[i] = "function body_" + i + "(chk,ctx){"
928
+ + blx + "return chk" + bodies[i] + ";}";
929
+ }
930
+ return out.join('');
931
+ };
932
+
933
+ function compileParts(context, body) {
934
+ var parts = '';
935
+ for (var i=1, len=body.length; i<len; i++) {
936
+ parts += dust.compileNode(context, body[i]);
937
+ }
938
+ return parts;
939
+ };
940
+
941
+ dust.compileNode = function(context, node) {
942
+ return dust.nodes[node[0]](context, node);
943
+ };
944
+
945
+ dust.nodes = {
946
+ body: function(context, node) {
947
+ var id = context.index++, name = "body_" + id;
948
+ context.bodies[id] = compileParts(context, node);
949
+ return name;
950
+ },
951
+
952
+ buffer: function(context, node) {
953
+ return ".write(" + escape(node[1]) + ")";
954
+ },
955
+
956
+ format: function(context, node) {
957
+ return ".write(" + escape(node[1] + node[2]) + ")";
958
+ },
959
+
960
+ reference: function(context, node) {
961
+ return ".reference(" + dust.compileNode(context, node[1])
962
+ + ",ctx," + dust.compileNode(context, node[2]) + ")";
963
+ },
964
+
965
+ "#": function(context, node) {
966
+ return compileSection(context, node, "section");
967
+ },
968
+
969
+ "?": function(context, node) {
970
+ return compileSection(context, node, "exists");
971
+ },
972
+
973
+ "^": function(context, node) {
974
+ return compileSection(context, node, "notexists");
975
+ },
976
+
977
+ "<": function(context, node) {
978
+ var bodies = node[4];
979
+ for (var i=1, len=bodies.length; i<len; i++) {
980
+ var param = bodies[i],
981
+ type = param[1][1];
982
+ if (type === "block") {
983
+ context.blocks[node[1].text] = dust.compileNode(context, param[2]);
984
+ return '';
985
+ }
986
+ }
987
+ return '';
988
+ },
989
+
990
+ "+": function(context, node) {
991
+ if(typeof(node[1].text) === "undefined" && typeof(node[4]) === "undefined"){
992
+ return ".block(ctx.getBlock("
993
+ + dust.compileNode(context, node[1])
994
+ + ",chk, ctx)," + dust.compileNode(context, node[2]) + ", {},"
995
+ + dust.compileNode(context, node[3])
996
+ + ")";
997
+ }else {
998
+ return ".block(ctx.getBlock("
999
+ + escape(node[1].text)
1000
+ + ")," + dust.compileNode(context, node[2]) + ","
1001
+ + dust.compileNode(context, node[4]) + ","
1002
+ + dust.compileNode(context, node[3])
1003
+ + ")";
1004
+ }
1005
+ },
1006
+
1007
+ "@": function(context, node) {
1008
+ return ".helper("
1009
+ + escape(node[1].text)
1010
+ + "," + dust.compileNode(context, node[2]) + ","
1011
+ + dust.compileNode(context, node[4]) + ","
1012
+ + dust.compileNode(context, node[3])
1013
+ + ")";
1014
+ },
1015
+
1016
+ "%": function(context, node) {
1017
+ // TODO: Move these hacks into pragma precompiler
1018
+ var name = node[1][1];
1019
+ if (!dust.pragmas[name]) return '';
1020
+
1021
+ var rawBodies = node[4];
1022
+ var bodies = {};
1023
+ for (var i=1, len=rawBodies.length; i<len; i++) {
1024
+ var b = rawBodies[i];
1025
+ bodies[b[1][1]] = b[2];
1026
+ }
1027
+
1028
+ var rawParams = node[3];
1029
+ var params = {};
1030
+ for (var i=1, len=rawParams.length; i<len; i++) {
1031
+ var p = rawParams[i];
1032
+ params[p[1][1]] = p[2][1];
1033
+ }
1034
+
1035
+ var ctx = node[2][1] ? node[2][1].text : null;
1036
+
1037
+ return dust.pragmas[name](context, ctx, bodies, params);
1038
+ },
1039
+
1040
+ partial: function(context, node) {
1041
+ return ".partial("
1042
+ + dust.compileNode(context, node[1])
1043
+ + "," + dust.compileNode(context, node[2])
1044
+ + "," + dust.compileNode(context, node[3]) + ")";
1045
+ },
1046
+
1047
+ context: function(context, node) {
1048
+ if (node[1]) {
1049
+ return "ctx.rebase(" + dust.compileNode(context, node[1]) + ")";
1050
+ }
1051
+ return "ctx";
1052
+ },
1053
+
1054
+ params: function(context, node) {
1055
+ var out = [];
1056
+ for (var i=1, len=node.length; i<len; i++) {
1057
+ out.push(dust.compileNode(context, node[i]));
1058
+ }
1059
+ if (out.length) {
1060
+ return "{" + out.join(',') + "}";
1061
+ }
1062
+ return "null";
1063
+ },
1064
+
1065
+ bodies: function(context, node) {
1066
+ var out = [];
1067
+ for (var i=1, len=node.length; i<len; i++) {
1068
+ out.push(dust.compileNode(context, node[i]));
1069
+ }
1070
+ return "{" + out.join(',') + "}";
1071
+ },
1072
+
1073
+ param: function(context, node) {
1074
+ return dust.compileNode(context, node[1]) + ":" + dust.compileNode(context, node[2]);
1075
+ },
1076
+
1077
+ filters: function(context, node) {
1078
+ var list = [];
1079
+ for (var i=1, len=node.length; i<len; i++) {
1080
+ var filter = node[i];
1081
+ list.push("\"" + filter + "\"");
1082
+ }
1083
+ return "\"" + context.auto + "\""
1084
+ + (list.length ? ",[" + list.join(',') + "]" : '');
1085
+ },
1086
+
1087
+ key: function(context, node) {
1088
+ return "ctx.get(\"" + node[1] + "\")";
1089
+ },
1090
+
1091
+ path: function(context, node) {
1092
+ var current = node[1],
1093
+ keys = node[2],
1094
+ list = [];
1095
+
1096
+ for (var i=0,len=keys.length; i<len; i++) {
1097
+ if (dust.isArray(keys[i]))
1098
+ list.push(dust.compileNode(context, keys[i]));
1099
+ else
1100
+ list.push("\"" + keys[i] + "\"");
1101
+ }
1102
+ return "ctx.getPath(" + current + ",[" + list.join(',') + "])";
1103
+ },
1104
+
1105
+ literal: function(context, node) {
1106
+ return escape(node[1]);
1107
+ }
1108
+ };
1109
+
1110
+ function compileSection(context, node, cmd) {
1111
+ return "." + cmd + "("
1112
+ + dust.compileNode(context, node[1])
1113
+ + "," + dust.compileNode(context, node[2]) + ","
1114
+ + dust.compileNode(context, node[4]) + ","
1115
+ + dust.compileNode(context, node[3])
1116
+ + ")";
1117
+ };
1118
+
1119
+ var escape = (typeof JSON === "undefined")
1120
+ ? function(str) { return "\"" + dust.escapeJs(str) + "\"" }
1121
+ : JSON.stringify;
1122
+
1123
+ return dust;
1124
+
1125
+ });
1126
+
1127
+ if (typeof exports !== 'undefined') {
1128
+ module.exports = dustCompiler;
1129
+ } else {
1130
+ dustCompiler(getGlobal());
1131
+ }
1132
+ (function(dust){
1133
+
1134
+ var parser = (function(){
1135
+ /*
1136
+ * Generated by PEG.js 0.7.0.
1137
+ *
1138
+ * http://pegjs.majda.cz/
1139
+ */
1140
+
1141
+ function quote(s) {
1142
+ /*
1143
+ * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
1144
+ * string literal except for the closing quote character, backslash,
1145
+ * carriage return, line separator, paragraph separator, and line feed.
1146
+ * Any character may appear in the form of an escape sequence.
1147
+ *
1148
+ * For portability, we also escape escape all control and non-ASCII
1149
+ * characters. Note that "\0" and "\v" escape sequences are not used
1150
+ * because JSHint does not like the first and IE the second.
1151
+ */
1152
+ return '"' + s
1153
+ .replace(/\\/g, '\\\\') // backslash
1154
+ .replace(/"/g, '\\"') // closing quote character
1155
+ .replace(/\x08/g, '\\b') // backspace
1156
+ .replace(/\t/g, '\\t') // horizontal tab
1157
+ .replace(/\n/g, '\\n') // line feed
1158
+ .replace(/\f/g, '\\f') // form feed
1159
+ .replace(/\r/g, '\\r') // carriage return
1160
+ .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape)
1161
+ + '"';
1162
+ }
1163
+
1164
+ var result = {
1165
+ /*
1166
+ * Parses the input with a generated parser. If the parsing is successfull,
1167
+ * returns a value explicitly or implicitly specified by the grammar from
1168
+ * which the parser was generated (see |PEG.buildParser|). If the parsing is
1169
+ * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
1170
+ */
1171
+ parse: function(input, startRule) {
1172
+ var parseFunctions = {
1173
+ "body": parse_body,
1174
+ "part": parse_part,
1175
+ "section": parse_section,
1176
+ "sec_tag_start": parse_sec_tag_start,
1177
+ "end_tag": parse_end_tag,
1178
+ "context": parse_context,
1179
+ "params": parse_params,
1180
+ "bodies": parse_bodies,
1181
+ "reference": parse_reference,
1182
+ "partial": parse_partial,
1183
+ "filters": parse_filters,
1184
+ "special": parse_special,
1185
+ "identifier": parse_identifier,
1186
+ "number": parse_number,
1187
+ "float": parse_float,
1188
+ "integer": parse_integer,
1189
+ "path": parse_path,
1190
+ "key": parse_key,
1191
+ "array": parse_array,
1192
+ "array_part": parse_array_part,
1193
+ "inline": parse_inline,
1194
+ "inline_part": parse_inline_part,
1195
+ "buffer": parse_buffer,
1196
+ "literal": parse_literal,
1197
+ "esc": parse_esc,
1198
+ "comment": parse_comment,
1199
+ "tag": parse_tag,
1200
+ "ld": parse_ld,
1201
+ "rd": parse_rd,
1202
+ "lb": parse_lb,
1203
+ "rb": parse_rb,
1204
+ "eol": parse_eol,
1205
+ "ws": parse_ws
1206
+ };
1207
+
1208
+ if (startRule !== undefined) {
1209
+ if (parseFunctions[startRule] === undefined) {
1210
+ throw new Error("Invalid rule name: " + quote(startRule) + ".");
1211
+ }
1212
+ } else {
1213
+ startRule = "body";
1214
+ }
1215
+
1216
+ var pos = { offset: 0, line: 1, column: 1, seenCR: false };
1217
+ var reportFailures = 0;
1218
+ var rightmostFailuresPos = { offset: 0, line: 1, column: 1, seenCR: false };
1219
+ var rightmostFailuresExpected = [];
1220
+
1221
+ function padLeft(input, padding, length) {
1222
+ var result = input;
1223
+
1224
+ var padLength = length - input.length;
1225
+ for (var i = 0; i < padLength; i++) {
1226
+ result = padding + result;
1227
+ }
1228
+
1229
+ return result;
1230
+ }
1231
+
1232
+ function escape(ch) {
1233
+ var charCode = ch.charCodeAt(0);
1234
+ var escapeChar;
1235
+ var length;
1236
+
1237
+ if (charCode <= 0xFF) {
1238
+ escapeChar = 'x';
1239
+ length = 2;
1240
+ } else {
1241
+ escapeChar = 'u';
1242
+ length = 4;
1243
+ }
1244
+
1245
+ return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
1246
+ }
1247
+
1248
+ function clone(object) {
1249
+ var result = {};
1250
+ for (var key in object) {
1251
+ result[key] = object[key];
1252
+ }
1253
+ return result;
1254
+ }
1255
+
1256
+ function advance(pos, n) {
1257
+ var endOffset = pos.offset + n;
1258
+
1259
+ for (var offset = pos.offset; offset < endOffset; offset++) {
1260
+ var ch = input.charAt(offset);
1261
+ if (ch === "\n") {
1262
+ if (!pos.seenCR) { pos.line++; }
1263
+ pos.column = 1;
1264
+ pos.seenCR = false;
1265
+ } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
1266
+ pos.line++;
1267
+ pos.column = 1;
1268
+ pos.seenCR = true;
1269
+ } else {
1270
+ pos.column++;
1271
+ pos.seenCR = false;
1272
+ }
1273
+ }
1274
+
1275
+ pos.offset += n;
1276
+ }
1277
+
1278
+ function matchFailed(failure) {
1279
+ if (pos.offset < rightmostFailuresPos.offset) {
1280
+ return;
1281
+ }
1282
+
1283
+ if (pos.offset > rightmostFailuresPos.offset) {
1284
+ rightmostFailuresPos = clone(pos);
1285
+ rightmostFailuresExpected = [];
1286
+ }
1287
+
1288
+ rightmostFailuresExpected.push(failure);
1289
+ }
1290
+
1291
+ function parse_body() {
1292
+ var result0, result1;
1293
+ var pos0;
1294
+
1295
+ pos0 = clone(pos);
1296
+ result0 = [];
1297
+ result1 = parse_part();
1298
+ while (result1 !== null) {
1299
+ result0.push(result1);
1300
+ result1 = parse_part();
1301
+ }
1302
+ if (result0 !== null) {
1303
+ result0 = (function(offset, line, column, p) { return ["body"].concat(p).concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0);
1304
+ }
1305
+ if (result0 === null) {
1306
+ pos = clone(pos0);
1307
+ }
1308
+ return result0;
1309
+ }
1310
+
1311
+ function parse_part() {
1312
+ var result0;
1313
+
1314
+ result0 = parse_comment();
1315
+ if (result0 === null) {
1316
+ result0 = parse_section();
1317
+ if (result0 === null) {
1318
+ result0 = parse_partial();
1319
+ if (result0 === null) {
1320
+ result0 = parse_special();
1321
+ if (result0 === null) {
1322
+ result0 = parse_reference();
1323
+ if (result0 === null) {
1324
+ result0 = parse_buffer();
1325
+ }
1326
+ }
1327
+ }
1328
+ }
1329
+ }
1330
+ return result0;
1331
+ }
1332
+
1333
+ function parse_section() {
1334
+ var result0, result1, result2, result3, result4, result5, result6;
1335
+ var pos0, pos1;
1336
+
1337
+ reportFailures++;
1338
+ pos0 = clone(pos);
1339
+ pos1 = clone(pos);
1340
+ result0 = parse_sec_tag_start();
1341
+ if (result0 !== null) {
1342
+ result1 = [];
1343
+ result2 = parse_ws();
1344
+ while (result2 !== null) {
1345
+ result1.push(result2);
1346
+ result2 = parse_ws();
1347
+ }
1348
+ if (result1 !== null) {
1349
+ result2 = parse_rd();
1350
+ if (result2 !== null) {
1351
+ result3 = parse_body();
1352
+ if (result3 !== null) {
1353
+ result4 = parse_bodies();
1354
+ if (result4 !== null) {
1355
+ result5 = parse_end_tag();
1356
+ result5 = result5 !== null ? result5 : "";
1357
+ if (result5 !== null) {
1358
+ result6 = (function(offset, line, column, t, b, e, n) {if( (!n) || (t[1].text !== n.text) ) { throw new Error("Expected end tag for "+t[1].text+" but it was not found. At line : "+line+", column : " + column)} return true;})(pos.offset, pos.line, pos.column, result0, result3, result4, result5) ? "" : null;
1359
+ if (result6 !== null) {
1360
+ result0 = [result0, result1, result2, result3, result4, result5, result6];
1361
+ } else {
1362
+ result0 = null;
1363
+ pos = clone(pos1);
1364
+ }
1365
+ } else {
1366
+ result0 = null;
1367
+ pos = clone(pos1);
1368
+ }
1369
+ } else {
1370
+ result0 = null;
1371
+ pos = clone(pos1);
1372
+ }
1373
+ } else {
1374
+ result0 = null;
1375
+ pos = clone(pos1);
1376
+ }
1377
+ } else {
1378
+ result0 = null;
1379
+ pos = clone(pos1);
1380
+ }
1381
+ } else {
1382
+ result0 = null;
1383
+ pos = clone(pos1);
1384
+ }
1385
+ } else {
1386
+ result0 = null;
1387
+ pos = clone(pos1);
1388
+ }
1389
+ if (result0 !== null) {
1390
+ result0 = (function(offset, line, column, t, b, e, n) { e.push(["param", ["literal", "block"], b]); t.push(e); return t.concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[0], result0[3], result0[4], result0[5]);
1391
+ }
1392
+ if (result0 === null) {
1393
+ pos = clone(pos0);
1394
+ }
1395
+ if (result0 === null) {
1396
+ pos0 = clone(pos);
1397
+ pos1 = clone(pos);
1398
+ result0 = parse_sec_tag_start();
1399
+ if (result0 !== null) {
1400
+ result1 = [];
1401
+ result2 = parse_ws();
1402
+ while (result2 !== null) {
1403
+ result1.push(result2);
1404
+ result2 = parse_ws();
1405
+ }
1406
+ if (result1 !== null) {
1407
+ if (input.charCodeAt(pos.offset) === 47) {
1408
+ result2 = "/";
1409
+ advance(pos, 1);
1410
+ } else {
1411
+ result2 = null;
1412
+ if (reportFailures === 0) {
1413
+ matchFailed("\"/\"");
1414
+ }
1415
+ }
1416
+ if (result2 !== null) {
1417
+ result3 = parse_rd();
1418
+ if (result3 !== null) {
1419
+ result0 = [result0, result1, result2, result3];
1420
+ } else {
1421
+ result0 = null;
1422
+ pos = clone(pos1);
1423
+ }
1424
+ } else {
1425
+ result0 = null;
1426
+ pos = clone(pos1);
1427
+ }
1428
+ } else {
1429
+ result0 = null;
1430
+ pos = clone(pos1);
1431
+ }
1432
+ } else {
1433
+ result0 = null;
1434
+ pos = clone(pos1);
1435
+ }
1436
+ if (result0 !== null) {
1437
+ result0 = (function(offset, line, column, t) { t.push(["bodies"]); return t.concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[0]);
1438
+ }
1439
+ if (result0 === null) {
1440
+ pos = clone(pos0);
1441
+ }
1442
+ }
1443
+ reportFailures--;
1444
+ if (reportFailures === 0 && result0 === null) {
1445
+ matchFailed("section");
1446
+ }
1447
+ return result0;
1448
+ }
1449
+
1450
+ function parse_sec_tag_start() {
1451
+ var result0, result1, result2, result3, result4, result5;
1452
+ var pos0, pos1;
1453
+
1454
+ pos0 = clone(pos);
1455
+ pos1 = clone(pos);
1456
+ result0 = parse_ld();
1457
+ if (result0 !== null) {
1458
+ if (/^[#?^<+@%]/.test(input.charAt(pos.offset))) {
1459
+ result1 = input.charAt(pos.offset);
1460
+ advance(pos, 1);
1461
+ } else {
1462
+ result1 = null;
1463
+ if (reportFailures === 0) {
1464
+ matchFailed("[#?^<+@%]");
1465
+ }
1466
+ }
1467
+ if (result1 !== null) {
1468
+ result2 = [];
1469
+ result3 = parse_ws();
1470
+ while (result3 !== null) {
1471
+ result2.push(result3);
1472
+ result3 = parse_ws();
1473
+ }
1474
+ if (result2 !== null) {
1475
+ result3 = parse_identifier();
1476
+ if (result3 !== null) {
1477
+ result4 = parse_context();
1478
+ if (result4 !== null) {
1479
+ result5 = parse_params();
1480
+ if (result5 !== null) {
1481
+ result0 = [result0, result1, result2, result3, result4, result5];
1482
+ } else {
1483
+ result0 = null;
1484
+ pos = clone(pos1);
1485
+ }
1486
+ } else {
1487
+ result0 = null;
1488
+ pos = clone(pos1);
1489
+ }
1490
+ } else {
1491
+ result0 = null;
1492
+ pos = clone(pos1);
1493
+ }
1494
+ } else {
1495
+ result0 = null;
1496
+ pos = clone(pos1);
1497
+ }
1498
+ } else {
1499
+ result0 = null;
1500
+ pos = clone(pos1);
1501
+ }
1502
+ } else {
1503
+ result0 = null;
1504
+ pos = clone(pos1);
1505
+ }
1506
+ if (result0 !== null) {
1507
+ result0 = (function(offset, line, column, t, n, c, p) { return [t, n, c, p] })(pos0.offset, pos0.line, pos0.column, result0[1], result0[3], result0[4], result0[5]);
1508
+ }
1509
+ if (result0 === null) {
1510
+ pos = clone(pos0);
1511
+ }
1512
+ return result0;
1513
+ }
1514
+
1515
+ function parse_end_tag() {
1516
+ var result0, result1, result2, result3, result4, result5;
1517
+ var pos0, pos1;
1518
+
1519
+ reportFailures++;
1520
+ pos0 = clone(pos);
1521
+ pos1 = clone(pos);
1522
+ result0 = parse_ld();
1523
+ if (result0 !== null) {
1524
+ if (input.charCodeAt(pos.offset) === 47) {
1525
+ result1 = "/";
1526
+ advance(pos, 1);
1527
+ } else {
1528
+ result1 = null;
1529
+ if (reportFailures === 0) {
1530
+ matchFailed("\"/\"");
1531
+ }
1532
+ }
1533
+ if (result1 !== null) {
1534
+ result2 = [];
1535
+ result3 = parse_ws();
1536
+ while (result3 !== null) {
1537
+ result2.push(result3);
1538
+ result3 = parse_ws();
1539
+ }
1540
+ if (result2 !== null) {
1541
+ result3 = parse_identifier();
1542
+ if (result3 !== null) {
1543
+ result4 = [];
1544
+ result5 = parse_ws();
1545
+ while (result5 !== null) {
1546
+ result4.push(result5);
1547
+ result5 = parse_ws();
1548
+ }
1549
+ if (result4 !== null) {
1550
+ result5 = parse_rd();
1551
+ if (result5 !== null) {
1552
+ result0 = [result0, result1, result2, result3, result4, result5];
1553
+ } else {
1554
+ result0 = null;
1555
+ pos = clone(pos1);
1556
+ }
1557
+ } else {
1558
+ result0 = null;
1559
+ pos = clone(pos1);
1560
+ }
1561
+ } else {
1562
+ result0 = null;
1563
+ pos = clone(pos1);
1564
+ }
1565
+ } else {
1566
+ result0 = null;
1567
+ pos = clone(pos1);
1568
+ }
1569
+ } else {
1570
+ result0 = null;
1571
+ pos = clone(pos1);
1572
+ }
1573
+ } else {
1574
+ result0 = null;
1575
+ pos = clone(pos1);
1576
+ }
1577
+ if (result0 !== null) {
1578
+ result0 = (function(offset, line, column, n) { return n })(pos0.offset, pos0.line, pos0.column, result0[3]);
1579
+ }
1580
+ if (result0 === null) {
1581
+ pos = clone(pos0);
1582
+ }
1583
+ reportFailures--;
1584
+ if (reportFailures === 0 && result0 === null) {
1585
+ matchFailed("end tag");
1586
+ }
1587
+ return result0;
1588
+ }
1589
+
1590
+ function parse_context() {
1591
+ var result0, result1;
1592
+ var pos0, pos1, pos2;
1593
+
1594
+ pos0 = clone(pos);
1595
+ pos1 = clone(pos);
1596
+ pos2 = clone(pos);
1597
+ if (input.charCodeAt(pos.offset) === 58) {
1598
+ result0 = ":";
1599
+ advance(pos, 1);
1600
+ } else {
1601
+ result0 = null;
1602
+ if (reportFailures === 0) {
1603
+ matchFailed("\":\"");
1604
+ }
1605
+ }
1606
+ if (result0 !== null) {
1607
+ result1 = parse_identifier();
1608
+ if (result1 !== null) {
1609
+ result0 = [result0, result1];
1610
+ } else {
1611
+ result0 = null;
1612
+ pos = clone(pos2);
1613
+ }
1614
+ } else {
1615
+ result0 = null;
1616
+ pos = clone(pos2);
1617
+ }
1618
+ if (result0 !== null) {
1619
+ result0 = (function(offset, line, column, n) {return n})(pos1.offset, pos1.line, pos1.column, result0[1]);
1620
+ }
1621
+ if (result0 === null) {
1622
+ pos = clone(pos1);
1623
+ }
1624
+ result0 = result0 !== null ? result0 : "";
1625
+ if (result0 !== null) {
1626
+ result0 = (function(offset, line, column, n) { return n ? ["context", n] : ["context"] })(pos0.offset, pos0.line, pos0.column, result0);
1627
+ }
1628
+ if (result0 === null) {
1629
+ pos = clone(pos0);
1630
+ }
1631
+ return result0;
1632
+ }
1633
+
1634
+ function parse_params() {
1635
+ var result0, result1, result2, result3, result4;
1636
+ var pos0, pos1, pos2;
1637
+
1638
+ reportFailures++;
1639
+ pos0 = clone(pos);
1640
+ result0 = [];
1641
+ pos1 = clone(pos);
1642
+ pos2 = clone(pos);
1643
+ result2 = parse_ws();
1644
+ if (result2 !== null) {
1645
+ result1 = [];
1646
+ while (result2 !== null) {
1647
+ result1.push(result2);
1648
+ result2 = parse_ws();
1649
+ }
1650
+ } else {
1651
+ result1 = null;
1652
+ }
1653
+ if (result1 !== null) {
1654
+ result2 = parse_key();
1655
+ if (result2 !== null) {
1656
+ if (input.charCodeAt(pos.offset) === 61) {
1657
+ result3 = "=";
1658
+ advance(pos, 1);
1659
+ } else {
1660
+ result3 = null;
1661
+ if (reportFailures === 0) {
1662
+ matchFailed("\"=\"");
1663
+ }
1664
+ }
1665
+ if (result3 !== null) {
1666
+ result4 = parse_number();
1667
+ if (result4 === null) {
1668
+ result4 = parse_identifier();
1669
+ if (result4 === null) {
1670
+ result4 = parse_inline();
1671
+ }
1672
+ }
1673
+ if (result4 !== null) {
1674
+ result1 = [result1, result2, result3, result4];
1675
+ } else {
1676
+ result1 = null;
1677
+ pos = clone(pos2);
1678
+ }
1679
+ } else {
1680
+ result1 = null;
1681
+ pos = clone(pos2);
1682
+ }
1683
+ } else {
1684
+ result1 = null;
1685
+ pos = clone(pos2);
1686
+ }
1687
+ } else {
1688
+ result1 = null;
1689
+ pos = clone(pos2);
1690
+ }
1691
+ if (result1 !== null) {
1692
+ result1 = (function(offset, line, column, k, v) {return ["param", ["literal", k], v]})(pos1.offset, pos1.line, pos1.column, result1[1], result1[3]);
1693
+ }
1694
+ if (result1 === null) {
1695
+ pos = clone(pos1);
1696
+ }
1697
+ while (result1 !== null) {
1698
+ result0.push(result1);
1699
+ pos1 = clone(pos);
1700
+ pos2 = clone(pos);
1701
+ result2 = parse_ws();
1702
+ if (result2 !== null) {
1703
+ result1 = [];
1704
+ while (result2 !== null) {
1705
+ result1.push(result2);
1706
+ result2 = parse_ws();
1707
+ }
1708
+ } else {
1709
+ result1 = null;
1710
+ }
1711
+ if (result1 !== null) {
1712
+ result2 = parse_key();
1713
+ if (result2 !== null) {
1714
+ if (input.charCodeAt(pos.offset) === 61) {
1715
+ result3 = "=";
1716
+ advance(pos, 1);
1717
+ } else {
1718
+ result3 = null;
1719
+ if (reportFailures === 0) {
1720
+ matchFailed("\"=\"");
1721
+ }
1722
+ }
1723
+ if (result3 !== null) {
1724
+ result4 = parse_number();
1725
+ if (result4 === null) {
1726
+ result4 = parse_identifier();
1727
+ if (result4 === null) {
1728
+ result4 = parse_inline();
1729
+ }
1730
+ }
1731
+ if (result4 !== null) {
1732
+ result1 = [result1, result2, result3, result4];
1733
+ } else {
1734
+ result1 = null;
1735
+ pos = clone(pos2);
1736
+ }
1737
+ } else {
1738
+ result1 = null;
1739
+ pos = clone(pos2);
1740
+ }
1741
+ } else {
1742
+ result1 = null;
1743
+ pos = clone(pos2);
1744
+ }
1745
+ } else {
1746
+ result1 = null;
1747
+ pos = clone(pos2);
1748
+ }
1749
+ if (result1 !== null) {
1750
+ result1 = (function(offset, line, column, k, v) {return ["param", ["literal", k], v]})(pos1.offset, pos1.line, pos1.column, result1[1], result1[3]);
1751
+ }
1752
+ if (result1 === null) {
1753
+ pos = clone(pos1);
1754
+ }
1755
+ }
1756
+ if (result0 !== null) {
1757
+ result0 = (function(offset, line, column, p) { return ["params"].concat(p) })(pos0.offset, pos0.line, pos0.column, result0);
1758
+ }
1759
+ if (result0 === null) {
1760
+ pos = clone(pos0);
1761
+ }
1762
+ reportFailures--;
1763
+ if (reportFailures === 0 && result0 === null) {
1764
+ matchFailed("params");
1765
+ }
1766
+ return result0;
1767
+ }
1768
+
1769
+ function parse_bodies() {
1770
+ var result0, result1, result2, result3, result4, result5;
1771
+ var pos0, pos1, pos2;
1772
+
1773
+ reportFailures++;
1774
+ pos0 = clone(pos);
1775
+ result0 = [];
1776
+ pos1 = clone(pos);
1777
+ pos2 = clone(pos);
1778
+ result1 = parse_ld();
1779
+ if (result1 !== null) {
1780
+ if (input.charCodeAt(pos.offset) === 58) {
1781
+ result2 = ":";
1782
+ advance(pos, 1);
1783
+ } else {
1784
+ result2 = null;
1785
+ if (reportFailures === 0) {
1786
+ matchFailed("\":\"");
1787
+ }
1788
+ }
1789
+ if (result2 !== null) {
1790
+ result3 = parse_key();
1791
+ if (result3 !== null) {
1792
+ result4 = parse_rd();
1793
+ if (result4 !== null) {
1794
+ result5 = parse_body();
1795
+ if (result5 !== null) {
1796
+ result1 = [result1, result2, result3, result4, result5];
1797
+ } else {
1798
+ result1 = null;
1799
+ pos = clone(pos2);
1800
+ }
1801
+ } else {
1802
+ result1 = null;
1803
+ pos = clone(pos2);
1804
+ }
1805
+ } else {
1806
+ result1 = null;
1807
+ pos = clone(pos2);
1808
+ }
1809
+ } else {
1810
+ result1 = null;
1811
+ pos = clone(pos2);
1812
+ }
1813
+ } else {
1814
+ result1 = null;
1815
+ pos = clone(pos2);
1816
+ }
1817
+ if (result1 !== null) {
1818
+ result1 = (function(offset, line, column, k, v) {return ["param", ["literal", k], v]})(pos1.offset, pos1.line, pos1.column, result1[2], result1[4]);
1819
+ }
1820
+ if (result1 === null) {
1821
+ pos = clone(pos1);
1822
+ }
1823
+ while (result1 !== null) {
1824
+ result0.push(result1);
1825
+ pos1 = clone(pos);
1826
+ pos2 = clone(pos);
1827
+ result1 = parse_ld();
1828
+ if (result1 !== null) {
1829
+ if (input.charCodeAt(pos.offset) === 58) {
1830
+ result2 = ":";
1831
+ advance(pos, 1);
1832
+ } else {
1833
+ result2 = null;
1834
+ if (reportFailures === 0) {
1835
+ matchFailed("\":\"");
1836
+ }
1837
+ }
1838
+ if (result2 !== null) {
1839
+ result3 = parse_key();
1840
+ if (result3 !== null) {
1841
+ result4 = parse_rd();
1842
+ if (result4 !== null) {
1843
+ result5 = parse_body();
1844
+ if (result5 !== null) {
1845
+ result1 = [result1, result2, result3, result4, result5];
1846
+ } else {
1847
+ result1 = null;
1848
+ pos = clone(pos2);
1849
+ }
1850
+ } else {
1851
+ result1 = null;
1852
+ pos = clone(pos2);
1853
+ }
1854
+ } else {
1855
+ result1 = null;
1856
+ pos = clone(pos2);
1857
+ }
1858
+ } else {
1859
+ result1 = null;
1860
+ pos = clone(pos2);
1861
+ }
1862
+ } else {
1863
+ result1 = null;
1864
+ pos = clone(pos2);
1865
+ }
1866
+ if (result1 !== null) {
1867
+ result1 = (function(offset, line, column, k, v) {return ["param", ["literal", k], v]})(pos1.offset, pos1.line, pos1.column, result1[2], result1[4]);
1868
+ }
1869
+ if (result1 === null) {
1870
+ pos = clone(pos1);
1871
+ }
1872
+ }
1873
+ if (result0 !== null) {
1874
+ result0 = (function(offset, line, column, p) { return ["bodies"].concat(p) })(pos0.offset, pos0.line, pos0.column, result0);
1875
+ }
1876
+ if (result0 === null) {
1877
+ pos = clone(pos0);
1878
+ }
1879
+ reportFailures--;
1880
+ if (reportFailures === 0 && result0 === null) {
1881
+ matchFailed("bodies");
1882
+ }
1883
+ return result0;
1884
+ }
1885
+
1886
+ function parse_reference() {
1887
+ var result0, result1, result2, result3;
1888
+ var pos0, pos1;
1889
+
1890
+ reportFailures++;
1891
+ pos0 = clone(pos);
1892
+ pos1 = clone(pos);
1893
+ result0 = parse_ld();
1894
+ if (result0 !== null) {
1895
+ result1 = parse_identifier();
1896
+ if (result1 !== null) {
1897
+ result2 = parse_filters();
1898
+ if (result2 !== null) {
1899
+ result3 = parse_rd();
1900
+ if (result3 !== null) {
1901
+ result0 = [result0, result1, result2, result3];
1902
+ } else {
1903
+ result0 = null;
1904
+ pos = clone(pos1);
1905
+ }
1906
+ } else {
1907
+ result0 = null;
1908
+ pos = clone(pos1);
1909
+ }
1910
+ } else {
1911
+ result0 = null;
1912
+ pos = clone(pos1);
1913
+ }
1914
+ } else {
1915
+ result0 = null;
1916
+ pos = clone(pos1);
1917
+ }
1918
+ if (result0 !== null) {
1919
+ result0 = (function(offset, line, column, n, f) { return ["reference", n, f].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]);
1920
+ }
1921
+ if (result0 === null) {
1922
+ pos = clone(pos0);
1923
+ }
1924
+ reportFailures--;
1925
+ if (reportFailures === 0 && result0 === null) {
1926
+ matchFailed("reference");
1927
+ }
1928
+ return result0;
1929
+ }
1930
+
1931
+ function parse_partial() {
1932
+ var result0, result1, result2, result3, result4, result5, result6, result7, result8;
1933
+ var pos0, pos1, pos2;
1934
+
1935
+ reportFailures++;
1936
+ pos0 = clone(pos);
1937
+ pos1 = clone(pos);
1938
+ result0 = parse_ld();
1939
+ if (result0 !== null) {
1940
+ if (input.charCodeAt(pos.offset) === 62) {
1941
+ result1 = ">";
1942
+ advance(pos, 1);
1943
+ } else {
1944
+ result1 = null;
1945
+ if (reportFailures === 0) {
1946
+ matchFailed("\">\"");
1947
+ }
1948
+ }
1949
+ if (result1 === null) {
1950
+ if (input.charCodeAt(pos.offset) === 43) {
1951
+ result1 = "+";
1952
+ advance(pos, 1);
1953
+ } else {
1954
+ result1 = null;
1955
+ if (reportFailures === 0) {
1956
+ matchFailed("\"+\"");
1957
+ }
1958
+ }
1959
+ }
1960
+ if (result1 !== null) {
1961
+ result2 = [];
1962
+ result3 = parse_ws();
1963
+ while (result3 !== null) {
1964
+ result2.push(result3);
1965
+ result3 = parse_ws();
1966
+ }
1967
+ if (result2 !== null) {
1968
+ pos2 = clone(pos);
1969
+ result3 = parse_key();
1970
+ if (result3 !== null) {
1971
+ result3 = (function(offset, line, column, k) {return ["literal", k]})(pos2.offset, pos2.line, pos2.column, result3);
1972
+ }
1973
+ if (result3 === null) {
1974
+ pos = clone(pos2);
1975
+ }
1976
+ if (result3 === null) {
1977
+ result3 = parse_inline();
1978
+ }
1979
+ if (result3 !== null) {
1980
+ result4 = parse_context();
1981
+ if (result4 !== null) {
1982
+ result5 = parse_params();
1983
+ if (result5 !== null) {
1984
+ result6 = [];
1985
+ result7 = parse_ws();
1986
+ while (result7 !== null) {
1987
+ result6.push(result7);
1988
+ result7 = parse_ws();
1989
+ }
1990
+ if (result6 !== null) {
1991
+ if (input.charCodeAt(pos.offset) === 47) {
1992
+ result7 = "/";
1993
+ advance(pos, 1);
1994
+ } else {
1995
+ result7 = null;
1996
+ if (reportFailures === 0) {
1997
+ matchFailed("\"/\"");
1998
+ }
1999
+ }
2000
+ if (result7 !== null) {
2001
+ result8 = parse_rd();
2002
+ if (result8 !== null) {
2003
+ result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
2004
+ } else {
2005
+ result0 = null;
2006
+ pos = clone(pos1);
2007
+ }
2008
+ } else {
2009
+ result0 = null;
2010
+ pos = clone(pos1);
2011
+ }
2012
+ } else {
2013
+ result0 = null;
2014
+ pos = clone(pos1);
2015
+ }
2016
+ } else {
2017
+ result0 = null;
2018
+ pos = clone(pos1);
2019
+ }
2020
+ } else {
2021
+ result0 = null;
2022
+ pos = clone(pos1);
2023
+ }
2024
+ } else {
2025
+ result0 = null;
2026
+ pos = clone(pos1);
2027
+ }
2028
+ } else {
2029
+ result0 = null;
2030
+ pos = clone(pos1);
2031
+ }
2032
+ } else {
2033
+ result0 = null;
2034
+ pos = clone(pos1);
2035
+ }
2036
+ } else {
2037
+ result0 = null;
2038
+ pos = clone(pos1);
2039
+ }
2040
+ if (result0 !== null) {
2041
+ result0 = (function(offset, line, column, s, n, c, p) { var key = (s ===">")? "partial" : s; return [key, n, c, p].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1], result0[3], result0[4], result0[5]);
2042
+ }
2043
+ if (result0 === null) {
2044
+ pos = clone(pos0);
2045
+ }
2046
+ reportFailures--;
2047
+ if (reportFailures === 0 && result0 === null) {
2048
+ matchFailed("partial");
2049
+ }
2050
+ return result0;
2051
+ }
2052
+
2053
+ function parse_filters() {
2054
+ var result0, result1, result2;
2055
+ var pos0, pos1, pos2;
2056
+
2057
+ reportFailures++;
2058
+ pos0 = clone(pos);
2059
+ result0 = [];
2060
+ pos1 = clone(pos);
2061
+ pos2 = clone(pos);
2062
+ if (input.charCodeAt(pos.offset) === 124) {
2063
+ result1 = "|";
2064
+ advance(pos, 1);
2065
+ } else {
2066
+ result1 = null;
2067
+ if (reportFailures === 0) {
2068
+ matchFailed("\"|\"");
2069
+ }
2070
+ }
2071
+ if (result1 !== null) {
2072
+ result2 = parse_key();
2073
+ if (result2 !== null) {
2074
+ result1 = [result1, result2];
2075
+ } else {
2076
+ result1 = null;
2077
+ pos = clone(pos2);
2078
+ }
2079
+ } else {
2080
+ result1 = null;
2081
+ pos = clone(pos2);
2082
+ }
2083
+ if (result1 !== null) {
2084
+ result1 = (function(offset, line, column, n) {return n})(pos1.offset, pos1.line, pos1.column, result1[1]);
2085
+ }
2086
+ if (result1 === null) {
2087
+ pos = clone(pos1);
2088
+ }
2089
+ while (result1 !== null) {
2090
+ result0.push(result1);
2091
+ pos1 = clone(pos);
2092
+ pos2 = clone(pos);
2093
+ if (input.charCodeAt(pos.offset) === 124) {
2094
+ result1 = "|";
2095
+ advance(pos, 1);
2096
+ } else {
2097
+ result1 = null;
2098
+ if (reportFailures === 0) {
2099
+ matchFailed("\"|\"");
2100
+ }
2101
+ }
2102
+ if (result1 !== null) {
2103
+ result2 = parse_key();
2104
+ if (result2 !== null) {
2105
+ result1 = [result1, result2];
2106
+ } else {
2107
+ result1 = null;
2108
+ pos = clone(pos2);
2109
+ }
2110
+ } else {
2111
+ result1 = null;
2112
+ pos = clone(pos2);
2113
+ }
2114
+ if (result1 !== null) {
2115
+ result1 = (function(offset, line, column, n) {return n})(pos1.offset, pos1.line, pos1.column, result1[1]);
2116
+ }
2117
+ if (result1 === null) {
2118
+ pos = clone(pos1);
2119
+ }
2120
+ }
2121
+ if (result0 !== null) {
2122
+ result0 = (function(offset, line, column, f) { return ["filters"].concat(f) })(pos0.offset, pos0.line, pos0.column, result0);
2123
+ }
2124
+ if (result0 === null) {
2125
+ pos = clone(pos0);
2126
+ }
2127
+ reportFailures--;
2128
+ if (reportFailures === 0 && result0 === null) {
2129
+ matchFailed("filters");
2130
+ }
2131
+ return result0;
2132
+ }
2133
+
2134
+ function parse_special() {
2135
+ var result0, result1, result2, result3;
2136
+ var pos0, pos1;
2137
+
2138
+ reportFailures++;
2139
+ pos0 = clone(pos);
2140
+ pos1 = clone(pos);
2141
+ result0 = parse_ld();
2142
+ if (result0 !== null) {
2143
+ if (input.charCodeAt(pos.offset) === 126) {
2144
+ result1 = "~";
2145
+ advance(pos, 1);
2146
+ } else {
2147
+ result1 = null;
2148
+ if (reportFailures === 0) {
2149
+ matchFailed("\"~\"");
2150
+ }
2151
+ }
2152
+ if (result1 !== null) {
2153
+ result2 = parse_key();
2154
+ if (result2 !== null) {
2155
+ result3 = parse_rd();
2156
+ if (result3 !== null) {
2157
+ result0 = [result0, result1, result2, result3];
2158
+ } else {
2159
+ result0 = null;
2160
+ pos = clone(pos1);
2161
+ }
2162
+ } else {
2163
+ result0 = null;
2164
+ pos = clone(pos1);
2165
+ }
2166
+ } else {
2167
+ result0 = null;
2168
+ pos = clone(pos1);
2169
+ }
2170
+ } else {
2171
+ result0 = null;
2172
+ pos = clone(pos1);
2173
+ }
2174
+ if (result0 !== null) {
2175
+ result0 = (function(offset, line, column, k) { return ["special", k].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[2]);
2176
+ }
2177
+ if (result0 === null) {
2178
+ pos = clone(pos0);
2179
+ }
2180
+ reportFailures--;
2181
+ if (reportFailures === 0 && result0 === null) {
2182
+ matchFailed("special");
2183
+ }
2184
+ return result0;
2185
+ }
2186
+
2187
+ function parse_identifier() {
2188
+ var result0;
2189
+ var pos0;
2190
+
2191
+ reportFailures++;
2192
+ pos0 = clone(pos);
2193
+ result0 = parse_path();
2194
+ if (result0 !== null) {
2195
+ result0 = (function(offset, line, column, p) { var arr = ["path"].concat(p); arr.text = p[1].join('.'); return arr; })(pos0.offset, pos0.line, pos0.column, result0);
2196
+ }
2197
+ if (result0 === null) {
2198
+ pos = clone(pos0);
2199
+ }
2200
+ if (result0 === null) {
2201
+ pos0 = clone(pos);
2202
+ result0 = parse_key();
2203
+ if (result0 !== null) {
2204
+ result0 = (function(offset, line, column, k) { var arr = ["key", k]; arr.text = k; return arr; })(pos0.offset, pos0.line, pos0.column, result0);
2205
+ }
2206
+ if (result0 === null) {
2207
+ pos = clone(pos0);
2208
+ }
2209
+ }
2210
+ reportFailures--;
2211
+ if (reportFailures === 0 && result0 === null) {
2212
+ matchFailed("identifier");
2213
+ }
2214
+ return result0;
2215
+ }
2216
+
2217
+ function parse_number() {
2218
+ var result0;
2219
+ var pos0;
2220
+
2221
+ reportFailures++;
2222
+ pos0 = clone(pos);
2223
+ result0 = parse_float();
2224
+ if (result0 === null) {
2225
+ result0 = parse_integer();
2226
+ }
2227
+ if (result0 !== null) {
2228
+ result0 = (function(offset, line, column, n) { return ['literal', n]; })(pos0.offset, pos0.line, pos0.column, result0);
2229
+ }
2230
+ if (result0 === null) {
2231
+ pos = clone(pos0);
2232
+ }
2233
+ reportFailures--;
2234
+ if (reportFailures === 0 && result0 === null) {
2235
+ matchFailed("number");
2236
+ }
2237
+ return result0;
2238
+ }
2239
+
2240
+ function parse_float() {
2241
+ var result0, result1, result2, result3;
2242
+ var pos0, pos1;
2243
+
2244
+ reportFailures++;
2245
+ pos0 = clone(pos);
2246
+ pos1 = clone(pos);
2247
+ result0 = parse_integer();
2248
+ if (result0 !== null) {
2249
+ if (input.charCodeAt(pos.offset) === 46) {
2250
+ result1 = ".";
2251
+ advance(pos, 1);
2252
+ } else {
2253
+ result1 = null;
2254
+ if (reportFailures === 0) {
2255
+ matchFailed("\".\"");
2256
+ }
2257
+ }
2258
+ if (result1 !== null) {
2259
+ result3 = parse_integer();
2260
+ if (result3 !== null) {
2261
+ result2 = [];
2262
+ while (result3 !== null) {
2263
+ result2.push(result3);
2264
+ result3 = parse_integer();
2265
+ }
2266
+ } else {
2267
+ result2 = null;
2268
+ }
2269
+ if (result2 !== null) {
2270
+ result0 = [result0, result1, result2];
2271
+ } else {
2272
+ result0 = null;
2273
+ pos = clone(pos1);
2274
+ }
2275
+ } else {
2276
+ result0 = null;
2277
+ pos = clone(pos1);
2278
+ }
2279
+ } else {
2280
+ result0 = null;
2281
+ pos = clone(pos1);
2282
+ }
2283
+ if (result0 !== null) {
2284
+ result0 = (function(offset, line, column, l, r) { return parseFloat(l + "." + r.join('')); })(pos0.offset, pos0.line, pos0.column, result0[0], result0[2]);
2285
+ }
2286
+ if (result0 === null) {
2287
+ pos = clone(pos0);
2288
+ }
2289
+ reportFailures--;
2290
+ if (reportFailures === 0 && result0 === null) {
2291
+ matchFailed("float");
2292
+ }
2293
+ return result0;
2294
+ }
2295
+
2296
+ function parse_integer() {
2297
+ var result0, result1;
2298
+ var pos0;
2299
+
2300
+ reportFailures++;
2301
+ pos0 = clone(pos);
2302
+ if (/^[0-9]/.test(input.charAt(pos.offset))) {
2303
+ result1 = input.charAt(pos.offset);
2304
+ advance(pos, 1);
2305
+ } else {
2306
+ result1 = null;
2307
+ if (reportFailures === 0) {
2308
+ matchFailed("[0-9]");
2309
+ }
2310
+ }
2311
+ if (result1 !== null) {
2312
+ result0 = [];
2313
+ while (result1 !== null) {
2314
+ result0.push(result1);
2315
+ if (/^[0-9]/.test(input.charAt(pos.offset))) {
2316
+ result1 = input.charAt(pos.offset);
2317
+ advance(pos, 1);
2318
+ } else {
2319
+ result1 = null;
2320
+ if (reportFailures === 0) {
2321
+ matchFailed("[0-9]");
2322
+ }
2323
+ }
2324
+ }
2325
+ } else {
2326
+ result0 = null;
2327
+ }
2328
+ if (result0 !== null) {
2329
+ result0 = (function(offset, line, column, digits) { return parseInt(digits.join(""), 10); })(pos0.offset, pos0.line, pos0.column, result0);
2330
+ }
2331
+ if (result0 === null) {
2332
+ pos = clone(pos0);
2333
+ }
2334
+ reportFailures--;
2335
+ if (reportFailures === 0 && result0 === null) {
2336
+ matchFailed("integer");
2337
+ }
2338
+ return result0;
2339
+ }
2340
+
2341
+ function parse_path() {
2342
+ var result0, result1, result2;
2343
+ var pos0, pos1;
2344
+
2345
+ reportFailures++;
2346
+ pos0 = clone(pos);
2347
+ pos1 = clone(pos);
2348
+ result0 = parse_key();
2349
+ result0 = result0 !== null ? result0 : "";
2350
+ if (result0 !== null) {
2351
+ result2 = parse_array_part();
2352
+ if (result2 === null) {
2353
+ result2 = parse_array();
2354
+ }
2355
+ if (result2 !== null) {
2356
+ result1 = [];
2357
+ while (result2 !== null) {
2358
+ result1.push(result2);
2359
+ result2 = parse_array_part();
2360
+ if (result2 === null) {
2361
+ result2 = parse_array();
2362
+ }
2363
+ }
2364
+ } else {
2365
+ result1 = null;
2366
+ }
2367
+ if (result1 !== null) {
2368
+ result0 = [result0, result1];
2369
+ } else {
2370
+ result0 = null;
2371
+ pos = clone(pos1);
2372
+ }
2373
+ } else {
2374
+ result0 = null;
2375
+ pos = clone(pos1);
2376
+ }
2377
+ if (result0 !== null) {
2378
+ result0 = (function(offset, line, column, k, d) {
2379
+ d = d[0];
2380
+ if (k && d) {
2381
+ d.unshift(k);
2382
+ return [false, d].concat([['line', line], ['col', column]]);
2383
+ }
2384
+ return [true, d].concat([['line', line], ['col', column]]);
2385
+ })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]);
2386
+ }
2387
+ if (result0 === null) {
2388
+ pos = clone(pos0);
2389
+ }
2390
+ if (result0 === null) {
2391
+ pos0 = clone(pos);
2392
+ pos1 = clone(pos);
2393
+ if (input.charCodeAt(pos.offset) === 46) {
2394
+ result0 = ".";
2395
+ advance(pos, 1);
2396
+ } else {
2397
+ result0 = null;
2398
+ if (reportFailures === 0) {
2399
+ matchFailed("\".\"");
2400
+ }
2401
+ }
2402
+ if (result0 !== null) {
2403
+ result1 = [];
2404
+ result2 = parse_array_part();
2405
+ if (result2 === null) {
2406
+ result2 = parse_array();
2407
+ }
2408
+ while (result2 !== null) {
2409
+ result1.push(result2);
2410
+ result2 = parse_array_part();
2411
+ if (result2 === null) {
2412
+ result2 = parse_array();
2413
+ }
2414
+ }
2415
+ if (result1 !== null) {
2416
+ result0 = [result0, result1];
2417
+ } else {
2418
+ result0 = null;
2419
+ pos = clone(pos1);
2420
+ }
2421
+ } else {
2422
+ result0 = null;
2423
+ pos = clone(pos1);
2424
+ }
2425
+ if (result0 !== null) {
2426
+ result0 = (function(offset, line, column, d) {
2427
+ if (d.length > 0) {
2428
+ return [true, d[0]].concat([['line', line], ['col', column]]);
2429
+ }
2430
+ return [true, []].concat([['line', line], ['col', column]]);
2431
+ })(pos0.offset, pos0.line, pos0.column, result0[1]);
2432
+ }
2433
+ if (result0 === null) {
2434
+ pos = clone(pos0);
2435
+ }
2436
+ }
2437
+ reportFailures--;
2438
+ if (reportFailures === 0 && result0 === null) {
2439
+ matchFailed("path");
2440
+ }
2441
+ return result0;
2442
+ }
2443
+
2444
+ function parse_key() {
2445
+ var result0, result1, result2;
2446
+ var pos0, pos1;
2447
+
2448
+ reportFailures++;
2449
+ pos0 = clone(pos);
2450
+ pos1 = clone(pos);
2451
+ if (/^[a-zA-Z_$]/.test(input.charAt(pos.offset))) {
2452
+ result0 = input.charAt(pos.offset);
2453
+ advance(pos, 1);
2454
+ } else {
2455
+ result0 = null;
2456
+ if (reportFailures === 0) {
2457
+ matchFailed("[a-zA-Z_$]");
2458
+ }
2459
+ }
2460
+ if (result0 !== null) {
2461
+ result1 = [];
2462
+ if (/^[0-9a-zA-Z_$\-]/.test(input.charAt(pos.offset))) {
2463
+ result2 = input.charAt(pos.offset);
2464
+ advance(pos, 1);
2465
+ } else {
2466
+ result2 = null;
2467
+ if (reportFailures === 0) {
2468
+ matchFailed("[0-9a-zA-Z_$\\-]");
2469
+ }
2470
+ }
2471
+ while (result2 !== null) {
2472
+ result1.push(result2);
2473
+ if (/^[0-9a-zA-Z_$\-]/.test(input.charAt(pos.offset))) {
2474
+ result2 = input.charAt(pos.offset);
2475
+ advance(pos, 1);
2476
+ } else {
2477
+ result2 = null;
2478
+ if (reportFailures === 0) {
2479
+ matchFailed("[0-9a-zA-Z_$\\-]");
2480
+ }
2481
+ }
2482
+ }
2483
+ if (result1 !== null) {
2484
+ result0 = [result0, result1];
2485
+ } else {
2486
+ result0 = null;
2487
+ pos = clone(pos1);
2488
+ }
2489
+ } else {
2490
+ result0 = null;
2491
+ pos = clone(pos1);
2492
+ }
2493
+ if (result0 !== null) {
2494
+ result0 = (function(offset, line, column, h, t) { return h + t.join('') })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]);
2495
+ }
2496
+ if (result0 === null) {
2497
+ pos = clone(pos0);
2498
+ }
2499
+ reportFailures--;
2500
+ if (reportFailures === 0 && result0 === null) {
2501
+ matchFailed("key");
2502
+ }
2503
+ return result0;
2504
+ }
2505
+
2506
+ function parse_array() {
2507
+ var result0, result1, result2;
2508
+ var pos0, pos1, pos2, pos3, pos4;
2509
+
2510
+ reportFailures++;
2511
+ pos0 = clone(pos);
2512
+ pos1 = clone(pos);
2513
+ pos2 = clone(pos);
2514
+ pos3 = clone(pos);
2515
+ result0 = parse_lb();
2516
+ if (result0 !== null) {
2517
+ pos4 = clone(pos);
2518
+ if (/^[0-9]/.test(input.charAt(pos.offset))) {
2519
+ result2 = input.charAt(pos.offset);
2520
+ advance(pos, 1);
2521
+ } else {
2522
+ result2 = null;
2523
+ if (reportFailures === 0) {
2524
+ matchFailed("[0-9]");
2525
+ }
2526
+ }
2527
+ if (result2 !== null) {
2528
+ result1 = [];
2529
+ while (result2 !== null) {
2530
+ result1.push(result2);
2531
+ if (/^[0-9]/.test(input.charAt(pos.offset))) {
2532
+ result2 = input.charAt(pos.offset);
2533
+ advance(pos, 1);
2534
+ } else {
2535
+ result2 = null;
2536
+ if (reportFailures === 0) {
2537
+ matchFailed("[0-9]");
2538
+ }
2539
+ }
2540
+ }
2541
+ } else {
2542
+ result1 = null;
2543
+ }
2544
+ if (result1 !== null) {
2545
+ result1 = (function(offset, line, column, n) {return n.join('')})(pos4.offset, pos4.line, pos4.column, result1);
2546
+ }
2547
+ if (result1 === null) {
2548
+ pos = clone(pos4);
2549
+ }
2550
+ if (result1 === null) {
2551
+ result1 = parse_identifier();
2552
+ }
2553
+ if (result1 !== null) {
2554
+ result2 = parse_rb();
2555
+ if (result2 !== null) {
2556
+ result0 = [result0, result1, result2];
2557
+ } else {
2558
+ result0 = null;
2559
+ pos = clone(pos3);
2560
+ }
2561
+ } else {
2562
+ result0 = null;
2563
+ pos = clone(pos3);
2564
+ }
2565
+ } else {
2566
+ result0 = null;
2567
+ pos = clone(pos3);
2568
+ }
2569
+ if (result0 !== null) {
2570
+ result0 = (function(offset, line, column, a) {return a; })(pos2.offset, pos2.line, pos2.column, result0[1]);
2571
+ }
2572
+ if (result0 === null) {
2573
+ pos = clone(pos2);
2574
+ }
2575
+ if (result0 !== null) {
2576
+ result1 = parse_array_part();
2577
+ result1 = result1 !== null ? result1 : "";
2578
+ if (result1 !== null) {
2579
+ result0 = [result0, result1];
2580
+ } else {
2581
+ result0 = null;
2582
+ pos = clone(pos1);
2583
+ }
2584
+ } else {
2585
+ result0 = null;
2586
+ pos = clone(pos1);
2587
+ }
2588
+ if (result0 !== null) {
2589
+ result0 = (function(offset, line, column, i, nk) { if(nk) { nk.unshift(i); } else {nk = [i] } return nk; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]);
2590
+ }
2591
+ if (result0 === null) {
2592
+ pos = clone(pos0);
2593
+ }
2594
+ reportFailures--;
2595
+ if (reportFailures === 0 && result0 === null) {
2596
+ matchFailed("array");
2597
+ }
2598
+ return result0;
2599
+ }
2600
+
2601
+ function parse_array_part() {
2602
+ var result0, result1, result2;
2603
+ var pos0, pos1, pos2, pos3;
2604
+
2605
+ reportFailures++;
2606
+ pos0 = clone(pos);
2607
+ pos1 = clone(pos);
2608
+ pos2 = clone(pos);
2609
+ pos3 = clone(pos);
2610
+ if (input.charCodeAt(pos.offset) === 46) {
2611
+ result1 = ".";
2612
+ advance(pos, 1);
2613
+ } else {
2614
+ result1 = null;
2615
+ if (reportFailures === 0) {
2616
+ matchFailed("\".\"");
2617
+ }
2618
+ }
2619
+ if (result1 !== null) {
2620
+ result2 = parse_key();
2621
+ if (result2 !== null) {
2622
+ result1 = [result1, result2];
2623
+ } else {
2624
+ result1 = null;
2625
+ pos = clone(pos3);
2626
+ }
2627
+ } else {
2628
+ result1 = null;
2629
+ pos = clone(pos3);
2630
+ }
2631
+ if (result1 !== null) {
2632
+ result1 = (function(offset, line, column, k) {return k})(pos2.offset, pos2.line, pos2.column, result1[1]);
2633
+ }
2634
+ if (result1 === null) {
2635
+ pos = clone(pos2);
2636
+ }
2637
+ if (result1 !== null) {
2638
+ result0 = [];
2639
+ while (result1 !== null) {
2640
+ result0.push(result1);
2641
+ pos2 = clone(pos);
2642
+ pos3 = clone(pos);
2643
+ if (input.charCodeAt(pos.offset) === 46) {
2644
+ result1 = ".";
2645
+ advance(pos, 1);
2646
+ } else {
2647
+ result1 = null;
2648
+ if (reportFailures === 0) {
2649
+ matchFailed("\".\"");
2650
+ }
2651
+ }
2652
+ if (result1 !== null) {
2653
+ result2 = parse_key();
2654
+ if (result2 !== null) {
2655
+ result1 = [result1, result2];
2656
+ } else {
2657
+ result1 = null;
2658
+ pos = clone(pos3);
2659
+ }
2660
+ } else {
2661
+ result1 = null;
2662
+ pos = clone(pos3);
2663
+ }
2664
+ if (result1 !== null) {
2665
+ result1 = (function(offset, line, column, k) {return k})(pos2.offset, pos2.line, pos2.column, result1[1]);
2666
+ }
2667
+ if (result1 === null) {
2668
+ pos = clone(pos2);
2669
+ }
2670
+ }
2671
+ } else {
2672
+ result0 = null;
2673
+ }
2674
+ if (result0 !== null) {
2675
+ result1 = parse_array();
2676
+ result1 = result1 !== null ? result1 : "";
2677
+ if (result1 !== null) {
2678
+ result0 = [result0, result1];
2679
+ } else {
2680
+ result0 = null;
2681
+ pos = clone(pos1);
2682
+ }
2683
+ } else {
2684
+ result0 = null;
2685
+ pos = clone(pos1);
2686
+ }
2687
+ if (result0 !== null) {
2688
+ result0 = (function(offset, line, column, d, a) { if (a) { return d.concat(a); } else { return d; } })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]);
2689
+ }
2690
+ if (result0 === null) {
2691
+ pos = clone(pos0);
2692
+ }
2693
+ reportFailures--;
2694
+ if (reportFailures === 0 && result0 === null) {
2695
+ matchFailed("array_part");
2696
+ }
2697
+ return result0;
2698
+ }
2699
+
2700
+ function parse_inline() {
2701
+ var result0, result1, result2;
2702
+ var pos0, pos1;
2703
+
2704
+ reportFailures++;
2705
+ pos0 = clone(pos);
2706
+ pos1 = clone(pos);
2707
+ if (input.charCodeAt(pos.offset) === 34) {
2708
+ result0 = "\"";
2709
+ advance(pos, 1);
2710
+ } else {
2711
+ result0 = null;
2712
+ if (reportFailures === 0) {
2713
+ matchFailed("\"\\\"\"");
2714
+ }
2715
+ }
2716
+ if (result0 !== null) {
2717
+ if (input.charCodeAt(pos.offset) === 34) {
2718
+ result1 = "\"";
2719
+ advance(pos, 1);
2720
+ } else {
2721
+ result1 = null;
2722
+ if (reportFailures === 0) {
2723
+ matchFailed("\"\\\"\"");
2724
+ }
2725
+ }
2726
+ if (result1 !== null) {
2727
+ result0 = [result0, result1];
2728
+ } else {
2729
+ result0 = null;
2730
+ pos = clone(pos1);
2731
+ }
2732
+ } else {
2733
+ result0 = null;
2734
+ pos = clone(pos1);
2735
+ }
2736
+ if (result0 !== null) {
2737
+ result0 = (function(offset, line, column) { return ["literal", ""].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column);
2738
+ }
2739
+ if (result0 === null) {
2740
+ pos = clone(pos0);
2741
+ }
2742
+ if (result0 === null) {
2743
+ pos0 = clone(pos);
2744
+ pos1 = clone(pos);
2745
+ if (input.charCodeAt(pos.offset) === 34) {
2746
+ result0 = "\"";
2747
+ advance(pos, 1);
2748
+ } else {
2749
+ result0 = null;
2750
+ if (reportFailures === 0) {
2751
+ matchFailed("\"\\\"\"");
2752
+ }
2753
+ }
2754
+ if (result0 !== null) {
2755
+ result1 = parse_literal();
2756
+ if (result1 !== null) {
2757
+ if (input.charCodeAt(pos.offset) === 34) {
2758
+ result2 = "\"";
2759
+ advance(pos, 1);
2760
+ } else {
2761
+ result2 = null;
2762
+ if (reportFailures === 0) {
2763
+ matchFailed("\"\\\"\"");
2764
+ }
2765
+ }
2766
+ if (result2 !== null) {
2767
+ result0 = [result0, result1, result2];
2768
+ } else {
2769
+ result0 = null;
2770
+ pos = clone(pos1);
2771
+ }
2772
+ } else {
2773
+ result0 = null;
2774
+ pos = clone(pos1);
2775
+ }
2776
+ } else {
2777
+ result0 = null;
2778
+ pos = clone(pos1);
2779
+ }
2780
+ if (result0 !== null) {
2781
+ result0 = (function(offset, line, column, l) { return ["literal", l].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1]);
2782
+ }
2783
+ if (result0 === null) {
2784
+ pos = clone(pos0);
2785
+ }
2786
+ if (result0 === null) {
2787
+ pos0 = clone(pos);
2788
+ pos1 = clone(pos);
2789
+ if (input.charCodeAt(pos.offset) === 34) {
2790
+ result0 = "\"";
2791
+ advance(pos, 1);
2792
+ } else {
2793
+ result0 = null;
2794
+ if (reportFailures === 0) {
2795
+ matchFailed("\"\\\"\"");
2796
+ }
2797
+ }
2798
+ if (result0 !== null) {
2799
+ result2 = parse_inline_part();
2800
+ if (result2 !== null) {
2801
+ result1 = [];
2802
+ while (result2 !== null) {
2803
+ result1.push(result2);
2804
+ result2 = parse_inline_part();
2805
+ }
2806
+ } else {
2807
+ result1 = null;
2808
+ }
2809
+ if (result1 !== null) {
2810
+ if (input.charCodeAt(pos.offset) === 34) {
2811
+ result2 = "\"";
2812
+ advance(pos, 1);
2813
+ } else {
2814
+ result2 = null;
2815
+ if (reportFailures === 0) {
2816
+ matchFailed("\"\\\"\"");
2817
+ }
2818
+ }
2819
+ if (result2 !== null) {
2820
+ result0 = [result0, result1, result2];
2821
+ } else {
2822
+ result0 = null;
2823
+ pos = clone(pos1);
2824
+ }
2825
+ } else {
2826
+ result0 = null;
2827
+ pos = clone(pos1);
2828
+ }
2829
+ } else {
2830
+ result0 = null;
2831
+ pos = clone(pos1);
2832
+ }
2833
+ if (result0 !== null) {
2834
+ result0 = (function(offset, line, column, p) { return ["body"].concat(p).concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1]);
2835
+ }
2836
+ if (result0 === null) {
2837
+ pos = clone(pos0);
2838
+ }
2839
+ }
2840
+ }
2841
+ reportFailures--;
2842
+ if (reportFailures === 0 && result0 === null) {
2843
+ matchFailed("inline");
2844
+ }
2845
+ return result0;
2846
+ }
2847
+
2848
+ function parse_inline_part() {
2849
+ var result0;
2850
+ var pos0;
2851
+
2852
+ result0 = parse_special();
2853
+ if (result0 === null) {
2854
+ result0 = parse_reference();
2855
+ if (result0 === null) {
2856
+ pos0 = clone(pos);
2857
+ result0 = parse_literal();
2858
+ if (result0 !== null) {
2859
+ result0 = (function(offset, line, column, l) { return ["buffer", l] })(pos0.offset, pos0.line, pos0.column, result0);
2860
+ }
2861
+ if (result0 === null) {
2862
+ pos = clone(pos0);
2863
+ }
2864
+ }
2865
+ }
2866
+ return result0;
2867
+ }
2868
+
2869
+ function parse_buffer() {
2870
+ var result0, result1, result2, result3, result4;
2871
+ var pos0, pos1, pos2, pos3;
2872
+
2873
+ reportFailures++;
2874
+ pos0 = clone(pos);
2875
+ pos1 = clone(pos);
2876
+ result0 = parse_eol();
2877
+ if (result0 !== null) {
2878
+ result1 = [];
2879
+ result2 = parse_ws();
2880
+ while (result2 !== null) {
2881
+ result1.push(result2);
2882
+ result2 = parse_ws();
2883
+ }
2884
+ if (result1 !== null) {
2885
+ result0 = [result0, result1];
2886
+ } else {
2887
+ result0 = null;
2888
+ pos = clone(pos1);
2889
+ }
2890
+ } else {
2891
+ result0 = null;
2892
+ pos = clone(pos1);
2893
+ }
2894
+ if (result0 !== null) {
2895
+ result0 = (function(offset, line, column, e, w) { return ["format", e, w.join('')].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]);
2896
+ }
2897
+ if (result0 === null) {
2898
+ pos = clone(pos0);
2899
+ }
2900
+ if (result0 === null) {
2901
+ pos0 = clone(pos);
2902
+ pos1 = clone(pos);
2903
+ pos2 = clone(pos);
2904
+ pos3 = clone(pos);
2905
+ reportFailures++;
2906
+ result1 = parse_tag();
2907
+ reportFailures--;
2908
+ if (result1 === null) {
2909
+ result1 = "";
2910
+ } else {
2911
+ result1 = null;
2912
+ pos = clone(pos3);
2913
+ }
2914
+ if (result1 !== null) {
2915
+ pos3 = clone(pos);
2916
+ reportFailures++;
2917
+ result2 = parse_comment();
2918
+ reportFailures--;
2919
+ if (result2 === null) {
2920
+ result2 = "";
2921
+ } else {
2922
+ result2 = null;
2923
+ pos = clone(pos3);
2924
+ }
2925
+ if (result2 !== null) {
2926
+ pos3 = clone(pos);
2927
+ reportFailures++;
2928
+ result3 = parse_eol();
2929
+ reportFailures--;
2930
+ if (result3 === null) {
2931
+ result3 = "";
2932
+ } else {
2933
+ result3 = null;
2934
+ pos = clone(pos3);
2935
+ }
2936
+ if (result3 !== null) {
2937
+ if (input.length > pos.offset) {
2938
+ result4 = input.charAt(pos.offset);
2939
+ advance(pos, 1);
2940
+ } else {
2941
+ result4 = null;
2942
+ if (reportFailures === 0) {
2943
+ matchFailed("any character");
2944
+ }
2945
+ }
2946
+ if (result4 !== null) {
2947
+ result1 = [result1, result2, result3, result4];
2948
+ } else {
2949
+ result1 = null;
2950
+ pos = clone(pos2);
2951
+ }
2952
+ } else {
2953
+ result1 = null;
2954
+ pos = clone(pos2);
2955
+ }
2956
+ } else {
2957
+ result1 = null;
2958
+ pos = clone(pos2);
2959
+ }
2960
+ } else {
2961
+ result1 = null;
2962
+ pos = clone(pos2);
2963
+ }
2964
+ if (result1 !== null) {
2965
+ result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[3]);
2966
+ }
2967
+ if (result1 === null) {
2968
+ pos = clone(pos1);
2969
+ }
2970
+ if (result1 !== null) {
2971
+ result0 = [];
2972
+ while (result1 !== null) {
2973
+ result0.push(result1);
2974
+ pos1 = clone(pos);
2975
+ pos2 = clone(pos);
2976
+ pos3 = clone(pos);
2977
+ reportFailures++;
2978
+ result1 = parse_tag();
2979
+ reportFailures--;
2980
+ if (result1 === null) {
2981
+ result1 = "";
2982
+ } else {
2983
+ result1 = null;
2984
+ pos = clone(pos3);
2985
+ }
2986
+ if (result1 !== null) {
2987
+ pos3 = clone(pos);
2988
+ reportFailures++;
2989
+ result2 = parse_comment();
2990
+ reportFailures--;
2991
+ if (result2 === null) {
2992
+ result2 = "";
2993
+ } else {
2994
+ result2 = null;
2995
+ pos = clone(pos3);
2996
+ }
2997
+ if (result2 !== null) {
2998
+ pos3 = clone(pos);
2999
+ reportFailures++;
3000
+ result3 = parse_eol();
3001
+ reportFailures--;
3002
+ if (result3 === null) {
3003
+ result3 = "";
3004
+ } else {
3005
+ result3 = null;
3006
+ pos = clone(pos3);
3007
+ }
3008
+ if (result3 !== null) {
3009
+ if (input.length > pos.offset) {
3010
+ result4 = input.charAt(pos.offset);
3011
+ advance(pos, 1);
3012
+ } else {
3013
+ result4 = null;
3014
+ if (reportFailures === 0) {
3015
+ matchFailed("any character");
3016
+ }
3017
+ }
3018
+ if (result4 !== null) {
3019
+ result1 = [result1, result2, result3, result4];
3020
+ } else {
3021
+ result1 = null;
3022
+ pos = clone(pos2);
3023
+ }
3024
+ } else {
3025
+ result1 = null;
3026
+ pos = clone(pos2);
3027
+ }
3028
+ } else {
3029
+ result1 = null;
3030
+ pos = clone(pos2);
3031
+ }
3032
+ } else {
3033
+ result1 = null;
3034
+ pos = clone(pos2);
3035
+ }
3036
+ if (result1 !== null) {
3037
+ result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[3]);
3038
+ }
3039
+ if (result1 === null) {
3040
+ pos = clone(pos1);
3041
+ }
3042
+ }
3043
+ } else {
3044
+ result0 = null;
3045
+ }
3046
+ if (result0 !== null) {
3047
+ result0 = (function(offset, line, column, b) { return ["buffer", b.join('')].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0);
3048
+ }
3049
+ if (result0 === null) {
3050
+ pos = clone(pos0);
3051
+ }
3052
+ }
3053
+ reportFailures--;
3054
+ if (reportFailures === 0 && result0 === null) {
3055
+ matchFailed("buffer");
3056
+ }
3057
+ return result0;
3058
+ }
3059
+
3060
+ function parse_literal() {
3061
+ var result0, result1, result2;
3062
+ var pos0, pos1, pos2, pos3;
3063
+
3064
+ reportFailures++;
3065
+ pos0 = clone(pos);
3066
+ pos1 = clone(pos);
3067
+ pos2 = clone(pos);
3068
+ pos3 = clone(pos);
3069
+ reportFailures++;
3070
+ result1 = parse_tag();
3071
+ reportFailures--;
3072
+ if (result1 === null) {
3073
+ result1 = "";
3074
+ } else {
3075
+ result1 = null;
3076
+ pos = clone(pos3);
3077
+ }
3078
+ if (result1 !== null) {
3079
+ result2 = parse_esc();
3080
+ if (result2 === null) {
3081
+ if (/^[^"]/.test(input.charAt(pos.offset))) {
3082
+ result2 = input.charAt(pos.offset);
3083
+ advance(pos, 1);
3084
+ } else {
3085
+ result2 = null;
3086
+ if (reportFailures === 0) {
3087
+ matchFailed("[^\"]");
3088
+ }
3089
+ }
3090
+ }
3091
+ if (result2 !== null) {
3092
+ result1 = [result1, result2];
3093
+ } else {
3094
+ result1 = null;
3095
+ pos = clone(pos2);
3096
+ }
3097
+ } else {
3098
+ result1 = null;
3099
+ pos = clone(pos2);
3100
+ }
3101
+ if (result1 !== null) {
3102
+ result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[1]);
3103
+ }
3104
+ if (result1 === null) {
3105
+ pos = clone(pos1);
3106
+ }
3107
+ if (result1 !== null) {
3108
+ result0 = [];
3109
+ while (result1 !== null) {
3110
+ result0.push(result1);
3111
+ pos1 = clone(pos);
3112
+ pos2 = clone(pos);
3113
+ pos3 = clone(pos);
3114
+ reportFailures++;
3115
+ result1 = parse_tag();
3116
+ reportFailures--;
3117
+ if (result1 === null) {
3118
+ result1 = "";
3119
+ } else {
3120
+ result1 = null;
3121
+ pos = clone(pos3);
3122
+ }
3123
+ if (result1 !== null) {
3124
+ result2 = parse_esc();
3125
+ if (result2 === null) {
3126
+ if (/^[^"]/.test(input.charAt(pos.offset))) {
3127
+ result2 = input.charAt(pos.offset);
3128
+ advance(pos, 1);
3129
+ } else {
3130
+ result2 = null;
3131
+ if (reportFailures === 0) {
3132
+ matchFailed("[^\"]");
3133
+ }
3134
+ }
3135
+ }
3136
+ if (result2 !== null) {
3137
+ result1 = [result1, result2];
3138
+ } else {
3139
+ result1 = null;
3140
+ pos = clone(pos2);
3141
+ }
3142
+ } else {
3143
+ result1 = null;
3144
+ pos = clone(pos2);
3145
+ }
3146
+ if (result1 !== null) {
3147
+ result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[1]);
3148
+ }
3149
+ if (result1 === null) {
3150
+ pos = clone(pos1);
3151
+ }
3152
+ }
3153
+ } else {
3154
+ result0 = null;
3155
+ }
3156
+ if (result0 !== null) {
3157
+ result0 = (function(offset, line, column, b) { return b.join('') })(pos0.offset, pos0.line, pos0.column, result0);
3158
+ }
3159
+ if (result0 === null) {
3160
+ pos = clone(pos0);
3161
+ }
3162
+ reportFailures--;
3163
+ if (reportFailures === 0 && result0 === null) {
3164
+ matchFailed("literal");
3165
+ }
3166
+ return result0;
3167
+ }
3168
+
3169
+ function parse_esc() {
3170
+ var result0;
3171
+ var pos0;
3172
+
3173
+ pos0 = clone(pos);
3174
+ if (input.substr(pos.offset, 2) === "\\\"") {
3175
+ result0 = "\\\"";
3176
+ advance(pos, 2);
3177
+ } else {
3178
+ result0 = null;
3179
+ if (reportFailures === 0) {
3180
+ matchFailed("\"\\\\\\\"\"");
3181
+ }
3182
+ }
3183
+ if (result0 !== null) {
3184
+ result0 = (function(offset, line, column) { return '"' })(pos0.offset, pos0.line, pos0.column);
3185
+ }
3186
+ if (result0 === null) {
3187
+ pos = clone(pos0);
3188
+ }
3189
+ return result0;
3190
+ }
3191
+
3192
+ function parse_comment() {
3193
+ var result0, result1, result2, result3;
3194
+ var pos0, pos1, pos2, pos3, pos4;
3195
+
3196
+ reportFailures++;
3197
+ pos0 = clone(pos);
3198
+ pos1 = clone(pos);
3199
+ if (input.substr(pos.offset, 2) === "{!") {
3200
+ result0 = "{!";
3201
+ advance(pos, 2);
3202
+ } else {
3203
+ result0 = null;
3204
+ if (reportFailures === 0) {
3205
+ matchFailed("\"{!\"");
3206
+ }
3207
+ }
3208
+ if (result0 !== null) {
3209
+ result1 = [];
3210
+ pos2 = clone(pos);
3211
+ pos3 = clone(pos);
3212
+ pos4 = clone(pos);
3213
+ reportFailures++;
3214
+ if (input.substr(pos.offset, 2) === "!}") {
3215
+ result2 = "!}";
3216
+ advance(pos, 2);
3217
+ } else {
3218
+ result2 = null;
3219
+ if (reportFailures === 0) {
3220
+ matchFailed("\"!}\"");
3221
+ }
3222
+ }
3223
+ reportFailures--;
3224
+ if (result2 === null) {
3225
+ result2 = "";
3226
+ } else {
3227
+ result2 = null;
3228
+ pos = clone(pos4);
3229
+ }
3230
+ if (result2 !== null) {
3231
+ if (input.length > pos.offset) {
3232
+ result3 = input.charAt(pos.offset);
3233
+ advance(pos, 1);
3234
+ } else {
3235
+ result3 = null;
3236
+ if (reportFailures === 0) {
3237
+ matchFailed("any character");
3238
+ }
3239
+ }
3240
+ if (result3 !== null) {
3241
+ result2 = [result2, result3];
3242
+ } else {
3243
+ result2 = null;
3244
+ pos = clone(pos3);
3245
+ }
3246
+ } else {
3247
+ result2 = null;
3248
+ pos = clone(pos3);
3249
+ }
3250
+ if (result2 !== null) {
3251
+ result2 = (function(offset, line, column, c) {return c})(pos2.offset, pos2.line, pos2.column, result2[1]);
3252
+ }
3253
+ if (result2 === null) {
3254
+ pos = clone(pos2);
3255
+ }
3256
+ while (result2 !== null) {
3257
+ result1.push(result2);
3258
+ pos2 = clone(pos);
3259
+ pos3 = clone(pos);
3260
+ pos4 = clone(pos);
3261
+ reportFailures++;
3262
+ if (input.substr(pos.offset, 2) === "!}") {
3263
+ result2 = "!}";
3264
+ advance(pos, 2);
3265
+ } else {
3266
+ result2 = null;
3267
+ if (reportFailures === 0) {
3268
+ matchFailed("\"!}\"");
3269
+ }
3270
+ }
3271
+ reportFailures--;
3272
+ if (result2 === null) {
3273
+ result2 = "";
3274
+ } else {
3275
+ result2 = null;
3276
+ pos = clone(pos4);
3277
+ }
3278
+ if (result2 !== null) {
3279
+ if (input.length > pos.offset) {
3280
+ result3 = input.charAt(pos.offset);
3281
+ advance(pos, 1);
3282
+ } else {
3283
+ result3 = null;
3284
+ if (reportFailures === 0) {
3285
+ matchFailed("any character");
3286
+ }
3287
+ }
3288
+ if (result3 !== null) {
3289
+ result2 = [result2, result3];
3290
+ } else {
3291
+ result2 = null;
3292
+ pos = clone(pos3);
3293
+ }
3294
+ } else {
3295
+ result2 = null;
3296
+ pos = clone(pos3);
3297
+ }
3298
+ if (result2 !== null) {
3299
+ result2 = (function(offset, line, column, c) {return c})(pos2.offset, pos2.line, pos2.column, result2[1]);
3300
+ }
3301
+ if (result2 === null) {
3302
+ pos = clone(pos2);
3303
+ }
3304
+ }
3305
+ if (result1 !== null) {
3306
+ if (input.substr(pos.offset, 2) === "!}") {
3307
+ result2 = "!}";
3308
+ advance(pos, 2);
3309
+ } else {
3310
+ result2 = null;
3311
+ if (reportFailures === 0) {
3312
+ matchFailed("\"!}\"");
3313
+ }
3314
+ }
3315
+ if (result2 !== null) {
3316
+ result0 = [result0, result1, result2];
3317
+ } else {
3318
+ result0 = null;
3319
+ pos = clone(pos1);
3320
+ }
3321
+ } else {
3322
+ result0 = null;
3323
+ pos = clone(pos1);
3324
+ }
3325
+ } else {
3326
+ result0 = null;
3327
+ pos = clone(pos1);
3328
+ }
3329
+ if (result0 !== null) {
3330
+ result0 = (function(offset, line, column, c) { return ["comment", c.join('')].concat([['line', line], ['col', column]]) })(pos0.offset, pos0.line, pos0.column, result0[1]);
3331
+ }
3332
+ if (result0 === null) {
3333
+ pos = clone(pos0);
3334
+ }
3335
+ reportFailures--;
3336
+ if (reportFailures === 0 && result0 === null) {
3337
+ matchFailed("comment");
3338
+ }
3339
+ return result0;
3340
+ }
3341
+
3342
+ function parse_tag() {
3343
+ var result0, result1, result2, result3, result4, result5, result6, result7;
3344
+ var pos0, pos1, pos2;
3345
+
3346
+ pos0 = clone(pos);
3347
+ result0 = parse_ld();
3348
+ if (result0 !== null) {
3349
+ result1 = [];
3350
+ result2 = parse_ws();
3351
+ while (result2 !== null) {
3352
+ result1.push(result2);
3353
+ result2 = parse_ws();
3354
+ }
3355
+ if (result1 !== null) {
3356
+ if (/^[#?^><+%:@\/~%]/.test(input.charAt(pos.offset))) {
3357
+ result2 = input.charAt(pos.offset);
3358
+ advance(pos, 1);
3359
+ } else {
3360
+ result2 = null;
3361
+ if (reportFailures === 0) {
3362
+ matchFailed("[#?^><+%:@\\/~%]");
3363
+ }
3364
+ }
3365
+ if (result2 !== null) {
3366
+ result3 = [];
3367
+ result4 = parse_ws();
3368
+ while (result4 !== null) {
3369
+ result3.push(result4);
3370
+ result4 = parse_ws();
3371
+ }
3372
+ if (result3 !== null) {
3373
+ pos1 = clone(pos);
3374
+ pos2 = clone(pos);
3375
+ reportFailures++;
3376
+ result5 = parse_rd();
3377
+ reportFailures--;
3378
+ if (result5 === null) {
3379
+ result5 = "";
3380
+ } else {
3381
+ result5 = null;
3382
+ pos = clone(pos2);
3383
+ }
3384
+ if (result5 !== null) {
3385
+ pos2 = clone(pos);
3386
+ reportFailures++;
3387
+ result6 = parse_eol();
3388
+ reportFailures--;
3389
+ if (result6 === null) {
3390
+ result6 = "";
3391
+ } else {
3392
+ result6 = null;
3393
+ pos = clone(pos2);
3394
+ }
3395
+ if (result6 !== null) {
3396
+ if (input.length > pos.offset) {
3397
+ result7 = input.charAt(pos.offset);
3398
+ advance(pos, 1);
3399
+ } else {
3400
+ result7 = null;
3401
+ if (reportFailures === 0) {
3402
+ matchFailed("any character");
3403
+ }
3404
+ }
3405
+ if (result7 !== null) {
3406
+ result5 = [result5, result6, result7];
3407
+ } else {
3408
+ result5 = null;
3409
+ pos = clone(pos1);
3410
+ }
3411
+ } else {
3412
+ result5 = null;
3413
+ pos = clone(pos1);
3414
+ }
3415
+ } else {
3416
+ result5 = null;
3417
+ pos = clone(pos1);
3418
+ }
3419
+ if (result5 !== null) {
3420
+ result4 = [];
3421
+ while (result5 !== null) {
3422
+ result4.push(result5);
3423
+ pos1 = clone(pos);
3424
+ pos2 = clone(pos);
3425
+ reportFailures++;
3426
+ result5 = parse_rd();
3427
+ reportFailures--;
3428
+ if (result5 === null) {
3429
+ result5 = "";
3430
+ } else {
3431
+ result5 = null;
3432
+ pos = clone(pos2);
3433
+ }
3434
+ if (result5 !== null) {
3435
+ pos2 = clone(pos);
3436
+ reportFailures++;
3437
+ result6 = parse_eol();
3438
+ reportFailures--;
3439
+ if (result6 === null) {
3440
+ result6 = "";
3441
+ } else {
3442
+ result6 = null;
3443
+ pos = clone(pos2);
3444
+ }
3445
+ if (result6 !== null) {
3446
+ if (input.length > pos.offset) {
3447
+ result7 = input.charAt(pos.offset);
3448
+ advance(pos, 1);
3449
+ } else {
3450
+ result7 = null;
3451
+ if (reportFailures === 0) {
3452
+ matchFailed("any character");
3453
+ }
3454
+ }
3455
+ if (result7 !== null) {
3456
+ result5 = [result5, result6, result7];
3457
+ } else {
3458
+ result5 = null;
3459
+ pos = clone(pos1);
3460
+ }
3461
+ } else {
3462
+ result5 = null;
3463
+ pos = clone(pos1);
3464
+ }
3465
+ } else {
3466
+ result5 = null;
3467
+ pos = clone(pos1);
3468
+ }
3469
+ }
3470
+ } else {
3471
+ result4 = null;
3472
+ }
3473
+ if (result4 !== null) {
3474
+ result5 = [];
3475
+ result6 = parse_ws();
3476
+ while (result6 !== null) {
3477
+ result5.push(result6);
3478
+ result6 = parse_ws();
3479
+ }
3480
+ if (result5 !== null) {
3481
+ result6 = parse_rd();
3482
+ if (result6 !== null) {
3483
+ result0 = [result0, result1, result2, result3, result4, result5, result6];
3484
+ } else {
3485
+ result0 = null;
3486
+ pos = clone(pos0);
3487
+ }
3488
+ } else {
3489
+ result0 = null;
3490
+ pos = clone(pos0);
3491
+ }
3492
+ } else {
3493
+ result0 = null;
3494
+ pos = clone(pos0);
3495
+ }
3496
+ } else {
3497
+ result0 = null;
3498
+ pos = clone(pos0);
3499
+ }
3500
+ } else {
3501
+ result0 = null;
3502
+ pos = clone(pos0);
3503
+ }
3504
+ } else {
3505
+ result0 = null;
3506
+ pos = clone(pos0);
3507
+ }
3508
+ } else {
3509
+ result0 = null;
3510
+ pos = clone(pos0);
3511
+ }
3512
+ if (result0 === null) {
3513
+ result0 = parse_reference();
3514
+ }
3515
+ return result0;
3516
+ }
3517
+
3518
+ function parse_ld() {
3519
+ var result0;
3520
+
3521
+ if (input.charCodeAt(pos.offset) === 123) {
3522
+ result0 = "{";
3523
+ advance(pos, 1);
3524
+ } else {
3525
+ result0 = null;
3526
+ if (reportFailures === 0) {
3527
+ matchFailed("\"{\"");
3528
+ }
3529
+ }
3530
+ return result0;
3531
+ }
3532
+
3533
+ function parse_rd() {
3534
+ var result0;
3535
+
3536
+ if (input.charCodeAt(pos.offset) === 125) {
3537
+ result0 = "}";
3538
+ advance(pos, 1);
3539
+ } else {
3540
+ result0 = null;
3541
+ if (reportFailures === 0) {
3542
+ matchFailed("\"}\"");
3543
+ }
3544
+ }
3545
+ return result0;
3546
+ }
3547
+
3548
+ function parse_lb() {
3549
+ var result0;
3550
+
3551
+ if (input.charCodeAt(pos.offset) === 91) {
3552
+ result0 = "[";
3553
+ advance(pos, 1);
3554
+ } else {
3555
+ result0 = null;
3556
+ if (reportFailures === 0) {
3557
+ matchFailed("\"[\"");
3558
+ }
3559
+ }
3560
+ return result0;
3561
+ }
3562
+
3563
+ function parse_rb() {
3564
+ var result0;
3565
+
3566
+ if (input.charCodeAt(pos.offset) === 93) {
3567
+ result0 = "]";
3568
+ advance(pos, 1);
3569
+ } else {
3570
+ result0 = null;
3571
+ if (reportFailures === 0) {
3572
+ matchFailed("\"]\"");
3573
+ }
3574
+ }
3575
+ return result0;
3576
+ }
3577
+
3578
+ function parse_eol() {
3579
+ var result0;
3580
+
3581
+ if (input.charCodeAt(pos.offset) === 10) {
3582
+ result0 = "\n";
3583
+ advance(pos, 1);
3584
+ } else {
3585
+ result0 = null;
3586
+ if (reportFailures === 0) {
3587
+ matchFailed("\"\\n\"");
3588
+ }
3589
+ }
3590
+ if (result0 === null) {
3591
+ if (input.substr(pos.offset, 2) === "\r\n") {
3592
+ result0 = "\r\n";
3593
+ advance(pos, 2);
3594
+ } else {
3595
+ result0 = null;
3596
+ if (reportFailures === 0) {
3597
+ matchFailed("\"\\r\\n\"");
3598
+ }
3599
+ }
3600
+ if (result0 === null) {
3601
+ if (input.charCodeAt(pos.offset) === 13) {
3602
+ result0 = "\r";
3603
+ advance(pos, 1);
3604
+ } else {
3605
+ result0 = null;
3606
+ if (reportFailures === 0) {
3607
+ matchFailed("\"\\r\"");
3608
+ }
3609
+ }
3610
+ if (result0 === null) {
3611
+ if (input.charCodeAt(pos.offset) === 8232) {
3612
+ result0 = "\u2028";
3613
+ advance(pos, 1);
3614
+ } else {
3615
+ result0 = null;
3616
+ if (reportFailures === 0) {
3617
+ matchFailed("\"\\u2028\"");
3618
+ }
3619
+ }
3620
+ if (result0 === null) {
3621
+ if (input.charCodeAt(pos.offset) === 8233) {
3622
+ result0 = "\u2029";
3623
+ advance(pos, 1);
3624
+ } else {
3625
+ result0 = null;
3626
+ if (reportFailures === 0) {
3627
+ matchFailed("\"\\u2029\"");
3628
+ }
3629
+ }
3630
+ }
3631
+ }
3632
+ }
3633
+ }
3634
+ return result0;
3635
+ }
3636
+
3637
+ function parse_ws() {
3638
+ var result0;
3639
+
3640
+ if (/^[\t\x0B\f \xA0\uFEFF]/.test(input.charAt(pos.offset))) {
3641
+ result0 = input.charAt(pos.offset);
3642
+ advance(pos, 1);
3643
+ } else {
3644
+ result0 = null;
3645
+ if (reportFailures === 0) {
3646
+ matchFailed("[\\t\\x0B\\f \\xA0\\uFEFF]");
3647
+ }
3648
+ }
3649
+ if (result0 === null) {
3650
+ result0 = parse_eol();
3651
+ }
3652
+ return result0;
3653
+ }
3654
+
3655
+
3656
+ function cleanupExpected(expected) {
3657
+ expected.sort();
3658
+
3659
+ var lastExpected = null;
3660
+ var cleanExpected = [];
3661
+ for (var i = 0; i < expected.length; i++) {
3662
+ if (expected[i] !== lastExpected) {
3663
+ cleanExpected.push(expected[i]);
3664
+ lastExpected = expected[i];
3665
+ }
3666
+ }
3667
+ return cleanExpected;
3668
+ }
3669
+
3670
+
3671
+
3672
+ var result = parseFunctions[startRule]();
3673
+
3674
+ /*
3675
+ * The parser is now in one of the following three states:
3676
+ *
3677
+ * 1. The parser successfully parsed the whole input.
3678
+ *
3679
+ * - |result !== null|
3680
+ * - |pos.offset === input.length|
3681
+ * - |rightmostFailuresExpected| may or may not contain something
3682
+ *
3683
+ * 2. The parser successfully parsed only a part of the input.
3684
+ *
3685
+ * - |result !== null|
3686
+ * - |pos.offset < input.length|
3687
+ * - |rightmostFailuresExpected| may or may not contain something
3688
+ *
3689
+ * 3. The parser did not successfully parse any part of the input.
3690
+ *
3691
+ * - |result === null|
3692
+ * - |pos.offset === 0|
3693
+ * - |rightmostFailuresExpected| contains at least one failure
3694
+ *
3695
+ * All code following this comment (including called functions) must
3696
+ * handle these states.
3697
+ */
3698
+ if (result === null || pos.offset !== input.length) {
3699
+ var offset = Math.max(pos.offset, rightmostFailuresPos.offset);
3700
+ var found = offset < input.length ? input.charAt(offset) : null;
3701
+ var errorPosition = pos.offset > rightmostFailuresPos.offset ? pos : rightmostFailuresPos;
3702
+
3703
+ throw new parser.SyntaxError(
3704
+ cleanupExpected(rightmostFailuresExpected),
3705
+ found,
3706
+ offset,
3707
+ errorPosition.line,
3708
+ errorPosition.column
3709
+ );
3710
+ }
3711
+
3712
+ return result;
3713
+ },
3714
+
3715
+ /* Returns the parser source code. */
3716
+ toSource: function() { return this._source; }
3717
+ };
3718
+
3719
+ /* Thrown when a parser encounters a syntax error. */
3720
+
3721
+ result.SyntaxError = function(expected, found, offset, line, column) {
3722
+ function buildMessage(expected, found) {
3723
+ var expectedHumanized, foundHumanized;
3724
+
3725
+ switch (expected.length) {
3726
+ case 0:
3727
+ expectedHumanized = "end of input";
3728
+ break;
3729
+ case 1:
3730
+ expectedHumanized = expected[0];
3731
+ break;
3732
+ default:
3733
+ expectedHumanized = expected.slice(0, expected.length - 1).join(", ")
3734
+ + " or "
3735
+ + expected[expected.length - 1];
3736
+ }
3737
+
3738
+ foundHumanized = found ? quote(found) : "end of input";
3739
+
3740
+ return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
3741
+ }
3742
+
3743
+ this.name = "SyntaxError";
3744
+ this.expected = expected;
3745
+ this.found = found;
3746
+ this.message = buildMessage(expected, found);
3747
+ this.offset = offset;
3748
+ this.line = line;
3749
+ this.column = column;
3750
+ };
3751
+
3752
+ result.SyntaxError.prototype = Error.prototype;
3753
+
3754
+ return result;
3755
+ })();
3756
+
3757
+ dust.parse = parser.parse;
3758
+
3759
+ })(typeof exports !== 'undefined' ? exports : getGlobal());