Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6056 efrain 1
/*! dustjs-linkedin - v2.7.2
2
* http://dustjs.com/
3
* Copyright (c) 2015 Aleksander Williams; Released under the MIT License */
4
(function (root, factory) {
5
  if (typeof define === 'function' && define.amd && define.amd.dust === true) {
6
    define('dust.core', [], factory);
7
  } else if (typeof exports === 'object') {
8
    module.exports = factory();
9
  } else {
10
    root.dust = factory();
11
  }
12
}(this, function() {
13
  var dust = {
14
        "version": "2.7.2"
15
      },
16
      NONE = 'NONE', ERROR = 'ERROR', WARN = 'WARN', INFO = 'INFO', DEBUG = 'DEBUG',
17
      EMPTY_FUNC = function() {};
18
 
19
  dust.config = {
20
    whitespace: false,
21
    amd: false,
22
    cjs: false,
23
    cache: true
24
  };
25
 
26
  // Directive aliases to minify code
27
  dust._aliases = {
28
    "write": "w",
29
    "end": "e",
30
    "map": "m",
31
    "render": "r",
32
    "reference": "f",
33
    "section": "s",
34
    "exists": "x",
35
    "notexists": "nx",
36
    "block": "b",
37
    "partial": "p",
38
    "helper": "h"
39
  };
40
 
41
  (function initLogging() {
42
    /*global process, console*/
43
    var loggingLevels = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, NONE: 4 },
44
        consoleLog,
45
        log;
46
 
47
    if (typeof console !== 'undefined' && console.log) {
48
      consoleLog = console.log;
49
      if(typeof consoleLog === 'function') {
50
        log = function() {
51
          consoleLog.apply(console, arguments);
52
        };
53
      } else {
54
        log = function() {
55
          consoleLog(Array.prototype.slice.apply(arguments).join(' '));
56
        };
57
      }
58
    } else {
59
      log = EMPTY_FUNC;
60
    }
61
 
62
    /**
63
     * Filters messages based on `dust.debugLevel`.
64
     * This default implementation will print to the console if it exists.
65
     * @param {String|Error} message the message to print/throw
66
     * @param {String} type the severity of the message(ERROR, WARN, INFO, or DEBUG)
67
     * @public
68
     */
69
    dust.log = function(message, type) {
70
      type = type || INFO;
71
      if (loggingLevels[type] >= loggingLevels[dust.debugLevel]) {
72
        log('[DUST:' + type + ']', message);
73
      }
74
    };
75
 
76
    dust.debugLevel = NONE;
77
    if(typeof process !== 'undefined' && process.env && /\bdust\b/.test(process.env.DEBUG)) {
78
      dust.debugLevel = DEBUG;
79
    }
80
 
81
  }());
82
 
83
  dust.helpers = {};
84
 
85
  dust.cache = {};
86
 
87
  dust.register = function(name, tmpl) {
88
    if (!name) {
89
      return;
90
    }
91
    tmpl.templateName = name;
92
    if (dust.config.cache !== false) {
93
      dust.cache[name] = tmpl;
94
    }
95
  };
96
 
97
  dust.render = function(nameOrTemplate, context, callback) {
98
    var chunk = new Stub(callback).head;
99
    try {
100
      load(nameOrTemplate, chunk, context).end();
101
    } catch (err) {
102
      chunk.setError(err);
103
    }
104
  };
105
 
106
  dust.stream = function(nameOrTemplate, context) {
107
    var stream = new Stream(),
108
        chunk = stream.head;
109
    dust.nextTick(function() {
110
      try {
111
        load(nameOrTemplate, chunk, context).end();
112
      } catch (err) {
113
        chunk.setError(err);
114
      }
115
    });
116
    return stream;
117
  };
118
 
119
  /**
120
   * Extracts a template function (body_0) from whatever is passed.
121
   * @param nameOrTemplate {*} Could be:
122
   *   - the name of a template to load from cache
123
   *   - a CommonJS-compiled template (a function with a `template` property)
124
   *   - a template function
125
   * @param loadFromCache {Boolean} if false, don't look in the cache
126
   * @return {Function} a template function, if found
127
   */
128
  function getTemplate(nameOrTemplate, loadFromCache/*=true*/) {
129
    if(!nameOrTemplate) {
130
      return;
131
    }
132
    if(typeof nameOrTemplate === 'function' && nameOrTemplate.template) {
133
      // Sugar away CommonJS module templates
134
      return nameOrTemplate.template;
135
    }
136
    if(dust.isTemplateFn(nameOrTemplate)) {
137
      // Template functions passed directly
138
      return nameOrTemplate;
139
    }
140
    if(loadFromCache !== false) {
141
      // Try loading a template with this name from cache
142
      return dust.cache[nameOrTemplate];
143
    }
144
  }
145
 
146
  function load(nameOrTemplate, chunk, context) {
147
    if(!nameOrTemplate) {
148
      return chunk.setError(new Error('No template or template name provided to render'));
149
    }
150
 
151
    var template = getTemplate(nameOrTemplate, dust.config.cache);
152
 
153
    if (template) {
154
      return template(chunk, Context.wrap(context, template.templateName));
155
    } else {
156
      if (dust.onLoad) {
157
        return chunk.map(function(chunk) {
158
          // Alias just so it's easier to read that this would always be a name
159
          var name = nameOrTemplate;
160
          // Three possible scenarios for a successful callback:
161
          //   - `require(nameOrTemplate)(dust); cb()`
162
          //   - `src = readFile('src.dust'); cb(null, src)`
163
          //   - `compiledTemplate = require(nameOrTemplate)(dust); cb(null, compiledTemplate)`
164
          function done(err, srcOrTemplate) {
165
            var template;
166
            if (err) {
167
              return chunk.setError(err);
168
            }
169
            // Prefer a template that is passed via callback over the cached version.
170
            template = getTemplate(srcOrTemplate, false) || getTemplate(name, dust.config.cache);
171
            if (!template) {
172
              // It's a template string, compile it and register under `name`
173
              if(dust.compile) {
174
                template = dust.loadSource(dust.compile(srcOrTemplate, name));
175
              } else {
176
                return chunk.setError(new Error('Dust compiler not available'));
177
              }
178
            }
179
            template(chunk, Context.wrap(context, template.templateName)).end();
180
          }
181
 
182
          if(dust.onLoad.length === 3) {
183
            dust.onLoad(name, context.options, done);
184
          } else {
185
            dust.onLoad(name, done);
186
          }
187
        });
188
      }
189
      return chunk.setError(new Error('Template Not Found: ' + nameOrTemplate));
190
    }
191
  }
192
 
193
  dust.loadSource = function(source) {
194
    /*jshint evil:true*/
195
    return eval(source);
196
  };
197
 
198
  if (Array.isArray) {
199
    dust.isArray = Array.isArray;
200
  } else {
201
    dust.isArray = function(arr) {
202
      return Object.prototype.toString.call(arr) === '[object Array]';
203
    };
204
  }
205
 
206
  dust.nextTick = (function() {
207
    return function(callback) {
208
      setTimeout(callback, 0);
209
    };
210
  })();
211
 
212
  /**
213
   * Dust has its own rules for what is "empty"-- which is not the same as falsy.
214
   * Empty arrays, null, and undefined are empty
215
   */
216
  dust.isEmpty = function(value) {
217
    if (value === 0) {
218
      return false;
219
    }
220
    if (dust.isArray(value) && !value.length) {
221
      return true;
222
    }
223
    return !value;
224
  };
225
 
226
  dust.isEmptyObject = function(obj) {
227
    var key;
228
    if (obj === null) {
229
      return false;
230
    }
231
    if (obj === undefined) {
232
      return false;
233
    }
234
    if (obj.length > 0) {
235
      return false;
236
    }
237
    for (key in obj) {
238
      if (Object.prototype.hasOwnProperty.call(obj, key)) {
239
        return false;
240
      }
241
    }
242
    return true;
243
  };
244
 
245
  dust.isTemplateFn = function(elem) {
246
    return typeof elem === 'function' &&
247
           elem.__dustBody;
248
  };
249
 
250
  /**
251
   * Decide somewhat-naively if something is a Thenable.
252
   * @param elem {*} object to inspect
253
   * @return {Boolean} is `elem` a Thenable?
254
   */
255
  dust.isThenable = function(elem) {
256
    return elem &&
257
           typeof elem === 'object' &&
258
           typeof elem.then === 'function';
259
  };
260
 
261
  /**
262
   * Decide very naively if something is a Stream.
263
   * @param elem {*} object to inspect
264
   * @return {Boolean} is `elem` a Stream?
265
   */
266
  dust.isStreamable = function(elem) {
267
    return elem &&
268
           typeof elem.on === 'function' &&
269
           typeof elem.pipe === 'function';
270
  };
271
 
272
  // apply the filter chain and return the output string
273
  dust.filter = function(string, auto, filters, context) {
274
    var i, len, name, filter;
275
    if (filters) {
276
      for (i = 0, len = filters.length; i < len; i++) {
277
        name = filters[i];
278
        if (!name.length) {
279
          continue;
280
        }
281
        filter = dust.filters[name];
282
        if (name === 's') {
283
          auto = null;
284
        } else if (typeof filter === 'function') {
285
          string = filter(string, context);
286
        } else {
287
          dust.log('Invalid filter `' + name + '`', WARN);
288
        }
289
      }
290
    }
291
    // by default always apply the h filter, unless asked to unescape with |s
292
    if (auto) {
293
      string = dust.filters[auto](string, context);
294
    }
295
    return string;
296
  };
297
 
298
  dust.filters = {
299
    h: function(value) { return dust.escapeHtml(value); },
300
    j: function(value) { return dust.escapeJs(value); },
301
    u: encodeURI,
302
    uc: encodeURIComponent,
303
    js: function(value) { return dust.escapeJSON(value); },
304
    jp: function(value) {
305
      if (!JSON) {dust.log('JSON is undefined; could not parse `' + value + '`', WARN);
306
        return value;
307
      } else {
308
        return JSON.parse(value);
309
      }
310
    }
311
  };
312
 
313
  function Context(stack, global, options, blocks, templateName) {
314
    if(stack !== undefined && !(stack instanceof Stack)) {
315
      stack = new Stack(stack);
316
    }
317
    this.stack = stack;
318
    this.global = global;
319
    this.options = options;
320
    this.blocks = blocks;
321
    this.templateName = templateName;
322
  }
323
 
324
  dust.makeBase = dust.context = function(global, options) {
325
    return new Context(undefined, global, options);
326
  };
327
 
328
  /**
329
   * Factory function that creates a closure scope around a Thenable-callback.
330
   * Returns a function that can be passed to a Thenable that will resume a
331
   * Context lookup once the Thenable resolves with new data, adding that new
332
   * data to the lookup stack.
333
   */
334
  function getWithResolvedData(ctx, cur, down) {
335
    return function(data) {
336
      return ctx.push(data)._get(cur, down);
337
    };
338
  }
339
 
340
  Context.wrap = function(context, name) {
341
    if (context instanceof Context) {
342
      return context;
343
    }
344
    return new Context(context, {}, {}, null, name);
345
  };
346
 
347
  /**
348
   * Public API for getting a value from the context.
349
   * @method get
350
   * @param {string|array} path The path to the value. Supported formats are:
351
   * 'key'
352
   * 'path.to.key'
353
   * '.path.to.key'
354
   * ['path', 'to', 'key']
355
   * ['key']
356
   * @param {boolean} [cur=false] Boolean which determines if the search should be limited to the
357
   * current context (true), or if get should search in parent contexts as well (false).
358
   * @public
359
   * @returns {string|object}
360
   */
361
  Context.prototype.get = function(path, cur) {
362
    if (typeof path === 'string') {
363
      if (path[0] === '.') {
364
        cur = true;
365
        path = path.substr(1);
366
      }
367
      path = path.split('.');
368
    }
369
    return this._get(cur, path);
370
  };
371
 
372
  /**
373
   * Get a value from the context
374
   * @method _get
375
   * @param {boolean} cur Get only from the current context
376
   * @param {array} down An array of each step in the path
377
   * @private
378
   * @return {string | object}
379
   */
380
  Context.prototype._get = function(cur, down) {
381
    var ctx = this.stack || {},
382
        i = 1,
383
        value, first, len, ctxThis, fn;
384
 
385
    first = down[0];
386
    len = down.length;
387
 
388
    if (cur && len === 0) {
389
      ctxThis = ctx;
390
      ctx = ctx.head;
391
    } else {
392
      if (!cur) {
393
        // Search up the stack for the first value
394
        while (ctx) {
395
          if (ctx.isObject) {
396
            ctxThis = ctx.head;
397
            value = ctx.head[first];
398
            if (value !== undefined) {
399
              break;
400
            }
401
          }
402
          ctx = ctx.tail;
403
        }
404
 
405
        // Try looking in the global context if we haven't found anything yet
406
        if (value !== undefined) {
407
          ctx = value;
408
        } else {
409
          ctx = this.global && this.global[first];
410
        }
411
      } else if (ctx) {
412
        // if scope is limited by a leading dot, don't search up the tree
413
        if(ctx.head) {
414
          ctx = ctx.head[first];
415
        } else {
416
          // context's head is empty, value we are searching for is not defined
417
          ctx = undefined;
418
        }
419
      }
420
 
421
      while (ctx && i < len) {
422
        if (dust.isThenable(ctx)) {
423
          // Bail early by returning a Thenable for the remainder of the search tree
424
          return ctx.then(getWithResolvedData(this, cur, down.slice(i)));
425
        }
426
        ctxThis = ctx;
427
        ctx = ctx[down[i]];
428
        i++;
429
      }
430
    }
431
 
432
    if (typeof ctx === 'function') {
433
      fn = function() {
434
        try {
435
          return ctx.apply(ctxThis, arguments);
436
        } catch (err) {
437
          dust.log(err, ERROR);
438
          throw err;
439
        }
440
      };
441
      fn.__dustBody = !!ctx.__dustBody;
442
      return fn;
443
    } else {
444
      if (ctx === undefined) {
445
        dust.log('Cannot find reference `{' + down.join('.') + '}` in template `' + this.getTemplateName() + '`', INFO);
446
      }
447
      return ctx;
448
    }
449
  };
450
 
451
  Context.prototype.getPath = function(cur, down) {
452
    return this._get(cur, down);
453
  };
454
 
455
  Context.prototype.push = function(head, idx, len) {
456
    if(head === undefined) {
457
      dust.log("Not pushing an undefined variable onto the context", INFO);
458
      return this;
459
    }
460
    return this.rebase(new Stack(head, this.stack, idx, len));
461
  };
462
 
463
  Context.prototype.pop = function() {
464
    var head = this.current();
465
    this.stack = this.stack && this.stack.tail;
466
    return head;
467
  };
468
 
469
  Context.prototype.rebase = function(head) {
470
    return new Context(head, this.global, this.options, this.blocks, this.getTemplateName());
471
  };
472
 
473
  Context.prototype.clone = function() {
474
    var context = this.rebase();
475
    context.stack = this.stack;
476
    return context;
477
  };
478
 
479
  Context.prototype.current = function() {
480
    return this.stack && this.stack.head;
481
  };
482
 
483
  Context.prototype.getBlock = function(key) {
484
    var blocks, len, fn;
485
 
486
    if (typeof key === 'function') {
487
      key = key(new Chunk(), this).data.join('');
488
    }
489
 
490
    blocks = this.blocks;
491
 
492
    if (!blocks) {
493
      dust.log('No blocks for context `' + key + '` in template `' + this.getTemplateName() + '`', DEBUG);
494
      return false;
495
    }
496
 
497
    len = blocks.length;
498
    while (len--) {
499
      fn = blocks[len][key];
500
      if (fn) {
501
        return fn;
502
      }
503
    }
504
 
505
    dust.log('Malformed template `' + this.getTemplateName() + '` was missing one or more blocks.');
506
    return false;
507
  };
508
 
509
  Context.prototype.shiftBlocks = function(locals) {
510
    var blocks = this.blocks,
511
        newBlocks;
512
 
513
    if (locals) {
514
      if (!blocks) {
515
        newBlocks = [locals];
516
      } else {
517
        newBlocks = blocks.concat([locals]);
518
      }
519
      return new Context(this.stack, this.global, this.options, newBlocks, this.getTemplateName());
520
    }
521
    return this;
522
  };
523
 
524
  Context.prototype.resolve = function(body) {
525
    var chunk;
526
 
527
    if(typeof body !== 'function') {
528
      return body;
529
    }
530
    chunk = new Chunk().render(body, this);
531
    if(chunk instanceof Chunk) {
532
      return chunk.data.join(''); // ie7 perf
533
    }
534
    return chunk;
535
  };
536
 
537
  Context.prototype.getTemplateName = function() {
538
    return this.templateName;
539
  };
540
 
541
  function Stack(head, tail, idx, len) {
542
    this.tail = tail;
543
    this.isObject = head && typeof head === 'object';
544
    this.head = head;
545
    this.index = idx;
546
    this.of = len;
547
  }
548
 
549
  function Stub(callback) {
550
    this.head = new Chunk(this);
551
    this.callback = callback;
552
    this.out = '';
553
  }
554
 
555
  Stub.prototype.flush = function() {
556
    var chunk = this.head;
557
 
558
    while (chunk) {
559
      if (chunk.flushable) {
560
        this.out += chunk.data.join(''); //ie7 perf
561
      } else if (chunk.error) {
562
        this.callback(chunk.error);
563
        dust.log('Rendering failed with error `' + chunk.error + '`', ERROR);
564
        this.flush = EMPTY_FUNC;
565
        return;
566
      } else {
567
        return;
568
      }
569
      chunk = chunk.next;
570
      this.head = chunk;
571
    }
572
    this.callback(null, this.out);
573
  };
574
 
575
  /**
576
   * Creates an interface sort of like a Streams2 ReadableStream.
577
   */
578
  function Stream() {
579
    this.head = new Chunk(this);
580
  }
581
 
582
  Stream.prototype.flush = function() {
583
    var chunk = this.head;
584
 
585
    while(chunk) {
586
      if (chunk.flushable) {
587
        this.emit('data', chunk.data.join('')); //ie7 perf
588
      } else if (chunk.error) {
589
        this.emit('error', chunk.error);
590
        this.emit('end');
591
        dust.log('Streaming failed with error `' + chunk.error + '`', ERROR);
592
        this.flush = EMPTY_FUNC;
593
        return;
594
      } else {
595
        return;
596
      }
597
      chunk = chunk.next;
598
      this.head = chunk;
599
    }
600
    this.emit('end');
601
  };
602
 
603
  /**
604
   * Executes listeners for `type` by passing data. Note that this is different from a
605
   * Node stream, which can pass an arbitrary number of arguments
606
   * @return `true` if event had listeners, `false` otherwise
607
   */
608
  Stream.prototype.emit = function(type, data) {
609
    var events = this.events || {},
610
        handlers = events[type] || [],
611
        i, l;
612
 
613
    if (!handlers.length) {
614
      dust.log('Stream broadcasting, but no listeners for `' + type + '`', DEBUG);
615
      return false;
616
    }
617
 
618
    handlers = handlers.slice(0);
619
    for (i = 0, l = handlers.length; i < l; i++) {
620
      handlers[i](data);
621
    }
622
    return true;
623
  };
624
 
625
  Stream.prototype.on = function(type, callback) {
626
    var events = this.events = this.events || {},
627
        handlers = events[type] = events[type] || [];
628
 
629
    if(typeof callback !== 'function') {
630
      dust.log('No callback function provided for `' + type + '` event listener', WARN);
631
    } else {
632
      handlers.push(callback);
633
    }
634
    return this;
635
  };
636
 
637
  /**
638
   * Pipes to a WritableStream. Note that backpressure isn't implemented,
639
   * so we just write as fast as we can.
640
   * @param stream {WritableStream}
641
   * @return self
642
   */
643
  Stream.prototype.pipe = function(stream) {
644
    if(typeof stream.write !== 'function' ||
645
       typeof stream.end !== 'function') {
646
      dust.log('Incompatible stream passed to `pipe`', WARN);
647
      return this;
648
    }
649
 
650
    var destEnded = false;
651
 
652
    if(typeof stream.emit === 'function') {
653
      stream.emit('pipe', this);
654
    }
655
 
656
    if(typeof stream.on === 'function') {
657
      stream.on('error', function() {
658
        destEnded = true;
659
      });
660
    }
661
 
662
    return this
663
    .on('data', function(data) {
664
      if(destEnded) {
665
        return;
666
      }
667
      try {
668
        stream.write(data, 'utf8');
669
      } catch (err) {
670
        dust.log(err, ERROR);
671
      }
672
    })
673
    .on('end', function() {
674
      if(destEnded) {
675
        return;
676
      }
677
      try {
678
        stream.end();
679
        destEnded = true;
680
      } catch (err) {
681
        dust.log(err, ERROR);
682
      }
683
    });
684
  };
685
 
686
  function Chunk(root, next, taps) {
687
    this.root = root;
688
    this.next = next;
689
    this.data = []; //ie7 perf
690
    this.flushable = false;
691
    this.taps = taps;
692
  }
693
 
694
  Chunk.prototype.write = function(data) {
695
    var taps = this.taps;
696
 
697
    if (taps) {
698
      data = taps.go(data);
699
    }
700
    this.data.push(data);
701
    return this;
702
  };
703
 
704
  Chunk.prototype.end = function(data) {
705
    if (data) {
706
      this.write(data);
707
    }
708
    this.flushable = true;
709
    this.root.flush();
710
    return this;
711
  };
712
 
713
  Chunk.prototype.map = function(callback) {
714
    var cursor = new Chunk(this.root, this.next, this.taps),
715
        branch = new Chunk(this.root, cursor, this.taps);
716
 
717
    this.next = branch;
718
    this.flushable = true;
719
    try {
720
      callback(branch);
721
    } catch(err) {
722
      dust.log(err, ERROR);
723
      branch.setError(err);
724
    }
725
    return cursor;
726
  };
727
 
728
  Chunk.prototype.tap = function(tap) {
729
    var taps = this.taps;
730
 
731
    if (taps) {
732
      this.taps = taps.push(tap);
733
    } else {
734
      this.taps = new Tap(tap);
735
    }
736
    return this;
737
  };
738
 
739
  Chunk.prototype.untap = function() {
740
    this.taps = this.taps.tail;
741
    return this;
742
  };
743
 
744
  Chunk.prototype.render = function(body, context) {
745
    return body(this, context);
746
  };
747
 
748
  Chunk.prototype.reference = function(elem, context, auto, filters) {
749
    if (typeof elem === 'function') {
750
      elem = elem.apply(context.current(), [this, context, null, {auto: auto, filters: filters}]);
751
      if (elem instanceof Chunk) {
752
        return elem;
753
      } else {
754
        return this.reference(elem, context, auto, filters);
755
      }
756
    }
757
    if (dust.isThenable(elem)) {
758
      return this.await(elem, context, null, auto, filters);
759
    } else if (dust.isStreamable(elem)) {
760
      return this.stream(elem, context, null, auto, filters);
761
    } else if (!dust.isEmpty(elem)) {
762
      return this.write(dust.filter(elem, auto, filters, context));
763
    } else {
764
      return this;
765
    }
766
  };
767
 
768
  Chunk.prototype.section = function(elem, context, bodies, params) {
769
    var body = bodies.block,
770
        skip = bodies['else'],
771
        chunk = this,
772
        i, len, head;
773
 
774
    if (typeof elem === 'function' && !dust.isTemplateFn(elem)) {
775
      try {
776
        elem = elem.apply(context.current(), [this, context, bodies, params]);
777
      } catch(err) {
778
        dust.log(err, ERROR);
779
        return this.setError(err);
780
      }
781
      // Functions that return chunks are assumed to have handled the chunk manually.
782
      // Make that chunk the current one and go to the next method in the chain.
783
      if (elem instanceof Chunk) {
784
        return elem;
785
      }
786
    }
787
 
788
    if (dust.isEmptyObject(bodies)) {
789
      // No bodies to render, and we've already invoked any function that was available in
790
      // hopes of returning a Chunk.
791
      return chunk;
792
    }
793
 
794
    if (!dust.isEmptyObject(params)) {
795
      context = context.push(params);
796
    }
797
 
798
    /*
799
    Dust's default behavior is to enumerate over the array elem, passing each object in the array to the block.
800
    When elem resolves to a value or object instead of an array, Dust sets the current context to the value
801
    and renders the block one time.
802
    */
803
    if (dust.isArray(elem)) {
804
      if (body) {
805
        len = elem.length;
806
        if (len > 0) {
807
          head = context.stack && context.stack.head || {};
808
          head.$len = len;
809
          for (i = 0; i < len; i++) {
810
            head.$idx = i;
811
            chunk = body(chunk, context.push(elem[i], i, len));
812
          }
813
          head.$idx = undefined;
814
          head.$len = undefined;
815
          return chunk;
816
        } else if (skip) {
817
          return skip(this, context);
818
        }
819
      }
820
    } else if (dust.isThenable(elem)) {
821
      return this.await(elem, context, bodies);
822
    } else if (dust.isStreamable(elem)) {
823
      return this.stream(elem, context, bodies);
824
    } else if (elem === true) {
825
     // true is truthy but does not change context
826
      if (body) {
827
        return body(this, context);
828
      }
829
    } else if (elem || elem === 0) {
830
       // everything that evaluates to true are truthy ( e.g. Non-empty strings and Empty objects are truthy. )
831
       // zero is truthy
832
       // for anonymous functions that did not returns a chunk, truthiness is evaluated based on the return value
833
      if (body) {
834
        return body(this, context.push(elem));
835
      }
836
     // nonexistent, scalar false value, scalar empty string, null,
837
     // undefined are all falsy
838
    } else if (skip) {
839
      return skip(this, context);
840
    }
841
    dust.log('Section without corresponding key in template `' + context.getTemplateName() + '`', DEBUG);
842
    return this;
843
  };
844
 
845
  Chunk.prototype.exists = function(elem, context, bodies) {
846
    var body = bodies.block,
847
        skip = bodies['else'];
848
 
849
    if (!dust.isEmpty(elem)) {
850
      if (body) {
851
        return body(this, context);
852
      }
853
      dust.log('No block for exists check in template `' + context.getTemplateName() + '`', DEBUG);
854
    } else if (skip) {
855
      return skip(this, context);
856
    }
857
    return this;
858
  };
859
 
860
  Chunk.prototype.notexists = function(elem, context, bodies) {
861
    var body = bodies.block,
862
        skip = bodies['else'];
863
 
864
    if (dust.isEmpty(elem)) {
865
      if (body) {
866
        return body(this, context);
867
      }
868
      dust.log('No block for not-exists check in template `' + context.getTemplateName() + '`', DEBUG);
869
    } else if (skip) {
870
      return skip(this, context);
871
    }
872
    return this;
873
  };
874
 
875
  Chunk.prototype.block = function(elem, context, bodies) {
876
    var body = elem || bodies.block;
877
 
878
    if (body) {
879
      return body(this, context);
880
    }
881
    return this;
882
  };
883
 
884
  Chunk.prototype.partial = function(elem, context, partialContext, params) {
885
    var head;
886
 
887
    if(params === undefined) {
888
      // Compatibility for < 2.7.0 where `partialContext` did not exist
889
      params = partialContext;
890
      partialContext = context;
891
    }
892
 
893
    if (!dust.isEmptyObject(params)) {
894
      partialContext = partialContext.clone();
895
      head = partialContext.pop();
896
      partialContext = partialContext.push(params)
897
                                     .push(head);
898
    }
899
 
900
    if (dust.isTemplateFn(elem)) {
901
      // The eventual result of evaluating `elem` is a partial name
902
      // Load the partial after getting its name and end the async chunk
903
      return this.capture(elem, context, function(name, chunk) {
904
        partialContext.templateName = name;
905
        load(name, chunk, partialContext).end();
906
      });
907
    } else {
908
      partialContext.templateName = elem;
909
      return load(elem, this, partialContext);
910
    }
911
  };
912
 
913
  Chunk.prototype.helper = function(name, context, bodies, params, auto) {
914
    var chunk = this,
915
        filters = params.filters,
916
        ret;
917
 
918
    // Pre-2.7.1 compat: if auto is undefined, it's an old template. Automatically escape
919
    if (auto === undefined) {
920
      auto = 'h';
921
    }
922
 
923
    // handle invalid helpers, similar to invalid filters
924
    if(dust.helpers[name]) {
925
      try {
926
        ret = dust.helpers[name](chunk, context, bodies, params);
927
        if (ret instanceof Chunk) {
928
          return ret;
929
        }
930
        if(typeof filters === 'string') {
931
          filters = filters.split('|');
932
        }
933
        if (!dust.isEmptyObject(bodies)) {
934
          return chunk.section(ret, context, bodies, params);
935
        }
936
        // Helpers act slightly differently from functions in context in that they will act as
937
        // a reference if they are self-closing (due to grammar limitations)
938
        // In the Chunk.await function we check to make sure bodies is null before acting as a reference
939
        return chunk.reference(ret, context, auto, filters);
940
      } catch(err) {
941
        dust.log('Error in helper `' + name + '`: ' + err.message, ERROR);
942
        return chunk.setError(err);
943
      }
944
    } else {
945
      dust.log('Helper `' + name + '` does not exist', WARN);
946
      return chunk;
947
    }
948
  };
949
 
950
  /**
951
   * Reserve a chunk to be evaluated once a thenable is resolved or rejected
952
   * @param thenable {Thenable} the target thenable to await
953
   * @param context {Context} context to use to render the deferred chunk
954
   * @param bodies {Object} must contain a "body", may contain an "error"
955
   * @param auto {String} automatically apply this filter if the Thenable is a reference
956
   * @param filters {Array} apply these filters if the Thenable is a reference
957
   * @return {Chunk}
958
   */
959
  Chunk.prototype.await = function(thenable, context, bodies, auto, filters) {
960
    return this.map(function(chunk) {
961
      thenable.then(function(data) {
962
        if (bodies) {
963
          chunk = chunk.section(data, context, bodies);
964
        } else {
965
          // Actually a reference. Self-closing sections don't render
966
          chunk = chunk.reference(data, context, auto, filters);
967
        }
968
        chunk.end();
969
      }, function(err) {
970
        var errorBody = bodies && bodies.error;
971
        if(errorBody) {
972
          chunk.render(errorBody, context.push(err)).end();
973
        } else {
974
          dust.log('Unhandled promise rejection in `' + context.getTemplateName() + '`', INFO);
975
          chunk.end();
976
        }
977
      });
978
    });
979
  };
980
 
981
  /**
982
   * Reserve a chunk to be evaluated with the contents of a streamable.
983
   * Currently an error event will bomb out the stream. Once an error
984
   * is received, we push it to an {:error} block if one exists, and log otherwise,
985
   * then stop listening to the stream.
986
   * @param streamable {Streamable} the target streamable that will emit events
987
   * @param context {Context} context to use to render each thunk
988
   * @param bodies {Object} must contain a "body", may contain an "error"
989
   * @return {Chunk}
990
   */
991
  Chunk.prototype.stream = function(stream, context, bodies, auto, filters) {
992
    var body = bodies && bodies.block,
993
        errorBody = bodies && bodies.error;
994
    return this.map(function(chunk) {
995
      var ended = false;
996
      stream
997
        .on('data', function data(thunk) {
998
          if(ended) {
999
            return;
1000
          }
1001
          if(body) {
1002
            // Fork a new chunk out of the blockstream so that we can flush it independently
1003
            chunk = chunk.map(function(chunk) {
1004
              chunk.render(body, context.push(thunk)).end();
1005
            });
1006
          } else if(!bodies) {
1007
            // When actually a reference, don't fork, just write into the master async chunk
1008
            chunk = chunk.reference(thunk, context, auto, filters);
1009
          }
1010
        })
1011
        .on('error', function error(err) {
1012
          if(ended) {
1013
            return;
1014
          }
1015
          if(errorBody) {
1016
            chunk.render(errorBody, context.push(err));
1017
          } else {
1018
            dust.log('Unhandled stream error in `' + context.getTemplateName() + '`', INFO);
1019
          }
1020
          if(!ended) {
1021
            ended = true;
1022
            chunk.end();
1023
          }
1024
        })
1025
        .on('end', function end() {
1026
          if(!ended) {
1027
            ended = true;
1028
            chunk.end();
1029
          }
1030
        });
1031
    });
1032
  };
1033
 
1034
  Chunk.prototype.capture = function(body, context, callback) {
1035
    return this.map(function(chunk) {
1036
      var stub = new Stub(function(err, out) {
1037
        if (err) {
1038
          chunk.setError(err);
1039
        } else {
1040
          callback(out, chunk);
1041
        }
1042
      });
1043
      body(stub.head, context).end();
1044
    });
1045
  };
1046
 
1047
  Chunk.prototype.setError = function(err) {
1048
    this.error = err;
1049
    this.root.flush();
1050
    return this;
1051
  };
1052
 
1053
  // Chunk aliases
1054
  for(var f in Chunk.prototype) {
1055
    if(dust._aliases[f]) {
1056
      Chunk.prototype[dust._aliases[f]] = Chunk.prototype[f];
1057
    }
1058
  }
1059
 
1060
  function Tap(head, tail) {
1061
    this.head = head;
1062
    this.tail = tail;
1063
  }
1064
 
1065
  Tap.prototype.push = function(tap) {
1066
    return new Tap(tap, this);
1067
  };
1068
 
1069
  Tap.prototype.go = function(value) {
1070
    var tap = this;
1071
 
1072
    while(tap) {
1073
      value = tap.head(value);
1074
      tap = tap.tail;
1075
    }
1076
    return value;
1077
  };
1078
 
1079
  var HCHARS = /[&<>"']/,
1080
      AMP    = /&/g,
1081
      LT     = /</g,
1082
      GT     = />/g,
1083
      QUOT   = /\"/g,
1084
      SQUOT  = /\'/g;
1085
 
1086
  dust.escapeHtml = function(s) {
1087
    if (typeof s === "string" || (s && typeof s.toString === "function")) {
1088
      if (typeof s !== "string") {
1089
        s = s.toString();
1090
      }
1091
      if (!HCHARS.test(s)) {
1092
        return s;
1093
      }
1094
      return s.replace(AMP,'&amp;').replace(LT,'&lt;').replace(GT,'&gt;').replace(QUOT,'&quot;').replace(SQUOT, '&#39;');
1095
    }
1096
    return s;
1097
  };
1098
 
1099
  var BS = /\\/g,
1100
      FS = /\//g,
1101
      CR = /\r/g,
1102
      LS = /\u2028/g,
1103
      PS = /\u2029/g,
1104
      NL = /\n/g,
1105
      LF = /\f/g,
1106
      SQ = /'/g,
1107
      DQ = /"/g,
1108
      TB = /\t/g;
1109
 
1110
  dust.escapeJs = function(s) {
1111
    if (typeof s === 'string') {
1112
      return s
1113
        .replace(BS, '\\\\')
1114
        .replace(FS, '\\/')
1115
        .replace(DQ, '\\"')
1116
        .replace(SQ, '\\\'')
1117
        .replace(CR, '\\r')
1118
        .replace(LS, '\\u2028')
1119
        .replace(PS, '\\u2029')
1120
        .replace(NL, '\\n')
1121
        .replace(LF, '\\f')
1122
        .replace(TB, '\\t');
1123
    }
1124
    return s;
1125
  };
1126
 
1127
  dust.escapeJSON = function(o) {
1128
    if (!JSON) {
1129
      dust.log('JSON is undefined; could not escape `' + o + '`', WARN);
1130
      return o;
1131
    } else {
1132
      return JSON.stringify(o)
1133
        .replace(LS, '\\u2028')
1134
        .replace(PS, '\\u2029')
1135
        .replace(LT, '\\u003c');
1136
    }
1137
  };
1138
 
1139
  return dust;
1140
 
1141
}));
1142
 
