gettext-po-parser
Version:
Gettext PO file parser
1,817 lines (1,710 loc) • 76.2 kB
JavaScript
/*
* Generated by PEG.js 0.10.0.
*
* http://pegjs.org/
*/
"use strict";
function peg$subclass(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor();
}
function peg$SyntaxError(message, expected, found, location) {
this.message = message;
this.expected = expected;
this.found = found;
this.location = location;
this.name = "SyntaxError";
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(this, peg$SyntaxError);
}
}
peg$subclass(peg$SyntaxError, Error);
peg$SyntaxError.buildMessage = function(expected, found) {
var DESCRIBE_EXPECTATION_FNS = {
literal: function(expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
"class": function(expectation) {
var escapedParts = "",
i;
for (i = 0; i < expectation.parts.length; i++) {
escapedParts += expectation.parts[i] instanceof Array
? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])
: classEscape(expectation.parts[i]);
}
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
},
any: function(expectation) {
return "any character";
},
end: function(expectation) {
return "end of input";
},
other: function(expectation) {
return expectation.description;
}
};
function hex(ch) {
return ch.charCodeAt(0).toString(16).toUpperCase();
}
function literalEscape(s) {
return s
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\0/g, '\\0')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
}
function classEscape(s) {
return s
.replace(/\\/g, '\\\\')
.replace(/\]/g, '\\]')
.replace(/\^/g, '\\^')
.replace(/-/g, '\\-')
.replace(/\0/g, '\\0')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
}
function describeExpectation(expectation) {
return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
}
function describeExpected(expected) {
var descriptions = new Array(expected.length),
i, j;
for (i = 0; i < expected.length; i++) {
descriptions[i] = describeExpectation(expected[i]);
}
descriptions.sort();
if (descriptions.length > 0) {
for (i = 1, j = 1; i < descriptions.length; i++) {
if (descriptions[i - 1] !== descriptions[i]) {
descriptions[j] = descriptions[i];
j++;
}
}
descriptions.length = j;
}
switch (descriptions.length) {
case 1:
return descriptions[0];
case 2:
return descriptions[0] + " or " + descriptions[1];
default:
return descriptions.slice(0, -1).join(", ")
+ ", or "
+ descriptions[descriptions.length - 1];
}
}
function describeFound(found) {
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
}
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
};
function peg$parse(input, options) {
options = options !== void 0 ? options : {};
var peg$FAILED = {},
peg$startRuleFunctions = { Catalog: peg$parseCatalog },
peg$startRuleFunction = peg$parseCatalog,
peg$c0 = function(first, rest) {
return {
location: location(),
messages: buildList(first, rest, 1),
};
},
peg$c1 = function(commentsGroup, previousStringsGroup) { return setParsingObsolete(false); },
peg$c2 = function(commentsGroup, previousStringsGroup, strings) {
return strings;
},
peg$c3 = "#~",
peg$c4 = peg$literalExpectation("#~", false),
peg$c5 = function(commentsGroup, previousStringsGroup) { return setParsingObsolete(true); },
peg$c6 = function(commentsGroup, previousStringsGroup, strings) {
return strings[0];
},
peg$c7 = function(commentsGroup, previousStringsGroup, strings) {
return [extractOptional(commentsGroup, 0) || [], extractOptional(previousStringsGroup, 0) || [null, null, null],
strings];
},
peg$c8 = function() { return setParsingObsolete(true); },
peg$c9 = function(commentsGroup, previousStringsGroup, strings) { return setParsingObsolete(false); },
peg$c10 = function(commentsGroup, previousStringsGroup, strings) {
return [extractOptional(commentsGroup, 0) || [], extractOptional(previousStringsGroup, 0) || [null, null, null],
strings];
},
peg$c11 = function() { return setParsingObsolete(false); },
peg$c12 = function(message) {
return message;
},
peg$c13 = function(message) {
const [comments, previousStrings, strings] = message;
const typeToComments = new Map();
for (const { type, ...comment } of comments) {
let typeComments = typeToComments.get(type);
if (!typeComments) {
typeComments = [];
typeToComments.set(type, typeComments);
}
typeComments.push(comment);
}
const translatorComments = typeToComments.get('translator') || [];
const extractedComments = typeToComments.get('extracted') || [];
const references = typeToComments.get('reference') || [];
const flags = typeToComments.has('flags') ? typeToComments.get('flags').reduce((mergedFlags, flags) => ({
location: {
start: mergedFlags.location.start,
end: flags.location.end,
},
value: [...mergedFlags.value, ...flags.value],
})) : null;
const [previousContext, previousUntranslatedString, previousUntranslatedPluralString] = previousStrings;
const [context, untranslatedString, untranslatedPluralString, translatedStrings, isObsolete] = strings;
return {
location: location(),
translatorComments,
extractedComments,
references,
flags,
previousContext,
previousUntranslatedString,
previousUntranslatedPluralString,
context,
untranslatedString,
untranslatedPluralString,
translatedStrings,
isObsolete,
};
},
peg$c14 = function(first, rest) { return buildList(first, rest, 1); },
peg$c15 = "#",
peg$c16 = peg$literalExpectation("#", false),
peg$c17 = "~",
peg$c18 = peg$literalExpectation("~", false),
peg$c19 = "|",
peg$c20 = peg$literalExpectation("|", false),
peg$c21 = " ",
peg$c22 = peg$literalExpectation(" ", false),
peg$c23 = /^[^\n]/,
peg$c24 = peg$classExpectation(["\n"], true, false),
peg$c25 = function(value) {
return {
location: location(),
type: 'translator',
value,
};
},
peg$c26 = "#.",
peg$c27 = peg$literalExpectation("#.", false),
peg$c28 = function(value) {
return {
location: location(),
type: 'extracted',
value,
};
},
peg$c29 = "#:",
peg$c30 = peg$literalExpectation("#:", false),
peg$c31 = function(value) {
return {
location: location(),
type: 'reference',
value,
};
},
peg$c32 = "#,",
peg$c33 = peg$literalExpectation("#,", false),
peg$c34 = ",",
peg$c35 = peg$literalExpectation(",", false),
peg$c36 = function(first, rest) {
return {
location: location(),
type: 'flags',
value: buildList(first, rest, 2),
};
},
peg$c37 = /^[^,\n]/,
peg$c38 = peg$classExpectation([",", "\n"], true, false),
peg$c39 = function(flag) { return flag.trim(); },
peg$c40 = function(previousContextGroup, previousUntranslatedString, previousUntranslatedPluralStringGroup) {
return [extractOptional(previousContextGroup, 0), previousUntranslatedString, extractOptional(previousUntranslatedPluralStringGroup, 1)];
},
peg$c41 = "#|",
peg$c42 = peg$literalExpectation("#|", false),
peg$c43 = "msgctxt",
peg$c44 = peg$literalExpectation("msgctxt", false),
peg$c45 = function(value) {
return {
location: location(),
value,
};
},
peg$c46 = "msgid",
peg$c47 = peg$literalExpectation("msgid", false),
peg$c48 = "msgid_plural",
peg$c49 = peg$literalExpectation("msgid_plural", false),
peg$c50 = function(contextGroup, untranslatedString, translatedString) {
return [extractOptional(contextGroup, 0), untranslatedString, null, [translatedString], isParsingObsolete];
},
peg$c51 = function(contextGroup, untranslatedString, untranslatedPluralString, translatedPluralStrings) {
return [extractOptional(contextGroup, 0), untranslatedString, untranslatedPluralString, translatedPluralStrings,
isParsingObsolete];
},
peg$c52 = "msgstr",
peg$c53 = peg$literalExpectation("msgstr", false),
peg$c54 = function(first, rest) {
if (first[0] !== 0) {
error('First translated plural string has non-zero index');
}
for (let i = 0; i < rest.length; ++i) {
if (rest[i][1][0] !== 1 + i) {
error('Translated plural string has wrong index');
}
}
return buildList(first[1], rest.map(it => it[1]), 1);
},
peg$c55 = "[",
peg$c56 = peg$literalExpectation("[", false),
peg$c57 = /^[0-9]/,
peg$c58 = peg$classExpectation([["0", "9"]], false, false),
peg$c59 = "]",
peg$c60 = peg$literalExpectation("]", false),
peg$c61 = function(digits, value) {
return [Number.parseInt(digits, 10), {
location: location(),
value,
}];
},
peg$c62 = function(first, rest) { return buildList(first, rest, 1).join(''); },
peg$c63 = "\"",
peg$c64 = peg$literalExpectation("\"", false),
peg$c65 = function(chars) {
if (options.rawString) {
const stringText = text();
return stringText.substring(1, stringText.length - 1);
} else {
return chars.join('');
}
},
peg$c66 = /^[^"\\\n]/,
peg$c67 = peg$classExpectation(["\"", "\\", "\n"], true, false),
peg$c68 = "\\'",
peg$c69 = peg$literalExpectation("\\'", false),
peg$c70 = "\\\"",
peg$c71 = peg$literalExpectation("\\\"", false),
peg$c72 = "\\?",
peg$c73 = peg$literalExpectation("\\?", false),
peg$c74 = "\\\\",
peg$c75 = peg$literalExpectation("\\\\", false),
peg$c76 = function() { return text().charAt(1); },
peg$c77 = "\\a",
peg$c78 = peg$literalExpectation("\\a", false),
peg$c79 = function() { return '\x07'; },
peg$c80 = "\\b",
peg$c81 = peg$literalExpectation("\\b", false),
peg$c82 = function() { return '\b'; },
peg$c83 = "\\f",
peg$c84 = peg$literalExpectation("\\f", false),
peg$c85 = function() { return '\f'; },
peg$c86 = "\\n",
peg$c87 = peg$literalExpectation("\\n", false),
peg$c88 = function() { return '\n'; },
peg$c89 = "\\r",
peg$c90 = peg$literalExpectation("\\r", false),
peg$c91 = function() { return '\r'; },
peg$c92 = "\\t",
peg$c93 = peg$literalExpectation("\\t", false),
peg$c94 = function() { return '\t'; },
peg$c95 = "\\v",
peg$c96 = peg$literalExpectation("\\v", false),
peg$c97 = function() { return '\v'; },
peg$c98 = "\\",
peg$c99 = peg$literalExpectation("\\", false),
peg$c100 = function(digits) { return String.fromCharCode(Number.parseInt(digits, 8)); },
peg$c101 = /^[0-7]/,
peg$c102 = peg$classExpectation([["0", "7"]], false, false),
peg$c103 = "\\x",
peg$c104 = peg$literalExpectation("\\x", false),
peg$c105 = function(digits) { return String.fromCharCode(Number.parseInt(digits, 16)); },
peg$c106 = "\\u",
peg$c107 = peg$literalExpectation("\\u", false),
peg$c108 = "\\U",
peg$c109 = peg$literalExpectation("\\U", false),
peg$c110 = function(universalCharacterName) {
const digits = universalCharacterName[1];
const charCode = Number.parseInt(digits, 16);
// The disallowed characters are the characters in the basic character set and the code positions reserved by
// ISO/IEC 10646 for control characters, the character DELETE, and the S-zone (reserved for use by UTF−16).
if ((charCode >= 0x0000 && charCode <= 0x001F)
|| (charCode >= 0x007F && charCode <= 0x009F)
|| (charCode >= 0xD800 && charCode <= 0xDFFF)) {
error('Disallowed character in universal character name: 0x' + digits);
}
return String.fromCharCode(charCode);
},
peg$c111 = /^[0-9a-fA-F]/,
peg$c112 = peg$classExpectation([["0", "9"], ["a", "f"], ["A", "F"]], false, false),
peg$c113 = peg$otherExpectation("Whitespace"),
peg$c114 = function() { return isParsingObsolete; },
peg$c115 = /^[ \f\n\r\t\x0B]/,
peg$c116 = peg$classExpectation([" ", "\f", "\n", "\r", "\t", "\x0B"], false, false),
peg$c117 = /^[ \f\r\t\x0B]/,
peg$c118 = peg$classExpectation([" ", "\f", "\r", "\t", "\x0B"], false, false),
peg$c119 = "\n",
peg$c120 = peg$literalExpectation("\n", false),
peg$c121 = peg$otherExpectation("NonNewlineWhitespace"),
peg$currPos = 0,
peg$savedPos = 0,
peg$posDetailsCache = [{ line: 1, column: 1 }],
peg$maxFailPos = 0,
peg$maxFailExpected = [],
peg$silentFails = 0,
peg$result;
if ("startRule" in options) {
if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
}
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
}
function text() {
return input.substring(peg$savedPos, peg$currPos);
}
function location() {
return peg$computeLocation(peg$savedPos, peg$currPos);
}
function expected(description, location) {
location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
throw peg$buildStructuredError(
[peg$otherExpectation(description)],
input.substring(peg$savedPos, peg$currPos),
location
);
}
function error(message, location) {
location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
throw peg$buildSimpleError(message, location);
}
function peg$literalExpectation(text, ignoreCase) {
return { type: "literal", text: text, ignoreCase: ignoreCase };
}
function peg$classExpectation(parts, inverted, ignoreCase) {
return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
}
function peg$anyExpectation() {
return { type: "any" };
}
function peg$endExpectation() {
return { type: "end" };
}
function peg$otherExpectation(description) {
return { type: "other", description: description };
}
function peg$computePosDetails(pos) {
var details = peg$posDetailsCache[pos], p;
if (details) {
return details;
} else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
p--;
}
details = peg$posDetailsCache[p];
details = {
line: details.line,
column: details.column
};
while (p < pos) {
if (input.charCodeAt(p) === 10) {
details.line++;
details.column = 1;
} else {
details.column++;
}
p++;
}
peg$posDetailsCache[pos] = details;
return details;
}
}
function peg$computeLocation(startPos, endPos) {
var startPosDetails = peg$computePosDetails(startPos),
endPosDetails = peg$computePosDetails(endPos);
return {
start: {
offset: startPos,
line: startPosDetails.line,
column: startPosDetails.column
},
end: {
offset: endPos,
line: endPosDetails.line,
column: endPosDetails.column
}
};
}
function peg$fail(expected) {
if (peg$currPos < peg$maxFailPos) { return; }
if (peg$currPos > peg$maxFailPos) {
peg$maxFailPos = peg$currPos;
peg$maxFailExpected = [];
}
peg$maxFailExpected.push(expected);
}
function peg$buildSimpleError(message, location) {
return new peg$SyntaxError(message, null, null, location);
}
function peg$buildStructuredError(expected, found, location) {
return new peg$SyntaxError(
peg$SyntaxError.buildMessage(expected, found),
expected,
found,
location
);
}
function peg$parseCatalog() {
var s0, s1, s2, s3, s4, s5, s6, s7;
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parseMessage();
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$currPos;
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s6 = peg$parseMessage();
if (s6 !== peg$FAILED) {
s5 = [s5, s6];
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$currPos;
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s6 = peg$parseMessage();
if (s6 !== peg$FAILED) {
s5 = [s5, s6];
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
}
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$currPos;
s6 = peg$parse_();
if (s6 !== peg$FAILED) {
s7 = peg$parseComments();
if (s7 !== peg$FAILED) {
s6 = [s6, s7];
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$currPos;
s6 = peg$parse_();
if (s6 !== peg$FAILED) {
s7 = peg$parseComments();
if (s7 !== peg$FAILED) {
s6 = [s6, s7];
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
}
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0(s2, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseMessage() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$currPos;
s3 = peg$parseComments();
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 === peg$FAILED) {
s2 = null;
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
s4 = peg$parsePreviousStrings();
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
s4 = peg$currPos;
peg$savedPos = peg$currPos;
s5 = peg$c1(s2, s3);
if (s5) {
s5 = void 0;
} else {
s5 = peg$FAILED;
}
if (s5 !== peg$FAILED) {
s6 = peg$parseStrings();
if (s6 !== peg$FAILED) {
peg$savedPos = s4;
s5 = peg$c2(s2, s3, s6);
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 === peg$FAILED) {
s4 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c3) {
s5 = peg$c3;
peg$currPos += 2;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c4); }
}
if (s5 !== peg$FAILED) {
s6 = peg$parse_();
if (s6 !== peg$FAILED) {
peg$savedPos = peg$currPos;
s7 = peg$c5(s2, s3);
if (s7) {
s7 = void 0;
} else {
s7 = peg$FAILED;
}
if (s7 !== peg$FAILED) {
s8 = peg$currPos;
s9 = peg$parseStrings();
if (s9 !== peg$FAILED) {
peg$savedPos = peg$currPos;
s10 = peg$c1(s2, s3);
if (s10) {
s10 = void 0;
} else {
s10 = peg$FAILED;
}
if (s10 !== peg$FAILED) {
s9 = [s9, s10];
s8 = s9;
} else {
peg$currPos = s8;
s8 = peg$FAILED;
}
} else {
peg$currPos = s8;
s8 = peg$FAILED;
}
if (s8 === peg$FAILED) {
peg$savedPos = peg$currPos;
s8 = peg$c1(s2, s3);
if (s8) {
s8 = peg$FAILED;
} else {
s8 = void 0;
}
}
if (s8 !== peg$FAILED) {
peg$savedPos = s4;
s5 = peg$c6(s2, s3, s8);
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
}
if (s4 !== peg$FAILED) {
peg$savedPos = s1;
s2 = peg$c7(s2, s3, s4);
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 === peg$FAILED) {
s1 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c3) {
s2 = peg$c3;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c4); }
}
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
peg$savedPos = peg$currPos;
s4 = peg$c8();
if (s4) {
s4 = void 0;
} else {
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
s5 = peg$currPos;
s6 = peg$currPos;
s7 = peg$parseComments();
if (s7 !== peg$FAILED) {
s8 = peg$parse_();
if (s8 !== peg$FAILED) {
s7 = [s7, s8];
s6 = s7;
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
if (s6 === peg$FAILED) {
s6 = null;
}
if (s6 !== peg$FAILED) {
s7 = peg$currPos;
s8 = peg$parsePreviousStrings();
if (s8 !== peg$FAILED) {
s9 = peg$parse_();
if (s9 !== peg$FAILED) {
s8 = [s8, s9];
s7 = s8;
} else {
peg$currPos = s7;
s7 = peg$FAILED;
}
} else {
peg$currPos = s7;
s7 = peg$FAILED;
}
if (s7 === peg$FAILED) {
s7 = null;
}
if (s7 !== peg$FAILED) {
s8 = peg$parseStrings();
if (s8 !== peg$FAILED) {
peg$savedPos = peg$currPos;
s9 = peg$c9(s6, s7, s8);
if (s9) {
s9 = void 0;
} else {
s9 = peg$FAILED;
}
if (s9 !== peg$FAILED) {
peg$savedPos = s5;
s6 = peg$c10(s6, s7, s8);
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
if (s5 === peg$FAILED) {
peg$savedPos = peg$currPos;
s5 = peg$c11();
if (s5) {
s5 = peg$FAILED;
} else {
s5 = void 0;
}
}
if (s5 !== peg$FAILED) {
peg$savedPos = s1;
s2 = peg$c12(s5);
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c13(s1);
}
s0 = s1;
return s0;
}
function peg$parseComments() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$parseComment();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parseComment();
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$currPos;
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parseComment();
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c14(s1, s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseComment() {
var s0;
s0 = peg$parseExtractedComment();
if (s0 === peg$FAILED) {
s0 = peg$parseReferenceComment();
if (s0 === peg$FAILED) {
s0 = peg$parseFlagsComment();
if (s0 === peg$FAILED) {
s0 = peg$parseTranslatorComment();
}
}
}
return s0;
}
function peg$parseTranslatorComment() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 35) {
s1 = peg$c15;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c16); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 126) {
s4 = peg$c17;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c18); }
}
if (s4 !== peg$FAILED) {
s5 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 124) {
s6 = peg$c19;
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c20); }
}
peg$silentFails--;
if (s6 === peg$FAILED) {
s5 = void 0;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = void 0;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 32) {
s3 = peg$c21;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c22); }
}
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
s4 = peg$currPos;
s5 = [];
if (peg$c23.test(input.charAt(peg$currPos))) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
while (s6 !== peg$FAILED) {
s5.push(s6);
if (peg$c23.test(input.charAt(peg$currPos))) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
}
if (s5 !== peg$FAILED) {
s4 = input.substring(s4, peg$currPos);
} else {
s4 = s5;
}
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c25(s4);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseExtractedComment() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c26) {
s1 = peg$c26;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 32) {
s2 = peg$c21;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c22); }
}
if (s2 === peg$FAILED) {
s2 = null;
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
s4 = [];
if (peg$c23.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
while (s5 !== peg$FAILED) {
s4.push(s5);
if (peg$c23.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
}
if (s4 !== peg$FAILED) {
s3 = input.substring(s3, peg$currPos);
} else {
s3 = s4;
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c28(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseReferenceComment() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c29) {
s1 = peg$c29;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c30); }
}
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 32) {
s2 = peg$c21;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c22); }
}
if (s2 === peg$FAILED) {
s2 = null;
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
s4 = [];
if (peg$c23.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
while (s5 !== peg$FAILED) {
s4.push(s5);
if (peg$c23.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
}
if (s4 !== peg$FAILED) {
s3 = input.substring(s3, peg$currPos);
} else {
s3 = s4;
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c31(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseFlagsComment() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c32) {
s1 = peg$c32;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c33); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$parseFlag();
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s6 = peg$c34;
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c35); }
}
if (s6 !== peg$FAILED) {
s7 = peg$parse__();
if (s7 !== peg$FAILED) {
s8 = peg$parseFlag();
if (s8 !== peg$FAILED) {
s6 = [s6, s7, s8];
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s6 = peg$c34;
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c35); }
}
if (s6 !== peg$FAILED) {
s7 = peg$parse__();
if (s7 !== peg$FAILED) {
s8 = peg$parseFlag();
if (s8 !== peg$FAILED) {
s6 = [s6, s7, s8];
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
}
if (s4 !== peg$FAILED) {
s5 = peg$currPos;
s6 = peg$parse__();
if (s6 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s7 = peg$c34;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c35); }
}
if (s7 !== peg$FAILED) {
s6 = [s6, s7];
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
if (s5 === peg$FAILED) {
s5 = null;
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c36(s3, s4);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseFlag() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = [];
if (peg$c37.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c38); }
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c37.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c38); }
}
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = input.substring(s1, peg$currPos);
} else {
s1 = s2;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c39(s1);
}
s0 = s1;
return s0;
}
function peg$parsePreviousStrings() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parsePreviousContext();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
s2 = [s2, s3];
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
s2 = peg$parsePreviousUntranslatedString();
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parsePreviousUntranslatedPluralString();
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c40(s1, s2, s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsePreviousContext() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c41) {
s1 = peg$c41;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c42); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
if (input.substr(peg$currPos, 7) === peg$c43) {
s3 = peg$c43;
peg$currPos += 7;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parseString();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c45(s5);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsePreviousUntranslatedString() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c41) {
s1 = peg$c41;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c42); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c46) {
s3 = peg$c46;
peg$currPos += 5;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c47); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parseString();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c45(s5);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsePreviousUntranslatedPluralString() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c41) {
s1 = peg$c41;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c42); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
if (input.substr(peg$currPos, 12) === peg$c48) {
s3 = peg$c48;
peg$currPos += 12;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c49); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parseString();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c45(s5);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseStrings() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parseContext();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
s2 = [s2, s3];
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
s2 = peg$parseUntranslatedString();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
s4 = peg$parseTranslatedString();
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c50(s1, s2, s4);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parseContext();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
s2 = [s2, s3];
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
s2 = peg$parseUntranslatedString();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
s4 = peg$parseUntranslatedPluralString();
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s6 = peg$parseTranslatedPluralStrings();
if (s6 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c51(s1, s2, s4, s6);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
return s0;
}
function peg$parseContext() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.substr(peg$currPos, 7) === peg$c43) {
s1 = peg$c43;
peg$currPos += 7;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseString();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c45(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseUntranslatedString() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.substr(peg$currPos, 5) === peg$c46) {
s1 = peg$c46;
peg$currPos += 5;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c47); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseString();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c45(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseUntranslatedPluralString() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.substr(peg$currPos, 12) === peg$c48) {
s1 = peg$c48;
peg$currPos += 12;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg