UNPKG

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