1143
(function(root, factory) {
1144
  if (typeof define === "function" && define.amd && define.amd.dust === true) {
1145
    define("dust.parse", ["dust.core"], function(dust) {
1146
      return factory(dust).parse;
1147
    });
1148
  } else if (typeof exports === 'object') {
1149
    // in Node, require this file if we want to use the parser as a standalone module
1150
    module.exports = factory(require('./dust'));
1151
    // @see server file for parser methods exposed in node
1152
  } else {
1153
    // in the browser, store the factory output if we want to use the parser directly
1154
    factory(root.dust);
1155
  }
1156
}(this, function(dust) {
1157
  var parser = (function() {
1158
  /*
1159
   * Generated by PEG.js 0.8.0.
1160
   *
1161
   * http://pegjs.majda.cz/
1162
   */
1163
 
1164
  function peg$subclass(child, parent) {
1165
    function ctor() { this.constructor = child; }
1166
    ctor.prototype = parent.prototype;
1167
    child.prototype = new ctor();
1168
  }
1169
 
1170
  function SyntaxError(message, expected, found, offset, line, column) {
1171
    this.message  = message;
1172
    this.expected = expected;
1173
    this.found    = found;
1174
    this.offset   = offset;
1175
    this.line     = line;
1176
    this.column   = column;
1177
 
1178
    this.name     = "SyntaxError";
1179
  }
1180
 
1181
  peg$subclass(SyntaxError, Error);
1182
 
1183
  function parse(input) {
1184
    var options = arguments.length > 1 ? arguments[1] : {},
1185
 
1186
        peg$FAILED = {},
1187
 
1188
        peg$startRuleFunctions = { start: peg$parsestart },
1189
        peg$startRuleFunction  = peg$parsestart,
1190
 
1191
        peg$c0 = [],
1192
        peg$c1 = function(p) {
1193
            var body = ["body"].concat(p);
1194
            return withPosition(body);
1195
          },
1196
        peg$c2 = { type: "other", description: "section" },
1197
        peg$c3 = peg$FAILED,
1198
        peg$c4 = null,
1199
        peg$c5 = function(t, b, e, n) {
1200
            if( (!n) || (t[1].text !== n.text) ) {
1201
              error("Expected end tag for "+t[1].text+" but it was not found.");
1202
            }
1203
            return true;
1204
          },
1205
        peg$c6 = void 0,
1206
        peg$c7 = function(t, b, e, n) {
1207
            e.push(["param", ["literal", "block"], b]);
1208
            t.push(e, ["filters"]);
1209
            return withPosition(t)
1210
          },
1211
        peg$c8 = "/",
1212
        peg$c9 = { type: "literal", value: "/", description: "\"/\"" },
1213
        peg$c10 = function(t) {
1214
            t.push(["bodies"], ["filters"]);
1215
            return withPosition(t)
1216
          },
1217
        peg$c11 = /^[#?\^<+@%]/,
1218
        peg$c12 = { type: "class", value: "[#?\\^<+@%]", description: "[#?\\^<+@%]" },
1219
        peg$c13 = function(t, n, c, p) { return [t, n, c, p] },
1220
        peg$c14 = { type: "other", description: "end tag" },
1221
        peg$c15 = function(n) { return n },
1222
        peg$c16 = ":",
1223
        peg$c17 = { type: "literal", value: ":", description: "\":\"" },
1224
        peg$c18 = function(n) {return n},
1225
        peg$c19 = function(n) { return n ? ["context", n] : ["context"] },
1226
        peg$c20 = { type: "other", description: "params" },
1227
        peg$c21 = "=",
1228
        peg$c22 = { type: "literal", value: "=", description: "\"=\"" },
1229
        peg$c23 = function(k, v) {return ["param", ["literal", k], v]},
1230
        peg$c24 = function(p) { return ["params"].concat(p) },
1231
        peg$c25 = { type: "other", description: "bodies" },
1232
        peg$c26 = function(p) { return ["bodies"].concat(p) },
1233
        peg$c27 = { type: "other", description: "reference" },
1234
        peg$c28 = function(n, f) { return withPosition(["reference", n, f]) },
1235
        peg$c29 = { type: "other", description: "partial" },
1236
        peg$c30 = ">",
1237
        peg$c31 = { type: "literal", value: ">", description: "\">\"" },
1238
        peg$c32 = "+",
1239
        peg$c33 = { type: "literal", value: "+", description: "\"+\"" },
1240
        peg$c34 = function(k) {return ["literal", k]},
1241
        peg$c35 = function(s, n, c, p) {
1242
            var key = (s === ">") ? "partial" : s;
1243
            return withPosition([key, n, c, p])
1244
          },
1245
        peg$c36 = { type: "other", description: "filters" },
1246
        peg$c37 = "|",
1247
        peg$c38 = { type: "literal", value: "|", description: "\"|\"" },
1248
        peg$c39 = function(f) { return ["filters"].concat(f) },
1249
        peg$c40 = { type: "other", description: "special" },
1250
        peg$c41 = "~",
1251
        peg$c42 = { type: "literal", value: "~", description: "\"~\"" },
1252
        peg$c43 = function(k) { return withPosition(["special", k]) },
1253
        peg$c44 = { type: "other", description: "identifier" },
1254
        peg$c45 = function(p) {
1255
            var arr = ["path"].concat(p);
1256
            arr.text = p[1].join('.').replace(/,line,\d+,col,\d+/g,'');
1257
            return arr;
1258
          },
1259
        peg$c46 = function(k) {
1260
            var arr = ["key", k];
1261
            arr.text = k;
1262
            return arr;
1263
          },
1264
        peg$c47 = { type: "other", description: "number" },
1265
        peg$c48 = function(n) { return ['literal', n]; },
1266
        peg$c49 = { type: "other", description: "float" },
1267
        peg$c50 = ".",
1268
        peg$c51 = { type: "literal", value: ".", description: "\".\"" },
1269
        peg$c52 = function(l, r) { return parseFloat(l + "." + r); },
1270
        peg$c53 = { type: "other", description: "unsigned_integer" },
1271
        peg$c54 = /^[0-9]/,
1272
        peg$c55 = { type: "class", value: "[0-9]", description: "[0-9]" },
1273
        peg$c56 = function(digits) { return makeInteger(digits); },
1274
        peg$c57 = { type: "other", description: "signed_integer" },
1275
        peg$c58 = "-",
1276
        peg$c59 = { type: "literal", value: "-", description: "\"-\"" },
1277
        peg$c60 = function(sign, n) { return n * -1; },
1278
        peg$c61 = { type: "other", description: "integer" },
1279
        peg$c62 = { type: "other", description: "path" },
1280
        peg$c63 = function(k, d) {
1281
            d = d[0];
1282
            if (k && d) {
1283
              d.unshift(k);
1284
              return withPosition([false, d])
1285
            }
1286
            return withPosition([true, d])
1287
          },
1288
        peg$c64 = function(d) {
1289
            if (d.length > 0) {
1290
              return withPosition([true, d[0]])
1291
            }
1292
            return withPosition([true, []])
1293
          },
1294
        peg$c65 = { type: "other", description: "key" },
1295
        peg$c66 = /^[a-zA-Z_$]/,
1296
        peg$c67 = { type: "class", value: "[a-zA-Z_$]", description: "[a-zA-Z_$]" },
1297
        peg$c68 = /^[0-9a-zA-Z_$\-]/,
1298
        peg$c69 = { type: "class", value: "[0-9a-zA-Z_$\\-]", description: "[0-9a-zA-Z_$\\-]" },
1299
        peg$c70 = function(h, t) { return h + t.join('') },
1300
        peg$c71 = { type: "other", description: "array" },
1301
        peg$c72 = function(n) {return n.join('')},
1302
        peg$c73 = function(a) {return a; },
1303
        peg$c74 = function(i, nk) { if(nk) { nk.unshift(i); } else {nk = [i] } return nk; },
1304
        peg$c75 = { type: "other", description: "array_part" },
1305
        peg$c76 = function(k) {return k},
1306
        peg$c77 = function(d, a) { if (a) { return d.concat(a); } else { return d; } },
1307
        peg$c78 = { type: "other", description: "inline" },
1308
        peg$c79 = "\"",
1309
        peg$c80 = { type: "literal", value: "\"", description: "\"\\\"\"" },
1310
        peg$c81 = function() { return withPosition(["literal", ""]) },
1311
        peg$c82 = function(l) { return withPosition(["literal", l]) },
1312
        peg$c83 = function(p) { return withPosition(["body"].concat(p)) },
1313
        peg$c84 = function(l) { return ["buffer", l] },
1314
        peg$c85 = { type: "other", description: "buffer" },
1315
        peg$c86 = function(e, w) { return withPosition(["format", e, w.join('')]) },
1316
        peg$c87 = { type: "any", description: "any character" },
1317
        peg$c88 = function(c) {return c},
1318
        peg$c89 = function(b) { return withPosition(["buffer", b.join('')]) },
1319
        peg$c90 = { type: "other", description: "literal" },
1320
        peg$c91 = /^[^"]/,
1321
        peg$c92 = { type: "class", value: "[^\"]", description: "[^\"]" },
1322
        peg$c93 = function(b) { return b.join('') },
1323
        peg$c94 = "\\\"",
1324
        peg$c95 = { type: "literal", value: "\\\"", description: "\"\\\\\\\"\"" },
1325
        peg$c96 = function() { return '"' },
1326
        peg$c97 = { type: "other", description: "raw" },
1327
        peg$c98 = "{`",
1328
        peg$c99 = { type: "literal", value: "{`", description: "\"{`\"" },
1329
        peg$c100 = "`}",
1330
        peg$c101 = { type: "literal", value: "`}", description: "\"`}\"" },
1331
        peg$c102 = function(character) {return character},
1332
        peg$c103 = function(rawText) { return withPosition(["raw", rawText.join('')]) },
1333
        peg$c104 = { type: "other", description: "comment" },
1334
        peg$c105 = "{!",
1335
        peg$c106 = { type: "literal", value: "{!", description: "\"{!\"" },
1336
        peg$c107 = "!}",
1337
        peg$c108 = { type: "literal", value: "!}", description: "\"!}\"" },
1338
        peg$c109 = function(c) { return withPosition(["comment", c.join('')]) },
1339
        peg$c110 = /^[#?\^><+%:@\/~%]/,
1340
        peg$c111 = { type: "class", value: "[#?\\^><+%:@\\/~%]", description: "[#?\\^><+%:@\\/~%]" },
1341
        peg$c112 = "{",
1342
        peg$c113 = { type: "literal", value: "{", description: "\"{\"" },
1343
        peg$c114 = "}",
1344
        peg$c115 = { type: "literal", value: "}", description: "\"}\"" },
1345
        peg$c116 = "[",
1346
        peg$c117 = { type: "literal", value: "[", description: "\"[\"" },
1347
        peg$c118 = "]",
1348
        peg$c119 = { type: "literal", value: "]", description: "\"]\"" },
1349
        peg$c120 = "\n",
1350
        peg$c121 = { type: "literal", value: "\n", description: "\"\\n\"" },
1351
        peg$c122 = "\r\n",
1352
        peg$c123 = { type: "literal", value: "\r\n", description: "\"\\r\\n\"" },
1353
        peg$c124 = "\r",
1354
        peg$c125 = { type: "literal", value: "\r", description: "\"\\r\"" },
1355
        peg$c126 = "\u2028",
1356
        peg$c127 = { type: "literal", value: "\u2028", description: "\"\\u2028\"" },
1357
        peg$c128 = "\u2029",
1358
        peg$c129 = { type: "literal", value: "\u2029", description: "\"\\u2029\"" },
1359
        peg$c130 = /^[\t\x0B\f \xA0\uFEFF]/,
1360
        peg$c131 = { type: "class", value: "[\\t\\x0B\\f \\xA0\\uFEFF]", description: "[\\t\\x0B\\f \\xA0\\uFEFF]" },
1361
 
1362
        peg$currPos          = 0,
1363
        peg$reportedPos      = 0,
1364
        peg$cachedPos        = 0,
1365
        peg$cachedPosDetails = { line: 1, column: 1, seenCR: false },
1366
        peg$maxFailPos       = 0,
1367
        peg$maxFailExpected  = [],
1368
        peg$silentFails      = 0,
1369
 
1370
        peg$result;
1371
 
1372
    if ("startRule" in options) {
1373
      if (!(options.startRule in peg$startRuleFunctions)) {
1374
        throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
1375
      }
1376
 
1377
      peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
1378
    }
1379
 
1380
    function text() {
1381
      return input.substring(peg$reportedPos, peg$currPos);
1382
    }
1383
 
1384
    function offset() {
1385
      return peg$reportedPos;
1386
    }
1387
 
1388
    function line() {
1389
      return peg$computePosDetails(peg$reportedPos).line;
1390
    }
1391
 
1392
    function column() {
1393
      return peg$computePosDetails(peg$reportedPos).column;
1394
    }
1395
 
1396
    function expected(description) {
1397
      throw peg$buildException(
1398
        null,
1399
        [{ type: "other", description: description }],
1400
        peg$reportedPos
1401
      );
1402
    }
1403
 
1404
    function error(message) {
1405
      throw peg$buildException(message, null, peg$reportedPos);
1406
    }
1407
 
1408
    function peg$computePosDetails(pos) {
1409
      function advance(details, startPos, endPos) {
1410
        var p, ch;
1411
 
1412
        for (p = startPos; p < endPos; p++) {
1413
          ch = input.charAt(p);
1414
          if (ch === "\n") {
1415
            if (!details.seenCR) { details.line++; }
1416
            details.column = 1;
1417
            details.seenCR = false;
1418
          } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
1419
            details.line++;
1420
            details.column = 1;
1421
            details.seenCR = true;
1422
          } else {
1423
            details.column++;
1424
            details.seenCR = false;
1425
          }
1426
        }
1427
      }
1428
 
1429
      if (peg$cachedPos !== pos) {
1430
        if (peg$cachedPos > pos) {
1431
          peg$cachedPos = 0;
1432
          peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
1433
        }
1434
        advance(peg$cachedPosDetails, peg$cachedPos, pos);
1435
        peg$cachedPos = pos;
1436
      }
1437
 
1438
      return peg$cachedPosDetails;
1439
    }
1440
 
1441
    function peg$fail(expected) {
1442
      if (peg$currPos < peg$maxFailPos) { return; }
1443
 
1444
      if (peg$currPos > peg$maxFailPos) {
1445
        peg$maxFailPos = peg$currPos;
1446
        peg$maxFailExpected = [];
1447
      }
1448
 
1449
      peg$maxFailExpected.push(expected);
1450
    }
1451
 
1452
    function peg$buildException(message, expected, pos) {
1453
      function cleanupExpected(expected) {
1454
        var i = 1;
1455
 
1456
        expected.sort(function(a, b) {
1457
          if (a.description < b.description) {
1458
            return -1;
1459
          } else if (a.description > b.description) {
1460
            return 1;
1461
          } else {
1462
            return 0;
1463
          }
1464
        });
1465
 
1466
        while (i < expected.length) {
1467
          if (expected[i - 1] === expected[i]) {
1468
            expected.splice(i, 1);
1469
          } else {
1470
            i++;
1471
          }
1472
        }
1473
      }
1474
 
1475
      function buildMessage(expected, found) {
1476
        function stringEscape(s) {
1477
          function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
1478
 
1479
          return s
1480
            .replace(/\\/g,   '\\\\')
1481
            .replace(/"/g,    '\\"')
1482
            .replace(/\x08/g, '\\b')
1483
            .replace(/\t/g,   '\\t')
1484
            .replace(/\n/g,   '\\n')
1485
            .replace(/\f/g,   '\\f')
1486
            .replace(/\r/g,   '\\r')
1487
            .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
1488
            .replace(/[\x10-\x1F\x80-\xFF]/g,    function(ch) { return '\\x'  + hex(ch); })
1489
            .replace(/[\u0180-\u0FFF]/g,         function(ch) { return '\\u0' + hex(ch); })
1490
            .replace(/[\u1080-\uFFFF]/g,         function(ch) { return '\\u'  + hex(ch); });
1491
        }
1492
 
1493
        var expectedDescs = new Array(expected.length),
1494
            expectedDesc, foundDesc, i;
1495
 
1496
        for (i = 0; i < expected.length; i++) {
1497
          expectedDescs[i] = expected[i].description;
1498
        }
1499
 
1500
        expectedDesc = expected.length > 1
1501
          ? expectedDescs.slice(0, -1).join(", ")
1502
              + " or "
1503
              + expectedDescs[expected.length - 1]
1504
          : expectedDescs[0];
1505
 
1506
        foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
1507
 
1508
        return "Expected " + expectedDesc + " but " + foundDesc + " found.";
1509
      }
1510
 
1511
      var posDetails = peg$computePosDetails(pos),
1512
          found      = pos < input.length ? input.charAt(pos) : null;
1513
 
1514
      if (expected !== null) {
1515
        cleanupExpected(expected);
1516
      }
1517
 
1518
      return new SyntaxError(
1519
        message !== null ? message : buildMessage(expected, found),
1520
        expected,
1521
        found,
1522
        pos,
1523
        posDetails.line,
1524
        posDetails.column
1525
      );
1526
    }
1527
 
1528
    function peg$parsestart() {
1529
      var s0;
1530
 
1531
      s0 = peg$parsebody();
1532
 
1533
      return s0;
1534
    }
1535
 
1536
    function peg$parsebody() {
1537
      var s0, s1, s2;
1538
 
1539
      s0 = peg$currPos;
1540
      s1 = [];
1541
      s2 = peg$parsepart();
1542
      while (s2 !== peg$FAILED) {
1543
        s1.push(s2);
1544
        s2 = peg$parsepart();
1545
      }
1546
      if (s1 !== peg$FAILED) {
1547
        peg$reportedPos = s0;
1548
        s1 = peg$c1(s1);
1549
      }
1550
      s0 = s1;
1551
 
1552
      return s0;
1553
    }
1554
 
1555
    function peg$parsepart() {
1556
      var s0;
1557
 
1558
      s0 = peg$parseraw();
1559
      if (s0 === peg$FAILED) {
1560
        s0 = peg$parsecomment();
1561
        if (s0 === peg$FAILED) {
1562
          s0 = peg$parsesection();
1563
          if (s0 === peg$FAILED) {
1564
            s0 = peg$parsepartial();
1565
            if (s0 === peg$FAILED) {
1566
              s0 = peg$parsespecial();
1567
              if (s0 === peg$FAILED) {
1568
                s0 = peg$parsereference();
1569
                if (s0 === peg$FAILED) {
1570
                  s0 = peg$parsebuffer();
1571
                }
1572
              }
1573
            }
1574
          }
1575
        }
1576
      }
1577
 
1578
      return s0;
1579
    }
1580
 
1581
    function peg$parsesection() {
1582
      var s0, s1, s2, s3, s4, s5, s6, s7;
1583
 
1584
      peg$silentFails++;
1585
      s0 = peg$currPos;
1586
      s1 = peg$parsesec_tag_start();
1587
      if (s1 !== peg$FAILED) {
1588
        s2 = [];
1589
        s3 = peg$parsews();
1590
        while (s3 !== peg$FAILED) {
1591
          s2.push(s3);
1592
          s3 = peg$parsews();
1593
        }
1594
        if (s2 !== peg$FAILED) {
1595
          s3 = peg$parserd();
1596
          if (s3 !== peg$FAILED) {
1597
            s4 = peg$parsebody();
1598
            if (s4 !== peg$FAILED) {
1599
              s5 = peg$parsebodies();
1600
              if (s5 !== peg$FAILED) {
1601
                s6 = peg$parseend_tag();
1602
                if (s6 === peg$FAILED) {
1603
                  s6 = peg$c4;
1604
                }
1605
                if (s6 !== peg$FAILED) {
1606
                  peg$reportedPos = peg$currPos;
1607
                  s7 = peg$c5(s1, s4, s5, s6);
1608
                  if (s7) {
1609
                    s7 = peg$c6;
1610
                  } else {
1611
                    s7 = peg$c3;
1612
                  }
1613
                  if (s7 !== peg$FAILED) {
1614
                    peg$reportedPos = s0;
1615
                    s1 = peg$c7(s1, s4, s5, s6);
1616
                    s0 = s1;
1617
                  } else {
1618
                    peg$currPos = s0;
1619
                    s0 = peg$c3;
1620
                  }
1621
                } else {
1622
                  peg$currPos = s0;
1623
                  s0 = peg$c3;
1624
                }
1625
              } else {
1626
                peg$currPos = s0;
1627
                s0 = peg$c3;
1628
              }
1629
            } else {
1630
              peg$currPos = s0;
1631
              s0 = peg$c3;
1632
            }
1633
          } else {
1634
            peg$currPos = s0;
1635
            s0 = peg$c3;
1636
          }
1637
        } else {
1638
          peg$currPos = s0;
1639
          s0 = peg$c3;
1640
        }
1641
      } else {
1642
        peg$currPos = s0;
1643
        s0 = peg$c3;
1644
      }
1645
      if (s0 === peg$FAILED) {
1646
        s0 = peg$currPos;
1647
        s1 = peg$parsesec_tag_start();
1648
        if (s1 !== peg$FAILED) {
1649
          s2 = [];
1650
          s3 = peg$parsews();
1651
          while (s3 !== peg$FAILED) {
1652
            s2.push(s3);
1653
            s3 = peg$parsews();
1654
          }
1655
          if (s2 !== peg$FAILED) {
1656
            if (input.charCodeAt(peg$currPos) === 47) {
1657
              s3 = peg$c8;
1658
              peg$currPos++;
1659
            } else {
1660
              s3 = peg$FAILED;
1661
              if (peg$silentFails === 0) { peg$fail(peg$c9); }
1662
            }
1663
            if (s3 !== peg$FAILED) {
1664
              s4 = peg$parserd();
1665
              if (s4 !== peg$FAILED) {
1666
                peg$reportedPos = s0;
1667
                s1 = peg$c10(s1);
1668
                s0 = s1;
1669
              } else {
1670
                peg$currPos = s0;
1671
                s0 = peg$c3;
1672
              }
1673
            } else {
1674
              peg$currPos = s0;
1675
              s0 = peg$c3;
1676
            }
1677
          } else {
1678
            peg$currPos = s0;
1679
            s0 = peg$c3;
1680
          }
1681
        } else {
1682
          peg$currPos = s0;
1683
          s0 = peg$c3;
1684
        }
1685
      }
1686
      peg$silentFails--;
1687
      if (s0 === peg$FAILED) {
1688
        s1 = peg$FAILED;
1689
        if (peg$silentFails === 0) { peg$fail(peg$c2); }
1690
      }
1691
 
1692
      return s0;
1693
    }
1694
 
1695
    function peg$parsesec_tag_start() {
1696
      var s0, s1, s2, s3, s4, s5, s6;
1697
 
1698
      s0 = peg$currPos;
1699
      s1 = peg$parseld();
1700
      if (s1 !== peg$FAILED) {
1701
        if (peg$c11.test(input.charAt(peg$currPos))) {
1702
          s2 = input.charAt(peg$currPos);
1703
          peg$currPos++;
1704
        } else {
1705
          s2 = peg$FAILED;
1706
          if (peg$silentFails === 0) { peg$fail(peg$c12); }
1707
        }
1708
        if (s2 !== peg$FAILED) {
1709
          s3 = [];
1710
          s4 = peg$parsews();
1711
          while (s4 !== peg$FAILED) {
1712
            s3.push(s4);
1713
            s4 = peg$parsews();
1714
          }
1715
          if (s3 !== peg$FAILED) {
1716
            s4 = peg$parseidentifier();
1717
            if (s4 !== peg$FAILED) {
1718
              s5 = peg$parsecontext();
1719
              if (s5 !== peg$FAILED) {
1720
                s6 = peg$parseparams();
1721
                if (s6 !== peg$FAILED) {
1722
                  peg$reportedPos = s0;
1723
                  s1 = peg$c13(s2, s4, s5, s6);
1724
                  s0 = s1;
1725
                } else {
1726
                  peg$currPos = s0;
1727
                  s0 = peg$c3;
1728
                }
1729
              } else {
1730
                peg$currPos = s0;
1731
                s0 = peg$c3;
1732
              }
1733
            } else {
1734
              peg$currPos = s0;
1735
              s0 = peg$c3;
1736
            }
1737
          } else {
1738
            peg$currPos = s0;
1739
            s0 = peg$c3;
1740
          }
1741
        } else {
1742
          peg$currPos = s0;
1743
          s0 = peg$c3;
1744
        }
1745
      } else {
1746
        peg$currPos = s0;
1747
        s0 = peg$c3;
1748
      }
1749
 
1750
      return s0;
1751
    }
1752
 
1753
    function peg$parseend_tag() {
1754
      var s0, s1, s2, s3, s4, s5, s6;
1755
 
1756
      peg$silentFails++;
1757
      s0 = peg$currPos;
1758
      s1 = peg$parseld();
1759
      if (s1 !== peg$FAILED) {
1760
        if (input.charCodeAt(peg$currPos) === 47) {
1761
          s2 = peg$c8;
1762
          peg$currPos++;
1763
        } else {
1764
          s2 = peg$FAILED;
1765
          if (peg$silentFails === 0) { peg$fail(peg$c9); }
1766
        }
1767
        if (s2 !== peg$FAILED) {
1768
          s3 = [];
1769
          s4 = peg$parsews();
1770
          while (s4 !== peg$FAILED) {
1771
            s3.push(s4);
1772
            s4 = peg$parsews();
1773
          }
1774
          if (s3 !== peg$FAILED) {
1775
            s4 = peg$parseidentifier();
1776
            if (s4 !== peg$FAILED) {
1777
              s5 = [];
1778
              s6 = peg$parsews();
1779
              while (s6 !== peg$FAILED) {
1780
                s5.push(s6);
1781
                s6 = peg$parsews();
1782
              }
1783
              if (s5 !== peg$FAILED) {
1784
                s6 = peg$parserd();
1785
                if (s6 !== peg$FAILED) {
1786
                  peg$reportedPos = s0;
1787
                  s1 = peg$c15(s4);
1788
                  s0 = s1;
1789
                } else {
1790
                  peg$currPos = s0;
1791
                  s0 = peg$c3;
1792
                }
1793
              } else {
1794
                peg$currPos = s0;
1795
                s0 = peg$c3;
1796
              }
1797
            } else {
1798
              peg$currPos = s0;
1799
              s0 = peg$c3;
1800
            }
1801
          } else {
1802
            peg$currPos = s0;
1803
            s0 = peg$c3;
1804
          }
1805
        } else {
1806
          peg$currPos = s0;
1807
          s0 = peg$c3;
1808
        }
1809
      } else {
1810
        peg$currPos = s0;
1811
        s0 = peg$c3;
1812
      }
1813
      peg$silentFails--;
1814
      if (s0 === peg$FAILED) {
1815
        s1 = peg$FAILED;
1816
        if (peg$silentFails === 0) { peg$fail(peg$c14); }
1817
      }
1818
 
1819
      return s0;
1820
    }
1821
 
1822
    function peg$parsecontext() {
1823
      var s0, s1, s2, s3;
1824
 
1825
      s0 = peg$currPos;
1826
      s1 = peg$currPos;
1827
      if (input.charCodeAt(peg$currPos) === 58) {
1828
        s2 = peg$c16;
1829
        peg$currPos++;
1830
      } else {
1831
        s2 = peg$FAILED;
1832
        if (peg$silentFails === 0) { peg$fail(peg$c17); }
1833
      }
1834
      if (s2 !== peg$FAILED) {
1835
        s3 = peg$parseidentifier();
1836
        if (s3 !== peg$FAILED) {
1837
          peg$reportedPos = s1;
1838
          s2 = peg$c18(s3);
1839
          s1 = s2;
1840
        } else {
1841
          peg$currPos = s1;
1842
          s1 = peg$c3;
1843
        }
1844
      } else {
1845
        peg$currPos = s1;
1846
        s1 = peg$c3;
1847
      }
1848
      if (s1 === peg$FAILED) {
1849
        s1 = peg$c4;
1850
      }
1851
      if (s1 !== peg$FAILED) {
1852
        peg$reportedPos = s0;
1853
        s1 = peg$c19(s1);
1854
      }
1855
      s0 = s1;
1856
 
1857
      return s0;
1858
    }
1859
 
1860
    function peg$parseparams() {
1861
      var s0, s1, s2, s3, s4, s5, s6;
1862
 
1863
      peg$silentFails++;
1864
      s0 = peg$currPos;
1865
      s1 = [];
1866
      s2 = peg$currPos;
1867
      s3 = [];
1868
      s4 = peg$parsews();
1869
      if (s4 !== peg$FAILED) {
1870
        while (s4 !== peg$FAILED) {
1871
          s3.push(s4);
1872
          s4 = peg$parsews();
1873
        }
1874
      } else {
1875
        s3 = peg$c3;
1876
      }
1877
      if (s3 !== peg$FAILED) {
1878
        s4 = peg$parsekey();
1879
        if (s4 !== peg$FAILED) {
1880
          if (input.charCodeAt(peg$currPos) === 61) {
1881
            s5 = peg$c21;
1882
            peg$currPos++;
1883
          } else {
1884
            s5 = peg$FAILED;
1885
            if (peg$silentFails === 0) { peg$fail(peg$c22); }
1886
          }
1887
          if (s5 !== peg$FAILED) {
1888
            s6 = peg$parsenumber();
1889
            if (s6 === peg$FAILED) {
1890
              s6 = peg$parseidentifier();
1891
              if (s6 === peg$FAILED) {
1892
                s6 = peg$parseinline();
1893
              }
1894
            }
1895
            if (s6 !== peg$FAILED) {
1896
              peg$reportedPos = s2;
1897
              s3 = peg$c23(s4, s6);
1898
              s2 = s3;
1899
            } else {
1900
              peg$currPos = s2;
1901
              s2 = peg$c3;
1902
            }
1903
          } else {
1904
            peg$currPos = s2;
1905
            s2 = peg$c3;
1906
          }
1907
        } else {
1908
          peg$currPos = s2;
1909
          s2 = peg$c3;
1910
        }
1911
      } else {
1912
        peg$currPos = s2;
1913
        s2 = peg$c3;
1914
      }
1915
      while (s2 !== peg$FAILED) {
1916
        s1.push(s2);
1917
        s2 = peg$currPos;
1918
        s3 = [];
1919
        s4 = peg$parsews();
1920
        if (s4 !== peg$FAILED) {
1921
          while (s4 !== peg$FAILED) {
1922
            s3.push(s4);
1923
            s4 = peg$parsews();
1924
          }
1925
        } else {
1926
          s3 = peg$c3;
1927
        }
1928
        if (s3 !== peg$FAILED) {
1929
          s4 = peg$parsekey();
1930
          if (s4 !== peg$FAILED) {
1931
            if (input.charCodeAt(peg$currPos) === 61) {
1932
              s5 = peg$c21;
1933
              peg$currPos++;
1934
            } else {
1935
              s5 = peg$FAILED;
1936
              if (peg$silentFails === 0) { peg$fail(peg$c22); }
1937
            }
1938
            if (s5 !== peg$FAILED) {
1939
              s6 = peg$parsenumber();
1940
              if (s6 === peg$FAILED) {
1941
                s6 = peg$parseidentifier();
1942
                if (s6 === peg$FAILED) {
1943
                  s6 = peg$parseinline();
1944
                }
1945
              }
1946
              if (s6 !== peg$FAILED) {
1947
                peg$reportedPos = s2;
1948
                s3 = peg$c23(s4, s6);
1949
                s2 = s3;
1950
              } else {
1951
                peg$currPos = s2;
1952
                s2 = peg$c3;
1953
              }
1954
            } else {
1955
              peg$currPos = s2;
1956
              s2 = peg$c3;
1957
            }
1958
          } else {
1959
            peg$currPos = s2;
1960
            s2 = peg$c3;
1961
          }
1962
        } else {
1963
          peg$currPos = s2;
1964
          s2 = peg$c3;
1965
        }
1966
      }
1967
      if (s1 !== peg$FAILED) {
1968
        peg$reportedPos = s0;
1969
        s1 = peg$c24(s1);
1970
      }
1971
      s0 = s1;
1972
      peg$silentFails--;
1973
      if (s0 === peg$FAILED) {
1974
        s1 = peg$FAILED;
1975
        if (peg$silentFails === 0) { peg$fail(peg$c20); }
1976
      }
1977
 
1978
      return s0;
1979
    }
1980
 
1981
    function peg$parsebodies() {
1982
      var s0, s1, s2, s3, s4, s5, s6, s7;
1983
 
1984
      peg$silentFails++;
1985
      s0 = peg$currPos;
1986
      s1 = [];
1987
      s2 = peg$currPos;
1988
      s3 = peg$parseld();
1989
      if (s3 !== peg$FAILED) {
1990
        if (input.charCodeAt(peg$currPos) === 58) {
1991
          s4 = peg$c16;
1992
          peg$currPos++;
1993
        } else {
1994
          s4 = peg$FAILED;
1995
          if (peg$silentFails === 0) { peg$fail(peg$c17); }
1996
        }
1997
        if (s4 !== peg$FAILED) {
1998
          s5 = peg$parsekey();
1999
          if (s5 !== peg$FAILED) {
2000
            s6 = peg$parserd();
2001
            if (s6 !== peg$FAILED) {
2002
              s7 = peg$parsebody();
2003
              if (s7 !== peg$FAILED) {
2004
                peg$reportedPos = s2;
2005
                s3 = peg$c23(s5, s7);
2006
                s2 = s3;
2007
              } else {
2008
                peg$currPos = s2;
2009
                s2 = peg$c3;
2010
              }
2011
            } else {
2012
              peg$currPos = s2;
2013
              s2 = peg$c3;
2014
            }
2015
          } else {
2016
            peg$currPos = s2;
2017
            s2 = peg$c3;
2018
          }
2019
        } else {
2020
          peg$currPos = s2;
2021
          s2 = peg$c3;
2022
        }
2023
      } else {
2024
        peg$currPos = s2;
2025
        s2 = peg$c3;
2026
      }
2027
      while (s2 !== peg$FAILED) {
2028
        s1.push(s2);
2029
        s2 = peg$currPos;
2030
        s3 = peg$parseld();
2031
        if (s3 !== peg$FAILED) {
2032
          if (input.charCodeAt(peg$currPos) === 58) {
2033
            s4 = peg$c16;
2034
            peg$currPos++;
2035
          } else {
2036
            s4 = peg$FAILED;
2037
            if (peg$silentFails === 0) { peg$fail(peg$c17); }
2038
          }
2039
          if (s4 !== peg$FAILED) {
2040
            s5 = peg$parsekey();
2041
            if (s5 !== peg$FAILED) {
2042
              s6 = peg$parserd();
2043
              if (s6 !== peg$FAILED) {
2044
                s7 = peg$parsebody();
2045
                if (s7 !== peg$FAILED) {
2046
                  peg$reportedPos = s2;
2047
                  s3 = peg$c23(s5, s7);
2048
                  s2 = s3;
2049
                } else {
2050
                  peg$currPos = s2;
2051
                  s2 = peg$c3;
2052
                }
2053
              } else {
2054
                peg$currPos = s2;
2055
                s2 = peg$c3;
2056
              }
2057
            } else {
2058
              peg$currPos = s2;
2059
              s2 = peg$c3;
2060
            }
2061
          } else {
2062
            peg$currPos = s2;
2063
            s2 = peg$c3;
2064
          }
2065
        } else {
2066
          peg$currPos = s2;
2067
          s2 = peg$c3;
2068
        }
2069
      }
2070
      if (s1 !== peg$FAILED) {
2071
        peg$reportedPos = s0;
2072
        s1 = peg$c26(s1);
2073
      }
2074
      s0 = s1;
2075
      peg$silentFails--;
2076
      if (s0 === peg$FAILED) {
2077
        s1 = peg$FAILED;
2078
        if (peg$silentFails === 0) { peg$fail(peg$c25); }
2079
      }
2080
 
2081
      return s0;
2082
    }
2083
 
2084
    function peg$parsereference() {
2085
      var s0, s1, s2, s3, s4;
2086
 
2087
      peg$silentFails++;
2088
      s0 = peg$currPos;
2089
      s1 = peg$parseld();
2090
      if (s1 !== peg$FAILED) {
2091
        s2 = peg$parseidentifier();
2092
        if (s2 !== peg$FAILED) {
2093
          s3 = peg$parsefilters();
2094
          if (s3 !== peg$FAILED) {
2095
            s4 = peg$parserd();
2096
            if (s4 !== peg$FAILED) {
2097
              peg$reportedPos = s0;
2098
              s1 = peg$c28(s2, s3);
2099
              s0 = s1;
2100
            } else {
2101
              peg$currPos = s0;
2102
              s0 = peg$c3;
2103
            }
2104
          } else {
2105
            peg$currPos = s0;
2106
            s0 = peg$c3;
2107
          }
2108
        } else {
2109
          peg$currPos = s0;
2110
          s0 = peg$c3;
2111
        }
2112
      } else {
2113
        peg$currPos = s0;
2114
        s0 = peg$c3;
2115
      }
2116
      peg$silentFails--;
2117
      if (s0 === peg$FAILED) {
2118
        s1 = peg$FAILED;
2119
        if (peg$silentFails === 0) { peg$fail(peg$c27); }
2120
      }
2121
 
2122
      return s0;
2123
    }
2124
 
2125
    function peg$parsepartial() {
2126
      var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
2127
 
2128
      peg$silentFails++;
2129
      s0 = peg$currPos;
2130
      s1 = peg$parseld();
2131
      if (s1 !== peg$FAILED) {
2132
        if (input.charCodeAt(peg$currPos) === 62) {
2133
          s2 = peg$c30;
2134
          peg$currPos++;
2135
        } else {
2136
          s2 = peg$FAILED;
2137
          if (peg$silentFails === 0) { peg$fail(peg$c31); }
2138
        }
2139
        if (s2 === peg$FAILED) {
2140
          if (input.charCodeAt(peg$currPos) === 43) {
2141
            s2 = peg$c32;
2142
            peg$currPos++;
2143
          } else {
2144
            s2 = peg$FAILED;
2145
            if (peg$silentFails === 0) { peg$fail(peg$c33); }
2146
          }
2147
        }
2148
        if (s2 !== peg$FAILED) {
2149
          s3 = [];
2150
          s4 = peg$parsews();
2151
          while (s4 !== peg$FAILED) {
2152
            s3.push(s4);
2153
            s4 = peg$parsews();
2154
          }
2155
          if (s3 !== peg$FAILED) {
2156
            s4 = peg$currPos;
2157
            s5 = peg$parsekey();
2158
            if (s5 !== peg$FAILED) {
2159
              peg$reportedPos = s4;
2160
              s5 = peg$c34(s5);
2161
            }
2162
            s4 = s5;
2163
            if (s4 === peg$FAILED) {
2164
              s4 = peg$parseinline();
2165
            }
2166
            if (s4 !== peg$FAILED) {
2167
              s5 = peg$parsecontext();
2168
              if (s5 !== peg$FAILED) {
2169
                s6 = peg$parseparams();
2170
                if (s6 !== peg$FAILED) {
2171
                  s7 = [];
2172
                  s8 = peg$parsews();
2173
                  while (s8 !== peg$FAILED) {
2174
                    s7.push(s8);
2175
                    s8 = peg$parsews();
2176
                  }
2177
                  if (s7 !== peg$FAILED) {
2178
                    if (input.charCodeAt(peg$currPos) === 47) {
2179
                      s8 = peg$c8;
2180
                      peg$currPos++;
2181
                    } else {
2182
                      s8 = peg$FAILED;
2183
                      if (peg$silentFails === 0) { peg$fail(peg$c9); }
2184
                    }
2185
                    if (s8 !== peg$FAILED) {
2186
                      s9 = peg$parserd();
2187
                      if (s9 !== peg$FAILED) {
2188
                        peg$reportedPos = s0;
2189
                        s1 = peg$c35(s2, s4, s5, s6);
2190
                        s0 = s1;
2191
                      } else {
2192
                        peg$currPos = s0;
2193
                        s0 = peg$c3;
2194
                      }
2195
                    } else {
2196
                      peg$currPos = s0;
2197
                      s0 = peg$c3;
2198
                    }
2199
                  } else {
2200
                    peg$currPos = s0;
2201
                    s0 = peg$c3;
2202
                  }
2203
                } else {
2204
                  peg$currPos = s0;
2205
                  s0 = peg$c3;
2206
                }
2207
              } else {
2208
                peg$currPos = s0;
2209
                s0 = peg$c3;
2210
              }
2211
            } else {
2212
              peg$currPos = s0;
2213
              s0 = peg$c3;
2214
            }
2215
          } else {
2216
            peg$currPos = s0;
2217
            s0 = peg$c3;
2218
          }
2219
        } else {
2220
          peg$currPos = s0;
2221
          s0 = peg$c3;
2222
        }
2223
      } else {
2224
        peg$currPos = s0;
2225
        s0 = peg$c3;
2226
      }
2227
      peg$silentFails--;
2228
      if (s0 === peg$FAILED) {
2229
        s1 = peg$FAILED;
2230
        if (peg$silentFails === 0) { peg$fail(peg$c29); }
2231
      }
2232
 
2233
      return s0;
2234
    }
2235
 
2236
    function peg$parsefilters() {
2237
      var s0, s1, s2, s3, s4;
2238
 
2239
      peg$silentFails++;
2240
      s0 = peg$currPos;
2241
      s1 = [];
2242
      s2 = peg$currPos;
2243
      if (input.charCodeAt(peg$currPos) === 124) {
2244
        s3 = peg$c37;
2245
        peg$currPos++;
2246
      } else {
2247
        s3 = peg$FAILED;
2248
        if (peg$silentFails === 0) { peg$fail(peg$c38); }
2249
      }
2250
      if (s3 !== peg$FAILED) {
2251
        s4 = peg$parsekey();
2252
        if (s4 !== peg$FAILED) {
2253
          peg$reportedPos = s2;
2254
          s3 = peg$c18(s4);
2255
          s2 = s3;
2256
        } else {
2257
          peg$currPos = s2;
2258
          s2 = peg$c3;
2259
        }
2260
      } else {
2261
        peg$currPos = s2;
2262
        s2 = peg$c3;
2263
      }
2264
      while (s2 !== peg$FAILED) {
2265
        s1.push(s2);
2266
        s2 = peg$currPos;
2267
        if (input.charCodeAt(peg$currPos) === 124) {
2268
          s3 = peg$c37;
2269
          peg$currPos++;
2270
        } else {
2271
          s3 = peg$FAILED;
2272
          if (peg$silentFails === 0) { peg$fail(peg$c38); }
2273
        }
2274
        if (s3 !== peg$FAILED) {
2275
          s4 = peg$parsekey();
2276
          if (s4 !== peg$FAILED) {
2277
            peg$reportedPos = s2;
2278
            s3 = peg$c18(s4);
2279
            s2 = s3;
2280
          } else {
2281
            peg$currPos = s2;
2282
            s2 = peg$c3;
2283
          }
2284
        } else {
2285
          peg$currPos = s2;
2286
          s2 = peg$c3;
2287
        }
2288
      }
2289
      if (s1 !== peg$FAILED) {
2290
        peg$reportedPos = s0;
2291
        s1 = peg$c39(s1);
2292
      }
2293
      s0 = s1;
2294
      peg$silentFails--;
2295
      if (s0 === peg$FAILED) {
2296
        s1 = peg$FAILED;
2297
        if (peg$silentFails === 0) { peg$fail(peg$c36); }
2298
      }
2299
 
2300
      return s0;
2301
    }
2302
 
2303
    function peg$parsespecial() {
2304
      var s0, s1, s2, s3, s4;
2305
 
2306
      peg$silentFails++;
2307
      s0 = peg$currPos;
2308
      s1 = peg$parseld();
2309
      if (s1 !== peg$FAILED) {
2310
        if (input.charCodeAt(peg$currPos) === 126) {
2311
          s2 = peg$c41;
2312
          peg$currPos++;
2313
        } else {
2314
          s2 = peg$FAILED;
2315
          if (peg$silentFails === 0) { peg$fail(peg$c42); }
2316
        }
2317
        if (s2 !== peg$FAILED) {
2318
          s3 = peg$parsekey();
2319
          if (s3 !== peg$FAILED) {
2320
            s4 = peg$parserd();
2321
            if (s4 !== peg$FAILED) {
2322
              peg$reportedPos = s0;
2323
              s1 = peg$c43(s3);
2324
              s0 = s1;
2325
            } else {
2326
              peg$currPos = s0;
2327
              s0 = peg$c3;
2328
            }
2329
          } else {
2330
            peg$currPos = s0;
2331
            s0 = peg$c3;
2332
          }
2333
        } else {
2334
          peg$currPos = s0;
2335
          s0 = peg$c3;
2336
        }
2337
      } else {
2338
        peg$currPos = s0;
2339
        s0 = peg$c3;
2340
      }
2341
      peg$silentFails--;
2342
      if (s0 === peg$FAILED) {
2343
        s1 = peg$FAILED;
2344
        if (peg$silentFails === 0) { peg$fail(peg$c40); }
2345
      }
2346
 
2347
      return s0;
2348
    }
2349
 
2350
    function peg$parseidentifier() {
2351
      var s0, s1;
2352
 
2353
      peg$silentFails++;
2354
      s0 = peg$currPos;
2355
      s1 = peg$parsepath();
2356
      if (s1 !== peg$FAILED) {
2357
        peg$reportedPos = s0;
2358
        s1 = peg$c45(s1);
2359
      }
2360
      s0 = s1;
2361
      if (s0 === peg$FAILED) {
2362
        s0 = peg$currPos;
2363
        s1 = peg$parsekey();
2364
        if (s1 !== peg$FAILED) {
2365
          peg$reportedPos = s0;
2366
          s1 = peg$c46(s1);
2367
        }
2368
        s0 = s1;
2369
      }
2370
      peg$silentFails--;
2371
      if (s0 === peg$FAILED) {
2372
        s1 = peg$FAILED;
2373
        if (peg$silentFails === 0) { peg$fail(peg$c44); }
2374
      }
2375
 
2376
      return s0;
2377
    }
2378
 
2379
    function peg$parsenumber() {
2380
      var s0, s1;
2381
 
2382
      peg$silentFails++;
2383
      s0 = peg$currPos;
2384
      s1 = peg$parsefloat();
2385
      if (s1 === peg$FAILED) {
2386
        s1 = peg$parseinteger();
2387
      }
2388
      if (s1 !== peg$FAILED) {
2389
        peg$reportedPos = s0;
2390
        s1 = peg$c48(s1);
2391
      }
2392
      s0 = s1;
2393
      peg$silentFails--;
2394
      if (s0 === peg$FAILED) {
2395
        s1 = peg$FAILED;
2396
        if (peg$silentFails === 0) { peg$fail(peg$c47); }
2397
      }
2398
 
2399
      return s0;
2400
    }
2401
 
2402
    function peg$parsefloat() {
2403
      var s0, s1, s2, s3;
2404
 
2405
      peg$silentFails++;
2406
      s0 = peg$currPos;
2407
      s1 = peg$parseinteger();
2408
      if (s1 !== peg$FAILED) {
2409
        if (input.charCodeAt(peg$currPos) === 46) {
2410
          s2 = peg$c50;
2411
          peg$currPos++;
2412
        } else {
2413
          s2 = peg$FAILED;
2414
          if (peg$silentFails === 0) { peg$fail(peg$c51); }
2415
        }
2416
        if (s2 !== peg$FAILED) {
2417
          s3 = peg$parseunsigned_integer();
2418
          if (s3 !== peg$FAILED) {
2419
            peg$reportedPos = s0;
2420
            s1 = peg$c52(s1, s3);
2421
            s0 = s1;
2422
          } else {
2423
            peg$currPos = s0;
2424
            s0 = peg$c3;
2425
          }
2426
        } else {
2427
          peg$currPos = s0;
2428
          s0 = peg$c3;
2429
        }
2430
      } else {
2431
        peg$currPos = s0;
2432
        s0 = peg$c3;
2433
      }
2434
      peg$silentFails--;
2435
      if (s0 === peg$FAILED) {
2436
        s1 = peg$FAILED;
2437
        if (peg$silentFails === 0) { peg$fail(peg$c49); }
2438
      }
2439
 
2440
      return s0;
2441
    }
2442
 
2443
    function peg$parseunsigned_integer() {
2444
      var s0, s1, s2;
2445
 
2446
      peg$silentFails++;
2447
      s0 = peg$currPos;
2448
      s1 = [];
2449
      if (peg$c54.test(input.charAt(peg$currPos))) {
2450
        s2 = input.charAt(peg$currPos);
2451
        peg$currPos++;
2452
      } else {
2453
        s2 = peg$FAILED;
2454
        if (peg$silentFails === 0) { peg$fail(peg$c55); }
2455
      }
2456
      if (s2 !== peg$FAILED) {
2457
        while (s2 !== peg$FAILED) {
2458
          s1.push(s2);
2459
          if (peg$c54.test(input.charAt(peg$currPos))) {
2460
            s2 = input.charAt(peg$currPos);
2461
            peg$currPos++;
2462
          } else {
2463
            s2 = peg$FAILED;
2464
            if (peg$silentFails === 0) { peg$fail(peg$c55); }
2465
          }
2466
        }
2467
      } else {
2468
        s1 = peg$c3;
2469
      }
2470
      if (s1 !== peg$FAILED) {
2471
        peg$reportedPos = s0;
2472
        s1 = peg$c56(s1);
2473
      }
2474
      s0 = s1;
2475
      peg$silentFails--;
2476
      if (s0 === peg$FAILED) {
2477
        s1 = peg$FAILED;
2478
        if (peg$silentFails === 0) { peg$fail(peg$c53); }
2479
      }
2480
 
2481
      return s0;
2482
    }
2483
 
2484
    function peg$parsesigned_integer() {
2485
      var s0, s1, s2;
2486
 
2487
      peg$silentFails++;
2488
      s0 = peg$currPos;
2489
      if (input.charCodeAt(peg$currPos) === 45) {
2490
        s1 = peg$c58;
2491
        peg$currPos++;
2492
      } else {
2493
        s1 = peg$FAILED;
2494
        if (peg$silentFails === 0) { peg$fail(peg$c59); }
2495
      }
2496
      if (s1 !== peg$FAILED) {
2497
        s2 = peg$parseunsigned_integer();
2498
        if (s2 !== peg$FAILED) {
2499
          peg$reportedPos = s0;
2500
          s1 = peg$c60(s1, s2);
2501
          s0 = s1;
2502
        } else {
2503
          peg$currPos = s0;
2504
          s0 = peg$c3;
2505
        }
2506
      } else {
2507
        peg$currPos = s0;
2508
        s0 = peg$c3;
2509
      }
2510
      peg$silentFails--;
2511
      if (s0 === peg$FAILED) {
2512
        s1 = peg$FAILED;
2513
        if (peg$silentFails === 0) { peg$fail(peg$c57); }
2514
      }
2515
 
2516
      return s0;
2517
    }
2518
 
2519
    function peg$parseinteger() {
2520
      var s0, s1;
2521
 
2522
      peg$silentFails++;
2523
      s0 = peg$parsesigned_integer();
2524
      if (s0 === peg$FAILED) {
2525
        s0 = peg$parseunsigned_integer();
2526
      }
2527
      peg$silentFails--;
2528
      if (s0 === peg$FAILED) {
2529
        s1 = peg$FAILED;
2530
        if (peg$silentFails === 0) { peg$fail(peg$c61); }
2531
      }
2532
 
2533
      return s0;
2534
    }
2535
 
2536
    function peg$parsepath() {
2537
      var s0, s1, s2, s3;
2538
 
2539
      peg$silentFails++;
2540
      s0 = peg$currPos;
2541
      s1 = peg$parsekey();
2542
      if (s1 === peg$FAILED) {
2543
        s1 = peg$c4;
2544
      }
2545
      if (s1 !== peg$FAILED) {
2546
        s2 = [];
2547
        s3 = peg$parsearray_part();
2548
        if (s3 === peg$FAILED) {
2549
          s3 = peg$parsearray();
2550
        }
2551
        if (s3 !== peg$FAILED) {
2552
          while (s3 !== peg$FAILED) {
2553
            s2.push(s3);
2554
            s3 = peg$parsearray_part();
2555
            if (s3 === peg$FAILED) {
2556
              s3 = peg$parsearray();
2557
            }
2558
          }
2559
        } else {
2560
          s2 = peg$c3;
2561
        }
2562
        if (s2 !== peg$FAILED) {
2563
          peg$reportedPos = s0;
2564
          s1 = peg$c63(s1, s2);
2565
          s0 = s1;
2566
        } else {
2567
          peg$currPos = s0;
2568
          s0 = peg$c3;
2569
        }
2570
      } else {
2571
        peg$currPos = s0;
2572
        s0 = peg$c3;
2573
      }
2574
      if (s0 === peg$FAILED) {
2575
        s0 = peg$currPos;
2576
        if (input.charCodeAt(peg$currPos) === 46) {
2577
          s1 = peg$c50;
2578
          peg$currPos++;
2579
        } else {
2580
          s1 = peg$FAILED;
2581
          if (peg$silentFails === 0) { peg$fail(peg$c51); }
2582
        }
2583
        if (s1 !== peg$FAILED) {
2584
          s2 = [];
2585
          s3 = peg$parsearray_part();
2586
          if (s3 === peg$FAILED) {
2587
            s3 = peg$parsearray();
2588
          }
2589
          while (s3 !== peg$FAILED) {
2590
            s2.push(s3);
2591
            s3 = peg$parsearray_part();
2592
            if (s3 === peg$FAILED) {
2593
              s3 = peg$parsearray();
2594
            }
2595
          }
2596
          if (s2 !== peg$FAILED) {
2597
            peg$reportedPos = s0;
2598
            s1 = peg$c64(s2);
2599
            s0 = s1;
2600
          } else {
2601
            peg$currPos = s0;
2602
            s0 = peg$c3;
2603
          }
2604
        } else {
2605
          peg$currPos = s0;
2606
          s0 = peg$c3;
2607
        }
2608
      }
2609
      peg$silentFails--;
2610
      if (s0 === peg$FAILED) {
2611
        s1 = peg$FAILED;
2612
        if (peg$silentFails === 0) { peg$fail(peg$c62); }
2613
      }
2614
 
2615
      return s0;
2616
    }
2617
 
2618
    function peg$parsekey() {
2619
      var s0, s1, s2, s3;
2620
 
2621
      peg$silentFails++;
2622
      s0 = peg$currPos;
2623
      if (peg$c66.test(input.charAt(peg$currPos))) {
2624
        s1 = input.charAt(peg$currPos);
2625
        peg$currPos++;
2626
      } else {
2627
        s1 = peg$FAILED;
2628
        if (peg$silentFails === 0) { peg$fail(peg$c67); }
2629
      }
2630
      if (s1 !== peg$FAILED) {
2631
        s2 = [];
2632
        if (peg$c68.test(input.charAt(peg$currPos))) {
2633
          s3 = input.charAt(peg$currPos);
2634
          peg$currPos++;
2635
        } else {
2636
          s3 = peg$FAILED;
2637
          if (peg$silentFails === 0) { peg$fail(peg$c69); }
2638
        }
2639
        while (s3 !== peg$FAILED) {
2640
          s2.push(s3);
2641
          if (peg$c68.test(input.charAt(peg$currPos))) {
2642
            s3 = input.charAt(peg$currPos);
2643
            peg$currPos++;
2644
          } else {
2645
            s3 = peg$FAILED;
2646
            if (peg$silentFails === 0) { peg$fail(peg$c69); }
2647
          }
2648
        }
2649
        if (s2 !== peg$FAILED) {
2650
          peg$reportedPos = s0;
2651
          s1 = peg$c70(s1, s2);
2652
          s0 = s1;
2653
        } else {
2654
          peg$currPos = s0;
2655
          s0 = peg$c3;
2656
        }
2657
      } else {
2658
        peg$currPos = s0;
2659
        s0 = peg$c3;
2660
      }
2661
      peg$silentFails--;
2662
      if (s0 === peg$FAILED) {
2663
        s1 = peg$FAILED;
2664
        if (peg$silentFails === 0) { peg$fail(peg$c65); }
2665
      }
2666
 
2667
      return s0;
2668
    }
2669
 
2670
    function peg$parsearray() {
2671
      var s0, s1, s2, s3, s4, s5;
2672
 
2673
      peg$silentFails++;
2674
      s0 = peg$currPos;
2675
      s1 = peg$currPos;
2676
      s2 = peg$parselb();
2677
      if (s2 !== peg$FAILED) {
2678
        s3 = peg$currPos;
2679
        s4 = [];
2680
        if (peg$c54.test(input.charAt(peg$currPos))) {
2681
          s5 = input.charAt(peg$currPos);
2682
          peg$currPos++;
2683
        } else {
2684
          s5 = peg$FAILED;
2685
          if (peg$silentFails === 0) { peg$fail(peg$c55); }
2686
        }
2687
        if (s5 !== peg$FAILED) {
2688
          while (s5 !== peg$FAILED) {
2689
            s4.push(s5);
2690
            if (peg$c54.test(input.charAt(peg$currPos))) {
2691
              s5 = input.charAt(peg$currPos);
2692
              peg$currPos++;
2693
            } else {
2694
              s5 = peg$FAILED;
2695
              if (peg$silentFails === 0) { peg$fail(peg$c55); }
2696
            }
2697
          }
2698
        } else {
2699
          s4 = peg$c3;
2700
        }
2701
        if (s4 !== peg$FAILED) {
2702
          peg$reportedPos = s3;
2703
          s4 = peg$c72(s4);
2704
        }
2705
        s3 = s4;
2706
        if (s3 === peg$FAILED) {
2707
          s3 = peg$parseidentifier();
2708
        }
2709
        if (s3 !== peg$FAILED) {
2710
          s4 = peg$parserb();
2711
          if (s4 !== peg$FAILED) {
2712
            peg$reportedPos = s1;
2713
            s2 = peg$c73(s3);
2714
            s1 = s2;
2715
          } else {
2716
            peg$currPos = s1;
2717
            s1 = peg$c3;
2718
          }
2719
        } else {
2720
          peg$currPos = s1;
2721
          s1 = peg$c3;
2722
        }
2723
      } else {
2724
        peg$currPos = s1;
2725
        s1 = peg$c3;
2726
      }
2727
      if (s1 !== peg$FAILED) {
2728
        s2 = peg$parsearray_part();
2729
        if (s2 === peg$FAILED) {
2730
          s2 = peg$c4;
2731
        }
2732
        if (s2 !== peg$FAILED) {
2733
          peg$reportedPos = s0;
2734
          s1 = peg$c74(s1, s2);
2735
          s0 = s1;
2736
        } else {
2737
          peg$currPos = s0;
2738
          s0 = peg$c3;
2739
        }
2740
      } else {
2741
        peg$currPos = s0;
2742
        s0 = peg$c3;
2743
      }
2744
      peg$silentFails--;
2745
      if (s0 === peg$FAILED) {
2746
        s1 = peg$FAILED;
2747
        if (peg$silentFails === 0) { peg$fail(peg$c71); }
2748
      }
2749
 
2750
      return s0;
2751
    }
2752
 
2753
    function peg$parsearray_part() {
2754
      var s0, s1, s2, s3, s4;
2755
 
2756
      peg$silentFails++;
2757
      s0 = peg$currPos;
2758
      s1 = [];
2759
      s2 = peg$currPos;
2760
      if (input.charCodeAt(peg$currPos) === 46) {
2761
        s3 = peg$c50;
2762
        peg$currPos++;
2763
      } else {
2764
        s3 = peg$FAILED;
2765
        if (peg$silentFails === 0) { peg$fail(peg$c51); }
2766
      }
2767
      if (s3 !== peg$FAILED) {
2768
        s4 = peg$parsekey();
2769
        if (s4 !== peg$FAILED) {
2770
          peg$reportedPos = s2;
2771
          s3 = peg$c76(s4);
2772
          s2 = s3;
2773
        } else {
2774
          peg$currPos = s2;
2775
          s2 = peg$c3;
2776
        }
2777
      } else {
2778
        peg$currPos = s2;
2779
        s2 = peg$c3;
2780
      }
2781
      if (s2 !== peg$FAILED) {
2782
        while (s2 !== peg$FAILED) {
2783
          s1.push(s2);
2784
          s2 = peg$currPos;
2785
          if (input.charCodeAt(peg$currPos) === 46) {
2786
            s3 = peg$c50;
2787
            peg$currPos++;
2788
          } else {
2789
            s3 = peg$FAILED;
2790
            if (peg$silentFails === 0) { peg$fail(peg$c51); }
2791
          }
2792
          if (s3 !== peg$FAILED) {
2793
            s4 = peg$parsekey();
2794
            if (s4 !== peg$FAILED) {
2795
              peg$reportedPos = s2;
2796
              s3 = peg$c76(s4);
2797
              s2 = s3;
2798
            } else {
2799
              peg$currPos = s2;
2800
              s2 = peg$c3;
2801
            }
2802
          } else {
2803
            peg$currPos = s2;
2804
            s2 = peg$c3;
2805
          }
2806
        }
2807
      } else {
2808
        s1 = peg$c3;
2809
      }
2810
      if (s1 !== peg$FAILED) {
2811
        s2 = peg$parsearray();
2812
        if (s2 === peg$FAILED) {
2813
          s2 = peg$c4;
2814
        }
2815
        if (s2 !== peg$FAILED) {
2816
          peg$reportedPos = s0;
2817
          s1 = peg$c77(s1, s2);
2818
          s0 = s1;
2819
        } else {
2820
          peg$currPos = s0;
2821
          s0 = peg$c3;
2822
        }
2823
      } else {
2824
        peg$currPos = s0;
2825
        s0 = peg$c3;
2826
      }
2827
      peg$silentFails--;
2828
      if (s0 === peg$FAILED) {
2829
        s1 = peg$FAILED;
2830
        if (peg$silentFails === 0) { peg$fail(peg$c75); }
2831
      }
2832
 
2833
      return s0;
2834
    }
2835
 
2836
    function peg$parseinline() {
2837
      var s0, s1, s2, s3;
2838
 
2839
      peg$silentFails++;
2840
      s0 = peg$currPos;
2841
      if (input.charCodeAt(peg$currPos) === 34) {
2842
        s1 = peg$c79;
2843
        peg$currPos++;
2844
      } else {
2845
        s1 = peg$FAILED;
2846
        if (peg$silentFails === 0) { peg$fail(peg$c80); }
2847
      }
2848
      if (s1 !== peg$FAILED) {
2849
        if (input.charCodeAt(peg$currPos) === 34) {
2850
          s2 = peg$c79;
2851
          peg$currPos++;
2852
        } else {
2853
          s2 = peg$FAILED;
2854
          if (peg$silentFails === 0) { peg$fail(peg$c80); }
2855
        }
2856
        if (s2 !== peg$FAILED) {
2857
          peg$reportedPos = s0;
2858
          s1 = peg$c81();
2859
          s0 = s1;
2860
        } else {
2861
          peg$currPos = s0;
2862
          s0 = peg$c3;
2863
        }
2864
      } else {
2865
        peg$currPos = s0;
2866
        s0 = peg$c3;
2867
      }
2868
      if (s0 === peg$FAILED) {
2869
        s0 = peg$currPos;
2870
        if (input.charCodeAt(peg$currPos) === 34) {
2871
          s1 = peg$c79;
2872
          peg$currPos++;
2873
        } else {
2874
          s1 = peg$FAILED;
2875
          if (peg$silentFails === 0) { peg$fail(peg$c80); }
2876
        }
2877
        if (s1 !== peg$FAILED) {
2878
          s2 = peg$parseliteral();
2879
          if (s2 !== peg$FAILED) {
2880
            if (input.charCodeAt(peg$currPos) === 34) {
2881
              s3 = peg$c79;
2882
              peg$currPos++;
2883
            } else {
2884
              s3 = peg$FAILED;
2885
              if (peg$silentFails === 0) { peg$fail(peg$c80); }
2886
            }
2887
            if (s3 !== peg$FAILED) {
2888
              peg$reportedPos = s0;
2889
              s1 = peg$c82(s2);
2890
              s0 = s1;
2891
            } else {
2892
              peg$currPos = s0;
2893
              s0 = peg$c3;
2894
            }
2895
          } else {
2896
            peg$currPos = s0;
2897
            s0 = peg$c3;
2898
          }
2899
        } else {
2900
          peg$currPos = s0;
2901
          s0 = peg$c3;
2902
        }
2903
        if (s0 === peg$FAILED) {
2904
          s0 = peg$currPos;
2905
          if (input.charCodeAt(peg$currPos) === 34) {
2906
            s1 = peg$c79;
2907
            peg$currPos++;
2908
          } else {
2909
            s1 = peg$FAILED;
2910
            if (peg$silentFails === 0) { peg$fail(peg$c80); }
2911
          }
2912
          if (s1 !== peg$FAILED) {
2913
            s2 = [];
2914
            s3 = peg$parseinline_part();
2915
            if (s3 !== peg$FAILED) {
2916
              while (s3 !== peg$FAILED) {
2917
                s2.push(s3);
2918
                s3 = peg$parseinline_part();
2919
              }
2920
            } else {
2921
              s2 = peg$c3;
2922
            }
2923
            if (s2 !== peg$FAILED) {
2924
              if (input.charCodeAt(peg$currPos) === 34) {
2925
                s3 = peg$c79;
2926
                peg$currPos++;
2927
              } else {
2928
                s3 = peg$FAILED;
2929
                if (peg$silentFails === 0) { peg$fail(peg$c80); }
2930
              }
2931
              if (s3 !== peg$FAILED) {
2932
                peg$reportedPos = s0;
2933
                s1 = peg$c83(s2);
2934
                s0 = s1;
2935
              } else {
2936
                peg$currPos = s0;
2937
                s0 = peg$c3;
2938
              }
2939
            } else {
2940
              peg$currPos = s0;
2941
              s0 = peg$c3;
2942
            }
2943
          } else {
2944
            peg$currPos = s0;
2945
            s0 = peg$c3;
2946
          }
2947
        }
2948
      }
2949
      peg$silentFails--;
2950
      if (s0 === peg$FAILED) {
2951
        s1 = peg$FAILED;
2952
        if (peg$silentFails === 0) { peg$fail(peg$c78); }
2953
      }
2954
 
2955
      return s0;
2956
    }
2957
 
2958
    function peg$parseinline_part() {
2959
      var s0, s1;
2960
 
2961
      s0 = peg$parsespecial();
2962
      if (s0 === peg$FAILED) {
2963
        s0 = peg$parsereference();
2964
        if (s0 === peg$FAILED) {
2965
          s0 = peg$currPos;
2966
          s1 = peg$parseliteral();
2967
          if (s1 !== peg$FAILED) {
2968
            peg$reportedPos = s0;
2969
            s1 = peg$c84(s1);
2970
          }
2971
          s0 = s1;
2972
        }
2973
      }
2974
 
2975
      return s0;
2976
    }
2977
 
2978
    function peg$parsebuffer() {
2979
      var s0, s1, s2, s3, s4, s5, s6, s7;
2980
 
2981
      peg$silentFails++;
2982
      s0 = peg$currPos;
2983
      s1 = peg$parseeol();
2984
      if (s1 !== peg$FAILED) {
2985
        s2 = [];
2986
        s3 = peg$parsews();
2987
        while (s3 !== peg$FAILED) {
2988
          s2.push(s3);
2989
          s3 = peg$parsews();
2990
        }
2991
        if (s2 !== peg$FAILED) {
2992
          peg$reportedPos = s0;
2993
          s1 = peg$c86(s1, s2);
2994
          s0 = s1;
2995
        } else {
2996
          peg$currPos = s0;
2997
          s0 = peg$c3;
2998
        }
2999
      } else {
3000
        peg$currPos = s0;
3001
        s0 = peg$c3;
3002
      }
3003
      if (s0 === peg$FAILED) {
3004
        s0 = peg$currPos;
3005
        s1 = [];
3006
        s2 = peg$currPos;
3007
        s3 = peg$currPos;
3008
        peg$silentFails++;
3009
        s4 = peg$parsetag();
3010
        peg$silentFails--;
3011
        if (s4 === peg$FAILED) {
3012
          s3 = peg$c6;
3013
        } else {
3014
          peg$currPos = s3;
3015
          s3 = peg$c3;
3016
        }
3017
        if (s3 !== peg$FAILED) {
3018
          s4 = peg$currPos;
3019
          peg$silentFails++;
3020
          s5 = peg$parseraw();
3021
          peg$silentFails--;
3022
          if (s5 === peg$FAILED) {
3023
            s4 = peg$c6;
3024
          } else {
3025
            peg$currPos = s4;
3026
            s4 = peg$c3;
3027
          }
3028
          if (s4 !== peg$FAILED) {
3029
            s5 = peg$currPos;
3030
            peg$silentFails++;
3031
            s6 = peg$parsecomment();
3032
            peg$silentFails--;
3033
            if (s6 === peg$FAILED) {
3034
              s5 = peg$c6;
3035
            } else {
3036
              peg$currPos = s5;
3037
              s5 = peg$c3;
3038
            }
3039
            if (s5 !== peg$FAILED) {
3040
              s6 = peg$currPos;
3041
              peg$silentFails++;
3042
              s7 = peg$parseeol();
3043
              peg$silentFails--;
3044
              if (s7 === peg$FAILED) {
3045
                s6 = peg$c6;
3046
              } else {
3047
                peg$currPos = s6;
3048
                s6 = peg$c3;
3049
              }
3050
              if (s6 !== peg$FAILED) {
3051
                if (input.length > peg$currPos) {
3052
                  s7 = input.charAt(peg$currPos);
3053
                  peg$currPos++;
3054
                } else {
3055
                  s7 = peg$FAILED;
3056
                  if (peg$silentFails === 0) { peg$fail(peg$c87); }
3057
                }
3058
                if (s7 !== peg$FAILED) {
3059
                  peg$reportedPos = s2;
3060
                  s3 = peg$c88(s7);
3061
                  s2 = s3;
3062
                } else {
3063
                  peg$currPos = s2;
3064
                  s2 = peg$c3;
3065
                }
3066
              } else {
3067
                peg$currPos = s2;
3068
                s2 = peg$c3;
3069
              }
3070
            } else {
3071
              peg$currPos = s2;
3072
              s2 = peg$c3;
3073
            }
3074
          } else {
3075
            peg$currPos = s2;
3076
            s2 = peg$c3;
3077
          }
3078
        } else {
3079
          peg$currPos = s2;
3080
          s2 = peg$c3;
3081
        }
3082
        if (s2 !== peg$FAILED) {
3083
          while (s2 !== peg$FAILED) {
3084
            s1.push(s2);
3085
            s2 = peg$currPos;
3086
            s3 = peg$currPos;
3087
            peg$silentFails++;
3088
            s4 = peg$parsetag();
3089
            peg$silentFails--;
3090
            if (s4 === peg$FAILED) {
3091
              s3 = peg$c6;
3092
            } else {
3093
              peg$currPos = s3;
3094
              s3 = peg$c3;
3095
            }
3096
            if (s3 !== peg$FAILED) {
3097
              s4 = peg$currPos;
3098
              peg$silentFails++;
3099
              s5 = peg$parseraw();
3100
              peg$silentFails--;
3101
              if (s5 === peg$FAILED) {
3102
                s4 = peg$c6;
3103
              } else {
3104
                peg$currPos = s4;
3105
                s4 = peg$c3;
3106
              }
3107
              if (s4 !== peg$FAILED) {
3108
                s5 = peg$currPos;
3109
                peg$silentFails++;
3110
                s6 = peg$parsecomment();
3111
                peg$silentFails--;
3112
                if (s6 === peg$FAILED) {
3113
                  s5 = peg$c6;
3114
                } else {
3115
                  peg$currPos = s5;
3116
                  s5 = peg$c3;
3117
                }
3118
                if (s5 !== peg$FAILED) {
3119
                  s6 = peg$currPos;
3120
                  peg$silentFails++;
3121
                  s7 = peg$parseeol();
3122
                  peg$silentFails--;
3123
                  if (s7 === peg$FAILED) {
3124
                    s6 = peg$c6;
3125
                  } else {
3126
                    peg$currPos = s6;
3127
                    s6 = peg$c3;
3128
                  }
3129
                  if (s6 !== peg$FAILED) {
3130
                    if (input.length > peg$currPos) {
3131
                      s7 = input.charAt(peg$currPos);
3132
                      peg$currPos++;
3133
                    } else {
3134
                      s7 = peg$FAILED;
3135
                      if (peg$silentFails === 0) { peg$fail(peg$c87); }
3136
                    }
3137
                    if (s7 !== peg$FAILED) {
3138
                      peg$reportedPos = s2;
3139
                      s3 = peg$c88(s7);
3140
                      s2 = s3;
3141
                    } else {
3142
                      peg$currPos = s2;
3143
                      s2 = peg$c3;
3144
                    }
3145
                  } else {
3146
                    peg$currPos = s2;
3147
                    s2 = peg$c3;
3148
                  }
3149
                } else {
3150
                  peg$currPos = s2;
3151
                  s2 = peg$c3;
3152
                }
3153
              } else {
3154
                peg$currPos = s2;
3155
                s2 = peg$c3;
3156
              }
3157
            } else {
3158
              peg$currPos = s2;
3159
              s2 = peg$c3;
3160
            }
3161
          }
3162
        } else {
3163
          s1 = peg$c3;
3164
        }
3165
        if (s1 !== peg$FAILED) {
3166
          peg$reportedPos = s0;
3167
          s1 = peg$c89(s1);
3168
        }
3169
        s0 = s1;
3170
      }
3171
      peg$silentFails--;
3172
      if (s0 === peg$FAILED) {
3173
        s1 = peg$FAILED;
3174
        if (peg$silentFails === 0) { peg$fail(peg$c85); }
3175
      }
3176
 
3177
      return s0;
3178
    }
3179
 
3180
    function peg$parseliteral() {
3181
      var s0, s1, s2, s3, s4;
3182
 
3183
      peg$silentFails++;
3184
      s0 = peg$currPos;
3185
      s1 = [];
3186
      s2 = peg$currPos;
3187
      s3 = peg$currPos;
3188
      peg$silentFails++;
3189
      s4 = peg$parsetag();
3190
      peg$silentFails--;
3191
      if (s4 === peg$FAILED) {
3192
        s3 = peg$c6;
3193
      } else {
3194
        peg$currPos = s3;
3195
        s3 = peg$c3;
3196
      }
3197
      if (s3 !== peg$FAILED) {
3198
        s4 = peg$parseesc();
3199
        if (s4 === peg$FAILED) {
3200
          if (peg$c91.test(input.charAt(peg$currPos))) {
3201
            s4 = input.charAt(peg$currPos);
3202
            peg$currPos++;
3203
          } else {
3204
            s4 = peg$FAILED;
3205
            if (peg$silentFails === 0) { peg$fail(peg$c92); }
3206
          }
3207
        }
3208
        if (s4 !== peg$FAILED) {
3209
          peg$reportedPos = s2;
3210
          s3 = peg$c88(s4);
3211
          s2 = s3;
3212
        } else {
3213
          peg$currPos = s2;
3214
          s2 = peg$c3;
3215
        }
3216
      } else {
3217
        peg$currPos = s2;
3218
        s2 = peg$c3;
3219
      }
3220
      if (s2 !== peg$FAILED) {
3221
        while (s2 !== peg$FAILED) {
3222
          s1.push(s2);
3223
          s2 = peg$currPos;
3224
          s3 = peg$currPos;
3225
          peg$silentFails++;
3226
          s4 = peg$parsetag();
3227
          peg$silentFails--;
3228
          if (s4 === peg$FAILED) {
3229
            s3 = peg$c6;
3230
          } else {
3231
            peg$currPos = s3;
3232
            s3 = peg$c3;
3233
          }
3234
          if (s3 !== peg$FAILED) {
3235
            s4 = peg$parseesc();
3236
            if (s4 === peg$FAILED) {
3237
              if (peg$c91.test(input.charAt(peg$currPos))) {
3238
                s4 = input.charAt(peg$currPos);
3239
                peg$currPos++;
3240
              } else {
3241
                s4 = peg$FAILED;
3242
                if (peg$silentFails === 0) { peg$fail(peg$c92); }
3243
              }
3244
            }
3245
            if (s4 !== peg$FAILED) {
3246
              peg$reportedPos = s2;
3247
              s3 = peg$c88(s4);
3248
              s2 = s3;
3249
            } else {
3250
              peg$currPos = s2;
3251
              s2 = peg$c3;
3252
            }
3253
          } else {
3254
            peg$currPos = s2;
3255
            s2 = peg$c3;
3256
          }
3257
        }
3258
      } else {
3259
        s1 = peg$c3;
3260
      }
3261
      if (s1 !== peg$FAILED) {
3262
        peg$reportedPos = s0;
3263
        s1 = peg$c93(s1);
3264
      }
3265
      s0 = s1;
3266
      peg$silentFails--;
3267
      if (s0 === peg$FAILED) {
3268
        s1 = peg$FAILED;
3269
        if (peg$silentFails === 0) { peg$fail(peg$c90); }
3270
      }
3271
 
3272
      return s0;
3273
    }
3274
 
3275
    function peg$parseesc() {
3276
      var s0, s1;
3277
 
3278
      s0 = peg$currPos;
3279
      if (input.substr(peg$currPos, 2) === peg$c94) {
3280
        s1 = peg$c94;
3281
        peg$currPos += 2;
3282
      } else {
3283
        s1 = peg$FAILED;
3284
        if (peg$silentFails === 0) { peg$fail(peg$c95); }
3285
      }
3286
      if (s1 !== peg$FAILED) {
3287
        peg$reportedPos = s0;
3288
        s1 = peg$c96();
3289
      }
3290
      s0 = s1;
3291
 
3292
      return s0;
3293
    }
3294
 
3295
    function peg$parseraw() {
3296
      var s0, s1, s2, s3, s4, s5;
3297
 
3298
      peg$silentFails++;
3299
      s0 = peg$currPos;
3300
      if (input.substr(peg$currPos, 2) === peg$c98) {
3301
        s1 = peg$c98;
3302
        peg$currPos += 2;
3303
      } else {
3304
        s1 = peg$FAILED;
3305
        if (peg$silentFails === 0) { peg$fail(peg$c99); }
3306
      }
3307
      if (s1 !== peg$FAILED) {
3308
        s2 = [];
3309
        s3 = peg$currPos;
3310
        s4 = peg$currPos;
3311
        peg$silentFails++;
3312
        if (input.substr(peg$currPos, 2) === peg$c100) {
3313
          s5 = peg$c100;
3314
          peg$currPos += 2;
3315
        } else {
3316
          s5 = peg$FAILED;
3317
          if (peg$silentFails === 0) { peg$fail(peg$c101); }
3318
        }
3319
        peg$silentFails--;
3320
        if (s5 === peg$FAILED) {
3321
          s4 = peg$c6;
3322
        } else {
3323
          peg$currPos = s4;
3324
          s4 = peg$c3;
3325
        }
3326
        if (s4 !== peg$FAILED) {
3327
          if (input.length > peg$currPos) {
3328
            s5 = input.charAt(peg$currPos);
3329
            peg$currPos++;
3330
          } else {
3331
            s5 = peg$FAILED;
3332
            if (peg$silentFails === 0) { peg$fail(peg$c87); }
3333
          }
3334
          if (s5 !== peg$FAILED) {
3335
            peg$reportedPos = s3;
3336
            s4 = peg$c102(s5);
3337
            s3 = s4;
3338
          } else {
3339
            peg$currPos = s3;
3340
            s3 = peg$c3;
3341
          }
3342
        } else {
3343
          peg$currPos = s3;
3344
          s3 = peg$c3;
3345
        }
3346
        while (s3 !== peg$FAILED) {
3347
          s2.push(s3);
3348
          s3 = peg$currPos;
3349
          s4 = peg$currPos;
3350
          peg$silentFails++;
3351
          if (input.substr(peg$currPos, 2) === peg$c100) {
3352
            s5 = peg$c100;
3353
            peg$currPos += 2;
3354
          } else {
3355
            s5 = peg$FAILED;
3356
            if (peg$silentFails === 0) { peg$fail(peg$c101); }
3357
          }
3358
          peg$silentFails--;
3359
          if (s5 === peg$FAILED) {
3360
            s4 = peg$c6;
3361
          } else {
3362
            peg$currPos = s4;
3363
            s4 = peg$c3;
3364
          }
3365
          if (s4 !== peg$FAILED) {
3366
            if (input.length > peg$currPos) {
3367
              s5 = input.charAt(peg$currPos);
3368
              peg$currPos++;
3369
            } else {
3370
              s5 = peg$FAILED;
3371
              if (peg$silentFails === 0) { peg$fail(peg$c87); }
3372
            }
3373
            if (s5 !== peg$FAILED) {
3374
              peg$reportedPos = s3;
3375
              s4 = peg$c102(s5);
3376
              s3 = s4;
3377
            } else {
3378
              peg$currPos = s3;
3379
              s3 = peg$c3;
3380
            }
3381
          } else {
3382
            peg$currPos = s3;
3383
            s3 = peg$c3;
3384
          }
3385
        }
3386
        if (s2 !== peg$FAILED) {
3387
          if (input.substr(peg$currPos, 2) === peg$c100) {
3388
            s3 = peg$c100;
3389
            peg$currPos += 2;
3390
          } else {
3391
            s3 = peg$FAILED;
3392
            if (peg$silentFails === 0) { peg$fail(peg$c101); }
3393
          }
3394
          if (s3 !== peg$FAILED) {
3395
            peg$reportedPos = s0;
3396
            s1 = peg$c103(s2);
3397
            s0 = s1;
3398
          } else {
3399
            peg$currPos = s0;
3400
            s0 = peg$c3;
3401
          }
3402
        } else {
3403
          peg$currPos = s0;
3404
          s0 = peg$c3;
3405
        }
3406
      } else {
3407
        peg$currPos = s0;
3408
        s0 = peg$c3;
3409
      }
3410
      peg$silentFails--;
3411
      if (s0 === peg$FAILED) {
3412
        s1 = peg$FAILED;
3413
        if (peg$silentFails === 0) { peg$fail(peg$c97); }
3414
      }
3415
 
3416
      return s0;
3417
    }
3418
 
3419
    function peg$parsecomment() {
3420
      var s0, s1, s2, s3, s4, s5;
3421
 
3422
      peg$silentFails++;
3423
      s0 = peg$currPos;
3424
      if (input.substr(peg$currPos, 2) === peg$c105) {
3425
        s1 = peg$c105;
3426
        peg$currPos += 2;
3427
      } else {
3428
        s1 = peg$FAILED;
3429
        if (peg$silentFails === 0) { peg$fail(peg$c106); }
3430
      }
3431
      if (s1 !== peg$FAILED) {
3432
        s2 = [];
3433
        s3 = peg$currPos;
3434
        s4 = peg$currPos;
3435
        peg$silentFails++;
3436
        if (input.substr(peg$currPos, 2) === peg$c107) {
3437
          s5 = peg$c107;
3438
          peg$currPos += 2;
3439
        } else {
3440
          s5 = peg$FAILED;
3441
          if (peg$silentFails === 0) { peg$fail(peg$c108); }
3442
        }
3443
        peg$silentFails--;
3444
        if (s5 === peg$FAILED) {
3445
          s4 = peg$c6;
3446
        } else {
3447
          peg$currPos = s4;
3448
          s4 = peg$c3;
3449
        }
3450
        if (s4 !== peg$FAILED) {
3451
          if (input.length > peg$currPos) {
3452
            s5 = input.charAt(peg$currPos);
3453
            peg$currPos++;
3454
          } else {
3455
            s5 = peg$FAILED;
3456
            if (peg$silentFails === 0) { peg$fail(peg$c87); }
3457
          }
3458
          if (s5 !== peg$FAILED) {
3459
            peg$reportedPos = s3;
3460
            s4 = peg$c88(s5);
3461
            s3 = s4;
3462
          } else {
3463
            peg$currPos = s3;
3464
            s3 = peg$c3;
3465
          }
3466
        } else {
3467
          peg$currPos = s3;
3468
          s3 = peg$c3;
3469
        }
3470
        while (s3 !== peg$FAILED) {
3471
          s2.push(s3);
3472
          s3 = peg$currPos;
3473
          s4 = peg$currPos;
3474
          peg$silentFails++;
3475
          if (input.substr(peg$currPos, 2) === peg$c107) {
3476
            s5 = peg$c107;
3477
            peg$currPos += 2;
3478
          } else {
3479
            s5 = peg$FAILED;
3480
            if (peg$silentFails === 0) { peg$fail(peg$c108); }
3481
          }
3482
          peg$silentFails--;
3483
          if (s5 === peg$FAILED) {
3484
            s4 = peg$c6;
3485
          } else {
3486
            peg$currPos = s4;
3487
            s4 = peg$c3;
3488
          }
3489
          if (s4 !== peg$FAILED) {
3490
            if (input.length > peg$currPos) {
3491
              s5 = input.charAt(peg$currPos);
3492
              peg$currPos++;
3493
            } else {
3494
              s5 = peg$FAILED;
3495
              if (peg$silentFails === 0) { peg$fail(peg$c87); }
3496
            }
3497
            if (s5 !== peg$FAILED) {
3498
              peg$reportedPos = s3;
3499
              s4 = peg$c88(s5);
3500
              s3 = s4;
3501
            } else {
3502
              peg$currPos = s3;
3503
              s3 = peg$c3;
3504
            }
3505
          } else {
3506
            peg$currPos = s3;
3507
            s3 = peg$c3;
3508
          }
3509
        }
3510
        if (s2 !== peg$FAILED) {
3511
          if (input.substr(peg$currPos, 2) === peg$c107) {
3512
            s3 = peg$c107;
3513
            peg$currPos += 2;
3514
          } else {
3515
            s3 = peg$FAILED;
3516
            if (peg$silentFails === 0) { peg$fail(peg$c108); }
3517
          }
3518
          if (s3 !== peg$FAILED) {
3519
            peg$reportedPos = s0;
3520
            s1 = peg$c109(s2);
3521
            s0 = s1;
3522
          } else {
3523
            peg$currPos = s0;
3524
            s0 = peg$c3;
3525
          }
3526
        } else {
3527
          peg$currPos = s0;
3528
          s0 = peg$c3;
3529
        }
3530
      } else {
3531
        peg$currPos = s0;
3532
        s0 = peg$c3;
3533
      }
3534
      peg$silentFails--;
3535
      if (s0 === peg$FAILED) {
3536
        s1 = peg$FAILED;
3537
        if (peg$silentFails === 0) { peg$fail(peg$c104); }
3538
      }
3539
 
3540
      return s0;
3541
    }
3542
 
3543
    function peg$parsetag() {
3544
      var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
3545
 
3546
      s0 = peg$currPos;
3547
      s1 = peg$parseld();
3548
      if (s1 !== peg$FAILED) {
3549
        s2 = [];
3550
        s3 = peg$parsews();
3551
        while (s3 !== peg$FAILED) {
3552
          s2.push(s3);
3553
          s3 = peg$parsews();
3554
        }
3555
        if (s2 !== peg$FAILED) {
3556
          if (peg$c110.test(input.charAt(peg$currPos))) {
3557
            s3 = input.charAt(peg$currPos);
3558
            peg$currPos++;
3559
          } else {
3560
            s3 = peg$FAILED;
3561
            if (peg$silentFails === 0) { peg$fail(peg$c111); }
3562
          }
3563
          if (s3 !== peg$FAILED) {
3564
            s4 = [];
3565
            s5 = peg$parsews();
3566
            while (s5 !== peg$FAILED) {
3567
              s4.push(s5);
3568
              s5 = peg$parsews();
3569
            }
3570
            if (s4 !== peg$FAILED) {
3571
              s5 = [];
3572
              s6 = peg$currPos;
3573
              s7 = peg$currPos;
3574
              peg$silentFails++;
3575
              s8 = peg$parserd();
3576
              peg$silentFails--;
3577
              if (s8 === peg$FAILED) {
3578
                s7 = peg$c6;
3579
              } else {
3580
                peg$currPos = s7;
3581
                s7 = peg$c3;
3582
              }
3583
              if (s7 !== peg$FAILED) {
3584
                s8 = peg$currPos;
3585
                peg$silentFails++;
3586
                s9 = peg$parseeol();
3587
                peg$silentFails--;
3588
                if (s9 === peg$FAILED) {
3589
                  s8 = peg$c6;
3590
                } else {
3591
                  peg$currPos = s8;
3592
                  s8 = peg$c3;
3593
                }
3594
                if (s8 !== peg$FAILED) {
3595
                  if (input.length > peg$currPos) {
3596
                    s9 = input.charAt(peg$currPos);
3597
                    peg$currPos++;
3598
                  } else {
3599
                    s9 = peg$FAILED;
3600
                    if (peg$silentFails === 0) { peg$fail(peg$c87); }
3601
                  }
3602
                  if (s9 !== peg$FAILED) {
3603
                    s7 = [s7, s8, s9];
3604
                    s6 = s7;
3605
                  } else {
3606
                    peg$currPos = s6;
3607
                    s6 = peg$c3;
3608
                  }
3609
                } else {
3610
                  peg$currPos = s6;
3611
                  s6 = peg$c3;
3612
                }
3613
              } else {
3614
                peg$currPos = s6;
3615
                s6 = peg$c3;
3616
              }
3617
              if (s6 !== peg$FAILED) {
3618
                while (s6 !== peg$FAILED) {
3619
                  s5.push(s6);
3620
                  s6 = peg$currPos;
3621
                  s7 = peg$currPos;
3622
                  peg$silentFails++;
3623
                  s8 = peg$parserd();
3624
                  peg$silentFails--;
3625
                  if (s8 === peg$FAILED) {
3626
                    s7 = peg$c6;
3627
                  } else {
3628
                    peg$currPos = s7;
3629
                    s7 = peg$c3;
3630
                  }
3631
                  if (s7 !== peg$FAILED) {
3632
                    s8 = peg$currPos;
3633
                    peg$silentFails++;
3634
                    s9 = peg$parseeol();
3635
                    peg$silentFails--;
3636
                    if (s9 === peg$FAILED) {
3637
                      s8 = peg$c6;
3638
                    } else {
3639
                      peg$currPos = s8;
3640
                      s8 = peg$c3;
3641
                    }
3642
                    if (s8 !== peg$FAILED) {
3643
                      if (input.length > peg$currPos) {
3644
                        s9 = input.charAt(peg$currPos);
3645
                        peg$currPos++;
3646
                      } else {
3647
                        s9 = peg$FAILED;
3648
                        if (peg$silentFails === 0) { peg$fail(peg$c87); }
3649
                      }
3650
                      if (s9 !== peg$FAILED) {
3651
                        s7 = [s7, s8, s9];
3652
                        s6 = s7;
3653
                      } else {
3654
                        peg$currPos = s6;
3655
                        s6 = peg$c3;
3656
                      }
3657
                    } else {
3658
                      peg$currPos = s6;
3659
                      s6 = peg$c3;
3660
                    }
3661
                  } else {
3662
                    peg$currPos = s6;
3663
                    s6 = peg$c3;
3664
                  }
3665
                }
3666
              } else {
3667
                s5 = peg$c3;
3668
              }
3669
              if (s5 !== peg$FAILED) {
3670
                s6 = [];
3671
                s7 = peg$parsews();
3672
                while (s7 !== peg$FAILED) {
3673
                  s6.push(s7);
3674
                  s7 = peg$parsews();
3675
                }
3676
                if (s6 !== peg$FAILED) {
3677
                  s7 = peg$parserd();
3678
                  if (s7 !== peg$FAILED) {
3679
                    s1 = [s1, s2, s3, s4, s5, s6, s7];
3680
                    s0 = s1;
3681
                  } else {
3682
                    peg$currPos = s0;
3683
                    s0 = peg$c3;
3684
                  }
3685
                } else {
3686
                  peg$currPos = s0;
3687
                  s0 = peg$c3;
3688
                }
3689
              } else {
3690
                peg$currPos = s0;
3691
                s0 = peg$c3;
3692
              }
3693
            } else {
3694
              peg$currPos = s0;
3695
              s0 = peg$c3;
3696
            }
3697
          } else {
3698
            peg$currPos = s0;
3699
            s0 = peg$c3;
3700
          }
3701
        } else {
3702
          peg$currPos = s0;
3703
          s0 = peg$c3;
3704
        }
3705
      } else {
3706
        peg$currPos = s0;
3707
        s0 = peg$c3;
3708
      }
3709
      if (s0 === peg$FAILED) {
3710
        s0 = peg$parsereference();
3711
      }
3712
 
3713
      return s0;
3714
    }
3715
 
3716
    function peg$parseld() {
3717
      var s0;
3718
 
3719
      if (input.charCodeAt(peg$currPos) === 123) {
3720
        s0 = peg$c112;
3721
        peg$currPos++;
3722
      } else {
3723
        s0 = peg$FAILED;
3724
        if (peg$silentFails === 0) { peg$fail(peg$c113); }
3725
      }
3726
 
3727
      return s0;
3728
    }
3729
 
3730
    function peg$parserd() {
3731
      var s0;
3732
 
3733
      if (input.charCodeAt(peg$currPos) === 125) {
3734
        s0 = peg$c114;
3735
        peg$currPos++;
3736
      } else {
3737
        s0 = peg$FAILED;
3738
        if (peg$silentFails === 0) { peg$fail(peg$c115); }
3739
      }
3740
 
3741
      return s0;
3742
    }
3743
 
3744
    function peg$parselb() {
3745
      var s0;
3746
 
3747
      if (input.charCodeAt(peg$currPos) === 91) {
3748
        s0 = peg$c116;
3749
        peg$currPos++;
3750
      } else {
3751
        s0 = peg$FAILED;
3752
        if (peg$silentFails === 0) { peg$fail(peg$c117); }
3753
      }
3754
 
3755
      return s0;
3756
    }
3757
 
3758
    function peg$parserb() {
3759
      var s0;
3760
 
3761
      if (input.charCodeAt(peg$currPos) === 93) {
3762
        s0 = peg$c118;
3763
        peg$currPos++;
3764
      } else {
3765
        s0 = peg$FAILED;
3766
        if (peg$silentFails === 0) { peg$fail(peg$c119); }
3767
      }
3768
 
3769
      return s0;
3770
    }
3771
 
3772
    function peg$parseeol() {
3773
      var s0;
3774
 
3775
      if (input.charCodeAt(peg$currPos) === 10) {
3776
        s0 = peg$c120;
3777
        peg$currPos++;
3778
      } else {
3779
        s0 = peg$FAILED;
3780
        if (peg$silentFails === 0) { peg$fail(peg$c121); }
3781
      }
3782
      if (s0 === peg$FAILED) {
3783
        if (input.substr(peg$currPos, 2) === peg$c122) {
3784
          s0 = peg$c122;
3785
          peg$currPos += 2;
3786
        } else {
3787
          s0 = peg$FAILED;
3788
          if (peg$silentFails === 0) { peg$fail(peg$c123); }
3789
        }
3790
        if (s0 === peg$FAILED) {
3791
          if (input.charCodeAt(peg$currPos) === 13) {
3792
            s0 = peg$c124;
3793
            peg$currPos++;
3794
          } else {
3795
            s0 = peg$FAILED;
3796
            if (peg$silentFails === 0) { peg$fail(peg$c125); }
3797
          }
3798
          if (s0 === peg$FAILED) {
3799
            if (input.charCodeAt(peg$currPos) === 8232) {
3800
              s0 = peg$c126;
3801
              peg$currPos++;
3802
            } else {
3803
              s0 = peg$FAILED;
3804
              if (peg$silentFails === 0) { peg$fail(peg$c127); }
3805
            }
3806
            if (s0 === peg$FAILED) {
3807
              if (input.charCodeAt(peg$currPos) === 8233) {
3808
                s0 = peg$c128;
3809
                peg$currPos++;
3810
              } else {
3811
                s0 = peg$FAILED;
3812
                if (peg$silentFails === 0) { peg$fail(peg$c129); }
3813
              }
3814
            }
3815
          }
3816
        }
3817
      }
3818
 
3819
      return s0;
3820
    }
3821
 
3822
    function peg$parsews() {
3823
      var s0;
3824
 
3825
      if (peg$c130.test(input.charAt(peg$currPos))) {
3826
        s0 = input.charAt(peg$currPos);
3827
        peg$currPos++;
3828
      } else {
3829
        s0 = peg$FAILED;
3830
        if (peg$silentFails === 0) { peg$fail(peg$c131); }
3831
      }
3832
      if (s0 === peg$FAILED) {
3833
        s0 = peg$parseeol();
3834
      }
3835
 
3836
      return s0;
3837
    }
3838
 
3839
 
3840
      function makeInteger(arr) {
3841
        return parseInt(arr.join(''), 10);
3842
      }
3843
      function withPosition(arr) {
3844
        return arr.concat([['line', line()], ['col', column()]]);
3845
      }
3846
 
3847
 
3848
    peg$result = peg$startRuleFunction();
3849
 
3850
    if (peg$result !== peg$FAILED && peg$currPos === input.length) {
3851
      return peg$result;
3852
    } else {
3853
      if (peg$result !== peg$FAILED && peg$currPos < input.length) {
3854
        peg$fail({ type: "end", description: "end of input" });
3855
      }
3856
 
3857
      throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
3858
    }
3859
  }
3860
 
3861
  return {
3862
    SyntaxError: SyntaxError,
3863
    parse:       parse
3864
  };
3865
})();
3866
 
3867
  // expose parser methods
3868
  dust.parse = parser.parse;
3869
 
3870
  return parser;
3871
}));
3872
 
3873
(function(root, factory) {
3874
  if (typeof define === "function" && define.amd && define.amd.dust === true) {
3875
    define("dust.compile", ["dust.core", "dust.parse"], function(dust, parse) {
3876
      return factory(parse, dust).compile;
3877
    });
3878
  } else if (typeof exports === 'object') {
3879
    // in Node, require this file if we want to use the compiler as a standalone module
3880
    module.exports = factory(require('./parser').parse, require('./dust'));
3881
  } else {
3882
    // in the browser, store the factory output if we want to use the compiler directly
3883
    factory(root.dust.parse, root.dust);
3884
  }
3885
}(this, function(parse, dust) {
3886
  var compiler = {},
3887
      isArray = dust.isArray;
3888
 
3889
 
3890
  compiler.compile = function(source, name) {
3891
    // the name parameter is optional.
3892
    // this can happen for templates that are rendered immediately (renderSource which calls compileFn) or
3893
    // for templates that are compiled as a callable (compileFn)
3894
    //
3895
    // for the common case (using compile and render) a name is required so that templates will be cached by name and rendered later, by name.
3896
 
3897
    try {
3898
      var ast = filterAST(parse(source));
3899
      return compile(ast, name);
3900
    }
3901
    catch (err)
3902
    {
3903
      if (!err.line || !err.column) {
3904
        throw err;
3905
      }
3906
      throw new SyntaxError(err.message + ' At line : ' + err.line + ', column : ' + err.column);
3907
    }
3908
  };
3909
 
3910
  function filterAST(ast) {
3911
    var context = {};
3912
    return compiler.filterNode(context, ast);
3913
  }
3914
 
3915
  compiler.filterNode = function(context, node) {
3916
    return compiler.optimizers[node[0]](context, node);
3917
  };
3918
 
3919
  compiler.optimizers = {
3920
    body:      compactBuffers,
3921
    buffer:    noop,
3922
    special:   convertSpecial,
3923
    format:    format,
3924
    reference: visit,
3925
    '#':       visit,
3926
    '?':       visit,
3927
    '^':       visit,
3928
    '<':       visit,
3929
    '+':       visit,
3930
    '@':       visit,
3931
    '%':       visit,
3932
    partial:   visit,
3933
    context:   visit,
3934
    params:    visit,
3935
    bodies:    visit,
3936
    param:     visit,
3937
    filters:   noop,
3938
    key:       noop,
3939
    path:      noop,
3940
    literal:   noop,
3941
    raw:       noop,
3942
    comment:   nullify,
3943
    line:      nullify,
3944
    col:       nullify
3945
  };
3946
 
3947
  compiler.pragmas = {
3948
    esc: function(compiler, context, bodies) {
3949
      var old = compiler.auto,
3950
          out;
3951
      if (!context) {
3952
        context = 'h';
3953
      }
3954
      compiler.auto = (context === 's') ? '' : context;
3955
      out = compileParts(compiler, bodies.block);
3956
      compiler.auto = old;
3957
      return out;
3958
    }
3959
  };
3960
 
3961
  function visit(context, node) {
3962
    var out = [node[0]],
3963
        i, len, res;
3964
    for (i=1, len=node.length; i<len; i++) {
3965
      res = compiler.filterNode(context, node[i]);
3966
      if (res) {
3967
        out.push(res);
3968
      }
3969
    }
3970
    return out;
3971
  }
3972
 
3973
  // Compacts consecutive buffer nodes into a single node
3974
  function compactBuffers(context, node) {
3975
    var out = [node[0]],
3976
        memo, i, len, res;
3977
    for (i=1, len=node.length; i<len; i++) {
3978
      res = compiler.filterNode(context, node[i]);
3979
      if (res) {
3980
        if (res[0] === 'buffer' || res[0] === 'format') {
3981
          if (memo) {
3982
            memo[0] = (res[0] === 'buffer') ? 'buffer' : memo[0];
3983
            memo[1] += res.slice(1, -2).join('');
3984
          } else {
3985
            memo = res;
3986
            out.push(res);
3987
          }
3988
        } else {
3989
          memo = null;
3990
          out.push(res);
3991
        }
3992
      }
3993
    }
3994
    return out;
3995
  }
3996
 
3997
  var specialChars = {
3998
    's': ' ',
3999
    'n': '\n',
4000
    'r': '\r',
4001
    'lb': '{',
4002
    'rb': '}'
4003
  };
4004
 
4005
  function convertSpecial(context, node) {
4006
    return ['buffer', specialChars[node[1]], node[2], node[3]];
4007
  }
4008
 
4009
  function noop(context, node) {
4010
    return node;
4011
  }
4012
 
4013
  function nullify(){}
4014
 
4015
  function format(context, node) {
4016
    if(dust.config.whitespace) {
4017
      // Format nodes are in the form ['format', eol, whitespace, line, col],
4018
      // which is unlike other nodes in that there are two pieces of content
4019
      // Join eol and whitespace together to normalize the node format
4020
      node.splice(1, 2, node.slice(1, -2).join(''));
4021
      return node;
4022
    }
4023
    return null;
4024
  }
4025
 
4026
  function compile(ast, name) {
4027
    var context = {
4028
      name: name,
4029
      bodies: [],
4030
      blocks: {},
4031
      index: 0,
4032
      auto: 'h'
4033
    },
4034
    escapedName = dust.escapeJs(name),
4035
    AMDName = name? '"' + escapedName + '",' : '',
4036
    compiled = 'function(dust){',
4037
    entry = compiler.compileNode(context, ast),
4038
    iife;
4039
 
4040
    if(name) {
4041
      compiled += 'dust.register("' + escapedName + '",' + entry + ');';
4042
    }
4043
 
4044
    compiled += compileBlocks(context) +
4045
                compileBodies(context) +
4046
                'return ' + entry + '}';
4047
 
4048
    iife = '(' + compiled + '(dust));';
4049
 
4050
    if(dust.config.amd) {
4051
      return 'define(' + AMDName + '["dust.core"],' + compiled + ');';
4052
    } else if(dust.config.cjs) {
4053
      return 'module.exports=function(dust){' +
4054
             'var tmpl=' + iife +
4055
             'var f=' + loaderFor().toString() + ';' +
4056
             'f.template=tmpl;return f}';
4057
    } else {
4058
      return iife;
4059
    }
4060
  }
4061
 
4062
  function compileBlocks(context) {
4063
    var out = [],
4064
        blocks = context.blocks,
4065
        name;
4066
 
4067
    for (name in blocks) {
4068
      out.push('"' + name + '":' + blocks[name]);
4069
    }
4070
    if (out.length) {
4071
      context.blocks = 'ctx=ctx.shiftBlocks(blocks);';
4072
      return 'var blocks={' + out.join(',') + '};';
4073
    } else {
4074
      context.blocks = '';
4075
    }
4076
    return context.blocks;
4077
  }
4078
 
4079
  function compileBodies(context) {
4080
    var out = [],
4081
        bodies = context.bodies,
4082
        blx = context.blocks,
4083
        i, len;
4084
 
4085
    for (i=0, len=bodies.length; i<len; i++) {
4086
      out[i] = 'function body_' + i + '(chk,ctx){' +
4087
          blx + 'return chk' + bodies[i] + ';}body_' + i + '.__dustBody=!0;';
4088
    }
4089
    return out.join('');
4090
  }
4091
 
4092
  function compileParts(context, body) {
4093
    var parts = '',
4094
        i, len;
4095
    for (i=1, len=body.length; i<len; i++) {
4096
      parts += compiler.compileNode(context, body[i]);
4097
    }
4098
    return parts;
4099
  }
4100
 
4101
  compiler.compileNode = function(context, node) {
4102
    return compiler.nodes[node[0]](context, node);
4103
  };
4104
 
4105
  compiler.nodes = {
4106
    body: function(context, node) {
4107
      var id = context.index++,
4108
          name = 'body_' + id;
4109
      context.bodies[id] = compileParts(context, node);
4110
      return name;
4111
    },
4112
 
4113
    buffer: function(context, node) {
4114
      return '.w(' + escape(node[1]) + ')';
4115
    },
4116
 
4117
    format: function(context, node) {
4118
      return '.w(' + escape(node[1]) + ')';
4119
    },
4120
 
4121
    reference: function(context, node) {
4122
      return '.f(' + compiler.compileNode(context, node[1]) +
4123
        ',ctx,' + compiler.compileNode(context, node[2]) + ')';
4124
    },
4125
 
4126
    '#': function(context, node) {
4127
      return compileSection(context, node, 'section');
4128
    },
4129
 
4130
    '?': function(context, node) {
4131
      return compileSection(context, node, 'exists');
4132
    },
4133
 
4134
    '^': function(context, node) {
4135
      return compileSection(context, node, 'notexists');
4136
    },
4137
 
4138
    '<': function(context, node) {
4139
      var bodies = node[4];
4140
      for (var i=1, len=bodies.length; i<len; i++) {
4141
        var param = bodies[i],
4142
            type = param[1][1];
4143
        if (type === 'block') {
4144
          context.blocks[node[1].text] = compiler.compileNode(context, param[2]);
4145
          return '';
4146
        }
4147
      }
4148
      return '';
4149
    },
4150
 
4151
    '+': function(context, node) {
4152
      if (typeof(node[1].text) === 'undefined'  && typeof(node[4]) === 'undefined'){
4153
        return '.b(ctx.getBlock(' +
4154
              compiler.compileNode(context, node[1]) +
4155
              ',chk, ctx),' + compiler.compileNode(context, node[2]) + ', {},' +
4156
              compiler.compileNode(context, node[3]) +
4157
              ')';
4158
      } else {
4159
        return '.b(ctx.getBlock(' +
4160
            escape(node[1].text) +
4161
            '),' + compiler.compileNode(context, node[2]) + ',' +
4162
            compiler.compileNode(context, node[4]) + ',' +
4163
            compiler.compileNode(context, node[3]) +
4164
            ')';
4165
      }
4166
    },
4167
 
4168
    '@': function(context, node) {
4169
      return '.h(' +
4170
        escape(node[1].text) +
4171
        ',' + compiler.compileNode(context, node[2]) + ',' +
4172
        compiler.compileNode(context, node[4]) + ',' +
4173
        compiler.compileNode(context, node[3]) + ',' +
4174
        compiler.compileNode(context, node[5]) +
4175
        ')';
4176
    },
4177
 
4178
    '%': function(context, node) {
4179
      // TODO: Move these hacks into pragma precompiler
4180
      var name = node[1][1],
4181
          rawBodies,
4182
          bodies,
4183
          rawParams,
4184
          params,
4185
          ctx, b, p, i, len;
4186
      if (!compiler.pragmas[name]) {
4187
        return '';
4188
      }
4189
 
4190
      rawBodies = node[4];
4191
      bodies = {};
4192
      for (i=1, len=rawBodies.length; i<len; i++) {
4193
        b = rawBodies[i];
4194
        bodies[b[1][1]] = b[2];
4195
      }
4196
 
4197
      rawParams = node[3];
4198
      params = {};
4199
      for (i=1, len=rawParams.length; i<len; i++) {
4200
        p = rawParams[i];
4201
        params[p[1][1]] = p[2][1];
4202
      }
4203
 
4204
      ctx = node[2][1] ? node[2][1].text : null;
4205
 
4206
      return compiler.pragmas[name](context, ctx, bodies, params);
4207
    },
4208
 
4209
    partial: function(context, node) {
4210
      return '.p(' +
4211
          compiler.compileNode(context, node[1]) +
4212
          ',ctx,' + compiler.compileNode(context, node[2]) +
4213
          ',' + compiler.compileNode(context, node[3]) + ')';
4214
    },
4215
 
4216
    context: function(context, node) {
4217
      if (node[1]) {
4218
        return 'ctx.rebase(' + compiler.compileNode(context, node[1]) + ')';
4219
      }
4220
      return 'ctx';
4221
    },
4222
 
4223
    params: function(context, node) {
4224
      var out = [];
4225
      for (var i=1, len=node.length; i<len; i++) {
4226
        out.push(compiler.compileNode(context, node[i]));
4227
      }
4228
      if (out.length) {
4229
        return '{' + out.join(',') + '}';
4230
      }
4231
      return '{}';
4232
    },
4233
 
4234
    bodies: function(context, node) {
4235
      var out = [];
4236
      for (var i=1, len=node.length; i<len; i++) {
4237
        out.push(compiler.compileNode(context, node[i]));
4238
      }
4239
      return '{' + out.join(',') + '}';
4240
    },
4241
 
4242
    param: function(context, node) {
4243
      return compiler.compileNode(context, node[1]) + ':' + compiler.compileNode(context, node[2]);
4244
    },
4245
 
4246
    filters: function(context, node) {
4247
      var list = [];
4248
      for (var i=1, len=node.length; i<len; i++) {
4249
        var filter = node[i];
4250
        list.push('"' + filter + '"');
4251
      }
4252
      return '"' + context.auto + '"' +
4253
        (list.length ? ',[' + list.join(',') + ']' : '');
4254
    },
4255
 
4256
    key: function(context, node) {
4257
      return 'ctx.get(["' + node[1] + '"], false)';
4258
    },
4259
 
4260
    path: function(context, node) {
4261
      var current = node[1],
4262
          keys = node[2],
4263
          list = [];
4264
 
4265
      for (var i=0,len=keys.length; i<len; i++) {
4266
        if (isArray(keys[i])) {
4267
          list.push(compiler.compileNode(context, keys[i]));
4268
        } else {
4269
          list.push('"' + keys[i] + '"');
4270
        }
4271
      }
4272
      return 'ctx.getPath(' + current + ', [' + list.join(',') + '])';
4273
    },
4274
 
4275
    literal: function(context, node) {
4276
      return escape(node[1]);
4277
    },
4278
    raw: function(context, node) {
4279
      return ".w(" + escape(node[1]) + ")";
4280
    }
4281
  };
4282
 
4283
  function compileSection(context, node, cmd) {
4284
    return '.' + (dust._aliases[cmd] || cmd) + '(' +
4285
      compiler.compileNode(context, node[1]) +
4286
      ',' + compiler.compileNode(context, node[2]) + ',' +
4287
      compiler.compileNode(context, node[4]) + ',' +
4288
      compiler.compileNode(context, node[3]) +
4289
      ')';
4290
  }
4291
 
4292
  var BS = /\\/g,
4293
      DQ = /"/g,
4294
      LF = /\f/g,
4295
      NL = /\n/g,
4296
      CR = /\r/g,
4297
      TB = /\t/g;
4298
  function escapeToJsSafeString(str) {
4299
    return str.replace(BS, '\\\\')
4300
              .replace(DQ, '\\"')
4301
              .replace(LF, '\\f')
4302
              .replace(NL, '\\n')
4303
              .replace(CR, '\\r')
4304
              .replace(TB, '\\t');
4305
  }
4306
 
4307
  var escape = (typeof JSON === 'undefined') ?
4308
                  function(str) { return '"' + escapeToJsSafeString(str) + '"';} :
4309
                  JSON.stringify;
4310
 
4311
  function renderSource(source, context, callback) {
4312
    var tmpl = dust.loadSource(dust.compile(source));
4313
    return loaderFor(tmpl)(context, callback);
4314
  }
4315
 
4316
  function compileFn(source, name) {
4317
    var tmpl = dust.loadSource(dust.compile(source, name));
4318
    return loaderFor(tmpl);
4319
  }
4320
 
4321
  function loaderFor(tmpl) {
4322
    return function load(ctx, cb) {
4323
      var fn = cb ? 'render' : 'stream';
4324
      return dust[fn](tmpl, ctx, cb);
4325
    };
4326
  }
4327
 
4328
  // expose compiler methods
4329
  dust.compiler = compiler;
4330
  dust.compile = dust.compiler.compile;
4331
  dust.renderSource = renderSource;
4332
  dust.compileFn = compileFn;
4333
 
4334
  // DEPRECATED legacy names. Removed in 2.8.0
4335
  dust.filterNode = compiler.filterNode;
4336
  dust.optimizers = compiler.optimizers;
4337
  dust.pragmas = compiler.pragmas;
4338
  dust.compileNode = compiler.compileNode;
4339
  dust.nodes = compiler.nodes;
4340
 
4341
  return compiler;
4342
 
4343
}));
4344
 
4345
if (typeof define === "function" && define.amd && define.amd.dust === true) {
4346
    define(["require", "dust.core", "dust.compile"], function(require, dust) {
4347
        dust.onLoad = function(name, cb) {
4348
            require([name], function() {
4349
                cb();
4350
            });
4351
        };
4352
        return dust;
4353
    });
4354
}