1 | module.exports = (function() {
|
2 | |
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | function peg$subclass(child, parent) {
|
9 | function ctor() { this.constructor = child; }
|
10 | ctor.prototype = parent.prototype;
|
11 | child.prototype = new ctor();
|
12 | }
|
13 |
|
14 | function SyntaxError(message, expected, found, offset, line, column) {
|
15 | this.message = message;
|
16 | this.expected = expected;
|
17 | this.found = found;
|
18 | this.offset = offset;
|
19 | this.line = line;
|
20 | this.column = column;
|
21 |
|
22 | this.name = "SyntaxError";
|
23 | }
|
24 |
|
25 | peg$subclass(SyntaxError, Error);
|
26 |
|
27 | function parse(input) {
|
28 | var options = arguments.length > 1 ? arguments[1] : {},
|
29 |
|
30 | peg$FAILED = {},
|
31 |
|
32 | peg$startRuleFunctions = { start: peg$parsestart },
|
33 | peg$startRuleFunction = peg$parsestart,
|
34 |
|
35 | peg$c0 = [],
|
36 | peg$c1 = peg$FAILED,
|
37 | peg$c2 = "((",
|
38 | peg$c3 = { type: "literal", value: "((", description: "\"((\"" },
|
39 | peg$c4 = "))",
|
40 | peg$c5 = { type: "literal", value: "))", description: "\"))\"" },
|
41 | peg$c6 = null,
|
42 | peg$c7 = function(forms, anchor) {
|
43 | return {
|
44 | type: 'plural',
|
45 | forms: regularForms(forms),
|
46 | strict: strictForms(forms),
|
47 | anchor: anchor || 'count'
|
48 | };
|
49 | },
|
50 | peg$c8 = "|",
|
51 | peg$c9 = { type: "literal", value: "|", description: "\"|\"" },
|
52 | peg$c10 = function(part, more) {
|
53 | return [part].concat(more);
|
54 | },
|
55 | peg$c11 = function(part) {
|
56 | return [part];
|
57 | },
|
58 | peg$c12 = "=",
|
59 | peg$c13 = { type: "literal", value: "=", description: "\"=\"" },
|
60 | peg$c14 = /^[0-9]/,
|
61 | peg$c15 = { type: "class", value: "[0-9]", description: "[0-9]" },
|
62 | peg$c16 = " ",
|
63 | peg$c17 = { type: "literal", value: " ", description: "\" \"" },
|
64 | peg$c18 = function(strict, form) {
|
65 | return {
|
66 | strict: strict.join(''),
|
67 | text: form.join('')
|
68 | }
|
69 | },
|
70 | peg$c19 = function() {
|
71 | return {
|
72 | text: text()
|
73 | };
|
74 | },
|
75 | peg$c20 = "\\",
|
76 | peg$c21 = { type: "literal", value: "\\", description: "\"\\\\\"" },
|
77 | peg$c22 = /^[\\|)(]/,
|
78 | peg$c23 = { type: "class", value: "[\\\\|)(]", description: "[\\\\|)(]" },
|
79 | peg$c24 = function(char) {
|
80 | return char;
|
81 | },
|
82 | peg$c25 = void 0,
|
83 | peg$c26 = { type: "any", description: "any character" },
|
84 | peg$c27 = function() {
|
85 | return text();
|
86 | },
|
87 | peg$c28 = ":",
|
88 | peg$c29 = { type: "literal", value: ":", description: "\":\"" },
|
89 | peg$c30 = function(name) {
|
90 | return name;
|
91 | },
|
92 | peg$c31 = "#{",
|
93 | peg$c32 = { type: "literal", value: "#{", description: "\"#{\"" },
|
94 | peg$c33 = "}",
|
95 | peg$c34 = { type: "literal", value: "}", description: "\"}\"" },
|
96 | peg$c35 = function(anchor) {
|
97 | return {
|
98 | type: 'variable',
|
99 | anchor: anchor
|
100 | };
|
101 | },
|
102 | peg$c36 = ".",
|
103 | peg$c37 = { type: "literal", value: ".", description: "\".\"" },
|
104 | peg$c38 = function() {
|
105 | return text()
|
106 | },
|
107 | peg$c39 = /^[a-zA-Z_$]/,
|
108 | peg$c40 = { type: "class", value: "[a-zA-Z_$]", description: "[a-zA-Z_$]" },
|
109 | peg$c41 = /^[a-zA-Z0-9_$]/,
|
110 | peg$c42 = { type: "class", value: "[a-zA-Z0-9_$]", description: "[a-zA-Z0-9_$]" },
|
111 | peg$c43 = function(lc) { return lc; },
|
112 | peg$c44 = function(literal_chars) {
|
113 | return {
|
114 | type: 'literal',
|
115 | text: literal_chars.join('')
|
116 | };
|
117 | },
|
118 | peg$c45 = /^[\\#()|]/,
|
119 | peg$c46 = { type: "class", value: "[\\\\#()|]", description: "[\\\\#()|]" },
|
120 |
|
121 | peg$currPos = 0,
|
122 | peg$reportedPos = 0,
|
123 | peg$cachedPos = 0,
|
124 | peg$cachedPosDetails = { line: 1, column: 1, seenCR: false },
|
125 | peg$maxFailPos = 0,
|
126 | peg$maxFailExpected = [],
|
127 | peg$silentFails = 0,
|
128 |
|
129 | peg$result;
|
130 |
|
131 | if ("startRule" in options) {
|
132 | if (!(options.startRule in peg$startRuleFunctions)) {
|
133 | throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
|
134 | }
|
135 |
|
136 | peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
|
137 | }
|
138 |
|
139 | function text() {
|
140 | return input.substring(peg$reportedPos, peg$currPos);
|
141 | }
|
142 |
|
143 | function offset() {
|
144 | return peg$reportedPos;
|
145 | }
|
146 |
|
147 | function line() {
|
148 | return peg$computePosDetails(peg$reportedPos).line;
|
149 | }
|
150 |
|
151 | function column() {
|
152 | return peg$computePosDetails(peg$reportedPos).column;
|
153 | }
|
154 |
|
155 | function expected(description) {
|
156 | throw peg$buildException(
|
157 | null,
|
158 | [{ type: "other", description: description }],
|
159 | peg$reportedPos
|
160 | );
|
161 | }
|
162 |
|
163 | function error(message) {
|
164 | throw peg$buildException(message, null, peg$reportedPos);
|
165 | }
|
166 |
|
167 | function peg$computePosDetails(pos) {
|
168 | function advance(details, startPos, endPos) {
|
169 | var p, ch;
|
170 |
|
171 | for (p = startPos; p < endPos; p++) {
|
172 | ch = input.charAt(p);
|
173 | if (ch === "\n") {
|
174 | if (!details.seenCR) { details.line++; }
|
175 | details.column = 1;
|
176 | details.seenCR = false;
|
177 | } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
|
178 | details.line++;
|
179 | details.column = 1;
|
180 | details.seenCR = true;
|
181 | } else {
|
182 | details.column++;
|
183 | details.seenCR = false;
|
184 | }
|
185 | }
|
186 | }
|
187 |
|
188 | if (peg$cachedPos !== pos) {
|
189 | if (peg$cachedPos > pos) {
|
190 | peg$cachedPos = 0;
|
191 | peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
|
192 | }
|
193 | advance(peg$cachedPosDetails, peg$cachedPos, pos);
|
194 | peg$cachedPos = pos;
|
195 | }
|
196 |
|
197 | return peg$cachedPosDetails;
|
198 | }
|
199 |
|
200 | function peg$fail(expected) {
|
201 | if (peg$currPos < peg$maxFailPos) { return; }
|
202 |
|
203 | if (peg$currPos > peg$maxFailPos) {
|
204 | peg$maxFailPos = peg$currPos;
|
205 | peg$maxFailExpected = [];
|
206 | }
|
207 |
|
208 | peg$maxFailExpected.push(expected);
|
209 | }
|
210 |
|
211 | function peg$buildException(message, expected, pos) {
|
212 | function cleanupExpected(expected) {
|
213 | var i = 1;
|
214 |
|
215 | expected.sort(function(a, b) {
|
216 | if (a.description < b.description) {
|
217 | return -1;
|
218 | } else if (a.description > b.description) {
|
219 | return 1;
|
220 | } else {
|
221 | return 0;
|
222 | }
|
223 | });
|
224 |
|
225 | while (i < expected.length) {
|
226 | if (expected[i - 1] === expected[i]) {
|
227 | expected.splice(i, 1);
|
228 | } else {
|
229 | i++;
|
230 | }
|
231 | }
|
232 | }
|
233 |
|
234 | function buildMessage(expected, found) {
|
235 | function stringEscape(s) {
|
236 | function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
|
237 |
|
238 | return s
|
239 | .replace(/\\/g, '\\\\')
|
240 | .replace(/"/g, '\\"')
|
241 | .replace(/\x08/g, '\\b')
|
242 | .replace(/\t/g, '\\t')
|
243 | .replace(/\n/g, '\\n')
|
244 | .replace(/\f/g, '\\f')
|
245 | .replace(/\r/g, '\\r')
|
246 | .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
|
247 | .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
|
248 | .replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
|
249 | .replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
|
250 | }
|
251 |
|
252 | var expectedDescs = new Array(expected.length),
|
253 | expectedDesc, foundDesc, i;
|
254 |
|
255 | for (i = 0; i < expected.length; i++) {
|
256 | expectedDescs[i] = expected[i].description;
|
257 | }
|
258 |
|
259 | expectedDesc = expected.length > 1
|
260 | ? expectedDescs.slice(0, -1).join(", ")
|
261 | + " or "
|
262 | + expectedDescs[expected.length - 1]
|
263 | : expectedDescs[0];
|
264 |
|
265 | foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
|
266 |
|
267 | return "Expected " + expectedDesc + " but " + foundDesc + " found.";
|
268 | }
|
269 |
|
270 | var posDetails = peg$computePosDetails(pos),
|
271 | found = pos < input.length ? input.charAt(pos) : null;
|
272 |
|
273 | if (expected !== null) {
|
274 | cleanupExpected(expected);
|
275 | }
|
276 |
|
277 | return new SyntaxError(
|
278 | message !== null ? message : buildMessage(expected, found),
|
279 | expected,
|
280 | found,
|
281 | pos,
|
282 | posDetails.line,
|
283 | posDetails.column
|
284 | );
|
285 | }
|
286 |
|
287 | function peg$parsestart() {
|
288 | var s0, s1;
|
289 |
|
290 | s0 = [];
|
291 | s1 = peg$parseliteral();
|
292 | if (s1 === peg$FAILED) {
|
293 | s1 = peg$parseplural();
|
294 | if (s1 === peg$FAILED) {
|
295 | s1 = peg$parsevariable();
|
296 | }
|
297 | }
|
298 | while (s1 !== peg$FAILED) {
|
299 | s0.push(s1);
|
300 | s1 = peg$parseliteral();
|
301 | if (s1 === peg$FAILED) {
|
302 | s1 = peg$parseplural();
|
303 | if (s1 === peg$FAILED) {
|
304 | s1 = peg$parsevariable();
|
305 | }
|
306 | }
|
307 | }
|
308 |
|
309 | return s0;
|
310 | }
|
311 |
|
312 | function peg$parseplural() {
|
313 | var s0, s1, s2, s3, s4;
|
314 |
|
315 | s0 = peg$currPos;
|
316 | if (input.substr(peg$currPos, 2) === peg$c2) {
|
317 | s1 = peg$c2;
|
318 | peg$currPos += 2;
|
319 | } else {
|
320 | s1 = peg$FAILED;
|
321 | if (peg$silentFails === 0) { peg$fail(peg$c3); }
|
322 | }
|
323 | if (s1 !== peg$FAILED) {
|
324 | s2 = peg$parseplural_forms();
|
325 | if (s2 !== peg$FAILED) {
|
326 | if (input.substr(peg$currPos, 2) === peg$c4) {
|
327 | s3 = peg$c4;
|
328 | peg$currPos += 2;
|
329 | } else {
|
330 | s3 = peg$FAILED;
|
331 | if (peg$silentFails === 0) { peg$fail(peg$c5); }
|
332 | }
|
333 | if (s3 !== peg$FAILED) {
|
334 | s4 = peg$parseplural_anchor();
|
335 | if (s4 === peg$FAILED) {
|
336 | s4 = peg$c6;
|
337 | }
|
338 | if (s4 !== peg$FAILED) {
|
339 | peg$reportedPos = s0;
|
340 | s1 = peg$c7(s2, s4);
|
341 | s0 = s1;
|
342 | } else {
|
343 | peg$currPos = s0;
|
344 | s0 = peg$c1;
|
345 | }
|
346 | } else {
|
347 | peg$currPos = s0;
|
348 | s0 = peg$c1;
|
349 | }
|
350 | } else {
|
351 | peg$currPos = s0;
|
352 | s0 = peg$c1;
|
353 | }
|
354 | } else {
|
355 | peg$currPos = s0;
|
356 | s0 = peg$c1;
|
357 | }
|
358 |
|
359 | return s0;
|
360 | }
|
361 |
|
362 | function peg$parseplural_forms() {
|
363 | var s0, s1, s2, s3;
|
364 |
|
365 | s0 = peg$currPos;
|
366 | s1 = peg$parseplural_part();
|
367 | if (s1 !== peg$FAILED) {
|
368 | if (input.charCodeAt(peg$currPos) === 124) {
|
369 | s2 = peg$c8;
|
370 | peg$currPos++;
|
371 | } else {
|
372 | s2 = peg$FAILED;
|
373 | if (peg$silentFails === 0) { peg$fail(peg$c9); }
|
374 | }
|
375 | if (s2 !== peg$FAILED) {
|
376 | s3 = peg$parseplural_forms();
|
377 | if (s3 !== peg$FAILED) {
|
378 | peg$reportedPos = s0;
|
379 | s1 = peg$c10(s1, s3);
|
380 | s0 = s1;
|
381 | } else {
|
382 | peg$currPos = s0;
|
383 | s0 = peg$c1;
|
384 | }
|
385 | } else {
|
386 | peg$currPos = s0;
|
387 | s0 = peg$c1;
|
388 | }
|
389 | } else {
|
390 | peg$currPos = s0;
|
391 | s0 = peg$c1;
|
392 | }
|
393 | if (s0 === peg$FAILED) {
|
394 | s0 = peg$currPos;
|
395 | s1 = peg$parseplural_part();
|
396 | if (s1 !== peg$FAILED) {
|
397 | peg$reportedPos = s0;
|
398 | s1 = peg$c11(s1);
|
399 | }
|
400 | s0 = s1;
|
401 | }
|
402 |
|
403 | return s0;
|
404 | }
|
405 |
|
406 | function peg$parseplural_part() {
|
407 | var s0, s1, s2, s3, s4, s5;
|
408 |
|
409 | s0 = peg$currPos;
|
410 | if (input.charCodeAt(peg$currPos) === 61) {
|
411 | s1 = peg$c12;
|
412 | peg$currPos++;
|
413 | } else {
|
414 | s1 = peg$FAILED;
|
415 | if (peg$silentFails === 0) { peg$fail(peg$c13); }
|
416 | }
|
417 | if (s1 !== peg$FAILED) {
|
418 | s2 = [];
|
419 | if (peg$c14.test(input.charAt(peg$currPos))) {
|
420 | s3 = input.charAt(peg$currPos);
|
421 | peg$currPos++;
|
422 | } else {
|
423 | s3 = peg$FAILED;
|
424 | if (peg$silentFails === 0) { peg$fail(peg$c15); }
|
425 | }
|
426 | if (s3 !== peg$FAILED) {
|
427 | while (s3 !== peg$FAILED) {
|
428 | s2.push(s3);
|
429 | if (peg$c14.test(input.charAt(peg$currPos))) {
|
430 | s3 = input.charAt(peg$currPos);
|
431 | peg$currPos++;
|
432 | } else {
|
433 | s3 = peg$FAILED;
|
434 | if (peg$silentFails === 0) { peg$fail(peg$c15); }
|
435 | }
|
436 | }
|
437 | } else {
|
438 | s2 = peg$c1;
|
439 | }
|
440 | if (s2 !== peg$FAILED) {
|
441 | if (input.charCodeAt(peg$currPos) === 32) {
|
442 | s3 = peg$c16;
|
443 | peg$currPos++;
|
444 | } else {
|
445 | s3 = peg$FAILED;
|
446 | if (peg$silentFails === 0) { peg$fail(peg$c17); }
|
447 | }
|
448 | if (s3 === peg$FAILED) {
|
449 | s3 = peg$c6;
|
450 | }
|
451 | if (s3 !== peg$FAILED) {
|
452 | s4 = [];
|
453 | s5 = peg$parseplural_char();
|
454 | if (s5 !== peg$FAILED) {
|
455 | while (s5 !== peg$FAILED) {
|
456 | s4.push(s5);
|
457 | s5 = peg$parseplural_char();
|
458 | }
|
459 | } else {
|
460 | s4 = peg$c1;
|
461 | }
|
462 | if (s4 !== peg$FAILED) {
|
463 | peg$reportedPos = s0;
|
464 | s1 = peg$c18(s2, s4);
|
465 | s0 = s1;
|
466 | } else {
|
467 | peg$currPos = s0;
|
468 | s0 = peg$c1;
|
469 | }
|
470 | } else {
|
471 | peg$currPos = s0;
|
472 | s0 = peg$c1;
|
473 | }
|
474 | } else {
|
475 | peg$currPos = s0;
|
476 | s0 = peg$c1;
|
477 | }
|
478 | } else {
|
479 | peg$currPos = s0;
|
480 | s0 = peg$c1;
|
481 | }
|
482 | if (s0 === peg$FAILED) {
|
483 | s0 = peg$currPos;
|
484 | s1 = [];
|
485 | s2 = peg$parseplural_char();
|
486 | if (s2 !== peg$FAILED) {
|
487 | while (s2 !== peg$FAILED) {
|
488 | s1.push(s2);
|
489 | s2 = peg$parseplural_char();
|
490 | }
|
491 | } else {
|
492 | s1 = peg$c1;
|
493 | }
|
494 | if (s1 !== peg$FAILED) {
|
495 | peg$reportedPos = s0;
|
496 | s1 = peg$c19();
|
497 | }
|
498 | s0 = s1;
|
499 | }
|
500 |
|
501 | return s0;
|
502 | }
|
503 |
|
504 | function peg$parseplural_char() {
|
505 | var s0, s1, s2;
|
506 |
|
507 | s0 = peg$currPos;
|
508 | if (input.charCodeAt(peg$currPos) === 92) {
|
509 | s1 = peg$c20;
|
510 | peg$currPos++;
|
511 | } else {
|
512 | s1 = peg$FAILED;
|
513 | if (peg$silentFails === 0) { peg$fail(peg$c21); }
|
514 | }
|
515 | if (s1 !== peg$FAILED) {
|
516 | if (peg$c22.test(input.charAt(peg$currPos))) {
|
517 | s2 = input.charAt(peg$currPos);
|
518 | peg$currPos++;
|
519 | } else {
|
520 | s2 = peg$FAILED;
|
521 | if (peg$silentFails === 0) { peg$fail(peg$c23); }
|
522 | }
|
523 | if (s2 !== peg$FAILED) {
|
524 | peg$reportedPos = s0;
|
525 | s1 = peg$c24(s2);
|
526 | s0 = s1;
|
527 | } else {
|
528 | peg$currPos = s0;
|
529 | s0 = peg$c1;
|
530 | }
|
531 | } else {
|
532 | peg$currPos = s0;
|
533 | s0 = peg$c1;
|
534 | }
|
535 | if (s0 === peg$FAILED) {
|
536 | s0 = peg$currPos;
|
537 | s1 = peg$currPos;
|
538 | peg$silentFails++;
|
539 | if (input.charCodeAt(peg$currPos) === 124) {
|
540 | s2 = peg$c8;
|
541 | peg$currPos++;
|
542 | } else {
|
543 | s2 = peg$FAILED;
|
544 | if (peg$silentFails === 0) { peg$fail(peg$c9); }
|
545 | }
|
546 | if (s2 === peg$FAILED) {
|
547 | if (input.substr(peg$currPos, 2) === peg$c4) {
|
548 | s2 = peg$c4;
|
549 | peg$currPos += 2;
|
550 | } else {
|
551 | s2 = peg$FAILED;
|
552 | if (peg$silentFails === 0) { peg$fail(peg$c5); }
|
553 | }
|
554 | }
|
555 | peg$silentFails--;
|
556 | if (s2 === peg$FAILED) {
|
557 | s1 = peg$c25;
|
558 | } else {
|
559 | peg$currPos = s1;
|
560 | s1 = peg$c1;
|
561 | }
|
562 | if (s1 !== peg$FAILED) {
|
563 | if (input.length > peg$currPos) {
|
564 | s2 = input.charAt(peg$currPos);
|
565 | peg$currPos++;
|
566 | } else {
|
567 | s2 = peg$FAILED;
|
568 | if (peg$silentFails === 0) { peg$fail(peg$c26); }
|
569 | }
|
570 | if (s2 !== peg$FAILED) {
|
571 | peg$reportedPos = s0;
|
572 | s1 = peg$c27();
|
573 | s0 = s1;
|
574 | } else {
|
575 | peg$currPos = s0;
|
576 | s0 = peg$c1;
|
577 | }
|
578 | } else {
|
579 | peg$currPos = s0;
|
580 | s0 = peg$c1;
|
581 | }
|
582 | }
|
583 |
|
584 | return s0;
|
585 | }
|
586 |
|
587 | function peg$parseplural_anchor() {
|
588 | var s0, s1, s2;
|
589 |
|
590 | s0 = peg$currPos;
|
591 | if (input.charCodeAt(peg$currPos) === 58) {
|
592 | s1 = peg$c28;
|
593 | peg$currPos++;
|
594 | } else {
|
595 | s1 = peg$FAILED;
|
596 | if (peg$silentFails === 0) { peg$fail(peg$c29); }
|
597 | }
|
598 | if (s1 !== peg$FAILED) {
|
599 | s2 = peg$parseidentifier();
|
600 | if (s2 !== peg$FAILED) {
|
601 | peg$reportedPos = s0;
|
602 | s1 = peg$c30(s2);
|
603 | s0 = s1;
|
604 | } else {
|
605 | peg$currPos = s0;
|
606 | s0 = peg$c1;
|
607 | }
|
608 | } else {
|
609 | peg$currPos = s0;
|
610 | s0 = peg$c1;
|
611 | }
|
612 |
|
613 | return s0;
|
614 | }
|
615 |
|
616 | function peg$parsevariable() {
|
617 | var s0, s1, s2, s3;
|
618 |
|
619 | s0 = peg$currPos;
|
620 | if (input.substr(peg$currPos, 2) === peg$c31) {
|
621 | s1 = peg$c31;
|
622 | peg$currPos += 2;
|
623 | } else {
|
624 | s1 = peg$FAILED;
|
625 | if (peg$silentFails === 0) { peg$fail(peg$c32); }
|
626 | }
|
627 | if (s1 !== peg$FAILED) {
|
628 | s2 = peg$parseidentifier();
|
629 | if (s2 !== peg$FAILED) {
|
630 | if (input.charCodeAt(peg$currPos) === 125) {
|
631 | s3 = peg$c33;
|
632 | peg$currPos++;
|
633 | } else {
|
634 | s3 = peg$FAILED;
|
635 | if (peg$silentFails === 0) { peg$fail(peg$c34); }
|
636 | }
|
637 | if (s3 !== peg$FAILED) {
|
638 | peg$reportedPos = s0;
|
639 | s1 = peg$c35(s2);
|
640 | s0 = s1;
|
641 | } else {
|
642 | peg$currPos = s0;
|
643 | s0 = peg$c1;
|
644 | }
|
645 | } else {
|
646 | peg$currPos = s0;
|
647 | s0 = peg$c1;
|
648 | }
|
649 | } else {
|
650 | peg$currPos = s0;
|
651 | s0 = peg$c1;
|
652 | }
|
653 |
|
654 | return s0;
|
655 | }
|
656 |
|
657 | function peg$parseidentifier() {
|
658 | var s0, s1, s2, s3, s4;
|
659 |
|
660 | s0 = peg$currPos;
|
661 | s1 = peg$parseidentifier_part();
|
662 | if (s1 !== peg$FAILED) {
|
663 | if (input.charCodeAt(peg$currPos) === 46) {
|
664 | s2 = peg$c36;
|
665 | peg$currPos++;
|
666 | } else {
|
667 | s2 = peg$FAILED;
|
668 | if (peg$silentFails === 0) { peg$fail(peg$c37); }
|
669 | }
|
670 | if (s2 !== peg$FAILED) {
|
671 | s3 = [];
|
672 | s4 = peg$parseidentifier();
|
673 | if (s4 !== peg$FAILED) {
|
674 | while (s4 !== peg$FAILED) {
|
675 | s3.push(s4);
|
676 | s4 = peg$parseidentifier();
|
677 | }
|
678 | } else {
|
679 | s3 = peg$c1;
|
680 | }
|
681 | if (s3 !== peg$FAILED) {
|
682 | peg$reportedPos = s0;
|
683 | s1 = peg$c38();
|
684 | s0 = s1;
|
685 | } else {
|
686 | peg$currPos = s0;
|
687 | s0 = peg$c1;
|
688 | }
|
689 | } else {
|
690 | peg$currPos = s0;
|
691 | s0 = peg$c1;
|
692 | }
|
693 | } else {
|
694 | peg$currPos = s0;
|
695 | s0 = peg$c1;
|
696 | }
|
697 | if (s0 === peg$FAILED) {
|
698 | s0 = peg$parseidentifier_part();
|
699 | }
|
700 |
|
701 | return s0;
|
702 | }
|
703 |
|
704 | function peg$parseidentifier_part() {
|
705 | var s0, s1, s2, s3;
|
706 |
|
707 | s0 = peg$currPos;
|
708 | if (peg$c39.test(input.charAt(peg$currPos))) {
|
709 | s1 = input.charAt(peg$currPos);
|
710 | peg$currPos++;
|
711 | } else {
|
712 | s1 = peg$FAILED;
|
713 | if (peg$silentFails === 0) { peg$fail(peg$c40); }
|
714 | }
|
715 | if (s1 !== peg$FAILED) {
|
716 | s2 = [];
|
717 | if (peg$c41.test(input.charAt(peg$currPos))) {
|
718 | s3 = input.charAt(peg$currPos);
|
719 | peg$currPos++;
|
720 | } else {
|
721 | s3 = peg$FAILED;
|
722 | if (peg$silentFails === 0) { peg$fail(peg$c42); }
|
723 | }
|
724 | while (s3 !== peg$FAILED) {
|
725 | s2.push(s3);
|
726 | if (peg$c41.test(input.charAt(peg$currPos))) {
|
727 | s3 = input.charAt(peg$currPos);
|
728 | peg$currPos++;
|
729 | } else {
|
730 | s3 = peg$FAILED;
|
731 | if (peg$silentFails === 0) { peg$fail(peg$c42); }
|
732 | }
|
733 | }
|
734 | if (s2 !== peg$FAILED) {
|
735 | peg$reportedPos = s0;
|
736 | s1 = peg$c27();
|
737 | s0 = s1;
|
738 | } else {
|
739 | peg$currPos = s0;
|
740 | s0 = peg$c1;
|
741 | }
|
742 | } else {
|
743 | peg$currPos = s0;
|
744 | s0 = peg$c1;
|
745 | }
|
746 |
|
747 | return s0;
|
748 | }
|
749 |
|
750 | function peg$parseliteral() {
|
751 | var s0, s1, s2, s3, s4;
|
752 |
|
753 | s0 = peg$currPos;
|
754 | s1 = [];
|
755 | s2 = peg$currPos;
|
756 | s3 = peg$currPos;
|
757 | peg$silentFails++;
|
758 | s4 = peg$parseplural();
|
759 | if (s4 === peg$FAILED) {
|
760 | s4 = peg$parsevariable();
|
761 | }
|
762 | peg$silentFails--;
|
763 | if (s4 === peg$FAILED) {
|
764 | s3 = peg$c25;
|
765 | } else {
|
766 | peg$currPos = s3;
|
767 | s3 = peg$c1;
|
768 | }
|
769 | if (s3 !== peg$FAILED) {
|
770 | s4 = peg$parseliteral_char();
|
771 | if (s4 !== peg$FAILED) {
|
772 | peg$reportedPos = s2;
|
773 | s3 = peg$c43(s4);
|
774 | s2 = s3;
|
775 | } else {
|
776 | peg$currPos = s2;
|
777 | s2 = peg$c1;
|
778 | }
|
779 | } else {
|
780 | peg$currPos = s2;
|
781 | s2 = peg$c1;
|
782 | }
|
783 | if (s2 !== peg$FAILED) {
|
784 | while (s2 !== peg$FAILED) {
|
785 | s1.push(s2);
|
786 | s2 = peg$currPos;
|
787 | s3 = peg$currPos;
|
788 | peg$silentFails++;
|
789 | s4 = peg$parseplural();
|
790 | if (s4 === peg$FAILED) {
|
791 | s4 = peg$parsevariable();
|
792 | }
|
793 | peg$silentFails--;
|
794 | if (s4 === peg$FAILED) {
|
795 | s3 = peg$c25;
|
796 | } else {
|
797 | peg$currPos = s3;
|
798 | s3 = peg$c1;
|
799 | }
|
800 | if (s3 !== peg$FAILED) {
|
801 | s4 = peg$parseliteral_char();
|
802 | if (s4 !== peg$FAILED) {
|
803 | peg$reportedPos = s2;
|
804 | s3 = peg$c43(s4);
|
805 | s2 = s3;
|
806 | } else {
|
807 | peg$currPos = s2;
|
808 | s2 = peg$c1;
|
809 | }
|
810 | } else {
|
811 | peg$currPos = s2;
|
812 | s2 = peg$c1;
|
813 | }
|
814 | }
|
815 | } else {
|
816 | s1 = peg$c1;
|
817 | }
|
818 | if (s1 !== peg$FAILED) {
|
819 | peg$reportedPos = s0;
|
820 | s1 = peg$c44(s1);
|
821 | }
|
822 | s0 = s1;
|
823 |
|
824 | return s0;
|
825 | }
|
826 |
|
827 | function peg$parseliteral_char() {
|
828 | var s0, s1, s2;
|
829 |
|
830 | s0 = peg$currPos;
|
831 | if (input.charCodeAt(peg$currPos) === 92) {
|
832 | s1 = peg$c20;
|
833 | peg$currPos++;
|
834 | } else {
|
835 | s1 = peg$FAILED;
|
836 | if (peg$silentFails === 0) { peg$fail(peg$c21); }
|
837 | }
|
838 | if (s1 !== peg$FAILED) {
|
839 | if (peg$c45.test(input.charAt(peg$currPos))) {
|
840 | s2 = input.charAt(peg$currPos);
|
841 | peg$currPos++;
|
842 | } else {
|
843 | s2 = peg$FAILED;
|
844 | if (peg$silentFails === 0) { peg$fail(peg$c46); }
|
845 | }
|
846 | if (s2 !== peg$FAILED) {
|
847 | peg$reportedPos = s0;
|
848 | s1 = peg$c24(s2);
|
849 | s0 = s1;
|
850 | } else {
|
851 | peg$currPos = s0;
|
852 | s0 = peg$c1;
|
853 | }
|
854 | } else {
|
855 | peg$currPos = s0;
|
856 | s0 = peg$c1;
|
857 | }
|
858 | if (s0 === peg$FAILED) {
|
859 | if (input.length > peg$currPos) {
|
860 | s0 = input.charAt(peg$currPos);
|
861 | peg$currPos++;
|
862 | } else {
|
863 | s0 = peg$FAILED;
|
864 | if (peg$silentFails === 0) { peg$fail(peg$c26); }
|
865 | }
|
866 | }
|
867 |
|
868 | return s0;
|
869 | }
|
870 |
|
871 |
|
872 | function regularForms(forms) {
|
873 | var result = [];
|
874 | for (var i=0; i<forms.length; i++) {
|
875 | if (forms[i].strict === undefined) { result.push(forms[i].text); }
|
876 | }
|
877 | return result;
|
878 | }
|
879 | function strictForms(forms) {
|
880 | var result = {};
|
881 | for (var i=0; i<forms.length; i++) {
|
882 | if (forms[i].strict !== undefined) { result[forms[i].strict] = forms[i].text; }
|
883 | }
|
884 | return result;
|
885 | }
|
886 |
|
887 |
|
888 | peg$result = peg$startRuleFunction();
|
889 |
|
890 | if (peg$result !== peg$FAILED && peg$currPos === input.length) {
|
891 | return peg$result;
|
892 | } else {
|
893 | if (peg$result !== peg$FAILED && peg$currPos < input.length) {
|
894 | peg$fail({ type: "end", description: "end of input" });
|
895 | }
|
896 |
|
897 | throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
|
898 | }
|
899 | }
|
900 |
|
901 | return {
|
902 | SyntaxError: SyntaxError,
|
903 | parse: parse
|
904 | };
|
905 | })();
|