| 1 | /** |
| 2 | * @preserve jed.js https://github.com/SlexAxton/Jed |
| 3 | */ |
| 4 | /* |
| 5 | ----------- |
| 6 | A gettext compatible i18n library for modern JavaScript Applications |
| 7 | |
| 8 | by Alex Sexton - AlexSexton [at] gmail - @SlexAxton |
| 9 | |
| 10 | MIT License |
| 11 | |
| 12 | A jQuery Foundation project - requires CLA to contribute - |
| 13 | https://contribute.jquery.org/CLA/ |
| 14 | |
| 15 | |
| 16 | |
| 17 | Jed offers the entire applicable GNU gettext spec'd set of |
| 18 | functions, but also offers some nicer wrappers around them. |
| 19 | The api for gettext was written for a language with no function |
| 20 | overloading, so Jed allows a little more of that. |
| 21 | |
| 22 | Many thanks to Joshua I. Miller - unrtst@cpan.org - who wrote |
| 23 | gettext.js back in 2008. I was able to vet a lot of my ideas |
| 24 | against his. I also made sure Jed passed against his tests |
| 25 | in order to offer easy upgrades -- jsgettext.berlios.de |
| 26 | */ |
| 27 | (function (root, undef) { |
| 28 | |
| 29 | // Set up some underscore-style functions, if you already have |
| 30 | // underscore, feel free to delete this section, and use it |
| 31 | // directly, however, the amount of functions used doesn't |
| 32 | // warrant having underscore as a full dependency. |
| 33 | // Underscore 1.3.0 was used to port and is licensed |
| 34 | // under the MIT License by Jeremy Ashkenas. |
| 35 | var ArrayProto = Array.prototype, |
| 36 | ObjProto = Object.prototype, |
| 37 | slice = ArrayProto.slice, |
| 38 | hasOwnProp = ObjProto.hasOwnProperty, |
| 39 | nativeForEach = ArrayProto.forEach, |
| 40 | breaker = {}; |
| 41 | |
| 42 | // We're not using the OOP style _ so we don't need the |
| 43 | // extra level of indirection. This still means that you |
| 44 | // sub out for real `_` though. |
| 45 | var _ = { |
| 46 | forEach : function( obj, iterator, context ) { |
| 47 | var i, l, key; |
| 48 | if ( obj === null ) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if ( nativeForEach && obj.forEach === nativeForEach ) { |
| 53 | obj.forEach( iterator, context ); |
| 54 | } |
| 55 | else if ( obj.length === +obj.length ) { |
| 56 | for ( i = 0, l = obj.length; i < l; i++ ) { |
| 57 | if ( i in obj && iterator.call( context, obj[i], i, obj ) === breaker ) { |
| 58 | return; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | else { |
| 63 | for ( key in obj) { |
| 64 | if ( hasOwnProp.call( obj, key ) ) { |
| 65 | if ( iterator.call (context, obj[key], key, obj ) === breaker ) { |
| 66 | return; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | }, |
| 72 | extend : function( obj ) { |
| 73 | this.forEach( slice.call( arguments, 1 ), function ( source ) { |
| 74 | for ( var prop in source ) { |
| 75 | obj[prop] = source[prop]; |
| 76 | } |
| 77 | }); |
| 78 | return obj; |
| 79 | } |
| 80 | }; |
| 81 | // END Miniature underscore impl |
| 82 | |
| 83 | // Jed is a constructor function |
| 84 | var Jed = function ( options ) { |
| 85 | // Some minimal defaults |
| 86 | this.defaults = { |
| 87 | "locale_data" : { |
| 88 | "messages" : { |
| 89 | "" : { |
| 90 | "domain" : "messages", |
| 91 | "lang" : "en", |
| 92 | "plural_forms" : "nplurals=2; plural=(n != 1);" |
| 93 | } |
| 94 | // There are no default keys, though |
| 95 | } |
| 96 | }, |
| 97 | // The default domain if one is missing |
| 98 | "domain" : "messages", |
| 99 | // enable debug mode to log untranslated strings to the console |
| 100 | "debug" : false |
| 101 | }; |
| 102 | |
| 103 | // Mix in the sent options with the default options |
| 104 | this.options = _.extend( {}, this.defaults, options ); |
| 105 | this.textdomain( this.options.domain ); |
| 106 | |
| 107 | if ( options.domain && ! this.options.locale_data[ this.options.domain ] ) { |
| 108 | throw new Error('Text domain set to non-existent domain: `' + options.domain + '`'); |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | // The gettext spec sets this character as the default |
| 113 | // delimiter for context lookups. |
| 114 | // e.g.: context\u0004key |
| 115 | // If your translation company uses something different, |
| 116 | // just change this at any time and it will use that instead. |
| 117 | Jed.context_delimiter = String.fromCharCode( 4 ); |
| 118 | |
| 119 | function getPluralFormFunc ( plural_form_string ) { |
| 120 | return Jed.PF.compile( plural_form_string || "nplurals=2; plural=(n != 1);"); |
| 121 | } |
| 122 | |
| 123 | function Chain( key, i18n ){ |
| 124 | this._key = key; |
| 125 | this._i18n = i18n; |
| 126 | } |
| 127 | |
| 128 | // Create a chainable api for adding args prettily |
| 129 | _.extend( Chain.prototype, { |
| 130 | onDomain : function ( domain ) { |
| 131 | this._domain = domain; |
| 132 | return this; |
| 133 | }, |
| 134 | withContext : function ( context ) { |
| 135 | this._context = context; |
| 136 | return this; |
| 137 | }, |
| 138 | ifPlural : function ( num, pkey ) { |
| 139 | this._val = num; |
| 140 | this._pkey = pkey; |
| 141 | return this; |
| 142 | }, |
| 143 | fetch : function ( sArr ) { |
| 144 | if ( {}.toString.call( sArr ) != '[object Array]' ) { |
| 145 | sArr = [].slice.call(arguments, 0); |
| 146 | } |
| 147 | return ( sArr && sArr.length ? Jed.sprintf : function(x){ return x; } )( |
| 148 | this._i18n.dcnpgettext(this._domain, this._context, this._key, this._pkey, this._val), |
| 149 | sArr |
| 150 | ); |
| 151 | } |
| 152 | }); |
| 153 | |
| 154 | // Add functions to the Jed prototype. |
| 155 | // These will be the functions on the object that's returned |
| 156 | // from creating a `new Jed()` |
| 157 | // These seem redundant, but they gzip pretty well. |
| 158 | _.extend( Jed.prototype, { |
| 159 | // The sexier api start point |
| 160 | translate : function ( key ) { |
| 161 | return new Chain( key, this ); |
| 162 | }, |
| 163 | |
| 164 | textdomain : function ( domain ) { |
| 165 | if ( ! domain ) { |
| 166 | return this._textdomain; |
| 167 | } |
| 168 | this._textdomain = domain; |
| 169 | }, |
| 170 | |
| 171 | gettext : function ( key ) { |
| 172 | return this.dcnpgettext.call( this, undef, undef, key ); |
| 173 | }, |
| 174 | |
| 175 | dgettext : function ( domain, key ) { |
| 176 | return this.dcnpgettext.call( this, domain, undef, key ); |
| 177 | }, |
| 178 | |
| 179 | dcgettext : function ( domain , key /*, category */ ) { |
| 180 | // Ignores the category anyways |
| 181 | return this.dcnpgettext.call( this, domain, undef, key ); |
| 182 | }, |
| 183 | |
| 184 | ngettext : function ( skey, pkey, val ) { |
| 185 | return this.dcnpgettext.call( this, undef, undef, skey, pkey, val ); |
| 186 | }, |
| 187 | |
| 188 | dngettext : function ( domain, skey, pkey, val ) { |
| 189 | return this.dcnpgettext.call( this, domain, undef, skey, pkey, val ); |
| 190 | }, |
| 191 | |
| 192 | dcngettext : function ( domain, skey, pkey, val/*, category */) { |
| 193 | return this.dcnpgettext.call( this, domain, undef, skey, pkey, val ); |
| 194 | }, |
| 195 | |
| 196 | pgettext : function ( context, key ) { |
| 197 | return this.dcnpgettext.call( this, undef, context, key ); |
| 198 | }, |
| 199 | |
| 200 | dpgettext : function ( domain, context, key ) { |
| 201 | return this.dcnpgettext.call( this, domain, context, key ); |
| 202 | }, |
| 203 | |
| 204 | dcpgettext : function ( domain, context, key/*, category */) { |
| 205 | return this.dcnpgettext.call( this, domain, context, key ); |
| 206 | }, |
| 207 | |
| 208 | npgettext : function ( context, skey, pkey, val ) { |
| 209 | return this.dcnpgettext.call( this, undef, context, skey, pkey, val ); |
| 210 | }, |
| 211 | |
| 212 | dnpgettext : function ( domain, context, skey, pkey, val ) { |
| 213 | return this.dcnpgettext.call( this, domain, context, skey, pkey, val ); |
| 214 | }, |
| 215 | |
| 216 | // The most fully qualified gettext function. It has every option. |
| 217 | // Since it has every option, we can use it from every other method. |
| 218 | // This is the bread and butter. |
| 219 | // Technically there should be one more argument in this function for 'Category', |
| 220 | // but since we never use it, we might as well not waste the bytes to define it. |
| 221 | dcnpgettext : function ( domain, context, singular_key, plural_key, val ) { |
| 222 | // Set some defaults |
| 223 | |
| 224 | plural_key = plural_key || singular_key; |
| 225 | |
| 226 | // Use the global domain default if one |
| 227 | // isn't explicitly passed in |
| 228 | domain = domain || this._textdomain; |
| 229 | |
| 230 | var fallback; |
| 231 | |
| 232 | // Handle special cases |
| 233 | |
| 234 | // No options found |
| 235 | if ( ! this.options ) { |
| 236 | // There's likely something wrong, but we'll return the correct key for english |
| 237 | // We do this by instantiating a brand new Jed instance with the default set |
| 238 | // for everything that could be broken. |
| 239 | fallback = new Jed(); |
| 240 | return fallback.dcnpgettext.call( fallback, undefined, undefined, singular_key, plural_key, val ); |
| 241 | } |
| 242 | |
| 243 | // No translation data provided |
| 244 | if ( ! this.options.locale_data ) { |
| 245 | throw new Error('No locale data provided.'); |
| 246 | } |
| 247 | |
| 248 | if ( ! this.options.locale_data[ domain ] ) { |
| 249 | throw new Error('Domain `' + domain + '` was not found.'); |
| 250 | } |
| 251 | |
| 252 | if ( ! this.options.locale_data[ domain ][ "" ] ) { |
| 253 | throw new Error('No locale meta information provided.'); |
| 254 | } |
| 255 | |
| 256 | // Make sure we have a truthy key. Otherwise we might start looking |
| 257 | // into the empty string key, which is the options for the locale |
| 258 | // data. |
| 259 | if ( ! singular_key ) { |
| 260 | throw new Error('No translation key found.'); |
| 261 | } |
| 262 | |
| 263 | var key = context ? context + Jed.context_delimiter + singular_key : singular_key, |
| 264 | locale_data = this.options.locale_data, |
| 265 | dict = locale_data[ domain ], |
| 266 | defaultConf = (locale_data.messages || this.defaults.locale_data.messages)[""], |
| 267 | pluralForms = dict[""].plural_forms || dict[""]["Plural-Forms"] || dict[""]["plural-forms"] || defaultConf.plural_forms || defaultConf["Plural-Forms"] || defaultConf["plural-forms"], |
| 268 | val_list, |
| 269 | res; |
| 270 | |
| 271 | var val_idx; |
| 272 | if (val === undefined) { |
| 273 | // No value passed in; assume singular key lookup. |
| 274 | val_idx = 0; |
| 275 | |
| 276 | } else { |
| 277 | // Value has been passed in; use plural-forms calculations. |
| 278 | |
| 279 | // Handle invalid numbers, but try casting strings for good measure |
| 280 | if ( typeof val != 'number' ) { |
| 281 | val = parseInt( val, 10 ); |
| 282 | |
| 283 | if ( isNaN( val ) ) { |
| 284 | throw new Error('The number that was passed in is not a number.'); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | val_idx = getPluralFormFunc(pluralForms)(val); |
| 289 | } |
| 290 | |
| 291 | // Throw an error if a domain isn't found |
| 292 | if ( ! dict ) { |
| 293 | throw new Error('No domain named `' + domain + '` could be found.'); |
| 294 | } |
| 295 | |
| 296 | val_list = dict[ key ]; |
| 297 | |
| 298 | // If there is no match, then revert back to |
| 299 | // english style singular/plural with the keys passed in. |
| 300 | if ( ! val_list || val_idx > val_list.length ) { |
| 301 | if (this.options.missing_key_callback) { |
| 302 | this.options.missing_key_callback(key, domain); |
| 303 | } |
| 304 | res = [ singular_key, plural_key ]; |
| 305 | |
| 306 | // collect untranslated strings |
| 307 | if (this.options.debug===true) { |
| 308 | console.log(res[ getPluralFormFunc(pluralForms)( val ) ]); |
| 309 | } |
| 310 | return res[ getPluralFormFunc()( val ) ]; |
| 311 | } |
| 312 | |
| 313 | res = val_list[ val_idx ]; |
| 314 | |
| 315 | // This includes empty strings on purpose |
| 316 | if ( ! res ) { |
| 317 | res = [ singular_key, plural_key ]; |
| 318 | return res[ getPluralFormFunc()( val ) ]; |
| 319 | } |
| 320 | return res; |
| 321 | } |
| 322 | }); |
| 323 | |
| 324 | |
| 325 | // We add in sprintf capabilities for post translation value interolation |
| 326 | // This is not internally used, so you can remove it if you have this |
| 327 | // available somewhere else, or want to use a different system. |
| 328 | |
| 329 | // We _slightly_ modify the normal sprintf behavior to more gracefully handle |
| 330 | // undefined values. |
| 331 | |
| 332 | /** |
| 333 | sprintf() for JavaScript 0.7-beta1 |
| 334 | http://www.diveintojavascript.com/projects/javascript-sprintf |
| 335 | |
| 336 | Copyright (c) Alexandru Marasteanu <alexaholic [at) gmail (dot] com> |
| 337 | All rights reserved. |
| 338 | |
| 339 | Redistribution and use in source and binary forms, with or without |
| 340 | modification, are permitted provided that the following conditions are met: |
| 341 | * Redistributions of source code must retain the above copyright |
| 342 | notice, this list of conditions and the following disclaimer. |
| 343 | * Redistributions in binary form must reproduce the above copyright |
| 344 | notice, this list of conditions and the following disclaimer in the |
| 345 | documentation and/or other materials provided with the distribution. |
| 346 | * Neither the name of sprintf() for JavaScript nor the |
| 347 | names of its contributors may be used to endorse or promote products |
| 348 | derived from this software without specific prior written permission. |
| 349 | |
| 350 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 351 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 352 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 353 | DISCLAIMED. IN NO EVENT SHALL Alexandru Marasteanu BE LIABLE FOR ANY |
| 354 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 355 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 356 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 357 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 358 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 359 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 360 | */ |
| 361 | var sprintf = (function() { |
| 362 | function get_type(variable) { |
| 363 | return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); |
| 364 | } |
| 365 | function str_repeat(input, multiplier) { |
| 366 | for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} |
| 367 | return output.join(''); |
| 368 | } |
| 369 | |
| 370 | var str_format = function() { |
| 371 | if (!str_format.cache.hasOwnProperty(arguments[0])) { |
| 372 | str_format.cache[arguments[0]] = str_format.parse(arguments[0]); |
| 373 | } |
| 374 | return str_format.format.call(null, str_format.cache[arguments[0]], arguments); |
| 375 | }; |
| 376 | |
| 377 | str_format.format = function(parse_tree, argv) { |
| 378 | var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; |
| 379 | for (i = 0; i < tree_length; i++) { |
| 380 | node_type = get_type(parse_tree[i]); |
| 381 | if (node_type === 'string') { |
| 382 | output.push(parse_tree[i]); |
| 383 | } |
| 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 | } |
| 395 | else if (match[1]) { // positional argument (explicit) |
| 396 | arg = argv[match[1]]; |
| 397 | } |
| 398 | else { // positional argument (implicit) |
| 399 | arg = argv[cursor++]; |
| 400 | } |
| 401 | |
| 402 | if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { |
| 403 | throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); |
| 404 | } |
| 405 | |
| 406 | // Jed EDIT |
| 407 | if ( typeof arg == 'undefined' || arg === null ) { |
| 408 | arg = ''; |
| 409 | } |
| 410 | // Jed EDIT |
| 411 | |
| 412 | switch (match[8]) { |
| 413 | case 'b': arg = arg.toString(2); break; |
| 414 | case 'c': arg = String.fromCharCode(arg); break; |
| 415 | case 'd': arg = parseInt(arg, 10); break; |
| 416 | case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; |
| 417 | case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; |
| 418 | case 'o': arg = arg.toString(8); break; |
| 419 | case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; |
| 420 | case 'u': arg = Math.abs(arg); break; |
| 421 | case 'x': arg = arg.toString(16); break; |
| 422 | case 'X': arg = arg.toString(16).toUpperCase(); break; |
| 423 | } |
| 424 | arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); |
| 425 | pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; |
| 426 | pad_length = match[6] - String(arg).length; |
| 427 | pad = match[6] ? str_repeat(pad_character, pad_length) : ''; |
| 428 | output.push(match[5] ? arg + pad : pad + arg); |
| 429 | } |
| 430 | } |
| 431 | return output.join(''); |
| 432 | }; |
| 433 | |
| 434 | str_format.cache = {}; |
| 435 | |
| 436 | str_format.parse = function(fmt) { |
| 437 | var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; |
| 438 | while (_fmt) { |
| 439 | if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { |
| 440 | parse_tree.push(match[0]); |
| 441 | } |
| 442 | else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { |
| 443 | parse_tree.push('%'); |
| 444 | } |
| 445 | else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { |
| 446 | if (match[2]) { |
| 447 | arg_names |= 1; |
| 448 | var field_list = [], replacement_field = match[2], field_match = []; |
| 449 | if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { |
| 450 | field_list.push(field_match[1]); |
| 451 | while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { |
| 452 | if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { |
| 453 | field_list.push(field_match[1]); |
| 454 | } |
| 455 | else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { |
| 456 | field_list.push(field_match[1]); |
| 457 | } |
| 458 | else { |
| 459 | throw('[sprintf] huh?'); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | else { |
| 464 | throw('[sprintf] huh?'); |
| 465 | } |
| 466 | match[2] = field_list; |
| 467 | } |
| 468 | else { |
| 469 | arg_names |= 2; |
| 470 | } |
| 471 | if (arg_names === 3) { |
| 472 | throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); |
| 473 | } |
| 474 | parse_tree.push(match); |
| 475 | } |
| 476 | else { |
| 477 | throw('[sprintf] huh?'); |
| 478 | } |
| 479 | _fmt = _fmt.substring(match[0].length); |
| 480 | } |
| 481 | return parse_tree; |
| 482 | }; |
| 483 | |
| 484 | return str_format; |
| 485 | })(); |
| 486 | |
| 487 | var vsprintf = function(fmt, argv) { |
| 488 | argv.unshift(fmt); |
| 489 | return sprintf.apply(null, argv); |
| 490 | }; |
| 491 | |
| 492 | Jed.parse_plural = function ( plural_forms, n ) { |
| 493 | plural_forms = plural_forms.replace(/n/g, n); |
| 494 | return Jed.parse_expression(plural_forms); |
| 495 | }; |
| 496 | |
| 497 | Jed.sprintf = function ( fmt, args ) { |
| 498 | if ( {}.toString.call( args ) == '[object Array]' ) { |
| 499 | return vsprintf( fmt, [].slice.call(args) ); |
| 500 | } |
| 501 | return sprintf.apply(this, [].slice.call(arguments) ); |
| 502 | }; |
| 503 | |
| 504 | Jed.prototype.sprintf = function () { |
| 505 | return Jed.sprintf.apply(this, arguments); |
| 506 | }; |
| 507 | // END sprintf Implementation |
| 508 | |
| 509 | // Start the Plural forms section |
| 510 | // This is a full plural form expression parser. It is used to avoid |
| 511 | // running 'eval' or 'new Function' directly against the plural |
| 512 | // forms. |
| 513 | // |
| 514 | // This can be important if you get translations done through a 3rd |
| 515 | // party vendor. I encourage you to use this instead, however, I |
| 516 | // also will provide a 'precompiler' that you can use at build time |
| 517 | // to output valid/safe function representations of the plural form |
| 518 | // expressions. This means you can build this code out for the most |
| 519 | // part. |
| 520 | Jed.PF = {}; |
| 521 | |
| 522 | Jed.PF.parse = function ( p ) { |
| 523 | var plural_str = Jed.PF.extractPluralExpr( p ); |
| 524 | return Jed.PF.parser.parse.call(Jed.PF.parser, plural_str); |
| 525 | }; |
| 526 | |
| 527 | Jed.PF.compile = function ( p ) { |
| 528 | // Handle trues and falses as 0 and 1 |
| 529 | function imply( val ) { |
| 530 | return (val === true ? 1 : val ? val : 0); |
| 531 | } |
| 532 | |
| 533 | var ast = Jed.PF.parse( p ); |
| 534 | return function ( n ) { |
| 535 | return imply( Jed.PF.interpreter( ast )( n ) ); |
| 536 | }; |
| 537 | }; |
| 538 | |
| 539 | Jed.PF.interpreter = function ( ast ) { |
| 540 | return function ( n ) { |
| 541 | var res; |
| 542 | switch ( ast.type ) { |
| 543 | case 'GROUP': |
| 544 | return Jed.PF.interpreter( ast.expr )( n ); |
| 545 | case 'TERNARY': |
| 546 | if ( Jed.PF.interpreter( ast.expr )( n ) ) { |
| 547 | return Jed.PF.interpreter( ast.truthy )( n ); |
| 548 | } |
| 549 | return Jed.PF.interpreter( ast.falsey )( n ); |
| 550 | case 'OR': |
| 551 | return Jed.PF.interpreter( ast.left )( n ) || Jed.PF.interpreter( ast.right )( n ); |
| 552 | case 'AND': |
| 553 | return Jed.PF.interpreter( ast.left )( n ) && Jed.PF.interpreter( ast.right )( n ); |
| 554 | case 'LT': |
| 555 | return Jed.PF.interpreter( ast.left )( n ) < Jed.PF.interpreter( ast.right )( n ); |
| 556 | case 'GT': |
| 557 | return Jed.PF.interpreter( ast.left )( n ) > Jed.PF.interpreter( ast.right )( n ); |
| 558 | case 'LTE': |
| 559 | return Jed.PF.interpreter( ast.left )( n ) <= Jed.PF.interpreter( ast.right )( n ); |
| 560 | case 'GTE': |
| 561 | return Jed.PF.interpreter( ast.left )( n ) >= Jed.PF.interpreter( ast.right )( n ); |
| 562 | case 'EQ': |
| 563 | return Jed.PF.interpreter( ast.left )( n ) == Jed.PF.interpreter( ast.right )( n ); |
| 564 | case 'NEQ': |
| 565 | return Jed.PF.interpreter( ast.left )( n ) != Jed.PF.interpreter( ast.right )( n ); |
| 566 | case 'MOD': |
| 567 | return Jed.PF.interpreter( ast.left )( n ) % Jed.PF.interpreter( ast.right )( n ); |
| 568 | case 'VAR': |
| 569 | return n; |
| 570 | case 'NUM': |
| 571 | return ast.val; |
| 572 | default: |
| 573 | throw new Error("Invalid Token found."); |
| 574 | } |
| 575 | }; |
| 576 | }; |
| 577 | |
| 578 | Jed.PF.regexps = { |
| 579 | TRIM_BEG: /^\s\s*/, |
| 580 | TRIM_END: /\s\s*$/, |
| 581 | HAS_SEMICOLON: /;\s*$/, |
| 582 | NPLURALS: /nplurals\=(\d+);/, |
| 583 | PLURAL: /plural\=(.*);/ |
| 584 | }; |
| 585 | |
| 586 | Jed.PF.extractPluralExpr = function ( p ) { |
| 587 | // trim first |
| 588 | p = p.replace(Jed.PF.regexps.TRIM_BEG, '').replace(Jed.PF.regexps.TRIM_END, ''); |
| 589 | |
| 590 | if (! Jed.PF.regexps.HAS_SEMICOLON.test(p)) { |
| 591 | p = p.concat(';'); |
| 592 | } |
| 593 | |
| 594 | var nplurals_matches = p.match( Jed.PF.regexps.NPLURALS ), |
| 595 | res = {}, |
| 596 | plural_matches; |
| 597 | |
| 598 | // Find the nplurals number |
| 599 | if ( nplurals_matches.length > 1 ) { |
| 600 | res.nplurals = nplurals_matches[1]; |
| 601 | } |
| 602 | else { |
| 603 | throw new Error('nplurals not found in plural_forms string: ' + p ); |
| 604 | } |
| 605 | |
| 606 | // remove that data to get to the formula |
| 607 | p = p.replace( Jed.PF.regexps.NPLURALS, "" ); |
| 608 | plural_matches = p.match( Jed.PF.regexps.PLURAL ); |
| 609 | |
| 610 | if (!( plural_matches && plural_matches.length > 1 ) ) { |
| 611 | throw new Error('`plural` expression not found: ' + p); |
| 612 | } |
| 613 | return plural_matches[ 1 ]; |
| 614 | }; |
| 615 | |
| 616 | /* Jison generated parser */ |
| 617 | Jed.PF.parser = (function(){ |
| 618 | |
| 619 | var parser = {trace: function trace() { }, |
| 620 | yy: {}, |
| 621 | symbols_: {"error":2,"expressions":3,"e":4,"EOF":5,"?":6,":":7,"||":8,"&&":9,"<":10,"<=":11,">":12,">=":13,"!=":14,"==":15,"%":16,"(":17,")":18,"n":19,"NUMBER":20,"$accept":0,"$end":1}, |
| 622 | terminals_: {2:"error",5:"EOF",6:"?",7:":",8:"||",9:"&&",10:"<",11:"<=",12:">",13:">=",14:"!=",15:"==",16:"%",17:"(",18:")",19:"n",20:"NUMBER"}, |
| 623 | productions_: [0,[3,2],[4,5],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,1],[4,1]], |
| 624 | performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) { |
| 625 | |
| 626 | var $0 = $$.length - 1; |
| 627 | switch (yystate) { |
| 628 | case 1: return { type : 'GROUP', expr: $$[$0-1] }; |
| 629 | break; |
| 630 | case 2:this.$ = { type: 'TERNARY', expr: $$[$0-4], truthy : $$[$0-2], falsey: $$[$0] }; |
| 631 | break; |
| 632 | case 3:this.$ = { type: "OR", left: $$[$0-2], right: $$[$0] }; |
| 633 | break; |
| 634 | case 4:this.$ = { type: "AND", left: $$[$0-2], right: $$[$0] }; |
| 635 | break; |
| 636 | case 5:this.$ = { type: 'LT', left: $$[$0-2], right: $$[$0] }; |
| 637 | break; |
| 638 | case 6:this.$ = { type: 'LTE', left: $$[$0-2], right: $$[$0] }; |
| 639 | break; |
| 640 | case 7:this.$ = { type: 'GT', left: $$[$0-2], right: $$[$0] }; |
| 641 | break; |
| 642 | case 8:this.$ = { type: 'GTE', left: $$[$0-2], right: $$[$0] }; |
| 643 | break; |
| 644 | case 9:this.$ = { type: 'NEQ', left: $$[$0-2], right: $$[$0] }; |
| 645 | break; |
| 646 | case 10:this.$ = { type: 'EQ', left: $$[$0-2], right: $$[$0] }; |
| 647 | break; |
| 648 | case 11:this.$ = { type: 'MOD', left: $$[$0-2], right: $$[$0] }; |
| 649 | break; |
| 650 | case 12:this.$ = { type: 'GROUP', expr: $$[$0-1] }; |
| 651 | break; |
| 652 | case 13:this.$ = { type: 'VAR' }; |
| 653 | break; |
| 654 | case 14:this.$ = { type: 'NUM', val: Number(yytext) }; |
| 655 | break; |
| 656 | } |
| 657 | }, |
| 658 | table: [{3:1,4:2,17:[1,3],19:[1,4],20:[1,5]},{1:[3]},{5:[1,6],6:[1,7],8:[1,8],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16]},{4:17,17:[1,3],19:[1,4],20:[1,5]},{5:[2,13],6:[2,13],7:[2,13],8:[2,13],9:[2,13],10:[2,13],11:[2,13],12:[2,13],13:[2,13],14:[2,13],15:[2,13],16:[2,13],18:[2,13]},{5:[2,14],6:[2,14],7:[2,14],8:[2,14],9:[2,14],10:[2,14],11:[2,14],12:[2,14],13:[2,14],14:[2,14],15:[2,14],16:[2,14],18:[2,14]},{1:[2,1]},{4:18,17:[1,3],19:[1,4],20:[1,5]},{4:19,17:[1,3],19:[1,4],20:[1,5]},{4:20,17:[1,3],19:[1,4],20:[1,5]},{4:21,17:[1,3],19:[1,4],20:[1,5]},{4:22,17:[1,3],19:[1,4],20:[1,5]},{4:23,17:[1,3],19:[1,4],20:[1,5]},{4:24,17:[1,3],19:[1,4],20:[1,5]},{4:25,17:[1,3],19:[1,4],20:[1,5]},{4:26,17:[1,3],19:[1,4],20:[1,5]},{4:27,17:[1,3],19:[1,4],20:[1,5]},{6:[1,7],8:[1,8],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16],18:[1,28]},{6:[1,7],7:[1,29],8:[1,8],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16]},{5:[2,3],6:[2,3],7:[2,3],8:[2,3],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16],18:[2,3]},{5:[2,4],6:[2,4],7:[2,4],8:[2,4],9:[2,4],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16],18:[2,4]},{5:[2,5],6:[2,5],7:[2,5],8:[2,5],9:[2,5],10:[2,5],11:[2,5],12:[2,5],13:[2,5],14:[2,5],15:[2,5],16:[1,16],18:[2,5]},{5:[2,6],6:[2,6],7:[2,6],8:[2,6],9:[2,6],10:[2,6],11:[2,6],12:[2,6],13:[2,6],14:[2,6],15:[2,6],16:[1,16],18:[2,6]},{5:[2,7],6:[2,7],7:[2,7],8:[2,7],9:[2,7],10:[2,7],11:[2,7],12:[2,7],13:[2,7],14:[2,7],15:[2,7],16:[1,16],18:[2,7]},{5:[2,8],6:[2,8],7:[2,8],8:[2,8],9:[2,8],10:[2,8],11:[2,8],12:[2,8],13:[2,8],14:[2,8],15:[2,8],16:[1,16],18:[2,8]},{5:[2,9],6:[2,9],7:[2,9],8:[2,9],9:[2,9],10:[2,9],11:[2,9],12:[2,9],13:[2,9],14:[2,9],15:[2,9],16:[1,16],18:[2,9]},{5:[2,10],6:[2,10],7:[2,10],8:[2,10],9:[2,10],10:[2,10],11:[2,10],12:[2,10],13:[2,10],14:[2,10],15:[2,10],16:[1,16],18:[2,10]},{5:[2,11],6:[2,11],7:[2,11],8:[2,11],9:[2,11],10:[2,11],11:[2,11],12:[2,11],13:[2,11],14:[2,11],15:[2,11],16:[2,11],18:[2,11]},{5:[2,12],6:[2,12],7:[2,12],8:[2,12],9:[2,12],10:[2,12],11:[2,12],12:[2,12],13:[2,12],14:[2,12],15:[2,12],16:[2,12],18:[2,12]},{4:30,17:[1,3],19:[1,4],20:[1,5]},{5:[2,2],6:[1,7],7:[2,2],8:[1,8],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16],18:[2,2]}], |
| 659 | defaultActions: {6:[2,1]}, |
| 660 | parseError: function parseError(str, hash) { |
| 661 | throw new Error(str); |
| 662 | }, |
| 663 | parse: function parse(input) { |
| 664 | var self = this, |
| 665 | stack = [0], |
| 666 | vstack = [null], // semantic value stack |
| 667 | lstack = [], // location stack |
| 668 | table = this.table, |
| 669 | yytext = '', |
| 670 | yylineno = 0, |
| 671 | yyleng = 0, |
| 672 | recovering = 0, |
| 673 | TERROR = 2, |
| 674 | EOF = 1; |
| 675 | |
| 676 | //this.reductionCount = this.shiftCount = 0; |
| 677 | |
| 678 | this.lexer.setInput(input); |
| 679 | this.lexer.yy = this.yy; |
| 680 | this.yy.lexer = this.lexer; |
| 681 | if (typeof this.lexer.yylloc == 'undefined') |
| 682 | this.lexer.yylloc = {}; |
| 683 | var yyloc = this.lexer.yylloc; |
| 684 | lstack.push(yyloc); |
| 685 | |
| 686 | if (typeof this.yy.parseError === 'function') |
| 687 | this.parseError = this.yy.parseError; |
| 688 | |
| 689 | function popStack (n) { |
| 690 | stack.length = stack.length - 2*n; |
| 691 | vstack.length = vstack.length - n; |
| 692 | lstack.length = lstack.length - n; |
| 693 | } |
| 694 | |
| 695 | function lex() { |
| 696 | var token; |
| 697 | token = self.lexer.lex() || 1; // $end = 1 |
| 698 | // if token isn't its numeric value, convert |
| 699 | if (typeof token !== 'number') { |
| 700 | token = self.symbols_[token] || token; |
| 701 | } |
| 702 | return token; |
| 703 | } |
| 704 | |
| 705 | var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected; |
| 706 | while (true) { |
| 707 | // retreive state number from top of stack |
| 708 | state = stack[stack.length-1]; |
| 709 | |
| 710 | // use default actions if available |
| 711 | if (this.defaultActions[state]) { |
| 712 | action = this.defaultActions[state]; |
| 713 | } else { |
| 714 | if (symbol == null) |
| 715 | symbol = lex(); |
| 716 | // read action for current state and first input |
| 717 | action = table[state] && table[state][symbol]; |
| 718 | } |
| 719 | |
| 720 | // handle parse error |
| 721 | _handle_error: |
| 722 | if (typeof action === 'undefined' || !action.length || !action[0]) { |
| 723 | |
| 724 | if (!recovering) { |
| 725 | // Report error |
| 726 | expected = []; |
| 727 | for (p in table[state]) if (this.terminals_[p] && p > 2) { |
| 728 | expected.push("'"+this.terminals_[p]+"'"); |
| 729 | } |
| 730 | var errStr = ''; |
| 731 | if (this.lexer.showPosition) { |
| 732 | errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'"; |
| 733 | } else { |
| 734 | errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " + |
| 735 | (symbol == 1 /*EOF*/ ? "end of input" : |
| 736 | ("'"+(this.terminals_[symbol] || symbol)+"'")); |
| 737 | } |
| 738 | this.parseError(errStr, |
| 739 | {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); |
| 740 | } |
| 741 | |
| 742 | // just recovered from another error |
| 743 | if (recovering == 3) { |
| 744 | if (symbol == EOF) { |
| 745 | throw new Error(errStr || 'Parsing halted.'); |
| 746 | } |
| 747 | |
| 748 | // discard current lookahead and grab another |
| 749 | yyleng = this.lexer.yyleng; |
| 750 | yytext = this.lexer.yytext; |
| 751 | yylineno = this.lexer.yylineno; |
| 752 | yyloc = this.lexer.yylloc; |
| 753 | symbol = lex(); |
| 754 | } |
| 755 | |
| 756 | // try to recover from error |
| 757 | while (1) { |
| 758 | // check for error recovery rule in this state |
| 759 | if ((TERROR.toString()) in table[state]) { |
| 760 | break; |
| 761 | } |
| 762 | if (state == 0) { |
| 763 | throw new Error(errStr || 'Parsing halted.'); |
| 764 | } |
| 765 | popStack(1); |
| 766 | state = stack[stack.length-1]; |
| 767 | } |
| 768 | |
| 769 | preErrorSymbol = symbol; // save the lookahead token |
| 770 | symbol = TERROR; // insert generic error symbol as new lookahead |
| 771 | state = stack[stack.length-1]; |
| 772 | action = table[state] && table[state][TERROR]; |
| 773 | recovering = 3; // allow 3 real symbols to be shifted before reporting a new error |
| 774 | } |
| 775 | |
| 776 | // this shouldn't happen, unless resolve defaults are off |
| 777 | if (action[0] instanceof Array && action.length > 1) { |
| 778 | throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol); |
| 779 | } |
| 780 | |
| 781 | switch (action[0]) { |
| 782 | |
| 783 | case 1: // shift |
| 784 | //this.shiftCount++; |
| 785 | |
| 786 | stack.push(symbol); |
| 787 | vstack.push(this.lexer.yytext); |
| 788 | lstack.push(this.lexer.yylloc); |
| 789 | stack.push(action[1]); // push state |
| 790 | symbol = null; |
| 791 | if (!preErrorSymbol) { // normal execution/no error |
| 792 | yyleng = this.lexer.yyleng; |
| 793 | yytext = this.lexer.yytext; |
| 794 | yylineno = this.lexer.yylineno; |
| 795 | yyloc = this.lexer.yylloc; |
| 796 | if (recovering > 0) |
| 797 | recovering--; |
| 798 | } else { // error just occurred, resume old lookahead f/ before error |
| 799 | symbol = preErrorSymbol; |
| 800 | preErrorSymbol = null; |
| 801 | } |
| 802 | break; |
| 803 | |
| 804 | case 2: // reduce |
| 805 | //this.reductionCount++; |
| 806 | |
| 807 | len = this.productions_[action[1]][1]; |
| 808 | |
| 809 | // perform semantic action |
| 810 | yyval.$ = vstack[vstack.length-len]; // default to $$ = $1 |
| 811 | // default location, uses first token for firsts, last for lasts |
| 812 | yyval._$ = { |
| 813 | first_line: lstack[lstack.length-(len||1)].first_line, |
| 814 | last_line: lstack[lstack.length-1].last_line, |
| 815 | first_column: lstack[lstack.length-(len||1)].first_column, |
| 816 | last_column: lstack[lstack.length-1].last_column |
| 817 | }; |
| 818 | r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); |
| 819 | |
| 820 | if (typeof r !== 'undefined') { |
| 821 | return r; |
| 822 | } |
| 823 | |
| 824 | // pop off stack |
| 825 | if (len) { |
| 826 | stack = stack.slice(0,-1*len*2); |
| 827 | vstack = vstack.slice(0, -1*len); |
| 828 | lstack = lstack.slice(0, -1*len); |
| 829 | } |
| 830 | |
| 831 | stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce) |
| 832 | vstack.push(yyval.$); |
| 833 | lstack.push(yyval._$); |
| 834 | // goto new state = table[STATE][NONTERMINAL] |
| 835 | newState = table[stack[stack.length-2]][stack[stack.length-1]]; |
| 836 | stack.push(newState); |
| 837 | break; |
| 838 | |
| 839 | case 3: // accept |
| 840 | return true; |
| 841 | } |
| 842 | |
| 843 | } |
| 844 | |
| 845 | return true; |
| 846 | }};/* Jison generated lexer */ |
| 847 | var lexer = (function(){ |
| 848 | |
| 849 | var lexer = ({EOF:1, |
| 850 | parseError:function parseError(str, hash) { |
| 851 | if (this.yy.parseError) { |
| 852 | this.yy.parseError(str, hash); |
| 853 | } else { |
| 854 | throw new Error(str); |
| 855 | } |
| 856 | }, |
| 857 | setInput:function (input) { |
| 858 | this._input = input; |
| 859 | this._more = this._less = this.done = false; |
| 860 | this.yylineno = this.yyleng = 0; |
| 861 | this.yytext = this.matched = this.match = ''; |
| 862 | this.conditionStack = ['INITIAL']; |
| 863 | this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0}; |
| 864 | return this; |
| 865 | }, |
| 866 | input:function () { |
| 867 | var ch = this._input[0]; |
| 868 | this.yytext+=ch; |
| 869 | this.yyleng++; |
| 870 | this.match+=ch; |
| 871 | this.matched+=ch; |
| 872 | var lines = ch.match(/\n/); |
| 873 | if (lines) this.yylineno++; |
| 874 | this._input = this._input.slice(1); |
| 875 | return ch; |
| 876 | }, |
| 877 | unput:function (ch) { |
| 878 | this._input = ch + this._input; |
| 879 | return this; |
| 880 | }, |
| 881 | more:function () { |
| 882 | this._more = true; |
| 883 | return this; |
| 884 | }, |
| 885 | pastInput:function () { |
| 886 | var past = this.matched.substr(0, this.matched.length - this.match.length); |
| 887 | return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); |
| 888 | }, |
| 889 | upcomingInput:function () { |
| 890 | var next = this.match; |
| 891 | if (next.length < 20) { |
| 892 | next += this._input.substr(0, 20-next.length); |
| 893 | } |
| 894 | return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, ""); |
| 895 | }, |
| 896 | showPosition:function () { |
| 897 | var pre = this.pastInput(); |
| 898 | var c = new Array(pre.length + 1).join("-"); |
| 899 | return pre + this.upcomingInput() + "\n" + c+"^"; |
| 900 | }, |
| 901 | next:function () { |
| 902 | if (this.done) { |
| 903 | return this.EOF; |
| 904 | } |
| 905 | if (!this._input) this.done = true; |
| 906 | |
| 907 | var token, |
| 908 | match, |
| 909 | col, |
| 910 | lines; |
| 911 | if (!this._more) { |
| 912 | this.yytext = ''; |
| 913 | this.match = ''; |
| 914 | } |
| 915 | var rules = this._currentRules(); |
| 916 | for (var i=0;i < rules.length; i++) { |
| 917 | match = this._input.match(this.rules[rules[i]]); |
| 918 | if (match) { |
| 919 | lines = match[0].match(/\n.*/g); |
| 920 | if (lines) this.yylineno += lines.length; |
| 921 | this.yylloc = {first_line: this.yylloc.last_line, |
| 922 | last_line: this.yylineno+1, |
| 923 | first_column: this.yylloc.last_column, |
| 924 | last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length} |
| 925 | this.yytext += match[0]; |
| 926 | this.match += match[0]; |
| 927 | this.matches = match; |
| 928 | this.yyleng = this.yytext.length; |
| 929 | this._more = false; |
| 930 | this._input = this._input.slice(match[0].length); |
| 931 | this.matched += match[0]; |
| 932 | token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]); |
| 933 | if (token) return token; |
| 934 | else return; |
| 935 | } |
| 936 | } |
| 937 | if (this._input === "") { |
| 938 | return this.EOF; |
| 939 | } else { |
| 940 | this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(), |
| 941 | {text: "", token: null, line: this.yylineno}); |
| 942 | } |
| 943 | }, |
| 944 | lex:function lex() { |
| 945 | var r = this.next(); |
| 946 | if (typeof r !== 'undefined') { |
| 947 | return r; |
| 948 | } else { |
| 949 | return this.lex(); |
| 950 | } |
| 951 | }, |
| 952 | begin:function begin(condition) { |
| 953 | this.conditionStack.push(condition); |
| 954 | }, |
| 955 | popState:function popState() { |
| 956 | return this.conditionStack.pop(); |
| 957 | }, |
| 958 | _currentRules:function _currentRules() { |
| 959 | return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules; |
| 960 | }, |
| 961 | topState:function () { |
| 962 | return this.conditionStack[this.conditionStack.length-2]; |
| 963 | }, |
| 964 | pushState:function begin(condition) { |
| 965 | this.begin(condition); |
| 966 | }}); |
| 967 | lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { |
| 968 | |
| 969 | var YYSTATE=YY_START; |
| 970 | switch($avoiding_name_collisions) { |
| 971 | case 0:/* skip whitespace */ |
| 972 | break; |
| 973 | case 1:return 20 |
| 974 | break; |
| 975 | case 2:return 19 |
| 976 | break; |
| 977 | case 3:return 8 |
| 978 | break; |
| 979 | case 4:return 9 |
| 980 | break; |
| 981 | case 5:return 6 |
| 982 | break; |
| 983 | case 6:return 7 |
| 984 | break; |
| 985 | case 7:return 11 |
| 986 | break; |
| 987 | case 8:return 13 |
| 988 | break; |
| 989 | case 9:return 10 |
| 990 | break; |
| 991 | case 10:return 12 |
| 992 | break; |
| 993 | case 11:return 14 |
| 994 | break; |
| 995 | case 12:return 15 |
| 996 | break; |
| 997 | case 13:return 16 |
| 998 | break; |
| 999 | case 14:return 17 |
| 1000 | break; |
| 1001 | case 15:return 18 |
| 1002 | break; |
| 1003 | case 16:return 5 |
| 1004 | break; |
| 1005 | case 17:return 'INVALID' |
| 1006 | break; |
| 1007 | } |
| 1008 | }; |
| 1009 | lexer.rules = [/^\s+/,/^[0-9]+(\.[0-9]+)?\b/,/^n\b/,/^\|\|/,/^&&/,/^\?/,/^:/,/^<=/,/^>=/,/^</,/^>/,/^!=/,/^==/,/^%/,/^\(/,/^\)/,/^$/,/^./]; |
| 1010 | lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],"inclusive":true}};return lexer;})() |
| 1011 | parser.lexer = lexer; |
| 1012 | return parser; |
| 1013 | })(); |
| 1014 | // End parser |
| 1015 | |
| 1016 | // Handle node, amd, and global systems |
| 1017 | if (typeof exports !== 'undefined') { |
| 1018 | if (typeof module !== 'undefined' && module.exports) { |
| 1019 | exports = module.exports = Jed; |
| 1020 | } |
| 1021 | exports.Jed = Jed; |
| 1022 | } |
| 1023 | else { |
| 1024 | if (typeof define === 'function' && define.amd) { |
| 1025 | define(function() { |
| 1026 | return Jed; |
| 1027 | }); |
| 1028 | } |
| 1029 | // Leak a global regardless of module system |
| 1030 | root['Jed'] = Jed; |
| 1031 | } |
| 1032 | |
| 1033 | })(this); |