dust-rails 0.3.0 → 0.4.0

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