@capillarytech/creatives-library 8.0.136-alpha.0 → 8.0.136-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/utils/jed.js ADDED
@@ -0,0 +1,1497 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * @preserve jed.js https://github.com/SlexAxton/Jed
4
+ */
5
+ /*
6
+ -----------
7
+ A gettext compatible i18n library for modern JavaScript Applications
8
+
9
+ by Alex Sexton - AlexSexton [at] gmail - @SlexAxton
10
+ WTFPL license for use
11
+ Dojo CLA for contributions
12
+
13
+ Jed offers the entire applicable GNU gettext spec'd set of
14
+ functions, but also offers some nicer wrappers around them.
15
+ The api for gettext was written for a language with no function
16
+ overloading, so Jed allows a little more of that.
17
+
18
+ Many thanks to Joshua I. Miller - unrtst@cpan.org - who wrote
19
+ gettext.js back in 2008. I was able to vet a lot of my ideas
20
+ against his. I also made sure Jed passed against his tests
21
+ in order to offer easy upgrades -- jsgettext.berlios.de
22
+ */
23
+ (function(root, undef) {
24
+
25
+ // Set up some underscore-style functions, if you already have
26
+ // underscore, feel free to delete this section, and use it
27
+ // directly, however, the amount of functions used doesn't
28
+ // warrant having underscore as a full dependency.
29
+ // Underscore 1.3.0 was used to port and is licensed
30
+ // under the MIT License by Jeremy Ashkenas.
31
+ var ArrayProto = Array.prototype,
32
+ ObjProto = Object.prototype,
33
+ slice = ArrayProto.slice,
34
+ hasOwnProp = ObjProto.hasOwnProperty,
35
+ nativeForEach = ArrayProto.forEach,
36
+ breaker = {};
37
+
38
+ // We're not using the OOP style _ so we don't need the
39
+ // extra level of indirection. This still means that you
40
+ // sub out for real `_` though.
41
+ var _ = {
42
+ forEach: function(obj, iterator, context) {
43
+ var i, l, key;
44
+ if (obj === null) {
45
+ return;
46
+ }
47
+
48
+ if (nativeForEach && obj.forEach === nativeForEach) {
49
+ obj.forEach(iterator, context);
50
+ } else if (obj.length === +obj.length) {
51
+ for (i = 0, l = obj.length; i < l; i++) {
52
+ if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) {
53
+ return;
54
+ }
55
+ }
56
+ } else {
57
+ for (key in obj) {
58
+ if (hasOwnProp.call(obj, key)) {
59
+ if (iterator.call(context, obj[key], key, obj) === breaker) {
60
+ return;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ },
66
+ extend: function(obj) {
67
+ this.forEach(slice.call(arguments, 1), function(source) {
68
+ for (var prop in source) {
69
+ obj[prop] = source[prop];
70
+ }
71
+ });
72
+ return obj;
73
+ }
74
+ };
75
+ // END Miniature underscore impl
76
+
77
+ // Jed is a constructor function
78
+ var Jed = function(options) {
79
+ // Some minimal defaults
80
+ this.defaults = {
81
+ "locale_data": {
82
+ "messages": {
83
+ "": {
84
+ "domain": "messages",
85
+ "lang": "en",
86
+ "plural_forms": "nplurals=2; plural=(n != 1);"
87
+ }
88
+ // There are no default keys, though
89
+ }
90
+ },
91
+ // The default domain if one is missing
92
+ "domain": "messages",
93
+ // enable debug mode to log untranslated strings to the console
94
+ "debug": false
95
+ };
96
+
97
+ // Mix in the sent options with the default options
98
+ this.options = _.extend({}, this.defaults, options);
99
+ this.textdomain(this.options.domain);
100
+
101
+ if (options.domain && !this.options.locale_data[this.options.domain]) {
102
+ throw new Error('Text domain set to non-existent domain: `' + options.domain + '`');
103
+ }
104
+ };
105
+
106
+ // The gettext spec sets this character as the default
107
+ // delimiter for context lookups.
108
+ // e.g.: context\u0004key
109
+ // If your translation company uses something different,
110
+ // just change this at any time and it will use that instead.
111
+ Jed.context_delimiter = String.fromCharCode(4);
112
+
113
+ function getPluralFormFunc(plural_form_string) {
114
+ return Jed.PF.compile(plural_form_string || "nplurals=2; plural=(n != 1);");
115
+ }
116
+
117
+ function Chain(key, i18n) {
118
+ this._key = key;
119
+ this._i18n = i18n;
120
+ }
121
+
122
+ // Create a chainable api for adding args prettily
123
+ _.extend(Chain.prototype, {
124
+ onDomain: function(domain) {
125
+ this._domain = domain;
126
+ return this;
127
+ },
128
+ withContext: function(context) {
129
+ this._context = context;
130
+ return this;
131
+ },
132
+ ifPlural: function(num, pkey) {
133
+ this._val = num;
134
+ this._pkey = pkey;
135
+ return this;
136
+ },
137
+ fetch: function(sArr) {
138
+ if ({}.toString.call(sArr) != '[object Array]') {
139
+ sArr = [].slice.call(arguments, 0);
140
+ }
141
+ return (sArr && sArr.length ? Jed.sprintf : function(x) {
142
+ return x;
143
+ })(
144
+ this._i18n.dcnpgettext(this._domain, this._context, this._key, this._pkey, this._val),
145
+ sArr
146
+ );
147
+ }
148
+ });
149
+
150
+ // Add functions to the Jed prototype.
151
+ // These will be the functions on the object that's returned
152
+ // from creating a `new Jed()`
153
+ // These seem redundant, but they gzip pretty well.
154
+ _.extend(Jed.prototype, {
155
+ // The sexier api start point
156
+ translate: function(key) {
157
+ return new Chain(key, this);
158
+ },
159
+
160
+ textdomain: function(domain) {
161
+ if (!domain) {
162
+ return this._textdomain;
163
+ }
164
+ this._textdomain = domain;
165
+ },
166
+
167
+ gettext: function(key) {
168
+ return this.dcnpgettext.call(this, undef, undef, key, null, 0);
169
+ },
170
+
171
+ dgettext: function(domain, key) {
172
+ return this.dcnpgettext.call(this, domain, undef, key, null, 0);
173
+ },
174
+
175
+ dcgettext: function(domain, key /*, category */ ) {
176
+ // Ignores the category anyways
177
+ return this.dcnpgettext.call(this, domain, undef, key);
178
+ },
179
+
180
+ ngettext: function(skey, pkey, val) {
181
+ return this.dcnpgettext.call(this, undef, undef, skey, pkey, val);
182
+ },
183
+
184
+ dngettext: function(domain, skey, pkey, val) {
185
+ return this.dcnpgettext.call(this, domain, undef, skey, pkey, val);
186
+ },
187
+
188
+ dcngettext: function(domain, skey, pkey, val /*, category */ ) {
189
+ return this.dcnpgettext.call(this, domain, undef, skey, pkey, val);
190
+ },
191
+
192
+ pgettext: function(context, key) {
193
+ return this.dcnpgettext.call(this, undef, context, key);
194
+ },
195
+
196
+ dpgettext: function(domain, context, key) {
197
+ return this.dcnpgettext.call(this, domain, context, key);
198
+ },
199
+
200
+ dcpgettext: function(domain, context, key /*, category */ ) {
201
+ return this.dcnpgettext.call(this, domain, context, key);
202
+ },
203
+
204
+ npgettext: function(context, skey, pkey, val) {
205
+ return this.dcnpgettext.call(this, undef, context, skey, pkey, val);
206
+ },
207
+
208
+ dnpgettext: function(domain, context, skey, pkey, val) {
209
+ return this.dcnpgettext.call(this, domain, context, skey, pkey, val);
210
+ },
211
+
212
+ // The most fully qualified gettext function. It has every option.
213
+ // Since it has every option, we can use it from every other method.
214
+ // This is the bread and butter.
215
+ // Technically there should be one more argument in this function for 'Category',
216
+ // but since we never use it, we might as well not waste the bytes to define it.
217
+ dcnpgettext: function(domain, context, singular_key, plural_key, val) {
218
+ // Set some defaults
219
+
220
+ plural_key = plural_key || singular_key;
221
+
222
+ // Use the global domain default if one
223
+ // isn't explicitly passed in
224
+ domain = domain || this._textdomain;
225
+
226
+ var fallback;
227
+
228
+ // Handle special cases
229
+
230
+ // No options found
231
+ if (!this.options) {
232
+ // There's likely something wrong, but we'll return the correct key for english
233
+ // We do this by instantiating a brand new Jed instance with the default set
234
+ // for everything that could be broken.
235
+ fallback = new Jed();
236
+ return fallback.dcnpgettext.call(fallback, undefined, undefined, singular_key, plural_key, val);
237
+ }
238
+
239
+ // No translation data provided
240
+ if (!this.options.locale_data) {
241
+ throw new Error('No locale data provided.');
242
+ }
243
+
244
+ if (!this.options.locale_data[domain]) {
245
+ throw new Error('Domain `' + domain + '` was not found.');
246
+ }
247
+
248
+ if (!this.options.locale_data[domain][""]) {
249
+ throw new Error('No locale meta information provided.');
250
+ }
251
+
252
+ // Make sure we have a truthy key. Otherwise we might start looking
253
+ // into the empty string key, which is the options for the locale
254
+ // data.
255
+ if (!singular_key) {
256
+ throw new Error('No translation key found.');
257
+ }
258
+
259
+ var key = context ? context + Jed.context_delimiter + singular_key : singular_key,
260
+ locale_data = this.options.locale_data,
261
+ dict = locale_data[domain],
262
+ defaultConf = (locale_data.messages || this.defaults.locale_data.messages)[""],
263
+ pluralForms = dict[""].plural_forms || dict[""]["Plural-Forms"] || dict[""]["plural-forms"] || defaultConf.plural_forms || defaultConf["Plural-Forms"] || defaultConf["plural-forms"],
264
+ val_list,
265
+ res;
266
+
267
+ var val_idx;
268
+ if (val === undefined) {
269
+ // No value passed in; assume singular key lookup.
270
+ val_idx = 0;
271
+
272
+ } else {
273
+ // Value has been passed in; use plural-forms calculations.
274
+
275
+ // Handle invalid numbers, but try casting strings for good measure
276
+ if (typeof val != 'number') {
277
+ val = parseInt(val, 10);
278
+
279
+ if (isNaN(val)) {
280
+ throw new Error('The number that was passed in is not a number.');
281
+ }
282
+ }
283
+
284
+ val_idx = getPluralFormFunc(pluralForms)(val);
285
+ }
286
+
287
+ // Throw an error if a domain isn't found
288
+ if (!dict) {
289
+ throw new Error('No domain named `' + domain + '` could be found.');
290
+ }
291
+
292
+ val_list = dict[key];
293
+
294
+ // If there is no match, then revert back to
295
+ // english style singular/plural with the keys passed in.
296
+ if (!val_list || val_idx > val_list.length) {
297
+ if (this.options.missing_key_callback) {
298
+ this.options.missing_key_callback(key, domain);
299
+ }
300
+ res = [singular_key, plural_key];
301
+
302
+ // collect untranslated strings
303
+ if (this.options.debug === true) {
304
+ console.log(res[getPluralFormFunc(pluralForms)(val)]);
305
+ }
306
+ return res[getPluralFormFunc()(val)];
307
+ }
308
+
309
+ res = val_list[val_idx];
310
+
311
+ // This includes empty strings on purpose
312
+ if (!res) {
313
+ res = [singular_key, plural_key];
314
+ return res[getPluralFormFunc()(val)];
315
+ }
316
+ return res;
317
+ }
318
+ });
319
+
320
+
321
+ // We add in sprintf capabilities for post translation value interolation
322
+ // This is not internally used, so you can remove it if you have this
323
+ // available somewhere else, or want to use a different system.
324
+
325
+ // We _slightly_ modify the normal sprintf behavior to more gracefully handle
326
+ // undefined values.
327
+
328
+ /**
329
+ sprintf() for JavaScript 0.7-beta1
330
+ http://www.diveintojavascript.com/projects/javascript-sprintf
331
+
332
+ Copyright (c) Alexandru Marasteanu <alexaholic [at) gmail (dot] com>
333
+ All rights reserved.
334
+
335
+ Redistribution and use in source and binary forms, with or without
336
+ modification, are permitted provided that the following conditions are met:
337
+ * Redistributions of source code must retain the above copyright
338
+ notice, this list of conditions and the following disclaimer.
339
+ * Redistributions in binary form must reproduce the above copyright
340
+ notice, this list of conditions and the following disclaimer in the
341
+ documentation and/or other materials provided with the distribution.
342
+ * Neither the name of sprintf() for JavaScript nor the
343
+ names of its contributors may be used to endorse or promote products
344
+ derived from this software without specific prior written permission.
345
+
346
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
347
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
348
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
349
+ DISCLAIMED. IN NO EVENT SHALL Alexandru Marasteanu BE LIABLE FOR ANY
350
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
351
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
352
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
353
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
354
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
355
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
356
+ */
357
+ var sprintf = (function() {
358
+ function get_type(variable) {
359
+ return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase();
360
+ }
361
+
362
+ function str_repeat(input, multiplier) {
363
+ for (var output = []; multiplier > 0; output[--multiplier] = input) { /* do nothing */ }
364
+ return output.join('');
365
+ }
366
+
367
+ var str_format = function() {
368
+ if (!str_format.cache.hasOwnProperty(arguments[0])) {
369
+ str_format.cache[arguments[0]] = str_format.parse(arguments[0]);
370
+ }
371
+ return str_format.format.call(null, str_format.cache[arguments[0]], arguments);
372
+ };
373
+
374
+ str_format.format = function(parse_tree, argv) {
375
+ var cursor = 1,
376
+ tree_length = parse_tree.length,
377
+ node_type = '',
378
+ arg, output = [],
379
+ i, k, match, pad, pad_character, pad_length;
380
+ for (i = 0; i < tree_length; i++) {
381
+ node_type = get_type(parse_tree[i]);
382
+ if (node_type === 'string') {
383
+ output.push(parse_tree[i]);
384
+ } else if (node_type === 'array') {
385
+ match = parse_tree[i]; // convenience purposes only
386
+ if (match[2]) { // keyword argument
387
+ arg = argv[cursor];
388
+ for (k = 0; k < match[2].length; k++) {
389
+ if (!arg.hasOwnProperty(match[2][k])) {
390
+ throw (sprintf('[sprintf] property "%s" does not exist', match[2][k]));
391
+ }
392
+ arg = arg[match[2][k]];
393
+ }
394
+ } else if (match[1]) { // positional argument (explicit)
395
+ arg = argv[match[1]];
396
+ } else { // positional argument (implicit)
397
+ arg = argv[cursor++];
398
+ }
399
+
400
+ if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) {
401
+ throw (sprintf('[sprintf] expecting number but found %s', get_type(arg)));
402
+ }
403
+
404
+ // Jed EDIT
405
+ if (typeof arg == 'undefined' || arg === null) {
406
+ arg = '';
407
+ }
408
+ // Jed EDIT
409
+
410
+ switch (match[8]) {
411
+ case 'b':
412
+ arg = arg.toString(2);
413
+ break;
414
+ case 'c':
415
+ arg = String.fromCharCode(arg);
416
+ break;
417
+ case 'd':
418
+ arg = parseInt(arg, 10);
419
+ break;
420
+ case 'e':
421
+ arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential();
422
+ break;
423
+ case 'f':
424
+ arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg);
425
+ break;
426
+ case 'o':
427
+ arg = arg.toString(8);
428
+ break;
429
+ case 's':
430
+ arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg);
431
+ break;
432
+ case 'u':
433
+ arg = Math.abs(arg);
434
+ break;
435
+ case 'x':
436
+ arg = arg.toString(16);
437
+ break;
438
+ case 'X':
439
+ arg = arg.toString(16).toUpperCase();
440
+ break;
441
+ }
442
+ arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+' + arg : arg);
443
+ pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' ';
444
+ pad_length = match[6] - String(arg).length;
445
+ pad = match[6] ? str_repeat(pad_character, pad_length) : '';
446
+ output.push(match[5] ? arg + pad : pad + arg);
447
+ }
448
+ }
449
+ return output.join('');
450
+ };
451
+
452
+ str_format.cache = {};
453
+
454
+ str_format.parse = function(fmt) {
455
+ var _fmt = fmt,
456
+ match = [],
457
+ parse_tree = [],
458
+ arg_names = 0;
459
+ while (_fmt) {
460
+ if ((match = /^[^\x25]+/.exec(_fmt)) !== null) {
461
+ parse_tree.push(match[0]);
462
+ } else if ((match = /^\x25{2}/.exec(_fmt)) !== null) {
463
+ parse_tree.push('%');
464
+ } else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) {
465
+ if (match[2]) {
466
+ arg_names |= 1;
467
+ var field_list = [],
468
+ replacement_field = match[2],
469
+ field_match = [];
470
+ if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
471
+ field_list.push(field_match[1]);
472
+ while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
473
+ if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
474
+ field_list.push(field_match[1]);
475
+ } else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) {
476
+ field_list.push(field_match[1]);
477
+ } else {
478
+ throw ('[sprintf] huh?');
479
+ }
480
+ }
481
+ } else {
482
+ throw ('[sprintf] huh?');
483
+ }
484
+ match[2] = field_list;
485
+ } else {
486
+ arg_names |= 2;
487
+ }
488
+ if (arg_names === 3) {
489
+ throw ('[sprintf] mixing positional and named placeholders is not (yet) supported');
490
+ }
491
+ parse_tree.push(match);
492
+ } else {
493
+ throw ('[sprintf] huh?');
494
+ }
495
+ _fmt = _fmt.substring(match[0].length);
496
+ }
497
+ return parse_tree;
498
+ };
499
+
500
+ return str_format;
501
+ })();
502
+
503
+ var vsprintf = function(fmt, argv) {
504
+ argv.unshift(fmt);
505
+ return sprintf.apply(null, argv);
506
+ };
507
+
508
+ Jed.parse_plural = function(plural_forms, n) {
509
+ plural_forms = plural_forms.replace(/n/g, n);
510
+ return Jed.parse_expression(plural_forms);
511
+ };
512
+
513
+ Jed.sprintf = function(fmt, args) {
514
+ if ({}.toString.call(args) == '[object Array]') {
515
+ return vsprintf(fmt, [].slice.call(args));
516
+ }
517
+ return sprintf.apply(this, [].slice.call(arguments));
518
+ };
519
+
520
+ Jed.prototype.sprintf = function() {
521
+ return Jed.sprintf.apply(this, arguments);
522
+ };
523
+ // END sprintf Implementation
524
+
525
+ // Start the Plural forms section
526
+ // This is a full plural form expression parser. It is used to avoid
527
+ // running 'eval' or 'new Function' directly against the plural
528
+ // forms.
529
+ //
530
+ // This can be important if you get translations done through a 3rd
531
+ // party vendor. I encourage you to use this instead, however, I
532
+ // also will provide a 'precompiler' that you can use at build time
533
+ // to output valid/safe function representations of the plural form
534
+ // expressions. This means you can build this code out for the most
535
+ // part.
536
+ Jed.PF = {};
537
+
538
+ Jed.PF.parse = function(p) {
539
+ var plural_str = Jed.PF.extractPluralExpr(p);
540
+ return Jed.PF.parser.parse.call(Jed.PF.parser, plural_str);
541
+ };
542
+
543
+ Jed.PF.compile = function(p) {
544
+ // Handle trues and falses as 0 and 1
545
+ function imply(val) {
546
+ return (val === true ? 1 : val ? val : 0);
547
+ }
548
+
549
+ var ast = Jed.PF.parse(p);
550
+ return function(n) {
551
+ return imply(Jed.PF.interpreter(ast)(n));
552
+ };
553
+ };
554
+
555
+ Jed.PF.interpreter = function(ast) {
556
+ return function(n) {
557
+ var res;
558
+ switch (ast.type) {
559
+ case 'GROUP':
560
+ return Jed.PF.interpreter(ast.expr)(n);
561
+ case 'TERNARY':
562
+ if (Jed.PF.interpreter(ast.expr)(n)) {
563
+ return Jed.PF.interpreter(ast.truthy)(n);
564
+ }
565
+ return Jed.PF.interpreter(ast.falsey)(n);
566
+ case 'OR':
567
+ return Jed.PF.interpreter(ast.left)(n) || Jed.PF.interpreter(ast.right)(n);
568
+ case 'AND':
569
+ return Jed.PF.interpreter(ast.left)(n) && Jed.PF.interpreter(ast.right)(n);
570
+ case 'LT':
571
+ return Jed.PF.interpreter(ast.left)(n) < Jed.PF.interpreter(ast.right)(n);
572
+ case 'GT':
573
+ return Jed.PF.interpreter(ast.left)(n) > Jed.PF.interpreter(ast.right)(n);
574
+ case 'LTE':
575
+ return Jed.PF.interpreter(ast.left)(n) <= Jed.PF.interpreter(ast.right)(n);
576
+ case 'GTE':
577
+ return Jed.PF.interpreter(ast.left)(n) >= Jed.PF.interpreter(ast.right)(n);
578
+ case 'EQ':
579
+ return Jed.PF.interpreter(ast.left)(n) == Jed.PF.interpreter(ast.right)(n);
580
+ case 'NEQ':
581
+ return Jed.PF.interpreter(ast.left)(n) != Jed.PF.interpreter(ast.right)(n);
582
+ case 'MOD':
583
+ return Jed.PF.interpreter(ast.left)(n) % Jed.PF.interpreter(ast.right)(n);
584
+ case 'VAR':
585
+ return n;
586
+ case 'NUM':
587
+ return ast.val;
588
+ default:
589
+ throw new Error("Invalid Token found.");
590
+ }
591
+ };
592
+ };
593
+
594
+ Jed.PF.extractPluralExpr = function(p) {
595
+ // trim first
596
+ p = p.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
597
+
598
+ if (!/;\s*$/.test(p)) {
599
+ p = p.concat(';');
600
+ }
601
+
602
+ var nplurals_re = /nplurals\=(\d+);/,
603
+ plural_re = /plural\=(.*);/,
604
+ nplurals_matches = p.match(nplurals_re),
605
+ res = {},
606
+ plural_matches;
607
+
608
+ // Find the nplurals number
609
+ if (nplurals_matches.length > 1) {
610
+ res.nplurals = nplurals_matches[1];
611
+ } else {
612
+ throw new Error('nplurals not found in plural_forms string: ' + p);
613
+ }
614
+
615
+ // remove that data to get to the formula
616
+ p = p.replace(nplurals_re, "");
617
+ plural_matches = p.match(plural_re);
618
+
619
+ if (!(plural_matches && plural_matches.length > 1)) {
620
+ throw new Error('`plural` expression not found: ' + p);
621
+ }
622
+ return plural_matches[1];
623
+ };
624
+
625
+ /* Jison generated parser */
626
+ Jed.PF.parser = (function() {
627
+
628
+ var parser = {
629
+ trace: function trace() {},
630
+ yy: {},
631
+ symbols_: {
632
+ "error": 2,
633
+ "expressions": 3,
634
+ "e": 4,
635
+ "EOF": 5,
636
+ "?": 6,
637
+ ":": 7,
638
+ "||": 8,
639
+ "&&": 9,
640
+ "<": 10,
641
+ "<=": 11,
642
+ ">": 12,
643
+ ">=": 13,
644
+ "!=": 14,
645
+ "==": 15,
646
+ "%": 16,
647
+ "(": 17,
648
+ ")": 18,
649
+ "n": 19,
650
+ "NUMBER": 20,
651
+ "$accept": 0,
652
+ "$end": 1
653
+ },
654
+ terminals_: {
655
+ 2: "error",
656
+ 5: "EOF",
657
+ 6: "?",
658
+ 7: ":",
659
+ 8: "||",
660
+ 9: "&&",
661
+ 10: "<",
662
+ 11: "<=",
663
+ 12: ">",
664
+ 13: ">=",
665
+ 14: "!=",
666
+ 15: "==",
667
+ 16: "%",
668
+ 17: "(",
669
+ 18: ")",
670
+ 19: "n",
671
+ 20: "NUMBER"
672
+ },
673
+ productions_: [0, [3, 2],
674
+ [4, 5],
675
+ [4, 3],
676
+ [4, 3],
677
+ [4, 3],
678
+ [4, 3],
679
+ [4, 3],
680
+ [4, 3],
681
+ [4, 3],
682
+ [4, 3],
683
+ [4, 3],
684
+ [4, 3],
685
+ [4, 1],
686
+ [4, 1]
687
+ ],
688
+ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) {
689
+
690
+ var $0 = $$.length - 1;
691
+ switch (yystate) {
692
+ case 1:
693
+ return {
694
+ type: 'GROUP',
695
+ expr: $$[$0 - 1]
696
+ };
697
+ break;
698
+ case 2:
699
+ this.$ = {
700
+ type: 'TERNARY',
701
+ expr: $$[$0 - 4],
702
+ truthy: $$[$0 - 2],
703
+ falsey: $$[$0]
704
+ };
705
+ break;
706
+ case 3:
707
+ this.$ = {
708
+ type: "OR",
709
+ left: $$[$0 - 2],
710
+ right: $$[$0]
711
+ };
712
+ break;
713
+ case 4:
714
+ this.$ = {
715
+ type: "AND",
716
+ left: $$[$0 - 2],
717
+ right: $$[$0]
718
+ };
719
+ break;
720
+ case 5:
721
+ this.$ = {
722
+ type: 'LT',
723
+ left: $$[$0 - 2],
724
+ right: $$[$0]
725
+ };
726
+ break;
727
+ case 6:
728
+ this.$ = {
729
+ type: 'LTE',
730
+ left: $$[$0 - 2],
731
+ right: $$[$0]
732
+ };
733
+ break;
734
+ case 7:
735
+ this.$ = {
736
+ type: 'GT',
737
+ left: $$[$0 - 2],
738
+ right: $$[$0]
739
+ };
740
+ break;
741
+ case 8:
742
+ this.$ = {
743
+ type: 'GTE',
744
+ left: $$[$0 - 2],
745
+ right: $$[$0]
746
+ };
747
+ break;
748
+ case 9:
749
+ this.$ = {
750
+ type: 'NEQ',
751
+ left: $$[$0 - 2],
752
+ right: $$[$0]
753
+ };
754
+ break;
755
+ case 10:
756
+ this.$ = {
757
+ type: 'EQ',
758
+ left: $$[$0 - 2],
759
+ right: $$[$0]
760
+ };
761
+ break;
762
+ case 11:
763
+ this.$ = {
764
+ type: 'MOD',
765
+ left: $$[$0 - 2],
766
+ right: $$[$0]
767
+ };
768
+ break;
769
+ case 12:
770
+ this.$ = {
771
+ type: 'GROUP',
772
+ expr: $$[$0 - 1]
773
+ };
774
+ break;
775
+ case 13:
776
+ this.$ = {
777
+ type: 'VAR'
778
+ };
779
+ break;
780
+ case 14:
781
+ this.$ = {
782
+ type: 'NUM',
783
+ val: Number(yytext)
784
+ };
785
+ break;
786
+ }
787
+ },
788
+ table: [{
789
+ 3: 1,
790
+ 4: 2,
791
+ 17: [1, 3],
792
+ 19: [1, 4],
793
+ 20: [1, 5]
794
+ }, {
795
+ 1: [3]
796
+ }, {
797
+ 5: [1, 6],
798
+ 6: [1, 7],
799
+ 8: [1, 8],
800
+ 9: [1, 9],
801
+ 10: [1, 10],
802
+ 11: [1, 11],
803
+ 12: [1, 12],
804
+ 13: [1, 13],
805
+ 14: [1, 14],
806
+ 15: [1, 15],
807
+ 16: [1, 16]
808
+ }, {
809
+ 4: 17,
810
+ 17: [1, 3],
811
+ 19: [1, 4],
812
+ 20: [1, 5]
813
+ }, {
814
+ 5: [2, 13],
815
+ 6: [2, 13],
816
+ 7: [2, 13],
817
+ 8: [2, 13],
818
+ 9: [2, 13],
819
+ 10: [2, 13],
820
+ 11: [2, 13],
821
+ 12: [2, 13],
822
+ 13: [2, 13],
823
+ 14: [2, 13],
824
+ 15: [2, 13],
825
+ 16: [2, 13],
826
+ 18: [2, 13]
827
+ }, {
828
+ 5: [2, 14],
829
+ 6: [2, 14],
830
+ 7: [2, 14],
831
+ 8: [2, 14],
832
+ 9: [2, 14],
833
+ 10: [2, 14],
834
+ 11: [2, 14],
835
+ 12: [2, 14],
836
+ 13: [2, 14],
837
+ 14: [2, 14],
838
+ 15: [2, 14],
839
+ 16: [2, 14],
840
+ 18: [2, 14]
841
+ }, {
842
+ 1: [2, 1]
843
+ }, {
844
+ 4: 18,
845
+ 17: [1, 3],
846
+ 19: [1, 4],
847
+ 20: [1, 5]
848
+ }, {
849
+ 4: 19,
850
+ 17: [1, 3],
851
+ 19: [1, 4],
852
+ 20: [1, 5]
853
+ }, {
854
+ 4: 20,
855
+ 17: [1, 3],
856
+ 19: [1, 4],
857
+ 20: [1, 5]
858
+ }, {
859
+ 4: 21,
860
+ 17: [1, 3],
861
+ 19: [1, 4],
862
+ 20: [1, 5]
863
+ }, {
864
+ 4: 22,
865
+ 17: [1, 3],
866
+ 19: [1, 4],
867
+ 20: [1, 5]
868
+ }, {
869
+ 4: 23,
870
+ 17: [1, 3],
871
+ 19: [1, 4],
872
+ 20: [1, 5]
873
+ }, {
874
+ 4: 24,
875
+ 17: [1, 3],
876
+ 19: [1, 4],
877
+ 20: [1, 5]
878
+ }, {
879
+ 4: 25,
880
+ 17: [1, 3],
881
+ 19: [1, 4],
882
+ 20: [1, 5]
883
+ }, {
884
+ 4: 26,
885
+ 17: [1, 3],
886
+ 19: [1, 4],
887
+ 20: [1, 5]
888
+ }, {
889
+ 4: 27,
890
+ 17: [1, 3],
891
+ 19: [1, 4],
892
+ 20: [1, 5]
893
+ }, {
894
+ 6: [1, 7],
895
+ 8: [1, 8],
896
+ 9: [1, 9],
897
+ 10: [1, 10],
898
+ 11: [1, 11],
899
+ 12: [1, 12],
900
+ 13: [1, 13],
901
+ 14: [1, 14],
902
+ 15: [1, 15],
903
+ 16: [1, 16],
904
+ 18: [1, 28]
905
+ }, {
906
+ 6: [1, 7],
907
+ 7: [1, 29],
908
+ 8: [1, 8],
909
+ 9: [1, 9],
910
+ 10: [1, 10],
911
+ 11: [1, 11],
912
+ 12: [1, 12],
913
+ 13: [1, 13],
914
+ 14: [1, 14],
915
+ 15: [1, 15],
916
+ 16: [1, 16]
917
+ }, {
918
+ 5: [2, 3],
919
+ 6: [2, 3],
920
+ 7: [2, 3],
921
+ 8: [2, 3],
922
+ 9: [1, 9],
923
+ 10: [1, 10],
924
+ 11: [1, 11],
925
+ 12: [1, 12],
926
+ 13: [1, 13],
927
+ 14: [1, 14],
928
+ 15: [1, 15],
929
+ 16: [1, 16],
930
+ 18: [2, 3]
931
+ }, {
932
+ 5: [2, 4],
933
+ 6: [2, 4],
934
+ 7: [2, 4],
935
+ 8: [2, 4],
936
+ 9: [2, 4],
937
+ 10: [1, 10],
938
+ 11: [1, 11],
939
+ 12: [1, 12],
940
+ 13: [1, 13],
941
+ 14: [1, 14],
942
+ 15: [1, 15],
943
+ 16: [1, 16],
944
+ 18: [2, 4]
945
+ }, {
946
+ 5: [2, 5],
947
+ 6: [2, 5],
948
+ 7: [2, 5],
949
+ 8: [2, 5],
950
+ 9: [2, 5],
951
+ 10: [2, 5],
952
+ 11: [2, 5],
953
+ 12: [2, 5],
954
+ 13: [2, 5],
955
+ 14: [2, 5],
956
+ 15: [2, 5],
957
+ 16: [1, 16],
958
+ 18: [2, 5]
959
+ }, {
960
+ 5: [2, 6],
961
+ 6: [2, 6],
962
+ 7: [2, 6],
963
+ 8: [2, 6],
964
+ 9: [2, 6],
965
+ 10: [2, 6],
966
+ 11: [2, 6],
967
+ 12: [2, 6],
968
+ 13: [2, 6],
969
+ 14: [2, 6],
970
+ 15: [2, 6],
971
+ 16: [1, 16],
972
+ 18: [2, 6]
973
+ }, {
974
+ 5: [2, 7],
975
+ 6: [2, 7],
976
+ 7: [2, 7],
977
+ 8: [2, 7],
978
+ 9: [2, 7],
979
+ 10: [2, 7],
980
+ 11: [2, 7],
981
+ 12: [2, 7],
982
+ 13: [2, 7],
983
+ 14: [2, 7],
984
+ 15: [2, 7],
985
+ 16: [1, 16],
986
+ 18: [2, 7]
987
+ }, {
988
+ 5: [2, 8],
989
+ 6: [2, 8],
990
+ 7: [2, 8],
991
+ 8: [2, 8],
992
+ 9: [2, 8],
993
+ 10: [2, 8],
994
+ 11: [2, 8],
995
+ 12: [2, 8],
996
+ 13: [2, 8],
997
+ 14: [2, 8],
998
+ 15: [2, 8],
999
+ 16: [1, 16],
1000
+ 18: [2, 8]
1001
+ }, {
1002
+ 5: [2, 9],
1003
+ 6: [2, 9],
1004
+ 7: [2, 9],
1005
+ 8: [2, 9],
1006
+ 9: [2, 9],
1007
+ 10: [2, 9],
1008
+ 11: [2, 9],
1009
+ 12: [2, 9],
1010
+ 13: [2, 9],
1011
+ 14: [2, 9],
1012
+ 15: [2, 9],
1013
+ 16: [1, 16],
1014
+ 18: [2, 9]
1015
+ }, {
1016
+ 5: [2, 10],
1017
+ 6: [2, 10],
1018
+ 7: [2, 10],
1019
+ 8: [2, 10],
1020
+ 9: [2, 10],
1021
+ 10: [2, 10],
1022
+ 11: [2, 10],
1023
+ 12: [2, 10],
1024
+ 13: [2, 10],
1025
+ 14: [2, 10],
1026
+ 15: [2, 10],
1027
+ 16: [1, 16],
1028
+ 18: [2, 10]
1029
+ }, {
1030
+ 5: [2, 11],
1031
+ 6: [2, 11],
1032
+ 7: [2, 11],
1033
+ 8: [2, 11],
1034
+ 9: [2, 11],
1035
+ 10: [2, 11],
1036
+ 11: [2, 11],
1037
+ 12: [2, 11],
1038
+ 13: [2, 11],
1039
+ 14: [2, 11],
1040
+ 15: [2, 11],
1041
+ 16: [2, 11],
1042
+ 18: [2, 11]
1043
+ }, {
1044
+ 5: [2, 12],
1045
+ 6: [2, 12],
1046
+ 7: [2, 12],
1047
+ 8: [2, 12],
1048
+ 9: [2, 12],
1049
+ 10: [2, 12],
1050
+ 11: [2, 12],
1051
+ 12: [2, 12],
1052
+ 13: [2, 12],
1053
+ 14: [2, 12],
1054
+ 15: [2, 12],
1055
+ 16: [2, 12],
1056
+ 18: [2, 12]
1057
+ }, {
1058
+ 4: 30,
1059
+ 17: [1, 3],
1060
+ 19: [1, 4],
1061
+ 20: [1, 5]
1062
+ }, {
1063
+ 5: [2, 2],
1064
+ 6: [1, 7],
1065
+ 7: [2, 2],
1066
+ 8: [1, 8],
1067
+ 9: [1, 9],
1068
+ 10: [1, 10],
1069
+ 11: [1, 11],
1070
+ 12: [1, 12],
1071
+ 13: [1, 13],
1072
+ 14: [1, 14],
1073
+ 15: [1, 15],
1074
+ 16: [1, 16],
1075
+ 18: [2, 2]
1076
+ }],
1077
+ defaultActions: {
1078
+ 6: [2, 1]
1079
+ },
1080
+ parseError: function parseError(str, hash) {
1081
+ throw new Error(str);
1082
+ },
1083
+ parse: function parse(input) {
1084
+ var self = this,
1085
+ stack = [0],
1086
+ vstack = [null], // semantic value stack
1087
+ lstack = [], // location stack
1088
+ table = this.table,
1089
+ yytext = '',
1090
+ yylineno = 0,
1091
+ yyleng = 0,
1092
+ recovering = 0,
1093
+ TERROR = 2,
1094
+ EOF = 1;
1095
+
1096
+ //this.reductionCount = this.shiftCount = 0;
1097
+
1098
+ this.lexer.setInput(input);
1099
+ this.lexer.yy = this.yy;
1100
+ this.yy.lexer = this.lexer;
1101
+ if (typeof this.lexer.yylloc == 'undefined')
1102
+ this.lexer.yylloc = {};
1103
+ var yyloc = this.lexer.yylloc;
1104
+ lstack.push(yyloc);
1105
+
1106
+ if (typeof this.yy.parseError === 'function')
1107
+ this.parseError = this.yy.parseError;
1108
+
1109
+ function popStack(n) {
1110
+ stack.length = stack.length - 2 * n;
1111
+ vstack.length = vstack.length - n;
1112
+ lstack.length = lstack.length - n;
1113
+ }
1114
+
1115
+ function lex() {
1116
+ var token;
1117
+ token = self.lexer.lex() || 1; // $end = 1
1118
+ // if token isn't its numeric value, convert
1119
+ if (typeof token !== 'number') {
1120
+ token = self.symbols_[token] || token;
1121
+ }
1122
+ return token;
1123
+ }
1124
+
1125
+ var symbol, preErrorSymbol, state, action, a, r, yyval = {},
1126
+ p, len, newState, expected;
1127
+ while (true) {
1128
+ // retreive state number from top of stack
1129
+ state = stack[stack.length - 1];
1130
+
1131
+ // use default actions if available
1132
+ if (this.defaultActions[state]) {
1133
+ action = this.defaultActions[state];
1134
+ } else {
1135
+ if (symbol == null)
1136
+ symbol = lex();
1137
+ // read action for current state and first input
1138
+ action = table[state] && table[state][symbol];
1139
+ }
1140
+
1141
+ // handle parse error
1142
+ _handle_error:
1143
+ if (typeof action === 'undefined' || !action.length || !action[0]) {
1144
+
1145
+ if (!recovering) {
1146
+ // Report error
1147
+ expected = [];
1148
+ for (p in table[state])
1149
+ if (this.terminals_[p] && p > 2) {
1150
+ expected.push("'" + this.terminals_[p] + "'");
1151
+ }
1152
+ var errStr = '';
1153
+ if (this.lexer.showPosition) {
1154
+ errStr = 'Parse error on line ' + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(', ') + ", got '" + this.terminals_[symbol] + "'";
1155
+ } else {
1156
+ errStr = 'Parse error on line ' + (yylineno + 1) + ": Unexpected " +
1157
+ (symbol == 1 /*EOF*/ ? "end of input" :
1158
+ ("'" + (this.terminals_[symbol] || symbol) + "'"));
1159
+ }
1160
+ this.parseError(errStr, {
1161
+ text: this.lexer.match,
1162
+ token: this.terminals_[symbol] || symbol,
1163
+ line: this.lexer.yylineno,
1164
+ loc: yyloc,
1165
+ expected: expected
1166
+ });
1167
+ }
1168
+
1169
+ // just recovered from another error
1170
+ if (recovering == 3) {
1171
+ if (symbol == EOF) {
1172
+ throw new Error(errStr || 'Parsing halted.');
1173
+ }
1174
+
1175
+ // discard current lookahead and grab another
1176
+ yyleng = this.lexer.yyleng;
1177
+ yytext = this.lexer.yytext;
1178
+ yylineno = this.lexer.yylineno;
1179
+ yyloc = this.lexer.yylloc;
1180
+ symbol = lex();
1181
+ }
1182
+
1183
+ // try to recover from error
1184
+ while (1) {
1185
+ // check for error recovery rule in this state
1186
+ if ((TERROR.toString()) in table[state]) {
1187
+ break;
1188
+ }
1189
+ if (state == 0) {
1190
+ throw new Error(errStr || 'Parsing halted.');
1191
+ }
1192
+ popStack(1);
1193
+ state = stack[stack.length - 1];
1194
+ }
1195
+
1196
+ preErrorSymbol = symbol; // save the lookahead token
1197
+ symbol = TERROR; // insert generic error symbol as new lookahead
1198
+ state = stack[stack.length - 1];
1199
+ action = table[state] && table[state][TERROR];
1200
+ recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
1201
+ }
1202
+
1203
+ // this shouldn't happen, unless resolve defaults are off
1204
+ if (action[0] instanceof Array && action.length > 1) {
1205
+ throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
1206
+ }
1207
+
1208
+ switch (action[0]) {
1209
+
1210
+ case 1: // shift
1211
+ //this.shiftCount++;
1212
+
1213
+ stack.push(symbol);
1214
+ vstack.push(this.lexer.yytext);
1215
+ lstack.push(this.lexer.yylloc);
1216
+ stack.push(action[1]); // push state
1217
+ symbol = null;
1218
+ if (!preErrorSymbol) { // normal execution/no error
1219
+ yyleng = this.lexer.yyleng;
1220
+ yytext = this.lexer.yytext;
1221
+ yylineno = this.lexer.yylineno;
1222
+ yyloc = this.lexer.yylloc;
1223
+ if (recovering > 0)
1224
+ recovering--;
1225
+ } else { // error just occurred, resume old lookahead f/ before error
1226
+ symbol = preErrorSymbol;
1227
+ preErrorSymbol = null;
1228
+ }
1229
+ break;
1230
+
1231
+ case 2: // reduce
1232
+ //this.reductionCount++;
1233
+
1234
+ len = this.productions_[action[1]][1];
1235
+
1236
+ // perform semantic action
1237
+ yyval.$ = vstack[vstack.length - len]; // default to $$ = $1
1238
+ // default location, uses first token for firsts, last for lasts
1239
+ yyval._$ = {
1240
+ first_line: lstack[lstack.length - (len || 1)].first_line,
1241
+ last_line: lstack[lstack.length - 1].last_line,
1242
+ first_column: lstack[lstack.length - (len || 1)].first_column,
1243
+ last_column: lstack[lstack.length - 1].last_column
1244
+ };
1245
+ r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
1246
+
1247
+ if (typeof r !== 'undefined') {
1248
+ return r;
1249
+ }
1250
+
1251
+ // pop off stack
1252
+ if (len) {
1253
+ stack = stack.slice(0, -1 * len * 2);
1254
+ vstack = vstack.slice(0, -1 * len);
1255
+ lstack = lstack.slice(0, -1 * len);
1256
+ }
1257
+
1258
+ stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce)
1259
+ vstack.push(yyval.$);
1260
+ lstack.push(yyval._$);
1261
+ // goto new state = table[STATE][NONTERMINAL]
1262
+ newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
1263
+ stack.push(newState);
1264
+ break;
1265
+
1266
+ case 3: // accept
1267
+ return true;
1268
+ }
1269
+
1270
+ }
1271
+
1272
+ return true;
1273
+ }
1274
+ }; /* Jison generated lexer */
1275
+ var lexer = (function() {
1276
+
1277
+ var lexer = ({
1278
+ EOF: 1,
1279
+ parseError: function parseError(str, hash) {
1280
+ if (this.yy.parseError) {
1281
+ this.yy.parseError(str, hash);
1282
+ } else {
1283
+ throw new Error(str);
1284
+ }
1285
+ },
1286
+ setInput: function(input) {
1287
+ this._input = input;
1288
+ this._more = this._less = this.done = false;
1289
+ this.yylineno = this.yyleng = 0;
1290
+ this.yytext = this.matched = this.match = '';
1291
+ this.conditionStack = ['INITIAL'];
1292
+ this.yylloc = {
1293
+ first_line: 1,
1294
+ first_column: 0,
1295
+ last_line: 1,
1296
+ last_column: 0
1297
+ };
1298
+ return this;
1299
+ },
1300
+ input: function() {
1301
+ var ch = this._input[0];
1302
+ this.yytext += ch;
1303
+ this.yyleng++;
1304
+ this.match += ch;
1305
+ this.matched += ch;
1306
+ var lines = ch.match(/\n/);
1307
+ if (lines) this.yylineno++;
1308
+ this._input = this._input.slice(1);
1309
+ return ch;
1310
+ },
1311
+ unput: function(ch) {
1312
+ this._input = ch + this._input;
1313
+ return this;
1314
+ },
1315
+ more: function() {
1316
+ this._more = true;
1317
+ return this;
1318
+ },
1319
+ pastInput: function() {
1320
+ var past = this.matched.substr(0, this.matched.length - this.match.length);
1321
+ return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
1322
+ },
1323
+ upcomingInput: function() {
1324
+ var next = this.match;
1325
+ if (next.length < 20) {
1326
+ next += this._input.substr(0, 20 - next.length);
1327
+ }
1328
+ return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
1329
+ },
1330
+ showPosition: function() {
1331
+ var pre = this.pastInput();
1332
+ var c = new Array(pre.length + 1).join("-");
1333
+ return pre + this.upcomingInput() + "\n" + c + "^";
1334
+ },
1335
+ next: function() {
1336
+ if (this.done) {
1337
+ return this.EOF;
1338
+ }
1339
+ if (!this._input) this.done = true;
1340
+
1341
+ var token,
1342
+ match,
1343
+ col,
1344
+ lines;
1345
+ if (!this._more) {
1346
+ this.yytext = '';
1347
+ this.match = '';
1348
+ }
1349
+ var rules = this._currentRules();
1350
+ for (var i = 0; i < rules.length; i++) {
1351
+ match = this._input.match(this.rules[rules[i]]);
1352
+ if (match) {
1353
+ lines = match[0].match(/\n.*/g);
1354
+ if (lines) this.yylineno += lines.length;
1355
+ this.yylloc = {
1356
+ first_line: this.yylloc.last_line,
1357
+ last_line: this.yylineno + 1,
1358
+ first_column: this.yylloc.last_column,
1359
+ last_column: lines ? lines[lines.length - 1].length - 1 : this.yylloc.last_column + match[0].length
1360
+ }
1361
+ this.yytext += match[0];
1362
+ this.match += match[0];
1363
+ this.matches = match;
1364
+ this.yyleng = this.yytext.length;
1365
+ this._more = false;
1366
+ this._input = this._input.slice(match[0].length);
1367
+ this.matched += match[0];
1368
+ token = this.performAction.call(this, this.yy, this, rules[i], this.conditionStack[this.conditionStack.length - 1]);
1369
+ if (token) return token;
1370
+ else return;
1371
+ }
1372
+ }
1373
+ if (this._input === "") {
1374
+ return this.EOF;
1375
+ } else {
1376
+ this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
1377
+ text: "",
1378
+ token: null,
1379
+ line: this.yylineno
1380
+ });
1381
+ }
1382
+ },
1383
+ lex: function lex() {
1384
+ var r = this.next();
1385
+ if (typeof r !== 'undefined') {
1386
+ return r;
1387
+ } else {
1388
+ return this.lex();
1389
+ }
1390
+ },
1391
+ begin: function begin(condition) {
1392
+ this.conditionStack.push(condition);
1393
+ },
1394
+ popState: function popState() {
1395
+ return this.conditionStack.pop();
1396
+ },
1397
+ _currentRules: function _currentRules() {
1398
+ return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
1399
+ },
1400
+ topState: function() {
1401
+ return this.conditionStack[this.conditionStack.length - 2];
1402
+ },
1403
+ pushState: function begin(condition) {
1404
+ this.begin(condition);
1405
+ }
1406
+ });
1407
+ lexer.performAction = function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
1408
+
1409
+ var YYSTATE = YY_START;
1410
+ switch ($avoiding_name_collisions) {
1411
+ case 0:
1412
+ /* skip whitespace */
1413
+ break;
1414
+ case 1:
1415
+ return 20
1416
+ break;
1417
+ case 2:
1418
+ return 19
1419
+ break;
1420
+ case 3:
1421
+ return 8
1422
+ break;
1423
+ case 4:
1424
+ return 9
1425
+ break;
1426
+ case 5:
1427
+ return 6
1428
+ break;
1429
+ case 6:
1430
+ return 7
1431
+ break;
1432
+ case 7:
1433
+ return 11
1434
+ break;
1435
+ case 8:
1436
+ return 13
1437
+ break;
1438
+ case 9:
1439
+ return 10
1440
+ break;
1441
+ case 10:
1442
+ return 12
1443
+ break;
1444
+ case 11:
1445
+ return 14
1446
+ break;
1447
+ case 12:
1448
+ return 15
1449
+ break;
1450
+ case 13:
1451
+ return 16
1452
+ break;
1453
+ case 14:
1454
+ return 17
1455
+ break;
1456
+ case 15:
1457
+ return 18
1458
+ break;
1459
+ case 16:
1460
+ return 5
1461
+ break;
1462
+ case 17:
1463
+ return 'INVALID'
1464
+ break;
1465
+ }
1466
+ };
1467
+ lexer.rules = [/^\s+/, /^[0-9]+(\.[0-9]+)?\b/, /^n\b/, /^\|\|/, /^&&/, /^\?/, /^:/, /^<=/, /^>=/, /^</, /^>/, /^!=/, /^==/, /^%/, /^\(/, /^\)/, /^$/, /^./];
1468
+ lexer.conditions = {
1469
+ "INITIAL": {
1470
+ "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
1471
+ "inclusive": true
1472
+ }
1473
+ };
1474
+ return lexer;
1475
+ })()
1476
+ parser.lexer = lexer;
1477
+ return parser;
1478
+ })();
1479
+ // End parser
1480
+
1481
+ // Handle node, amd, and global systems
1482
+ if (typeof exports !== 'undefined') {
1483
+ if (typeof module !== 'undefined' && module.exports) {
1484
+ exports = module.exports = Jed;
1485
+ }
1486
+ exports.Jed = Jed;
1487
+ } else {
1488
+ if (typeof define === 'function' && define.amd) {
1489
+ define('jed', function() {
1490
+ return Jed;
1491
+ });
1492
+ }
1493
+ // Leak a global regardless of module system
1494
+ root['Jed'] = Jed;
1495
+ }
1496
+
1497
+ })(this);