intl-messageformat 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +4 -3
- package/core.js +1 -1965
- package/dist/core.d.ts +2 -2
- package/dist/core.js +12 -8
- package/dist/core.js.map +1 -1
- package/dist/umd/intl-messageformat.js +12 -7
- package/dist/umd/intl-messageformat.js.map +1 -1
- package/dist/umd/intl-messageformat.min.js +1 -1
- package/dist/umd/intl-messageformat.min.js.map +1 -1
- package/lib/core.d.ts +2 -2
- package/lib/core.js +12 -8
- package/lib/core.js.map +1 -1
- package/package.json +3 -3
- package/src/core.ts +15 -8
package/core.js
CHANGED
|
@@ -1,1965 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
7
|
-
Copyrights licensed under the New BSD License.
|
|
8
|
-
See the accompanying LICENSE file for terms.
|
|
9
|
-
*/
|
|
10
|
-
var __extends = (undefined && undefined.__extends) || (function () {
|
|
11
|
-
var extendStatics = function (d, b) {
|
|
12
|
-
extendStatics = Object.setPrototypeOf ||
|
|
13
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
14
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
15
|
-
return extendStatics(d, b);
|
|
16
|
-
};
|
|
17
|
-
return function (d, b) {
|
|
18
|
-
extendStatics(d, b);
|
|
19
|
-
function __() { this.constructor = d; }
|
|
20
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
21
|
-
};
|
|
22
|
-
})();
|
|
23
|
-
var Compiler = /** @class */ (function () {
|
|
24
|
-
function Compiler(locales, formats, formatters) {
|
|
25
|
-
this.locales = [];
|
|
26
|
-
this.formats = {
|
|
27
|
-
number: {},
|
|
28
|
-
date: {},
|
|
29
|
-
time: {}
|
|
30
|
-
};
|
|
31
|
-
this.pluralNumberFormat = null;
|
|
32
|
-
this.currentPlural = null;
|
|
33
|
-
this.pluralStack = [];
|
|
34
|
-
this.locales = locales;
|
|
35
|
-
this.formats = formats;
|
|
36
|
-
this.formatters = formatters;
|
|
37
|
-
}
|
|
38
|
-
Compiler.prototype.compile = function (ast) {
|
|
39
|
-
this.pluralStack = [];
|
|
40
|
-
this.currentPlural = null;
|
|
41
|
-
this.pluralNumberFormat = null;
|
|
42
|
-
return this.compileMessage(ast);
|
|
43
|
-
};
|
|
44
|
-
Compiler.prototype.compileMessage = function (ast) {
|
|
45
|
-
var _this = this;
|
|
46
|
-
if (!(ast && ast.type === 'messageFormatPattern')) {
|
|
47
|
-
throw new Error('Message AST is not of type: "messageFormatPattern"');
|
|
48
|
-
}
|
|
49
|
-
var elements = ast.elements;
|
|
50
|
-
var pattern = elements
|
|
51
|
-
.filter(function (el) {
|
|
52
|
-
return el.type === 'messageTextElement' || el.type === 'argumentElement';
|
|
53
|
-
})
|
|
54
|
-
.map(function (el) {
|
|
55
|
-
return el.type === 'messageTextElement'
|
|
56
|
-
? _this.compileMessageText(el)
|
|
57
|
-
: _this.compileArgument(el);
|
|
58
|
-
});
|
|
59
|
-
if (pattern.length !== elements.length) {
|
|
60
|
-
throw new Error('Message element does not have a valid type');
|
|
61
|
-
}
|
|
62
|
-
return pattern;
|
|
63
|
-
};
|
|
64
|
-
Compiler.prototype.compileMessageText = function (element) {
|
|
65
|
-
// When this `element` is part of plural sub-pattern and its value contains
|
|
66
|
-
// an unescaped '#', use a `PluralOffsetString` helper to properly output
|
|
67
|
-
// the number with the correct offset in the string.
|
|
68
|
-
if (this.currentPlural && /(^|[^\\])#/g.test(element.value)) {
|
|
69
|
-
// Create a cache a NumberFormat instance that can be reused for any
|
|
70
|
-
// PluralOffsetString instance in this message.
|
|
71
|
-
if (!this.pluralNumberFormat) {
|
|
72
|
-
this.pluralNumberFormat = new Intl.NumberFormat(this.locales);
|
|
73
|
-
}
|
|
74
|
-
return new PluralOffsetString(this.currentPlural.id, this.currentPlural.format.offset, this.pluralNumberFormat, element.value);
|
|
75
|
-
}
|
|
76
|
-
// Unescape the escaped '#'s in the message text.
|
|
77
|
-
return element.value.replace(/\\#/g, '#');
|
|
78
|
-
};
|
|
79
|
-
Compiler.prototype.compileArgument = function (element) {
|
|
80
|
-
var format = element.format, id = element.id;
|
|
81
|
-
var formatters = this.formatters;
|
|
82
|
-
if (!format) {
|
|
83
|
-
return new StringFormat(id);
|
|
84
|
-
}
|
|
85
|
-
var _a = this, formats = _a.formats, locales = _a.locales;
|
|
86
|
-
switch (format.type) {
|
|
87
|
-
case 'numberFormat':
|
|
88
|
-
return {
|
|
89
|
-
id: id,
|
|
90
|
-
format: formatters.getNumberFormat(locales, formats.number[format.style]).format
|
|
91
|
-
};
|
|
92
|
-
case 'dateFormat':
|
|
93
|
-
return {
|
|
94
|
-
id: id,
|
|
95
|
-
format: formatters.getDateTimeFormat(locales, formats.date[format.style]).format
|
|
96
|
-
};
|
|
97
|
-
case 'timeFormat':
|
|
98
|
-
return {
|
|
99
|
-
id: id,
|
|
100
|
-
format: formatters.getDateTimeFormat(locales, formats.time[format.style]).format
|
|
101
|
-
};
|
|
102
|
-
case 'pluralFormat':
|
|
103
|
-
return new PluralFormat(id, format.offset, this.compileOptions(element), formatters.getPluralRules(locales, {
|
|
104
|
-
type: format.ordinal ? 'ordinal' : 'cardinal'
|
|
105
|
-
}));
|
|
106
|
-
case 'selectFormat':
|
|
107
|
-
return new SelectFormat(id, this.compileOptions(element));
|
|
108
|
-
default:
|
|
109
|
-
throw new Error('Message element does not have a valid format type');
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
Compiler.prototype.compileOptions = function (element) {
|
|
113
|
-
var _this = this;
|
|
114
|
-
var format = element.format;
|
|
115
|
-
var options = format.options;
|
|
116
|
-
// Save the current plural element, if any, then set it to a new value when
|
|
117
|
-
// compiling the options sub-patterns. This conforms the spec's algorithm
|
|
118
|
-
// for handling `"#"` syntax in message text.
|
|
119
|
-
this.pluralStack.push(this.currentPlural);
|
|
120
|
-
this.currentPlural = format.type === 'pluralFormat' ? element : null;
|
|
121
|
-
var optionsHash = options.reduce(function (all, option) {
|
|
122
|
-
// Compile the sub-pattern and save it under the options's selector.
|
|
123
|
-
all[option.selector] = _this.compileMessage(option.value);
|
|
124
|
-
return all;
|
|
125
|
-
}, {});
|
|
126
|
-
// Pop the plural stack to put back the original current plural value.
|
|
127
|
-
this.currentPlural = this.pluralStack.pop();
|
|
128
|
-
return optionsHash;
|
|
129
|
-
};
|
|
130
|
-
return Compiler;
|
|
131
|
-
}());
|
|
132
|
-
// -- Compiler Helper Classes --------------------------------------------------
|
|
133
|
-
var Formatter = /** @class */ (function () {
|
|
134
|
-
function Formatter(id) {
|
|
135
|
-
this.id = id;
|
|
136
|
-
}
|
|
137
|
-
return Formatter;
|
|
138
|
-
}());
|
|
139
|
-
var StringFormat = /** @class */ (function (_super) {
|
|
140
|
-
__extends(StringFormat, _super);
|
|
141
|
-
function StringFormat() {
|
|
142
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
143
|
-
}
|
|
144
|
-
StringFormat.prototype.format = function (value) {
|
|
145
|
-
if (!value && typeof value !== 'number') {
|
|
146
|
-
return '';
|
|
147
|
-
}
|
|
148
|
-
return typeof value === 'string' ? value : String(value);
|
|
149
|
-
};
|
|
150
|
-
return StringFormat;
|
|
151
|
-
}(Formatter));
|
|
152
|
-
var PluralFormat = /** @class */ (function () {
|
|
153
|
-
function PluralFormat(id, offset, options, pluralRules) {
|
|
154
|
-
this.id = id;
|
|
155
|
-
this.offset = offset;
|
|
156
|
-
this.options = options;
|
|
157
|
-
this.pluralRules = pluralRules;
|
|
158
|
-
}
|
|
159
|
-
PluralFormat.prototype.getOption = function (value) {
|
|
160
|
-
var options = this.options;
|
|
161
|
-
var option = options['=' + value] ||
|
|
162
|
-
options[this.pluralRules.select(value - this.offset)];
|
|
163
|
-
return option || options.other;
|
|
164
|
-
};
|
|
165
|
-
return PluralFormat;
|
|
166
|
-
}());
|
|
167
|
-
var PluralOffsetString = /** @class */ (function (_super) {
|
|
168
|
-
__extends(PluralOffsetString, _super);
|
|
169
|
-
function PluralOffsetString(id, offset, numberFormat, string) {
|
|
170
|
-
var _this = _super.call(this, id) || this;
|
|
171
|
-
_this.offset = offset;
|
|
172
|
-
_this.numberFormat = numberFormat;
|
|
173
|
-
_this.string = string;
|
|
174
|
-
return _this;
|
|
175
|
-
}
|
|
176
|
-
PluralOffsetString.prototype.format = function (value) {
|
|
177
|
-
var number = this.numberFormat.format(value - this.offset);
|
|
178
|
-
return this.string
|
|
179
|
-
.replace(/(^|[^\\])#/g, '$1' + number)
|
|
180
|
-
.replace(/\\#/g, '#');
|
|
181
|
-
};
|
|
182
|
-
return PluralOffsetString;
|
|
183
|
-
}(Formatter));
|
|
184
|
-
var SelectFormat = /** @class */ (function () {
|
|
185
|
-
function SelectFormat(id, options) {
|
|
186
|
-
this.id = id;
|
|
187
|
-
this.options = options;
|
|
188
|
-
}
|
|
189
|
-
SelectFormat.prototype.getOption = function (value) {
|
|
190
|
-
var options = this.options;
|
|
191
|
-
return options[value] || options.other;
|
|
192
|
-
};
|
|
193
|
-
return SelectFormat;
|
|
194
|
-
}());
|
|
195
|
-
function isSelectOrPluralFormat(f) {
|
|
196
|
-
return !!f.options;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
var parser = /*
|
|
200
|
-
* Generated by PEG.js 0.10.0.
|
|
201
|
-
*
|
|
202
|
-
* http://pegjs.org/
|
|
203
|
-
*/
|
|
204
|
-
(function() {
|
|
205
|
-
|
|
206
|
-
function peg$subclass(child, parent) {
|
|
207
|
-
function ctor() { this.constructor = child; }
|
|
208
|
-
ctor.prototype = parent.prototype;
|
|
209
|
-
child.prototype = new ctor();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function peg$SyntaxError(message, expected, found, location) {
|
|
213
|
-
this.message = message;
|
|
214
|
-
this.expected = expected;
|
|
215
|
-
this.found = found;
|
|
216
|
-
this.location = location;
|
|
217
|
-
this.name = "SyntaxError";
|
|
218
|
-
|
|
219
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
220
|
-
Error.captureStackTrace(this, peg$SyntaxError);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
peg$subclass(peg$SyntaxError, Error);
|
|
225
|
-
|
|
226
|
-
peg$SyntaxError.buildMessage = function(expected, found) {
|
|
227
|
-
var DESCRIBE_EXPECTATION_FNS = {
|
|
228
|
-
literal: function(expectation) {
|
|
229
|
-
return "\"" + literalEscape(expectation.text) + "\"";
|
|
230
|
-
},
|
|
231
|
-
|
|
232
|
-
"class": function(expectation) {
|
|
233
|
-
var escapedParts = "",
|
|
234
|
-
i;
|
|
235
|
-
|
|
236
|
-
for (i = 0; i < expectation.parts.length; i++) {
|
|
237
|
-
escapedParts += expectation.parts[i] instanceof Array
|
|
238
|
-
? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])
|
|
239
|
-
: classEscape(expectation.parts[i]);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
any: function(expectation) {
|
|
246
|
-
return "any character";
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
end: function(expectation) {
|
|
250
|
-
return "end of input";
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
other: function(expectation) {
|
|
254
|
-
return expectation.description;
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
function hex(ch) {
|
|
259
|
-
return ch.charCodeAt(0).toString(16).toUpperCase();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function literalEscape(s) {
|
|
263
|
-
return s
|
|
264
|
-
.replace(/\\/g, '\\\\')
|
|
265
|
-
.replace(/"/g, '\\"')
|
|
266
|
-
.replace(/\0/g, '\\0')
|
|
267
|
-
.replace(/\t/g, '\\t')
|
|
268
|
-
.replace(/\n/g, '\\n')
|
|
269
|
-
.replace(/\r/g, '\\r')
|
|
270
|
-
.replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
|
|
271
|
-
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function classEscape(s) {
|
|
275
|
-
return s
|
|
276
|
-
.replace(/\\/g, '\\\\')
|
|
277
|
-
.replace(/\]/g, '\\]')
|
|
278
|
-
.replace(/\^/g, '\\^')
|
|
279
|
-
.replace(/-/g, '\\-')
|
|
280
|
-
.replace(/\0/g, '\\0')
|
|
281
|
-
.replace(/\t/g, '\\t')
|
|
282
|
-
.replace(/\n/g, '\\n')
|
|
283
|
-
.replace(/\r/g, '\\r')
|
|
284
|
-
.replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
|
|
285
|
-
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function describeExpectation(expectation) {
|
|
289
|
-
return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function describeExpected(expected) {
|
|
293
|
-
var descriptions = new Array(expected.length),
|
|
294
|
-
i, j;
|
|
295
|
-
|
|
296
|
-
for (i = 0; i < expected.length; i++) {
|
|
297
|
-
descriptions[i] = describeExpectation(expected[i]);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
descriptions.sort();
|
|
301
|
-
|
|
302
|
-
if (descriptions.length > 0) {
|
|
303
|
-
for (i = 1, j = 1; i < descriptions.length; i++) {
|
|
304
|
-
if (descriptions[i - 1] !== descriptions[i]) {
|
|
305
|
-
descriptions[j] = descriptions[i];
|
|
306
|
-
j++;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
descriptions.length = j;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
switch (descriptions.length) {
|
|
313
|
-
case 1:
|
|
314
|
-
return descriptions[0];
|
|
315
|
-
|
|
316
|
-
case 2:
|
|
317
|
-
return descriptions[0] + " or " + descriptions[1];
|
|
318
|
-
|
|
319
|
-
default:
|
|
320
|
-
return descriptions.slice(0, -1).join(", ")
|
|
321
|
-
+ ", or "
|
|
322
|
-
+ descriptions[descriptions.length - 1];
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function describeFound(found) {
|
|
327
|
-
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
function peg$parse(input, options) {
|
|
334
|
-
options = options !== void 0 ? options : {};
|
|
335
|
-
|
|
336
|
-
var peg$FAILED = {},
|
|
337
|
-
|
|
338
|
-
peg$startRuleFunctions = { start: peg$parsestart },
|
|
339
|
-
peg$startRuleFunction = peg$parsestart,
|
|
340
|
-
|
|
341
|
-
peg$c0 = function(elements) {
|
|
342
|
-
return {
|
|
343
|
-
type : 'messageFormatPattern',
|
|
344
|
-
elements: elements,
|
|
345
|
-
location: location()
|
|
346
|
-
};
|
|
347
|
-
},
|
|
348
|
-
peg$c1 = function(chunks) {
|
|
349
|
-
return chunks.reduce(function (all, chunk) {
|
|
350
|
-
return all.concat(chunk)
|
|
351
|
-
}, []).join('')
|
|
352
|
-
},
|
|
353
|
-
peg$c2 = function(messageText) {
|
|
354
|
-
return {
|
|
355
|
-
type : 'messageTextElement',
|
|
356
|
-
value: messageText,
|
|
357
|
-
location: location()
|
|
358
|
-
};
|
|
359
|
-
},
|
|
360
|
-
peg$c3 = function(chars) { return chars.join(''); },
|
|
361
|
-
peg$c4 = "{",
|
|
362
|
-
peg$c5 = peg$literalExpectation("{", false),
|
|
363
|
-
peg$c6 = ",",
|
|
364
|
-
peg$c7 = peg$literalExpectation(",", false),
|
|
365
|
-
peg$c8 = "}",
|
|
366
|
-
peg$c9 = peg$literalExpectation("}", false),
|
|
367
|
-
peg$c10 = function(id, format) {
|
|
368
|
-
return {
|
|
369
|
-
type : 'argumentElement',
|
|
370
|
-
id : id,
|
|
371
|
-
format: format && format[2],
|
|
372
|
-
location: location()
|
|
373
|
-
};
|
|
374
|
-
},
|
|
375
|
-
peg$c11 = "number",
|
|
376
|
-
peg$c12 = peg$literalExpectation("number", false),
|
|
377
|
-
peg$c13 = "date",
|
|
378
|
-
peg$c14 = peg$literalExpectation("date", false),
|
|
379
|
-
peg$c15 = "time",
|
|
380
|
-
peg$c16 = peg$literalExpectation("time", false),
|
|
381
|
-
peg$c17 = function(type, style) {
|
|
382
|
-
return {
|
|
383
|
-
type : type + 'Format',
|
|
384
|
-
style: style && style[2],
|
|
385
|
-
location: location()
|
|
386
|
-
};
|
|
387
|
-
},
|
|
388
|
-
peg$c18 = "plural",
|
|
389
|
-
peg$c19 = peg$literalExpectation("plural", false),
|
|
390
|
-
peg$c20 = function(pluralStyle) {
|
|
391
|
-
return {
|
|
392
|
-
type : pluralStyle.type,
|
|
393
|
-
ordinal: false,
|
|
394
|
-
offset : pluralStyle.offset || 0,
|
|
395
|
-
options: pluralStyle.options,
|
|
396
|
-
location: location()
|
|
397
|
-
};
|
|
398
|
-
},
|
|
399
|
-
peg$c21 = "selectordinal",
|
|
400
|
-
peg$c22 = peg$literalExpectation("selectordinal", false),
|
|
401
|
-
peg$c23 = function(pluralStyle) {
|
|
402
|
-
return {
|
|
403
|
-
type : pluralStyle.type,
|
|
404
|
-
ordinal: true,
|
|
405
|
-
offset : pluralStyle.offset || 0,
|
|
406
|
-
options: pluralStyle.options,
|
|
407
|
-
location: location()
|
|
408
|
-
}
|
|
409
|
-
},
|
|
410
|
-
peg$c24 = "select",
|
|
411
|
-
peg$c25 = peg$literalExpectation("select", false),
|
|
412
|
-
peg$c26 = function(options) {
|
|
413
|
-
return {
|
|
414
|
-
type : 'selectFormat',
|
|
415
|
-
options: options,
|
|
416
|
-
location: location()
|
|
417
|
-
};
|
|
418
|
-
},
|
|
419
|
-
peg$c27 = "=",
|
|
420
|
-
peg$c28 = peg$literalExpectation("=", false),
|
|
421
|
-
peg$c29 = function(selector, pattern) {
|
|
422
|
-
return {
|
|
423
|
-
type : 'optionalFormatPattern',
|
|
424
|
-
selector: selector,
|
|
425
|
-
value : pattern,
|
|
426
|
-
location: location()
|
|
427
|
-
};
|
|
428
|
-
},
|
|
429
|
-
peg$c30 = "offset:",
|
|
430
|
-
peg$c31 = peg$literalExpectation("offset:", false),
|
|
431
|
-
peg$c32 = function(number) {
|
|
432
|
-
return number;
|
|
433
|
-
},
|
|
434
|
-
peg$c33 = function(offset, options) {
|
|
435
|
-
return {
|
|
436
|
-
type : 'pluralFormat',
|
|
437
|
-
offset : offset,
|
|
438
|
-
options: options,
|
|
439
|
-
location: location()
|
|
440
|
-
};
|
|
441
|
-
},
|
|
442
|
-
peg$c34 = peg$otherExpectation("whitespace"),
|
|
443
|
-
peg$c35 = /^[ \t\n\r]/,
|
|
444
|
-
peg$c36 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false),
|
|
445
|
-
peg$c37 = peg$otherExpectation("optionalWhitespace"),
|
|
446
|
-
peg$c38 = /^[0-9]/,
|
|
447
|
-
peg$c39 = peg$classExpectation([["0", "9"]], false, false),
|
|
448
|
-
peg$c40 = /^[0-9a-f]/i,
|
|
449
|
-
peg$c41 = peg$classExpectation([["0", "9"], ["a", "f"]], false, true),
|
|
450
|
-
peg$c42 = "0",
|
|
451
|
-
peg$c43 = peg$literalExpectation("0", false),
|
|
452
|
-
peg$c44 = /^[1-9]/,
|
|
453
|
-
peg$c45 = peg$classExpectation([["1", "9"]], false, false),
|
|
454
|
-
peg$c46 = function(digits) {
|
|
455
|
-
return parseInt(digits, 10);
|
|
456
|
-
},
|
|
457
|
-
peg$c47 = "'",
|
|
458
|
-
peg$c48 = peg$literalExpectation("'", false),
|
|
459
|
-
peg$c49 = /^[ \t\n\r,.+={}#]/,
|
|
460
|
-
peg$c50 = peg$classExpectation([" ", "\t", "\n", "\r", ",", ".", "+", "=", "{", "}", "#"], false, false),
|
|
461
|
-
peg$c51 = peg$anyExpectation(),
|
|
462
|
-
peg$c52 = function(char) { return char; },
|
|
463
|
-
peg$c53 = function(sequence) { return sequence; },
|
|
464
|
-
peg$c54 = /^[^{}\\\0-\x1F\x7F \t\n\r]/,
|
|
465
|
-
peg$c55 = peg$classExpectation(["{", "}", "\\", ["\0", "\x1F"], "\x7F", " ", "\t", "\n", "\r"], true, false),
|
|
466
|
-
peg$c56 = "\\\\",
|
|
467
|
-
peg$c57 = peg$literalExpectation("\\\\", false),
|
|
468
|
-
peg$c58 = function() { return '\\'; },
|
|
469
|
-
peg$c59 = "\\#",
|
|
470
|
-
peg$c60 = peg$literalExpectation("\\#", false),
|
|
471
|
-
peg$c61 = function() { return '\\#'; },
|
|
472
|
-
peg$c62 = "\\{",
|
|
473
|
-
peg$c63 = peg$literalExpectation("\\{", false),
|
|
474
|
-
peg$c64 = function() { return '\u007B'; },
|
|
475
|
-
peg$c65 = "\\}",
|
|
476
|
-
peg$c66 = peg$literalExpectation("\\}", false),
|
|
477
|
-
peg$c67 = function() { return '\u007D'; },
|
|
478
|
-
peg$c68 = "\\u",
|
|
479
|
-
peg$c69 = peg$literalExpectation("\\u", false),
|
|
480
|
-
peg$c70 = function(digits) {
|
|
481
|
-
return String.fromCharCode(parseInt(digits, 16));
|
|
482
|
-
},
|
|
483
|
-
|
|
484
|
-
peg$currPos = 0,
|
|
485
|
-
peg$savedPos = 0,
|
|
486
|
-
peg$posDetailsCache = [{ line: 1, column: 1 }],
|
|
487
|
-
peg$maxFailPos = 0,
|
|
488
|
-
peg$maxFailExpected = [],
|
|
489
|
-
peg$silentFails = 0,
|
|
490
|
-
|
|
491
|
-
peg$result;
|
|
492
|
-
|
|
493
|
-
if ("startRule" in options) {
|
|
494
|
-
if (!(options.startRule in peg$startRuleFunctions)) {
|
|
495
|
-
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
function location() {
|
|
502
|
-
return peg$computeLocation(peg$savedPos, peg$currPos);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function peg$literalExpectation(text, ignoreCase) {
|
|
506
|
-
return { type: "literal", text: text, ignoreCase: ignoreCase };
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
function peg$classExpectation(parts, inverted, ignoreCase) {
|
|
510
|
-
return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
function peg$anyExpectation() {
|
|
514
|
-
return { type: "any" };
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function peg$endExpectation() {
|
|
518
|
-
return { type: "end" };
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
function peg$otherExpectation(description) {
|
|
522
|
-
return { type: "other", description: description };
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
function peg$computePosDetails(pos) {
|
|
526
|
-
var details = peg$posDetailsCache[pos], p;
|
|
527
|
-
|
|
528
|
-
if (details) {
|
|
529
|
-
return details;
|
|
530
|
-
} else {
|
|
531
|
-
p = pos - 1;
|
|
532
|
-
while (!peg$posDetailsCache[p]) {
|
|
533
|
-
p--;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
details = peg$posDetailsCache[p];
|
|
537
|
-
details = {
|
|
538
|
-
line: details.line,
|
|
539
|
-
column: details.column
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
while (p < pos) {
|
|
543
|
-
if (input.charCodeAt(p) === 10) {
|
|
544
|
-
details.line++;
|
|
545
|
-
details.column = 1;
|
|
546
|
-
} else {
|
|
547
|
-
details.column++;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
p++;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
peg$posDetailsCache[pos] = details;
|
|
554
|
-
return details;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function peg$computeLocation(startPos, endPos) {
|
|
559
|
-
var startPosDetails = peg$computePosDetails(startPos),
|
|
560
|
-
endPosDetails = peg$computePosDetails(endPos);
|
|
561
|
-
|
|
562
|
-
return {
|
|
563
|
-
start: {
|
|
564
|
-
offset: startPos,
|
|
565
|
-
line: startPosDetails.line,
|
|
566
|
-
column: startPosDetails.column
|
|
567
|
-
},
|
|
568
|
-
end: {
|
|
569
|
-
offset: endPos,
|
|
570
|
-
line: endPosDetails.line,
|
|
571
|
-
column: endPosDetails.column
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
function peg$fail(expected) {
|
|
577
|
-
if (peg$currPos < peg$maxFailPos) { return; }
|
|
578
|
-
|
|
579
|
-
if (peg$currPos > peg$maxFailPos) {
|
|
580
|
-
peg$maxFailPos = peg$currPos;
|
|
581
|
-
peg$maxFailExpected = [];
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
peg$maxFailExpected.push(expected);
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function peg$buildStructuredError(expected, found, location) {
|
|
588
|
-
return new peg$SyntaxError(
|
|
589
|
-
peg$SyntaxError.buildMessage(expected, found),
|
|
590
|
-
expected,
|
|
591
|
-
found,
|
|
592
|
-
location
|
|
593
|
-
);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
function peg$parsestart() {
|
|
597
|
-
var s0;
|
|
598
|
-
|
|
599
|
-
s0 = peg$parsemessageFormatPattern();
|
|
600
|
-
|
|
601
|
-
return s0;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
function peg$parsemessageFormatPattern() {
|
|
605
|
-
var s0, s1, s2;
|
|
606
|
-
|
|
607
|
-
s0 = peg$currPos;
|
|
608
|
-
s1 = [];
|
|
609
|
-
s2 = peg$parsemessageFormatElement();
|
|
610
|
-
while (s2 !== peg$FAILED) {
|
|
611
|
-
s1.push(s2);
|
|
612
|
-
s2 = peg$parsemessageFormatElement();
|
|
613
|
-
}
|
|
614
|
-
if (s1 !== peg$FAILED) {
|
|
615
|
-
peg$savedPos = s0;
|
|
616
|
-
s1 = peg$c0(s1);
|
|
617
|
-
}
|
|
618
|
-
s0 = s1;
|
|
619
|
-
|
|
620
|
-
return s0;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function peg$parsemessageFormatElement() {
|
|
624
|
-
var s0;
|
|
625
|
-
|
|
626
|
-
s0 = peg$parsemessageTextElement();
|
|
627
|
-
if (s0 === peg$FAILED) {
|
|
628
|
-
s0 = peg$parseargumentElement();
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
return s0;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
function peg$parsemessageText() {
|
|
635
|
-
var s0, s1, s2, s3, s4, s5;
|
|
636
|
-
|
|
637
|
-
s0 = peg$currPos;
|
|
638
|
-
s1 = [];
|
|
639
|
-
s2 = peg$currPos;
|
|
640
|
-
s3 = peg$parse_();
|
|
641
|
-
if (s3 !== peg$FAILED) {
|
|
642
|
-
s4 = peg$parsechars();
|
|
643
|
-
if (s4 !== peg$FAILED) {
|
|
644
|
-
s5 = peg$parse_();
|
|
645
|
-
if (s5 !== peg$FAILED) {
|
|
646
|
-
s3 = [s3, s4, s5];
|
|
647
|
-
s2 = s3;
|
|
648
|
-
} else {
|
|
649
|
-
peg$currPos = s2;
|
|
650
|
-
s2 = peg$FAILED;
|
|
651
|
-
}
|
|
652
|
-
} else {
|
|
653
|
-
peg$currPos = s2;
|
|
654
|
-
s2 = peg$FAILED;
|
|
655
|
-
}
|
|
656
|
-
} else {
|
|
657
|
-
peg$currPos = s2;
|
|
658
|
-
s2 = peg$FAILED;
|
|
659
|
-
}
|
|
660
|
-
if (s2 !== peg$FAILED) {
|
|
661
|
-
while (s2 !== peg$FAILED) {
|
|
662
|
-
s1.push(s2);
|
|
663
|
-
s2 = peg$currPos;
|
|
664
|
-
s3 = peg$parse_();
|
|
665
|
-
if (s3 !== peg$FAILED) {
|
|
666
|
-
s4 = peg$parsechars();
|
|
667
|
-
if (s4 !== peg$FAILED) {
|
|
668
|
-
s5 = peg$parse_();
|
|
669
|
-
if (s5 !== peg$FAILED) {
|
|
670
|
-
s3 = [s3, s4, s5];
|
|
671
|
-
s2 = s3;
|
|
672
|
-
} else {
|
|
673
|
-
peg$currPos = s2;
|
|
674
|
-
s2 = peg$FAILED;
|
|
675
|
-
}
|
|
676
|
-
} else {
|
|
677
|
-
peg$currPos = s2;
|
|
678
|
-
s2 = peg$FAILED;
|
|
679
|
-
}
|
|
680
|
-
} else {
|
|
681
|
-
peg$currPos = s2;
|
|
682
|
-
s2 = peg$FAILED;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
} else {
|
|
686
|
-
s1 = peg$FAILED;
|
|
687
|
-
}
|
|
688
|
-
if (s1 !== peg$FAILED) {
|
|
689
|
-
peg$savedPos = s0;
|
|
690
|
-
s1 = peg$c1(s1);
|
|
691
|
-
}
|
|
692
|
-
s0 = s1;
|
|
693
|
-
if (s0 === peg$FAILED) {
|
|
694
|
-
s0 = peg$currPos;
|
|
695
|
-
s1 = peg$parsews();
|
|
696
|
-
if (s1 !== peg$FAILED) {
|
|
697
|
-
s0 = input.substring(s0, peg$currPos);
|
|
698
|
-
} else {
|
|
699
|
-
s0 = s1;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
return s0;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
function peg$parsemessageTextElement() {
|
|
707
|
-
var s0, s1;
|
|
708
|
-
|
|
709
|
-
s0 = peg$currPos;
|
|
710
|
-
s1 = peg$parsemessageText();
|
|
711
|
-
if (s1 !== peg$FAILED) {
|
|
712
|
-
peg$savedPos = s0;
|
|
713
|
-
s1 = peg$c2(s1);
|
|
714
|
-
}
|
|
715
|
-
s0 = s1;
|
|
716
|
-
|
|
717
|
-
return s0;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
function peg$parseargument() {
|
|
721
|
-
var s0, s1, s2;
|
|
722
|
-
|
|
723
|
-
s0 = peg$parsenumber();
|
|
724
|
-
if (s0 === peg$FAILED) {
|
|
725
|
-
s0 = peg$currPos;
|
|
726
|
-
s1 = [];
|
|
727
|
-
s2 = peg$parsequoteEscapedChar();
|
|
728
|
-
while (s2 !== peg$FAILED) {
|
|
729
|
-
s1.push(s2);
|
|
730
|
-
s2 = peg$parsequoteEscapedChar();
|
|
731
|
-
}
|
|
732
|
-
if (s1 !== peg$FAILED) {
|
|
733
|
-
peg$savedPos = s0;
|
|
734
|
-
s1 = peg$c3(s1);
|
|
735
|
-
}
|
|
736
|
-
s0 = s1;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
return s0;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
function peg$parseargumentElement() {
|
|
743
|
-
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
|
|
744
|
-
|
|
745
|
-
s0 = peg$currPos;
|
|
746
|
-
if (input.charCodeAt(peg$currPos) === 123) {
|
|
747
|
-
s1 = peg$c4;
|
|
748
|
-
peg$currPos++;
|
|
749
|
-
} else {
|
|
750
|
-
s1 = peg$FAILED;
|
|
751
|
-
if (peg$silentFails === 0) { peg$fail(peg$c5); }
|
|
752
|
-
}
|
|
753
|
-
if (s1 !== peg$FAILED) {
|
|
754
|
-
s2 = peg$parse_();
|
|
755
|
-
if (s2 !== peg$FAILED) {
|
|
756
|
-
s3 = peg$parseargument();
|
|
757
|
-
if (s3 !== peg$FAILED) {
|
|
758
|
-
s4 = peg$parse_();
|
|
759
|
-
if (s4 !== peg$FAILED) {
|
|
760
|
-
s5 = peg$currPos;
|
|
761
|
-
if (input.charCodeAt(peg$currPos) === 44) {
|
|
762
|
-
s6 = peg$c6;
|
|
763
|
-
peg$currPos++;
|
|
764
|
-
} else {
|
|
765
|
-
s6 = peg$FAILED;
|
|
766
|
-
if (peg$silentFails === 0) { peg$fail(peg$c7); }
|
|
767
|
-
}
|
|
768
|
-
if (s6 !== peg$FAILED) {
|
|
769
|
-
s7 = peg$parse_();
|
|
770
|
-
if (s7 !== peg$FAILED) {
|
|
771
|
-
s8 = peg$parseelementFormat();
|
|
772
|
-
if (s8 !== peg$FAILED) {
|
|
773
|
-
s6 = [s6, s7, s8];
|
|
774
|
-
s5 = s6;
|
|
775
|
-
} else {
|
|
776
|
-
peg$currPos = s5;
|
|
777
|
-
s5 = peg$FAILED;
|
|
778
|
-
}
|
|
779
|
-
} else {
|
|
780
|
-
peg$currPos = s5;
|
|
781
|
-
s5 = peg$FAILED;
|
|
782
|
-
}
|
|
783
|
-
} else {
|
|
784
|
-
peg$currPos = s5;
|
|
785
|
-
s5 = peg$FAILED;
|
|
786
|
-
}
|
|
787
|
-
if (s5 === peg$FAILED) {
|
|
788
|
-
s5 = null;
|
|
789
|
-
}
|
|
790
|
-
if (s5 !== peg$FAILED) {
|
|
791
|
-
s6 = peg$parse_();
|
|
792
|
-
if (s6 !== peg$FAILED) {
|
|
793
|
-
if (input.charCodeAt(peg$currPos) === 125) {
|
|
794
|
-
s7 = peg$c8;
|
|
795
|
-
peg$currPos++;
|
|
796
|
-
} else {
|
|
797
|
-
s7 = peg$FAILED;
|
|
798
|
-
if (peg$silentFails === 0) { peg$fail(peg$c9); }
|
|
799
|
-
}
|
|
800
|
-
if (s7 !== peg$FAILED) {
|
|
801
|
-
peg$savedPos = s0;
|
|
802
|
-
s1 = peg$c10(s3, s5);
|
|
803
|
-
s0 = s1;
|
|
804
|
-
} else {
|
|
805
|
-
peg$currPos = s0;
|
|
806
|
-
s0 = peg$FAILED;
|
|
807
|
-
}
|
|
808
|
-
} else {
|
|
809
|
-
peg$currPos = s0;
|
|
810
|
-
s0 = peg$FAILED;
|
|
811
|
-
}
|
|
812
|
-
} else {
|
|
813
|
-
peg$currPos = s0;
|
|
814
|
-
s0 = peg$FAILED;
|
|
815
|
-
}
|
|
816
|
-
} else {
|
|
817
|
-
peg$currPos = s0;
|
|
818
|
-
s0 = peg$FAILED;
|
|
819
|
-
}
|
|
820
|
-
} else {
|
|
821
|
-
peg$currPos = s0;
|
|
822
|
-
s0 = peg$FAILED;
|
|
823
|
-
}
|
|
824
|
-
} else {
|
|
825
|
-
peg$currPos = s0;
|
|
826
|
-
s0 = peg$FAILED;
|
|
827
|
-
}
|
|
828
|
-
} else {
|
|
829
|
-
peg$currPos = s0;
|
|
830
|
-
s0 = peg$FAILED;
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
return s0;
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
function peg$parseelementFormat() {
|
|
837
|
-
var s0;
|
|
838
|
-
|
|
839
|
-
s0 = peg$parsesimpleFormat();
|
|
840
|
-
if (s0 === peg$FAILED) {
|
|
841
|
-
s0 = peg$parsepluralFormat();
|
|
842
|
-
if (s0 === peg$FAILED) {
|
|
843
|
-
s0 = peg$parseselectOrdinalFormat();
|
|
844
|
-
if (s0 === peg$FAILED) {
|
|
845
|
-
s0 = peg$parseselectFormat();
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
return s0;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
function peg$parsesimpleFormat() {
|
|
854
|
-
var s0, s1, s2, s3, s4, s5, s6;
|
|
855
|
-
|
|
856
|
-
s0 = peg$currPos;
|
|
857
|
-
if (input.substr(peg$currPos, 6) === peg$c11) {
|
|
858
|
-
s1 = peg$c11;
|
|
859
|
-
peg$currPos += 6;
|
|
860
|
-
} else {
|
|
861
|
-
s1 = peg$FAILED;
|
|
862
|
-
if (peg$silentFails === 0) { peg$fail(peg$c12); }
|
|
863
|
-
}
|
|
864
|
-
if (s1 === peg$FAILED) {
|
|
865
|
-
if (input.substr(peg$currPos, 4) === peg$c13) {
|
|
866
|
-
s1 = peg$c13;
|
|
867
|
-
peg$currPos += 4;
|
|
868
|
-
} else {
|
|
869
|
-
s1 = peg$FAILED;
|
|
870
|
-
if (peg$silentFails === 0) { peg$fail(peg$c14); }
|
|
871
|
-
}
|
|
872
|
-
if (s1 === peg$FAILED) {
|
|
873
|
-
if (input.substr(peg$currPos, 4) === peg$c15) {
|
|
874
|
-
s1 = peg$c15;
|
|
875
|
-
peg$currPos += 4;
|
|
876
|
-
} else {
|
|
877
|
-
s1 = peg$FAILED;
|
|
878
|
-
if (peg$silentFails === 0) { peg$fail(peg$c16); }
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
if (s1 !== peg$FAILED) {
|
|
883
|
-
s2 = peg$parse_();
|
|
884
|
-
if (s2 !== peg$FAILED) {
|
|
885
|
-
s3 = peg$currPos;
|
|
886
|
-
if (input.charCodeAt(peg$currPos) === 44) {
|
|
887
|
-
s4 = peg$c6;
|
|
888
|
-
peg$currPos++;
|
|
889
|
-
} else {
|
|
890
|
-
s4 = peg$FAILED;
|
|
891
|
-
if (peg$silentFails === 0) { peg$fail(peg$c7); }
|
|
892
|
-
}
|
|
893
|
-
if (s4 !== peg$FAILED) {
|
|
894
|
-
s5 = peg$parse_();
|
|
895
|
-
if (s5 !== peg$FAILED) {
|
|
896
|
-
s6 = peg$parsechars();
|
|
897
|
-
if (s6 !== peg$FAILED) {
|
|
898
|
-
s4 = [s4, s5, s6];
|
|
899
|
-
s3 = s4;
|
|
900
|
-
} else {
|
|
901
|
-
peg$currPos = s3;
|
|
902
|
-
s3 = peg$FAILED;
|
|
903
|
-
}
|
|
904
|
-
} else {
|
|
905
|
-
peg$currPos = s3;
|
|
906
|
-
s3 = peg$FAILED;
|
|
907
|
-
}
|
|
908
|
-
} else {
|
|
909
|
-
peg$currPos = s3;
|
|
910
|
-
s3 = peg$FAILED;
|
|
911
|
-
}
|
|
912
|
-
if (s3 === peg$FAILED) {
|
|
913
|
-
s3 = null;
|
|
914
|
-
}
|
|
915
|
-
if (s3 !== peg$FAILED) {
|
|
916
|
-
peg$savedPos = s0;
|
|
917
|
-
s1 = peg$c17(s1, s3);
|
|
918
|
-
s0 = s1;
|
|
919
|
-
} else {
|
|
920
|
-
peg$currPos = s0;
|
|
921
|
-
s0 = peg$FAILED;
|
|
922
|
-
}
|
|
923
|
-
} else {
|
|
924
|
-
peg$currPos = s0;
|
|
925
|
-
s0 = peg$FAILED;
|
|
926
|
-
}
|
|
927
|
-
} else {
|
|
928
|
-
peg$currPos = s0;
|
|
929
|
-
s0 = peg$FAILED;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
return s0;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
function peg$parsepluralFormat() {
|
|
936
|
-
var s0, s1, s2, s3, s4, s5;
|
|
937
|
-
|
|
938
|
-
s0 = peg$currPos;
|
|
939
|
-
if (input.substr(peg$currPos, 6) === peg$c18) {
|
|
940
|
-
s1 = peg$c18;
|
|
941
|
-
peg$currPos += 6;
|
|
942
|
-
} else {
|
|
943
|
-
s1 = peg$FAILED;
|
|
944
|
-
if (peg$silentFails === 0) { peg$fail(peg$c19); }
|
|
945
|
-
}
|
|
946
|
-
if (s1 !== peg$FAILED) {
|
|
947
|
-
s2 = peg$parse_();
|
|
948
|
-
if (s2 !== peg$FAILED) {
|
|
949
|
-
if (input.charCodeAt(peg$currPos) === 44) {
|
|
950
|
-
s3 = peg$c6;
|
|
951
|
-
peg$currPos++;
|
|
952
|
-
} else {
|
|
953
|
-
s3 = peg$FAILED;
|
|
954
|
-
if (peg$silentFails === 0) { peg$fail(peg$c7); }
|
|
955
|
-
}
|
|
956
|
-
if (s3 !== peg$FAILED) {
|
|
957
|
-
s4 = peg$parse_();
|
|
958
|
-
if (s4 !== peg$FAILED) {
|
|
959
|
-
s5 = peg$parsepluralStyle();
|
|
960
|
-
if (s5 !== peg$FAILED) {
|
|
961
|
-
peg$savedPos = s0;
|
|
962
|
-
s1 = peg$c20(s5);
|
|
963
|
-
s0 = s1;
|
|
964
|
-
} else {
|
|
965
|
-
peg$currPos = s0;
|
|
966
|
-
s0 = peg$FAILED;
|
|
967
|
-
}
|
|
968
|
-
} else {
|
|
969
|
-
peg$currPos = s0;
|
|
970
|
-
s0 = peg$FAILED;
|
|
971
|
-
}
|
|
972
|
-
} else {
|
|
973
|
-
peg$currPos = s0;
|
|
974
|
-
s0 = peg$FAILED;
|
|
975
|
-
}
|
|
976
|
-
} else {
|
|
977
|
-
peg$currPos = s0;
|
|
978
|
-
s0 = peg$FAILED;
|
|
979
|
-
}
|
|
980
|
-
} else {
|
|
981
|
-
peg$currPos = s0;
|
|
982
|
-
s0 = peg$FAILED;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
return s0;
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
function peg$parseselectOrdinalFormat() {
|
|
989
|
-
var s0, s1, s2, s3, s4, s5;
|
|
990
|
-
|
|
991
|
-
s0 = peg$currPos;
|
|
992
|
-
if (input.substr(peg$currPos, 13) === peg$c21) {
|
|
993
|
-
s1 = peg$c21;
|
|
994
|
-
peg$currPos += 13;
|
|
995
|
-
} else {
|
|
996
|
-
s1 = peg$FAILED;
|
|
997
|
-
if (peg$silentFails === 0) { peg$fail(peg$c22); }
|
|
998
|
-
}
|
|
999
|
-
if (s1 !== peg$FAILED) {
|
|
1000
|
-
s2 = peg$parse_();
|
|
1001
|
-
if (s2 !== peg$FAILED) {
|
|
1002
|
-
if (input.charCodeAt(peg$currPos) === 44) {
|
|
1003
|
-
s3 = peg$c6;
|
|
1004
|
-
peg$currPos++;
|
|
1005
|
-
} else {
|
|
1006
|
-
s3 = peg$FAILED;
|
|
1007
|
-
if (peg$silentFails === 0) { peg$fail(peg$c7); }
|
|
1008
|
-
}
|
|
1009
|
-
if (s3 !== peg$FAILED) {
|
|
1010
|
-
s4 = peg$parse_();
|
|
1011
|
-
if (s4 !== peg$FAILED) {
|
|
1012
|
-
s5 = peg$parsepluralStyle();
|
|
1013
|
-
if (s5 !== peg$FAILED) {
|
|
1014
|
-
peg$savedPos = s0;
|
|
1015
|
-
s1 = peg$c23(s5);
|
|
1016
|
-
s0 = s1;
|
|
1017
|
-
} else {
|
|
1018
|
-
peg$currPos = s0;
|
|
1019
|
-
s0 = peg$FAILED;
|
|
1020
|
-
}
|
|
1021
|
-
} else {
|
|
1022
|
-
peg$currPos = s0;
|
|
1023
|
-
s0 = peg$FAILED;
|
|
1024
|
-
}
|
|
1025
|
-
} else {
|
|
1026
|
-
peg$currPos = s0;
|
|
1027
|
-
s0 = peg$FAILED;
|
|
1028
|
-
}
|
|
1029
|
-
} else {
|
|
1030
|
-
peg$currPos = s0;
|
|
1031
|
-
s0 = peg$FAILED;
|
|
1032
|
-
}
|
|
1033
|
-
} else {
|
|
1034
|
-
peg$currPos = s0;
|
|
1035
|
-
s0 = peg$FAILED;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
return s0;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
function peg$parseselectFormat() {
|
|
1042
|
-
var s0, s1, s2, s3, s4, s5, s6;
|
|
1043
|
-
|
|
1044
|
-
s0 = peg$currPos;
|
|
1045
|
-
if (input.substr(peg$currPos, 6) === peg$c24) {
|
|
1046
|
-
s1 = peg$c24;
|
|
1047
|
-
peg$currPos += 6;
|
|
1048
|
-
} else {
|
|
1049
|
-
s1 = peg$FAILED;
|
|
1050
|
-
if (peg$silentFails === 0) { peg$fail(peg$c25); }
|
|
1051
|
-
}
|
|
1052
|
-
if (s1 !== peg$FAILED) {
|
|
1053
|
-
s2 = peg$parse_();
|
|
1054
|
-
if (s2 !== peg$FAILED) {
|
|
1055
|
-
if (input.charCodeAt(peg$currPos) === 44) {
|
|
1056
|
-
s3 = peg$c6;
|
|
1057
|
-
peg$currPos++;
|
|
1058
|
-
} else {
|
|
1059
|
-
s3 = peg$FAILED;
|
|
1060
|
-
if (peg$silentFails === 0) { peg$fail(peg$c7); }
|
|
1061
|
-
}
|
|
1062
|
-
if (s3 !== peg$FAILED) {
|
|
1063
|
-
s4 = peg$parse_();
|
|
1064
|
-
if (s4 !== peg$FAILED) {
|
|
1065
|
-
s5 = [];
|
|
1066
|
-
s6 = peg$parseoptionalFormatPattern();
|
|
1067
|
-
if (s6 !== peg$FAILED) {
|
|
1068
|
-
while (s6 !== peg$FAILED) {
|
|
1069
|
-
s5.push(s6);
|
|
1070
|
-
s6 = peg$parseoptionalFormatPattern();
|
|
1071
|
-
}
|
|
1072
|
-
} else {
|
|
1073
|
-
s5 = peg$FAILED;
|
|
1074
|
-
}
|
|
1075
|
-
if (s5 !== peg$FAILED) {
|
|
1076
|
-
peg$savedPos = s0;
|
|
1077
|
-
s1 = peg$c26(s5);
|
|
1078
|
-
s0 = s1;
|
|
1079
|
-
} else {
|
|
1080
|
-
peg$currPos = s0;
|
|
1081
|
-
s0 = peg$FAILED;
|
|
1082
|
-
}
|
|
1083
|
-
} else {
|
|
1084
|
-
peg$currPos = s0;
|
|
1085
|
-
s0 = peg$FAILED;
|
|
1086
|
-
}
|
|
1087
|
-
} else {
|
|
1088
|
-
peg$currPos = s0;
|
|
1089
|
-
s0 = peg$FAILED;
|
|
1090
|
-
}
|
|
1091
|
-
} else {
|
|
1092
|
-
peg$currPos = s0;
|
|
1093
|
-
s0 = peg$FAILED;
|
|
1094
|
-
}
|
|
1095
|
-
} else {
|
|
1096
|
-
peg$currPos = s0;
|
|
1097
|
-
s0 = peg$FAILED;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
return s0;
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
function peg$parseselector() {
|
|
1104
|
-
var s0, s1, s2, s3;
|
|
1105
|
-
|
|
1106
|
-
s0 = peg$currPos;
|
|
1107
|
-
s1 = peg$currPos;
|
|
1108
|
-
if (input.charCodeAt(peg$currPos) === 61) {
|
|
1109
|
-
s2 = peg$c27;
|
|
1110
|
-
peg$currPos++;
|
|
1111
|
-
} else {
|
|
1112
|
-
s2 = peg$FAILED;
|
|
1113
|
-
if (peg$silentFails === 0) { peg$fail(peg$c28); }
|
|
1114
|
-
}
|
|
1115
|
-
if (s2 !== peg$FAILED) {
|
|
1116
|
-
s3 = peg$parsenumber();
|
|
1117
|
-
if (s3 !== peg$FAILED) {
|
|
1118
|
-
s2 = [s2, s3];
|
|
1119
|
-
s1 = s2;
|
|
1120
|
-
} else {
|
|
1121
|
-
peg$currPos = s1;
|
|
1122
|
-
s1 = peg$FAILED;
|
|
1123
|
-
}
|
|
1124
|
-
} else {
|
|
1125
|
-
peg$currPos = s1;
|
|
1126
|
-
s1 = peg$FAILED;
|
|
1127
|
-
}
|
|
1128
|
-
if (s1 !== peg$FAILED) {
|
|
1129
|
-
s0 = input.substring(s0, peg$currPos);
|
|
1130
|
-
} else {
|
|
1131
|
-
s0 = s1;
|
|
1132
|
-
}
|
|
1133
|
-
if (s0 === peg$FAILED) {
|
|
1134
|
-
s0 = peg$parsechars();
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
return s0;
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
function peg$parseoptionalFormatPattern() {
|
|
1141
|
-
var s0, s1, s2, s3, s4, s5, s6;
|
|
1142
|
-
|
|
1143
|
-
s0 = peg$currPos;
|
|
1144
|
-
s1 = peg$parse_();
|
|
1145
|
-
if (s1 !== peg$FAILED) {
|
|
1146
|
-
s2 = peg$parseselector();
|
|
1147
|
-
if (s2 !== peg$FAILED) {
|
|
1148
|
-
s3 = peg$parse_();
|
|
1149
|
-
if (s3 !== peg$FAILED) {
|
|
1150
|
-
if (input.charCodeAt(peg$currPos) === 123) {
|
|
1151
|
-
s4 = peg$c4;
|
|
1152
|
-
peg$currPos++;
|
|
1153
|
-
} else {
|
|
1154
|
-
s4 = peg$FAILED;
|
|
1155
|
-
if (peg$silentFails === 0) { peg$fail(peg$c5); }
|
|
1156
|
-
}
|
|
1157
|
-
if (s4 !== peg$FAILED) {
|
|
1158
|
-
s5 = peg$parsemessageFormatPattern();
|
|
1159
|
-
if (s5 !== peg$FAILED) {
|
|
1160
|
-
if (input.charCodeAt(peg$currPos) === 125) {
|
|
1161
|
-
s6 = peg$c8;
|
|
1162
|
-
peg$currPos++;
|
|
1163
|
-
} else {
|
|
1164
|
-
s6 = peg$FAILED;
|
|
1165
|
-
if (peg$silentFails === 0) { peg$fail(peg$c9); }
|
|
1166
|
-
}
|
|
1167
|
-
if (s6 !== peg$FAILED) {
|
|
1168
|
-
peg$savedPos = s0;
|
|
1169
|
-
s1 = peg$c29(s2, s5);
|
|
1170
|
-
s0 = s1;
|
|
1171
|
-
} else {
|
|
1172
|
-
peg$currPos = s0;
|
|
1173
|
-
s0 = peg$FAILED;
|
|
1174
|
-
}
|
|
1175
|
-
} else {
|
|
1176
|
-
peg$currPos = s0;
|
|
1177
|
-
s0 = peg$FAILED;
|
|
1178
|
-
}
|
|
1179
|
-
} else {
|
|
1180
|
-
peg$currPos = s0;
|
|
1181
|
-
s0 = peg$FAILED;
|
|
1182
|
-
}
|
|
1183
|
-
} else {
|
|
1184
|
-
peg$currPos = s0;
|
|
1185
|
-
s0 = peg$FAILED;
|
|
1186
|
-
}
|
|
1187
|
-
} else {
|
|
1188
|
-
peg$currPos = s0;
|
|
1189
|
-
s0 = peg$FAILED;
|
|
1190
|
-
}
|
|
1191
|
-
} else {
|
|
1192
|
-
peg$currPos = s0;
|
|
1193
|
-
s0 = peg$FAILED;
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
return s0;
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
function peg$parseoffset() {
|
|
1200
|
-
var s0, s1, s2, s3;
|
|
1201
|
-
|
|
1202
|
-
s0 = peg$currPos;
|
|
1203
|
-
if (input.substr(peg$currPos, 7) === peg$c30) {
|
|
1204
|
-
s1 = peg$c30;
|
|
1205
|
-
peg$currPos += 7;
|
|
1206
|
-
} else {
|
|
1207
|
-
s1 = peg$FAILED;
|
|
1208
|
-
if (peg$silentFails === 0) { peg$fail(peg$c31); }
|
|
1209
|
-
}
|
|
1210
|
-
if (s1 !== peg$FAILED) {
|
|
1211
|
-
s2 = peg$parse_();
|
|
1212
|
-
if (s2 !== peg$FAILED) {
|
|
1213
|
-
s3 = peg$parsenumber();
|
|
1214
|
-
if (s3 !== peg$FAILED) {
|
|
1215
|
-
peg$savedPos = s0;
|
|
1216
|
-
s1 = peg$c32(s3);
|
|
1217
|
-
s0 = s1;
|
|
1218
|
-
} else {
|
|
1219
|
-
peg$currPos = s0;
|
|
1220
|
-
s0 = peg$FAILED;
|
|
1221
|
-
}
|
|
1222
|
-
} else {
|
|
1223
|
-
peg$currPos = s0;
|
|
1224
|
-
s0 = peg$FAILED;
|
|
1225
|
-
}
|
|
1226
|
-
} else {
|
|
1227
|
-
peg$currPos = s0;
|
|
1228
|
-
s0 = peg$FAILED;
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
return s0;
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
function peg$parsepluralStyle() {
|
|
1235
|
-
var s0, s1, s2, s3, s4;
|
|
1236
|
-
|
|
1237
|
-
s0 = peg$currPos;
|
|
1238
|
-
s1 = peg$parseoffset();
|
|
1239
|
-
if (s1 === peg$FAILED) {
|
|
1240
|
-
s1 = null;
|
|
1241
|
-
}
|
|
1242
|
-
if (s1 !== peg$FAILED) {
|
|
1243
|
-
s2 = peg$parse_();
|
|
1244
|
-
if (s2 !== peg$FAILED) {
|
|
1245
|
-
s3 = [];
|
|
1246
|
-
s4 = peg$parseoptionalFormatPattern();
|
|
1247
|
-
if (s4 !== peg$FAILED) {
|
|
1248
|
-
while (s4 !== peg$FAILED) {
|
|
1249
|
-
s3.push(s4);
|
|
1250
|
-
s4 = peg$parseoptionalFormatPattern();
|
|
1251
|
-
}
|
|
1252
|
-
} else {
|
|
1253
|
-
s3 = peg$FAILED;
|
|
1254
|
-
}
|
|
1255
|
-
if (s3 !== peg$FAILED) {
|
|
1256
|
-
peg$savedPos = s0;
|
|
1257
|
-
s1 = peg$c33(s1, s3);
|
|
1258
|
-
s0 = s1;
|
|
1259
|
-
} else {
|
|
1260
|
-
peg$currPos = s0;
|
|
1261
|
-
s0 = peg$FAILED;
|
|
1262
|
-
}
|
|
1263
|
-
} else {
|
|
1264
|
-
peg$currPos = s0;
|
|
1265
|
-
s0 = peg$FAILED;
|
|
1266
|
-
}
|
|
1267
|
-
} else {
|
|
1268
|
-
peg$currPos = s0;
|
|
1269
|
-
s0 = peg$FAILED;
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
return s0;
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
function peg$parsews() {
|
|
1276
|
-
var s0, s1;
|
|
1277
|
-
|
|
1278
|
-
peg$silentFails++;
|
|
1279
|
-
s0 = [];
|
|
1280
|
-
if (peg$c35.test(input.charAt(peg$currPos))) {
|
|
1281
|
-
s1 = input.charAt(peg$currPos);
|
|
1282
|
-
peg$currPos++;
|
|
1283
|
-
} else {
|
|
1284
|
-
s1 = peg$FAILED;
|
|
1285
|
-
if (peg$silentFails === 0) { peg$fail(peg$c36); }
|
|
1286
|
-
}
|
|
1287
|
-
if (s1 !== peg$FAILED) {
|
|
1288
|
-
while (s1 !== peg$FAILED) {
|
|
1289
|
-
s0.push(s1);
|
|
1290
|
-
if (peg$c35.test(input.charAt(peg$currPos))) {
|
|
1291
|
-
s1 = input.charAt(peg$currPos);
|
|
1292
|
-
peg$currPos++;
|
|
1293
|
-
} else {
|
|
1294
|
-
s1 = peg$FAILED;
|
|
1295
|
-
if (peg$silentFails === 0) { peg$fail(peg$c36); }
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
} else {
|
|
1299
|
-
s0 = peg$FAILED;
|
|
1300
|
-
}
|
|
1301
|
-
peg$silentFails--;
|
|
1302
|
-
if (s0 === peg$FAILED) {
|
|
1303
|
-
s1 = peg$FAILED;
|
|
1304
|
-
if (peg$silentFails === 0) { peg$fail(peg$c34); }
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
return s0;
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
function peg$parse_() {
|
|
1311
|
-
var s0, s1, s2;
|
|
1312
|
-
|
|
1313
|
-
peg$silentFails++;
|
|
1314
|
-
s0 = peg$currPos;
|
|
1315
|
-
s1 = [];
|
|
1316
|
-
s2 = peg$parsews();
|
|
1317
|
-
while (s2 !== peg$FAILED) {
|
|
1318
|
-
s1.push(s2);
|
|
1319
|
-
s2 = peg$parsews();
|
|
1320
|
-
}
|
|
1321
|
-
if (s1 !== peg$FAILED) {
|
|
1322
|
-
s0 = input.substring(s0, peg$currPos);
|
|
1323
|
-
} else {
|
|
1324
|
-
s0 = s1;
|
|
1325
|
-
}
|
|
1326
|
-
peg$silentFails--;
|
|
1327
|
-
if (s0 === peg$FAILED) {
|
|
1328
|
-
s1 = peg$FAILED;
|
|
1329
|
-
if (peg$silentFails === 0) { peg$fail(peg$c37); }
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
return s0;
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
function peg$parsedigit() {
|
|
1336
|
-
var s0;
|
|
1337
|
-
|
|
1338
|
-
if (peg$c38.test(input.charAt(peg$currPos))) {
|
|
1339
|
-
s0 = input.charAt(peg$currPos);
|
|
1340
|
-
peg$currPos++;
|
|
1341
|
-
} else {
|
|
1342
|
-
s0 = peg$FAILED;
|
|
1343
|
-
if (peg$silentFails === 0) { peg$fail(peg$c39); }
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
return s0;
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
function peg$parsehexDigit() {
|
|
1350
|
-
var s0;
|
|
1351
|
-
|
|
1352
|
-
if (peg$c40.test(input.charAt(peg$currPos))) {
|
|
1353
|
-
s0 = input.charAt(peg$currPos);
|
|
1354
|
-
peg$currPos++;
|
|
1355
|
-
} else {
|
|
1356
|
-
s0 = peg$FAILED;
|
|
1357
|
-
if (peg$silentFails === 0) { peg$fail(peg$c41); }
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
return s0;
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
function peg$parsenumber() {
|
|
1364
|
-
var s0, s1, s2, s3, s4, s5;
|
|
1365
|
-
|
|
1366
|
-
s0 = peg$currPos;
|
|
1367
|
-
if (input.charCodeAt(peg$currPos) === 48) {
|
|
1368
|
-
s1 = peg$c42;
|
|
1369
|
-
peg$currPos++;
|
|
1370
|
-
} else {
|
|
1371
|
-
s1 = peg$FAILED;
|
|
1372
|
-
if (peg$silentFails === 0) { peg$fail(peg$c43); }
|
|
1373
|
-
}
|
|
1374
|
-
if (s1 === peg$FAILED) {
|
|
1375
|
-
s1 = peg$currPos;
|
|
1376
|
-
s2 = peg$currPos;
|
|
1377
|
-
if (peg$c44.test(input.charAt(peg$currPos))) {
|
|
1378
|
-
s3 = input.charAt(peg$currPos);
|
|
1379
|
-
peg$currPos++;
|
|
1380
|
-
} else {
|
|
1381
|
-
s3 = peg$FAILED;
|
|
1382
|
-
if (peg$silentFails === 0) { peg$fail(peg$c45); }
|
|
1383
|
-
}
|
|
1384
|
-
if (s3 !== peg$FAILED) {
|
|
1385
|
-
s4 = [];
|
|
1386
|
-
s5 = peg$parsedigit();
|
|
1387
|
-
while (s5 !== peg$FAILED) {
|
|
1388
|
-
s4.push(s5);
|
|
1389
|
-
s5 = peg$parsedigit();
|
|
1390
|
-
}
|
|
1391
|
-
if (s4 !== peg$FAILED) {
|
|
1392
|
-
s3 = [s3, s4];
|
|
1393
|
-
s2 = s3;
|
|
1394
|
-
} else {
|
|
1395
|
-
peg$currPos = s2;
|
|
1396
|
-
s2 = peg$FAILED;
|
|
1397
|
-
}
|
|
1398
|
-
} else {
|
|
1399
|
-
peg$currPos = s2;
|
|
1400
|
-
s2 = peg$FAILED;
|
|
1401
|
-
}
|
|
1402
|
-
if (s2 !== peg$FAILED) {
|
|
1403
|
-
s1 = input.substring(s1, peg$currPos);
|
|
1404
|
-
} else {
|
|
1405
|
-
s1 = s2;
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
if (s1 !== peg$FAILED) {
|
|
1409
|
-
peg$savedPos = s0;
|
|
1410
|
-
s1 = peg$c46(s1);
|
|
1411
|
-
}
|
|
1412
|
-
s0 = s1;
|
|
1413
|
-
|
|
1414
|
-
return s0;
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
function peg$parsequoteEscapedChar() {
|
|
1418
|
-
var s0, s1, s2;
|
|
1419
|
-
|
|
1420
|
-
s0 = peg$currPos;
|
|
1421
|
-
s1 = peg$currPos;
|
|
1422
|
-
peg$silentFails++;
|
|
1423
|
-
if (input.charCodeAt(peg$currPos) === 39) {
|
|
1424
|
-
s2 = peg$c47;
|
|
1425
|
-
peg$currPos++;
|
|
1426
|
-
} else {
|
|
1427
|
-
s2 = peg$FAILED;
|
|
1428
|
-
if (peg$silentFails === 0) { peg$fail(peg$c48); }
|
|
1429
|
-
}
|
|
1430
|
-
if (s2 === peg$FAILED) {
|
|
1431
|
-
if (peg$c49.test(input.charAt(peg$currPos))) {
|
|
1432
|
-
s2 = input.charAt(peg$currPos);
|
|
1433
|
-
peg$currPos++;
|
|
1434
|
-
} else {
|
|
1435
|
-
s2 = peg$FAILED;
|
|
1436
|
-
if (peg$silentFails === 0) { peg$fail(peg$c50); }
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
peg$silentFails--;
|
|
1440
|
-
if (s2 === peg$FAILED) {
|
|
1441
|
-
s1 = void 0;
|
|
1442
|
-
} else {
|
|
1443
|
-
peg$currPos = s1;
|
|
1444
|
-
s1 = peg$FAILED;
|
|
1445
|
-
}
|
|
1446
|
-
if (s1 !== peg$FAILED) {
|
|
1447
|
-
if (input.length > peg$currPos) {
|
|
1448
|
-
s2 = input.charAt(peg$currPos);
|
|
1449
|
-
peg$currPos++;
|
|
1450
|
-
} else {
|
|
1451
|
-
s2 = peg$FAILED;
|
|
1452
|
-
if (peg$silentFails === 0) { peg$fail(peg$c51); }
|
|
1453
|
-
}
|
|
1454
|
-
if (s2 !== peg$FAILED) {
|
|
1455
|
-
peg$savedPos = s0;
|
|
1456
|
-
s1 = peg$c52(s2);
|
|
1457
|
-
s0 = s1;
|
|
1458
|
-
} else {
|
|
1459
|
-
peg$currPos = s0;
|
|
1460
|
-
s0 = peg$FAILED;
|
|
1461
|
-
}
|
|
1462
|
-
} else {
|
|
1463
|
-
peg$currPos = s0;
|
|
1464
|
-
s0 = peg$FAILED;
|
|
1465
|
-
}
|
|
1466
|
-
if (s0 === peg$FAILED) {
|
|
1467
|
-
s0 = peg$currPos;
|
|
1468
|
-
if (input.charCodeAt(peg$currPos) === 39) {
|
|
1469
|
-
s1 = peg$c47;
|
|
1470
|
-
peg$currPos++;
|
|
1471
|
-
} else {
|
|
1472
|
-
s1 = peg$FAILED;
|
|
1473
|
-
if (peg$silentFails === 0) { peg$fail(peg$c48); }
|
|
1474
|
-
}
|
|
1475
|
-
if (s1 !== peg$FAILED) {
|
|
1476
|
-
s2 = peg$parseescape();
|
|
1477
|
-
if (s2 !== peg$FAILED) {
|
|
1478
|
-
peg$savedPos = s0;
|
|
1479
|
-
s1 = peg$c53(s2);
|
|
1480
|
-
s0 = s1;
|
|
1481
|
-
} else {
|
|
1482
|
-
peg$currPos = s0;
|
|
1483
|
-
s0 = peg$FAILED;
|
|
1484
|
-
}
|
|
1485
|
-
} else {
|
|
1486
|
-
peg$currPos = s0;
|
|
1487
|
-
s0 = peg$FAILED;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
return s0;
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
function peg$parseapostrophe() {
|
|
1495
|
-
var s0;
|
|
1496
|
-
|
|
1497
|
-
if (input.charCodeAt(peg$currPos) === 39) {
|
|
1498
|
-
s0 = peg$c47;
|
|
1499
|
-
peg$currPos++;
|
|
1500
|
-
} else {
|
|
1501
|
-
s0 = peg$FAILED;
|
|
1502
|
-
if (peg$silentFails === 0) { peg$fail(peg$c48); }
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
return s0;
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
function peg$parseescape() {
|
|
1509
|
-
var s0;
|
|
1510
|
-
|
|
1511
|
-
if (peg$c49.test(input.charAt(peg$currPos))) {
|
|
1512
|
-
s0 = input.charAt(peg$currPos);
|
|
1513
|
-
peg$currPos++;
|
|
1514
|
-
} else {
|
|
1515
|
-
s0 = peg$FAILED;
|
|
1516
|
-
if (peg$silentFails === 0) { peg$fail(peg$c50); }
|
|
1517
|
-
}
|
|
1518
|
-
if (s0 === peg$FAILED) {
|
|
1519
|
-
s0 = peg$parseapostrophe();
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
return s0;
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
function peg$parsechar() {
|
|
1526
|
-
var s0, s1, s2, s3, s4, s5, s6, s7;
|
|
1527
|
-
|
|
1528
|
-
s0 = peg$currPos;
|
|
1529
|
-
if (input.charCodeAt(peg$currPos) === 39) {
|
|
1530
|
-
s1 = peg$c47;
|
|
1531
|
-
peg$currPos++;
|
|
1532
|
-
} else {
|
|
1533
|
-
s1 = peg$FAILED;
|
|
1534
|
-
if (peg$silentFails === 0) { peg$fail(peg$c48); }
|
|
1535
|
-
}
|
|
1536
|
-
if (s1 !== peg$FAILED) {
|
|
1537
|
-
s2 = peg$parseapostrophe();
|
|
1538
|
-
if (s2 !== peg$FAILED) {
|
|
1539
|
-
peg$savedPos = s0;
|
|
1540
|
-
s1 = peg$c53(s2);
|
|
1541
|
-
s0 = s1;
|
|
1542
|
-
} else {
|
|
1543
|
-
peg$currPos = s0;
|
|
1544
|
-
s0 = peg$FAILED;
|
|
1545
|
-
}
|
|
1546
|
-
} else {
|
|
1547
|
-
peg$currPos = s0;
|
|
1548
|
-
s0 = peg$FAILED;
|
|
1549
|
-
}
|
|
1550
|
-
if (s0 === peg$FAILED) {
|
|
1551
|
-
if (peg$c54.test(input.charAt(peg$currPos))) {
|
|
1552
|
-
s0 = input.charAt(peg$currPos);
|
|
1553
|
-
peg$currPos++;
|
|
1554
|
-
} else {
|
|
1555
|
-
s0 = peg$FAILED;
|
|
1556
|
-
if (peg$silentFails === 0) { peg$fail(peg$c55); }
|
|
1557
|
-
}
|
|
1558
|
-
if (s0 === peg$FAILED) {
|
|
1559
|
-
s0 = peg$currPos;
|
|
1560
|
-
if (input.substr(peg$currPos, 2) === peg$c56) {
|
|
1561
|
-
s1 = peg$c56;
|
|
1562
|
-
peg$currPos += 2;
|
|
1563
|
-
} else {
|
|
1564
|
-
s1 = peg$FAILED;
|
|
1565
|
-
if (peg$silentFails === 0) { peg$fail(peg$c57); }
|
|
1566
|
-
}
|
|
1567
|
-
if (s1 !== peg$FAILED) {
|
|
1568
|
-
peg$savedPos = s0;
|
|
1569
|
-
s1 = peg$c58();
|
|
1570
|
-
}
|
|
1571
|
-
s0 = s1;
|
|
1572
|
-
if (s0 === peg$FAILED) {
|
|
1573
|
-
s0 = peg$currPos;
|
|
1574
|
-
if (input.substr(peg$currPos, 2) === peg$c59) {
|
|
1575
|
-
s1 = peg$c59;
|
|
1576
|
-
peg$currPos += 2;
|
|
1577
|
-
} else {
|
|
1578
|
-
s1 = peg$FAILED;
|
|
1579
|
-
if (peg$silentFails === 0) { peg$fail(peg$c60); }
|
|
1580
|
-
}
|
|
1581
|
-
if (s1 !== peg$FAILED) {
|
|
1582
|
-
peg$savedPos = s0;
|
|
1583
|
-
s1 = peg$c61();
|
|
1584
|
-
}
|
|
1585
|
-
s0 = s1;
|
|
1586
|
-
if (s0 === peg$FAILED) {
|
|
1587
|
-
s0 = peg$currPos;
|
|
1588
|
-
if (input.substr(peg$currPos, 2) === peg$c62) {
|
|
1589
|
-
s1 = peg$c62;
|
|
1590
|
-
peg$currPos += 2;
|
|
1591
|
-
} else {
|
|
1592
|
-
s1 = peg$FAILED;
|
|
1593
|
-
if (peg$silentFails === 0) { peg$fail(peg$c63); }
|
|
1594
|
-
}
|
|
1595
|
-
if (s1 !== peg$FAILED) {
|
|
1596
|
-
peg$savedPos = s0;
|
|
1597
|
-
s1 = peg$c64();
|
|
1598
|
-
}
|
|
1599
|
-
s0 = s1;
|
|
1600
|
-
if (s0 === peg$FAILED) {
|
|
1601
|
-
s0 = peg$currPos;
|
|
1602
|
-
if (input.substr(peg$currPos, 2) === peg$c65) {
|
|
1603
|
-
s1 = peg$c65;
|
|
1604
|
-
peg$currPos += 2;
|
|
1605
|
-
} else {
|
|
1606
|
-
s1 = peg$FAILED;
|
|
1607
|
-
if (peg$silentFails === 0) { peg$fail(peg$c66); }
|
|
1608
|
-
}
|
|
1609
|
-
if (s1 !== peg$FAILED) {
|
|
1610
|
-
peg$savedPos = s0;
|
|
1611
|
-
s1 = peg$c67();
|
|
1612
|
-
}
|
|
1613
|
-
s0 = s1;
|
|
1614
|
-
if (s0 === peg$FAILED) {
|
|
1615
|
-
s0 = peg$currPos;
|
|
1616
|
-
if (input.substr(peg$currPos, 2) === peg$c68) {
|
|
1617
|
-
s1 = peg$c68;
|
|
1618
|
-
peg$currPos += 2;
|
|
1619
|
-
} else {
|
|
1620
|
-
s1 = peg$FAILED;
|
|
1621
|
-
if (peg$silentFails === 0) { peg$fail(peg$c69); }
|
|
1622
|
-
}
|
|
1623
|
-
if (s1 !== peg$FAILED) {
|
|
1624
|
-
s2 = peg$currPos;
|
|
1625
|
-
s3 = peg$currPos;
|
|
1626
|
-
s4 = peg$parsehexDigit();
|
|
1627
|
-
if (s4 !== peg$FAILED) {
|
|
1628
|
-
s5 = peg$parsehexDigit();
|
|
1629
|
-
if (s5 !== peg$FAILED) {
|
|
1630
|
-
s6 = peg$parsehexDigit();
|
|
1631
|
-
if (s6 !== peg$FAILED) {
|
|
1632
|
-
s7 = peg$parsehexDigit();
|
|
1633
|
-
if (s7 !== peg$FAILED) {
|
|
1634
|
-
s4 = [s4, s5, s6, s7];
|
|
1635
|
-
s3 = s4;
|
|
1636
|
-
} else {
|
|
1637
|
-
peg$currPos = s3;
|
|
1638
|
-
s3 = peg$FAILED;
|
|
1639
|
-
}
|
|
1640
|
-
} else {
|
|
1641
|
-
peg$currPos = s3;
|
|
1642
|
-
s3 = peg$FAILED;
|
|
1643
|
-
}
|
|
1644
|
-
} else {
|
|
1645
|
-
peg$currPos = s3;
|
|
1646
|
-
s3 = peg$FAILED;
|
|
1647
|
-
}
|
|
1648
|
-
} else {
|
|
1649
|
-
peg$currPos = s3;
|
|
1650
|
-
s3 = peg$FAILED;
|
|
1651
|
-
}
|
|
1652
|
-
if (s3 !== peg$FAILED) {
|
|
1653
|
-
s2 = input.substring(s2, peg$currPos);
|
|
1654
|
-
} else {
|
|
1655
|
-
s2 = s3;
|
|
1656
|
-
}
|
|
1657
|
-
if (s2 !== peg$FAILED) {
|
|
1658
|
-
peg$savedPos = s0;
|
|
1659
|
-
s1 = peg$c70(s2);
|
|
1660
|
-
s0 = s1;
|
|
1661
|
-
} else {
|
|
1662
|
-
peg$currPos = s0;
|
|
1663
|
-
s0 = peg$FAILED;
|
|
1664
|
-
}
|
|
1665
|
-
} else {
|
|
1666
|
-
peg$currPos = s0;
|
|
1667
|
-
s0 = peg$FAILED;
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
return s0;
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
function peg$parsechars() {
|
|
1680
|
-
var s0, s1, s2;
|
|
1681
|
-
|
|
1682
|
-
s0 = peg$currPos;
|
|
1683
|
-
s1 = [];
|
|
1684
|
-
s2 = peg$parsechar();
|
|
1685
|
-
if (s2 !== peg$FAILED) {
|
|
1686
|
-
while (s2 !== peg$FAILED) {
|
|
1687
|
-
s1.push(s2);
|
|
1688
|
-
s2 = peg$parsechar();
|
|
1689
|
-
}
|
|
1690
|
-
} else {
|
|
1691
|
-
s1 = peg$FAILED;
|
|
1692
|
-
}
|
|
1693
|
-
if (s1 !== peg$FAILED) {
|
|
1694
|
-
peg$savedPos = s0;
|
|
1695
|
-
s1 = peg$c3(s1);
|
|
1696
|
-
}
|
|
1697
|
-
s0 = s1;
|
|
1698
|
-
|
|
1699
|
-
return s0;
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
peg$result = peg$startRuleFunction();
|
|
1703
|
-
|
|
1704
|
-
if (peg$result !== peg$FAILED && peg$currPos === input.length) {
|
|
1705
|
-
return peg$result;
|
|
1706
|
-
} else {
|
|
1707
|
-
if (peg$result !== peg$FAILED && peg$currPos < input.length) {
|
|
1708
|
-
peg$fail(peg$endExpectation());
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
throw peg$buildStructuredError(
|
|
1712
|
-
peg$maxFailExpected,
|
|
1713
|
-
peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
|
|
1714
|
-
peg$maxFailPos < input.length
|
|
1715
|
-
? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
|
|
1716
|
-
: peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
|
|
1717
|
-
);
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
return {
|
|
1722
|
-
SyntaxError: peg$SyntaxError,
|
|
1723
|
-
parse: peg$parse
|
|
1724
|
-
};
|
|
1725
|
-
})();
|
|
1726
|
-
|
|
1727
|
-
/*
|
|
1728
|
-
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
1729
|
-
Copyrights licensed under the New BSD License.
|
|
1730
|
-
See the accompanying LICENSE file for terms.
|
|
1731
|
-
*/
|
|
1732
|
-
var __extends$1 = (undefined && undefined.__extends) || (function () {
|
|
1733
|
-
var extendStatics = function (d, b) {
|
|
1734
|
-
extendStatics = Object.setPrototypeOf ||
|
|
1735
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
1736
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
1737
|
-
return extendStatics(d, b);
|
|
1738
|
-
};
|
|
1739
|
-
return function (d, b) {
|
|
1740
|
-
extendStatics(d, b);
|
|
1741
|
-
function __() { this.constructor = d; }
|
|
1742
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
1743
|
-
};
|
|
1744
|
-
})();
|
|
1745
|
-
var __assign = (undefined && undefined.__assign) || function () {
|
|
1746
|
-
__assign = Object.assign || function(t) {
|
|
1747
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1748
|
-
s = arguments[i];
|
|
1749
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
1750
|
-
t[p] = s[p];
|
|
1751
|
-
}
|
|
1752
|
-
return t;
|
|
1753
|
-
};
|
|
1754
|
-
return __assign.apply(this, arguments);
|
|
1755
|
-
};
|
|
1756
|
-
// -- MessageFormat --------------------------------------------------------
|
|
1757
|
-
function resolveLocale(locales) {
|
|
1758
|
-
if (typeof locales === 'string') {
|
|
1759
|
-
locales = [locales];
|
|
1760
|
-
}
|
|
1761
|
-
try {
|
|
1762
|
-
return Intl.NumberFormat.supportedLocalesOf(locales, {
|
|
1763
|
-
// IE11 localeMatcher `lookup` seems to convert `en` -> `en-US`
|
|
1764
|
-
// but not other browsers,
|
|
1765
|
-
localeMatcher: 'best fit'
|
|
1766
|
-
})[0];
|
|
1767
|
-
}
|
|
1768
|
-
catch (e) {
|
|
1769
|
-
return IntlMessageFormat.defaultLocale;
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
function formatPatterns(pattern, values) {
|
|
1773
|
-
var result = '';
|
|
1774
|
-
for (var _i = 0, pattern_1 = pattern; _i < pattern_1.length; _i++) {
|
|
1775
|
-
var part = pattern_1[_i];
|
|
1776
|
-
// Exist early for string parts.
|
|
1777
|
-
if (typeof part === 'string') {
|
|
1778
|
-
result += part;
|
|
1779
|
-
continue;
|
|
1780
|
-
}
|
|
1781
|
-
var id = part.id;
|
|
1782
|
-
// Enforce that all required values are provided by the caller.
|
|
1783
|
-
if (!(values && id in values)) {
|
|
1784
|
-
throw new FormatError("A value must be provided for: " + id, id);
|
|
1785
|
-
}
|
|
1786
|
-
var value = values[id];
|
|
1787
|
-
// Recursively format plural and select parts' option — which can be a
|
|
1788
|
-
// nested pattern structure. The choosing of the option to use is
|
|
1789
|
-
// abstracted-by and delegated-to the part helper object.
|
|
1790
|
-
if (isSelectOrPluralFormat(part)) {
|
|
1791
|
-
result += formatPatterns(part.getOption(value), values);
|
|
1792
|
-
}
|
|
1793
|
-
else {
|
|
1794
|
-
result += part.format(value);
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
return result;
|
|
1798
|
-
}
|
|
1799
|
-
function mergeConfig(c1, c2) {
|
|
1800
|
-
if (!c2) {
|
|
1801
|
-
return c1;
|
|
1802
|
-
}
|
|
1803
|
-
return __assign({}, (c1 || {}), (c2 || {}), Object.keys(c1).reduce(function (all, k) {
|
|
1804
|
-
all[k] = __assign({}, c1[k], (c2[k] || {}));
|
|
1805
|
-
return all;
|
|
1806
|
-
}, {}));
|
|
1807
|
-
}
|
|
1808
|
-
function mergeConfigs(defaultConfig, configs) {
|
|
1809
|
-
if (!configs) {
|
|
1810
|
-
return defaultConfig;
|
|
1811
|
-
}
|
|
1812
|
-
return Object.keys(defaultConfig).reduce(function (all, k) {
|
|
1813
|
-
all[k] = mergeConfig(defaultConfig[k], configs[k]);
|
|
1814
|
-
return all;
|
|
1815
|
-
}, __assign({}, defaultConfig));
|
|
1816
|
-
}
|
|
1817
|
-
var FormatError = /** @class */ (function (_super) {
|
|
1818
|
-
__extends$1(FormatError, _super);
|
|
1819
|
-
function FormatError(msg, variableId) {
|
|
1820
|
-
var _this = _super.call(this, msg) || this;
|
|
1821
|
-
_this.variableId = variableId;
|
|
1822
|
-
return _this;
|
|
1823
|
-
}
|
|
1824
|
-
return FormatError;
|
|
1825
|
-
}(Error));
|
|
1826
|
-
function createDefaultFormatters() {
|
|
1827
|
-
return {
|
|
1828
|
-
getNumberFormat: function () {
|
|
1829
|
-
var _a;
|
|
1830
|
-
var args = [];
|
|
1831
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1832
|
-
args[_i] = arguments[_i];
|
|
1833
|
-
}
|
|
1834
|
-
return new ((_a = Intl.NumberFormat).bind.apply(_a, [void 0].concat(args)))();
|
|
1835
|
-
},
|
|
1836
|
-
getDateTimeFormat: function () {
|
|
1837
|
-
var _a;
|
|
1838
|
-
var args = [];
|
|
1839
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1840
|
-
args[_i] = arguments[_i];
|
|
1841
|
-
}
|
|
1842
|
-
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, [void 0].concat(args)))();
|
|
1843
|
-
},
|
|
1844
|
-
getPluralRules: function () {
|
|
1845
|
-
var _a;
|
|
1846
|
-
var args = [];
|
|
1847
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1848
|
-
args[_i] = arguments[_i];
|
|
1849
|
-
}
|
|
1850
|
-
return new ((_a = Intl.PluralRules).bind.apply(_a, [void 0].concat(args)))();
|
|
1851
|
-
}
|
|
1852
|
-
};
|
|
1853
|
-
}
|
|
1854
|
-
var IntlMessageFormat = /** @class */ (function () {
|
|
1855
|
-
function IntlMessageFormat(message, locales, overrideFormats, opts) {
|
|
1856
|
-
var _this = this;
|
|
1857
|
-
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
|
|
1858
|
-
this.format = function (values) {
|
|
1859
|
-
try {
|
|
1860
|
-
return formatPatterns(_this.pattern, values);
|
|
1861
|
-
}
|
|
1862
|
-
catch (e) {
|
|
1863
|
-
if (e.variableId) {
|
|
1864
|
-
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + _this.message + "'");
|
|
1865
|
-
}
|
|
1866
|
-
else {
|
|
1867
|
-
throw e;
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
};
|
|
1871
|
-
// Parse string messages into an AST.
|
|
1872
|
-
this.ast =
|
|
1873
|
-
typeof message === 'string'
|
|
1874
|
-
? IntlMessageFormat.__parse(message)
|
|
1875
|
-
: message;
|
|
1876
|
-
this.message = typeof message === 'string' ? message : '';
|
|
1877
|
-
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
|
|
1878
|
-
throw new TypeError('A message must be provided as a String or AST.');
|
|
1879
|
-
}
|
|
1880
|
-
// Creates a new object with the specified `formats` merged with the default
|
|
1881
|
-
// formats.
|
|
1882
|
-
var formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
|
|
1883
|
-
// Defined first because it's used to build the format pattern.
|
|
1884
|
-
this.locale = resolveLocale(locales || []);
|
|
1885
|
-
var formatters = (opts && opts.formatters) || createDefaultFormatters();
|
|
1886
|
-
// Compile the `ast` to a pattern that is highly optimized for repeated
|
|
1887
|
-
// `format()` invocations. **Note:** This passes the `locales` set provided
|
|
1888
|
-
// to the constructor instead of just the resolved locale.
|
|
1889
|
-
this.pattern = new Compiler(locales, formats, formatters).compile(this.ast);
|
|
1890
|
-
// "Bind" `format()` method to `this` so it can be passed by reference like
|
|
1891
|
-
// the other `Intl` APIs.
|
|
1892
|
-
}
|
|
1893
|
-
IntlMessageFormat.prototype.resolvedOptions = function () {
|
|
1894
|
-
return { locale: this.locale };
|
|
1895
|
-
};
|
|
1896
|
-
IntlMessageFormat.prototype.getAst = function () {
|
|
1897
|
-
return this.ast;
|
|
1898
|
-
};
|
|
1899
|
-
IntlMessageFormat.defaultLocale = 'en';
|
|
1900
|
-
IntlMessageFormat.__parse = parser.parse;
|
|
1901
|
-
// Default format options used as the prototype of the `formats` provided to the
|
|
1902
|
-
// constructor. These are used when constructing the internal Intl.NumberFormat
|
|
1903
|
-
// and Intl.DateTimeFormat instances.
|
|
1904
|
-
IntlMessageFormat.formats = {
|
|
1905
|
-
number: {
|
|
1906
|
-
currency: {
|
|
1907
|
-
style: 'currency'
|
|
1908
|
-
},
|
|
1909
|
-
percent: {
|
|
1910
|
-
style: 'percent'
|
|
1911
|
-
}
|
|
1912
|
-
},
|
|
1913
|
-
date: {
|
|
1914
|
-
short: {
|
|
1915
|
-
month: 'numeric',
|
|
1916
|
-
day: 'numeric',
|
|
1917
|
-
year: '2-digit'
|
|
1918
|
-
},
|
|
1919
|
-
medium: {
|
|
1920
|
-
month: 'short',
|
|
1921
|
-
day: 'numeric',
|
|
1922
|
-
year: 'numeric'
|
|
1923
|
-
},
|
|
1924
|
-
long: {
|
|
1925
|
-
month: 'long',
|
|
1926
|
-
day: 'numeric',
|
|
1927
|
-
year: 'numeric'
|
|
1928
|
-
},
|
|
1929
|
-
full: {
|
|
1930
|
-
weekday: 'long',
|
|
1931
|
-
month: 'long',
|
|
1932
|
-
day: 'numeric',
|
|
1933
|
-
year: 'numeric'
|
|
1934
|
-
}
|
|
1935
|
-
},
|
|
1936
|
-
time: {
|
|
1937
|
-
short: {
|
|
1938
|
-
hour: 'numeric',
|
|
1939
|
-
minute: 'numeric'
|
|
1940
|
-
},
|
|
1941
|
-
medium: {
|
|
1942
|
-
hour: 'numeric',
|
|
1943
|
-
minute: 'numeric',
|
|
1944
|
-
second: 'numeric'
|
|
1945
|
-
},
|
|
1946
|
-
long: {
|
|
1947
|
-
hour: 'numeric',
|
|
1948
|
-
minute: 'numeric',
|
|
1949
|
-
second: 'numeric',
|
|
1950
|
-
timeZoneName: 'short'
|
|
1951
|
-
},
|
|
1952
|
-
full: {
|
|
1953
|
-
hour: 'numeric',
|
|
1954
|
-
minute: 'numeric',
|
|
1955
|
-
second: 'numeric',
|
|
1956
|
-
timeZoneName: 'short'
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
return IntlMessageFormat;
|
|
1961
|
-
}());
|
|
1962
|
-
|
|
1963
|
-
exports.IntlMessageFormat = IntlMessageFormat;
|
|
1964
|
-
exports.createDefaultFormatters = createDefaultFormatters;
|
|
1965
|
-
exports.default = IntlMessageFormat;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __extends=function(){var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),Compiler=function(){function t(t,e,r){this.locales=[],this.formats={number:{},date:{},time:{}},this.pluralNumberFormat=null,this.currentPlural=null,this.pluralStack=[],this.locales=t,this.formats=e,this.formatters=r}return t.prototype.compile=function(t){return this.pluralStack=[],this.currentPlural=null,this.pluralNumberFormat=null,this.compileMessage(t)},t.prototype.compileMessage=function(t){var e=this;if(!t||"messageFormatPattern"!==t.type)throw new Error('Message AST is not of type: "messageFormatPattern"');var r=t.elements,n=r.filter(function(t){return"messageTextElement"===t.type||"argumentElement"===t.type}).map(function(t){return"messageTextElement"===t.type?e.compileMessageText(t):e.compileArgument(t)});if(n.length!==r.length)throw new Error("Message element does not have a valid type");return n},t.prototype.compileMessageText=function(t){return this.currentPlural&&/(^|[^\\])#/g.test(t.value)?(this.pluralNumberFormat||(this.pluralNumberFormat=new Intl.NumberFormat(this.locales)),new PluralOffsetString(this.currentPlural.id,this.currentPlural.format.offset,this.pluralNumberFormat,t.value)):t.value.replace(/\\#/g,"#")},t.prototype.compileArgument=function(t){var e=t.format,r=t.id,n=this.formatters;if(!e)return new StringFormat(r);var o=this.formats,a=this.locales;switch(e.type){case"numberFormat":return{id:r,format:n.getNumberFormat(a,o.number[e.style]).format};case"dateFormat":return{id:r,format:n.getDateTimeFormat(a,o.date[e.style]).format};case"timeFormat":return{id:r,format:n.getDateTimeFormat(a,o.time[e.style]).format};case"pluralFormat":return new PluralFormat(r,e.offset,this.compileOptions(t),n.getPluralRules(a,{type:e.ordinal?"ordinal":"cardinal"}));case"selectFormat":return new SelectFormat(r,this.compileOptions(t));default:throw new Error("Message element does not have a valid format type")}},t.prototype.compileOptions=function(t){var r=this,e=t.format,n=e.options;this.pluralStack.push(this.currentPlural),this.currentPlural="pluralFormat"===e.type?t:null;var o=n.reduce(function(t,e){return t[e.selector]=r.compileMessage(e.value),t},{});return this.currentPlural=this.pluralStack.pop(),o},t}(),Formatter=function(t){this.id=t},StringFormat=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.format=function(t){return t||"number"==typeof t?"string"==typeof t?t:String(t):""},e}(Formatter),PluralFormat=function(){function t(t,e,r,n){this.id=t,this.offset=e,this.options=r,this.pluralRules=n}return t.prototype.getOption=function(t){var e=this.options;return e["="+t]||e[this.pluralRules.select(t-this.offset)]||e.other},t}(),PluralOffsetString=function(a){function t(t,e,r,n){var o=a.call(this,t)||this;return o.offset=e,o.numberFormat=r,o.string=n,o}return __extends(t,a),t.prototype.format=function(t){var e=this.numberFormat.format(t-this.offset);return this.string.replace(/(^|[^\\])#/g,"$1"+e).replace(/\\#/g,"#")},t}(Formatter),SelectFormat=function(){function t(t,e){this.id=t,this.options=e}return t.prototype.getOption=function(t){var e=this.options;return e[t]||e.other},t}();function isSelectOrPluralFormat(t){return!!t.options}var __extends$1=function(){var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function resolveLocale(t){"string"==typeof t&&(t=[t]);try{return Intl.NumberFormat.supportedLocalesOf(t,{localeMatcher:"best fit"})[0]}catch(t){return IntlMessageFormat.defaultLocale}}function formatPatterns(t,e){for(var r="",n=0,o=t;n<o.length;n++){var a=o[n];if("string"!=typeof a){var i=a.id;if(!(e&&i in e))throw new FormatError("A value must be provided for: "+i,i);var s=e[i];isSelectOrPluralFormat(a)?r+=formatPatterns(a.getOption(s),e):r+=a.format(s)}else r+=a}return r}function mergeConfig(r,n){return n?__assign({},r||{},n||{},Object.keys(r).reduce(function(t,e){return t[e]=__assign({},r[e],n[e]||{}),t},{})):r}function mergeConfigs(r,n){return n?Object.keys(r).reduce(function(t,e){return t[e]=mergeConfig(r[e],n[e]),t},__assign({},r)):r}var FormatError=function(n){function t(t,e){var r=n.call(this,t)||this;return r.variableId=e,r}return __extends$1(t,n),t}(Error);function createDefaultFormatters(){return{getNumberFormat:function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return new((t=Intl.NumberFormat).bind.apply(t,[void 0].concat(e)))},getDateTimeFormat:function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return new((t=Intl.DateTimeFormat).bind.apply(t,[void 0].concat(e)))},getPluralRules:function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return new((t=Intl.PluralRules).bind.apply(t,[void 0].concat(e)))}}}var IntlMessageFormat=function(){function s(t,e,r,n){var o=this;if(void 0===e&&(e=s.defaultLocale),this.format=function(t){try{return formatPatterns(o.pattern,t)}catch(t){throw t.variableId?new Error("The intl string context variable '"+t.variableId+"' was not provided to the string '"+o.message+"'"):t}},"string"==typeof t){if(!s.__parse)throw new TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");this.ast=s.__parse(t)}else this.ast=t;if(this.message=t,!this.ast||"messageFormatPattern"!==this.ast.type)throw new TypeError("A message must be provided as a String or AST.");var a=mergeConfigs(s.formats,r);this.locale=resolveLocale(e||[]);var i=n&&n.formatters||createDefaultFormatters();this.pattern=new Compiler(e,a,i).compile(this.ast)}return s.prototype.resolvedOptions=function(){return{locale:this.locale}},s.prototype.getAst=function(){return this.ast},s.defaultLocale="en",s.__parse=void 0,s.formats={number:{currency:{style:"currency"},percent:{style:"percent"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},s}();exports.IntlMessageFormat=IntlMessageFormat,exports.createDefaultFormatters=createDefaultFormatters,exports.default=IntlMessageFormat;
|