Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function parse(input) {
  2.     var options = arguments.length > 1 ? arguments[1] : {},
  3.  
  4.         peg$FAILED = {},
  5.  
  6.         peg$startRuleFunctions = { start: peg$parsestart },
  7.         peg$startRuleFunction  = peg$parsestart,
  8.  
  9.         peg$c0 = [],
  10.         peg$c1 = function(elements) {
  11.                 return {
  12.                     type    : 'messageFormatPattern',
  13.                     elements: elements
  14.                 };
  15.             },
  16.         peg$c2 = peg$FAILED,
  17.         peg$c3 = function(text) {
  18.                 var string = '',
  19.                     i, j, outerLen, inner, innerLen;
  20.  
  21.                 for (i = 0, outerLen = text.length; i < outerLen; i += 1) {
  22.                     inner = text[i];
  23.  
  24.                     for (j = 0, innerLen = inner.length; j < innerLen; j += 1) {
  25.                         string += inner[j];
  26.                     }
  27.                 }
  28.  
  29.                 return string;
  30.             },
  31.         peg$c4 = function(messageText) {
  32.                 return {
  33.                     type : 'messageTextElement',
  34.                     value: messageText
  35.                 };
  36.             },
  37.         peg$c5 = /^[^ \t\n\r,.+={}#]/,
  38.         peg$c6 = { type: "class", value: "[^ \\t\\n\\r,.+={}#]", description: "[^ \\t\\n\\r,.+={}#]" },
  39.         peg$c7 = "{",
  40.         peg$c8 = { type: "literal", value: "{", description: "\"{\"" },
  41.         peg$c9 = null,
  42.         peg$c10 = ",",
  43.         peg$c11 = { type: "literal", value: ",", description: "\",\"" },
  44.         peg$c12 = "}",
  45.         peg$c13 = { type: "literal", value: "}", description: "\"}\"" },
  46.         peg$c14 = function(id, format) {
  47.                 return {
  48.                     type  : 'argumentElement',
  49.                     id    : id,
  50.                     format: format && format[2]
  51.                 };
  52.             },
  53.         peg$c15 = "number",
  54.         peg$c16 = { type: "literal", value: "number", description: "\"number\"" },
  55.         peg$c17 = "date",
  56.         peg$c18 = { type: "literal", value: "date", description: "\"date\"" },
  57.         peg$c19 = "time",
  58.         peg$c20 = { type: "literal", value: "time", description: "\"time\"" },
  59.         peg$c21 = function(type, style) {
  60.                 return {
  61.                     type : type + 'Format',
  62.                     style: style && style[2]
  63.                 };
  64.             },
  65.         peg$c22 = "plural",
  66.         peg$c23 = { type: "literal", value: "plural", description: "\"plural\"" },
  67.         peg$c24 = function(pluralStyle) {
  68.                 return {
  69.                     type   : pluralStyle.type,
  70.                     ordinal: false,
  71.                     offset : pluralStyle.offset || 0,
  72.                     options: pluralStyle.options
  73.                 };
  74.             },
  75.         peg$c25 = "selectordinal",
  76.         peg$c26 = { type: "literal", value: "selectordinal", description: "\"selectordinal\"" },
  77.         peg$c27 = function(pluralStyle) {
  78.                 return {
  79.                     type   : pluralStyle.type,
  80.                     ordinal: true,
  81.                     offset : pluralStyle.offset || 0,
  82.                     options: pluralStyle.options
  83.                 }
  84.             },
  85.         peg$c28 = "select",
  86.         peg$c29 = { type: "literal", value: "select", description: "\"select\"" },
  87.         peg$c30 = function(options) {
  88.                 return {
  89.                     type   : 'selectFormat',
  90.                     options: options
  91.                 };
  92.             },
  93.         peg$c31 = "=",
  94.         peg$c32 = { type: "literal", value: "=", description: "\"=\"" },
  95.         peg$c33 = function(selector, pattern) {
  96.                 return {
  97.                     type    : 'optionalFormatPattern',
  98.                     selector: selector,
  99.                     value   : pattern
  100.                 };
  101.             },
  102.         peg$c34 = "offset:",
  103.         peg$c35 = { type: "literal", value: "offset:", description: "\"offset:\"" },
  104.         peg$c36 = function(number) {
  105.                 return number;
  106.             },
  107.         peg$c37 = function(offset, options) {
  108.                 return {
  109.                     type   : 'pluralFormat',
  110.                     offset : offset,
  111.                     options: options
  112.                 };
  113.             },
  114.         peg$c38 = { type: "other", description: "whitespace" },
  115.         peg$c39 = /^[ \t\n\r]/,
  116.         peg$c40 = { type: "class", value: "[ \\t\\n\\r]", description: "[ \\t\\n\\r]" },
  117.         peg$c41 = { type: "other", description: "optionalWhitespace" },
  118.         peg$c42 = /^[0-9]/,
  119.         peg$c43 = { type: "class", value: "[0-9]", description: "[0-9]" },
  120.         peg$c44 = /^[0-9a-f]/i,
  121.         peg$c45 = { type: "class", value: "[0-9a-f]i", description: "[0-9a-f]i" },
  122.         peg$c46 = "0",
  123.         peg$c47 = { type: "literal", value: "0", description: "\"0\"" },
  124.         peg$c48 = /^[1-9]/,
  125.         peg$c49 = { type: "class", value: "[1-9]", description: "[1-9]" },
  126.         peg$c50 = function(digits) {
  127.             return parseInt(digits, 10);
  128.         },
  129.         peg$c51 = /^[^{}\\\0-\x1F \t\n\r]/,
  130.         peg$c52 = { type: "class", value: "[^{}\\\\\\0-\\x1F \\t\\n\\r]", description: "[^{}\\\\\\0-\\x1F \\t\\n\\r]" },
  131.         peg$c53 = "\\#",
  132.         peg$c54 = { type: "literal", value: "\\#", description: "\"\\\\#\"" },
  133.         peg$c55 = function() { return '\\#'; },
  134.         peg$c56 = "\\{",
  135.         peg$c57 = { type: "literal", value: "\\{", description: "\"\\\\{\"" },
  136.         peg$c58 = function() { return '\u007B'; },
  137.         peg$c59 = "\\}",
  138.         peg$c60 = { type: "literal", value: "\\}", description: "\"\\\\}\"" },
  139.         peg$c61 = function() { return '\u007D'; },
  140.         peg$c62 = "\\u",
  141.         peg$c63 = { type: "literal", value: "\\u", description: "\"\\\\u\"" },
  142.         peg$c64 = function(digits) {
  143.                 return String.fromCharCode(parseInt(digits, 16));
  144.             },
  145.         peg$c65 = function(chars) { return chars.join(''); },
  146.  
  147.         peg$currPos          = 0,
  148.         peg$reportedPos      = 0,
  149.         peg$cachedPos        = 0,
  150.         peg$cachedPosDetails = { line: 1, column: 1, seenCR: false },
  151.         peg$maxFailPos       = 0,
  152.         peg$maxFailExpected  = [],
  153.         peg$silentFails      = 0,
  154.  
  155.         peg$result;
  156.  
  157.     if ("startRule" in options) {
  158.       if (!(options.startRule in peg$startRuleFunctions)) {
  159.         throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
  160.       }
  161.  
  162.       peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
  163.     }
  164.  
  165.     function text() {
  166.       return input.substring(peg$reportedPos, peg$currPos);
  167.     }
  168.  
  169.     function offset() {
  170.       return peg$reportedPos;
  171.     }
  172.  
  173.     function line() {
  174.       return peg$computePosDetails(peg$reportedPos).line;
  175.     }
  176.  
  177.     function column() {
  178.       return peg$computePosDetails(peg$reportedPos).column;
  179.     }
  180.  
  181.     function expected(description) {
  182.       throw peg$buildException(
  183.         null,
  184.         [{ type: "other", description: description }],
  185.         peg$reportedPos
  186.       );
  187.     }
  188.  
  189.     function error(message) {
  190.       throw peg$buildException(message, null, peg$reportedPos);
  191.     }
  192.  
  193.     function peg$computePosDetails(pos) {
  194.       function advance(details, startPos, endPos) {
  195.         var p, ch;
  196.  
  197.         for (p = startPos; p < endPos; p++) {
  198.           ch = input.charAt(p);
  199.           if (ch === "\n") {
  200.             if (!details.seenCR) { details.line++; }
  201.             details.column = 1;
  202.             details.seenCR = false;
  203.           } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
  204.             details.line++;
  205.             details.column = 1;
  206.             details.seenCR = true;
  207.           } else {
  208.             details.column++;
  209.             details.seenCR = false;
  210.           }
  211.         }
  212.       }
  213.  
  214.       if (peg$cachedPos !== pos) {
  215.         if (peg$cachedPos > pos) {
  216.           peg$cachedPos = 0;
  217.           peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
  218.         }
  219.         advance(peg$cachedPosDetails, peg$cachedPos, pos);
  220.         peg$cachedPos = pos;
  221.       }
  222.  
  223.       return peg$cachedPosDetails;
  224.     }
  225.  
  226.     function peg$fail(expected) {
  227.       if (peg$currPos < peg$maxFailPos) { return; }
  228.  
  229.       if (peg$currPos > peg$maxFailPos) {
  230.         peg$maxFailPos = peg$currPos;
  231.         peg$maxFailExpected = [];
  232.       }
  233.  
  234.       peg$maxFailExpected.push(expected);
  235.     }
  236.  
  237.     function peg$buildException(message, expected, pos) {
  238.       function cleanupExpected(expected) {
  239.         var i = 1;
  240.  
  241.         expected.sort(function(a, b) {
  242.           if (a.description < b.description) {
  243.             return -1;
  244.           } else if (a.description > b.description) {
  245.             return 1;
  246.           } else {
  247.             return 0;
  248.           }
  249.         });
  250.  
  251.         while (i < expected.length) {
  252.           if (expected[i - 1] === expected[i]) {
  253.             expected.splice(i, 1);
  254.           } else {
  255.             i++;
  256.           }
  257.         }
  258.       }
  259.  
  260.       function buildMessage(expected, found) {
  261.         function stringEscape(s) {
  262.           function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
  263.  
  264.           return s
  265.             .replace(/\\/g,   '\\\\')
  266.             .replace(/"/g,    '\\"')
  267.             .replace(/\x08/g, '\\b')
  268.             .replace(/\t/g,   '\\t')
  269.             .replace(/\n/g,   '\\n')
  270.             .replace(/\f/g,   '\\f')
  271.             .replace(/\r/g,   '\\r')
  272.             .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
  273.             .replace(/[\x10-\x1F\x80-\xFF]/g,    function(ch) { return '\\x'  + hex(ch); })
  274.             .replace(/[\u0180-\u0FFF]/g,         function(ch) { return '\\u0' + hex(ch); })
  275.             .replace(/[\u1080-\uFFFF]/g,         function(ch) { return '\\u'  + hex(ch); });
  276.         }
  277.  
  278.         var expectedDescs = new Array(expected.length),
  279.             expectedDesc, foundDesc, i;
  280.  
  281.         for (i = 0; i < expected.length; i++) {
  282.           expectedDescs[i] = expected[i].description;
  283.         }
  284.  
  285.         expectedDesc = expected.length > 1
  286.           ? expectedDescs.slice(0, -1).join(", ")
  287.               + " or "
  288.               + expectedDescs[expected.length - 1]
  289.           : expectedDescs[0];
  290.  
  291.         foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
  292.  
  293.         return "Expected " + expectedDesc + " but " + foundDesc + " found.";
  294.       }
  295.  
  296.       var posDetails = peg$computePosDetails(pos),
  297.           found      = pos < input.length ? input.charAt(pos) : null;
  298.  
  299.       if (expected !== null) {
  300.         cleanupExpected(expected);
  301.       }
  302.  
  303.       return new SyntaxError(
  304.         message !== null ? message : buildMessage(expected, found),
  305.         expected,
  306.         found,
  307.         pos,
  308.         posDetails.line,
  309.         posDetails.column
  310.       );
  311.     }
  312.  
  313.     function peg$parsestart() {
  314.       var s0;
  315.  
  316.       s0 = peg$parsemessageFormatPattern();
  317.  
  318.       return s0;
  319.     }
  320.  
  321.     function peg$parsemessageFormatPattern() {
  322.       var s0, s1, s2;
  323.  
  324.       s0 = peg$currPos;
  325.       s1 = [];
  326.       s2 = peg$parsemessageFormatElement();
  327.       while (s2 !== peg$FAILED) {
  328.         s1.push(s2);
  329.         s2 = peg$parsemessageFormatElement();
  330.       }
  331.       if (s1 !== peg$FAILED) {
  332.         peg$reportedPos = s0;
  333.         s1 = peg$c1(s1);
  334.       }
  335.       s0 = s1;
  336.  
  337.       return s0;
  338.     }
  339.  
  340.     function peg$parsemessageFormatElement() {
  341.       var s0;
  342.  
  343.       s0 = peg$parsemessageTextElement();
  344.       if (s0 === peg$FAILED) {
  345.         s0 = peg$parseargumentElement();
  346.       }
  347.  
  348.       return s0;
  349.     }
  350.  
  351.     function peg$parsemessageText() {
  352.       var s0, s1, s2, s3, s4, s5;
  353.  
  354.       s0 = peg$currPos;
  355.       s1 = [];
  356.       s2 = peg$currPos;
  357.       s3 = peg$parse_();
  358.       if (s3 !== peg$FAILED) {
  359.         s4 = peg$parsechars();
  360.         if (s4 !== peg$FAILED) {
  361.           s5 = peg$parse_();
  362.           if (s5 !== peg$FAILED) {
  363.             s3 = [s3, s4, s5];
  364.             s2 = s3;
  365.           } else {
  366.             peg$currPos = s2;
  367.             s2 = peg$c2;
  368.           }
  369.         } else {
  370.           peg$currPos = s2;
  371.           s2 = peg$c2;
  372.         }
  373.       } else {
  374.         peg$currPos = s2;
  375.         s2 = peg$c2;
  376.       }
  377.       if (s2 !== peg$FAILED) {
  378.         while (s2 !== peg$FAILED) {
  379.           s1.push(s2);
  380.           s2 = peg$currPos;
  381.           s3 = peg$parse_();
  382.           if (s3 !== peg$FAILED) {
  383.             s4 = peg$parsechars();
  384.             if (s4 !== peg$FAILED) {
  385.               s5 = peg$parse_();
  386.               if (s5 !== peg$FAILED) {
  387.                 s3 = [s3, s4, s5];
  388.                 s2 = s3;
  389.               } else {
  390.                 peg$currPos = s2;
  391.                 s2 = peg$c2;
  392.               }
  393.             } else {
  394.               peg$currPos = s2;
  395.               s2 = peg$c2;
  396.             }
  397.           } else {
  398.             peg$currPos = s2;
  399.             s2 = peg$c2;
  400.           }
  401.         }
  402.       } else {
  403.         s1 = peg$c2;
  404.       }
  405.       if (s1 !== peg$FAILED) {
  406.         peg$reportedPos = s0;
  407.         s1 = peg$c3(s1);
  408.       }
  409.       s0 = s1;
  410.       if (s0 === peg$FAILED) {
  411.         s0 = peg$currPos;
  412.         s1 = peg$parsews();
  413.         if (s1 !== peg$FAILED) {
  414.           s1 = input.substring(s0, peg$currPos);
  415.         }
  416.         s0 = s1;
  417.       }
  418.  
  419.       return s0;
  420.     }
  421.  
  422.     function peg$parsemessageTextElement() {
  423.       var s0, s1;
  424.  
  425.       s0 = peg$currPos;
  426.       s1 = peg$parsemessageText();
  427.       if (s1 !== peg$FAILED) {
  428.         peg$reportedPos = s0;
  429.         s1 = peg$c4(s1);
  430.       }
  431.       s0 = s1;
  432.  
  433.       return s0;
  434.     }
  435.  
  436.     function peg$parseargument() {
  437.       var s0, s1, s2;
  438.  
  439.       s0 = peg$parsenumber();
  440.       if (s0 === peg$FAILED) {
  441.         s0 = peg$currPos;
  442.         s1 = [];
  443.         if (peg$c5.test(input.charAt(peg$currPos))) {
  444.           s2 = input.charAt(peg$currPos);
  445.           peg$currPos++;
  446.         } else {
  447.           s2 = peg$FAILED;
  448.           if (peg$silentFails === 0) { peg$fail(peg$c6); }
  449.         }
  450.         if (s2 !== peg$FAILED) {
  451.           while (s2 !== peg$FAILED) {
  452.             s1.push(s2);
  453.             if (peg$c5.test(input.charAt(peg$currPos))) {
  454.               s2 = input.charAt(peg$currPos);
  455.               peg$currPos++;
  456.             } else {
  457.               s2 = peg$FAILED;
  458.               if (peg$silentFails === 0) { peg$fail(peg$c6); }
  459.             }
  460.           }
  461.         } else {
  462.           s1 = peg$c2;
  463.         }
  464.         if (s1 !== peg$FAILED) {
  465.           s1 = input.substring(s0, peg$currPos);
  466.         }
  467.         s0 = s1;
  468.       }
  469.  
  470.       return s0;
  471.     }
  472.  
  473.     function peg$parseargumentElement() {
  474.       var s0, s1, s2, s3, s4, s5, s6, s7, s8;
  475.  
  476.       s0 = peg$currPos;
  477.       if (input.charCodeAt(peg$currPos) === 123) {
  478.         s1 = peg$c7;
  479.         peg$currPos++;
  480.       } else {
  481.         s1 = peg$FAILED;
  482.         if (peg$silentFails === 0) { peg$fail(peg$c8); }
  483.       }
  484.       if (s1 !== peg$FAILED) {
  485.         s2 = peg$parse_();
  486.         if (s2 !== peg$FAILED) {
  487.           s3 = peg$parseargument();
  488.           if (s3 !== peg$FAILED) {
  489.             s4 = peg$parse_();
  490.             if (s4 !== peg$FAILED) {
  491.               s5 = peg$currPos;
  492.               if (input.charCodeAt(peg$currPos) === 44) {
  493.                 s6 = peg$c10;
  494.                 peg$currPos++;
  495.               } else {
  496.                 s6 = peg$FAILED;
  497.                 if (peg$silentFails === 0) { peg$fail(peg$c11); }
  498.               }
  499.               if (s6 !== peg$FAILED) {
  500.                 s7 = peg$parse_();
  501.                 if (s7 !== peg$FAILED) {
  502.                   s8 = peg$parseelementFormat();
  503.                   if (s8 !== peg$FAILED) {
  504.                     s6 = [s6, s7, s8];
  505.                     s5 = s6;
  506.                   } else {
  507.                     peg$currPos = s5;
  508.                     s5 = peg$c2;
  509.                   }
  510.                 } else {
  511.                   peg$currPos = s5;
  512.                   s5 = peg$c2;
  513.                 }
  514.               } else {
  515.                 peg$currPos = s5;
  516.                 s5 = peg$c2;
  517.               }
  518.               if (s5 === peg$FAILED) {
  519.                 s5 = peg$c9;
  520.               }
  521.               if (s5 !== peg$FAILED) {
  522.                 s6 = peg$parse_();
  523.                 if (s6 !== peg$FAILED) {
  524.                   if (input.charCodeAt(peg$currPos) === 125) {
  525.                     s7 = peg$c12;
  526.                     peg$currPos++;
  527.                   } else {
  528.                     s7 = peg$FAILED;
  529.                     if (peg$silentFails === 0) { peg$fail(peg$c13); }
  530.                   }
  531.                   if (s7 !== peg$FAILED) {
  532.                     peg$reportedPos = s0;
  533.                     s1 = peg$c14(s3, s5);
  534.                     s0 = s1;
  535.                   } else {
  536.                     peg$currPos = s0;
  537.                     s0 = peg$c2;
  538.                   }
  539.                 } else {
  540.                   peg$currPos = s0;
  541.                   s0 = peg$c2;
  542.                 }
  543.               } else {
  544.                 peg$currPos = s0;
  545.                 s0 = peg$c2;
  546.               }
  547.             } else {
  548.               peg$currPos = s0;
  549.               s0 = peg$c2;
  550.             }
  551.           } else {
  552.             peg$currPos = s0;
  553.             s0 = peg$c2;
  554.           }
  555.         } else {
  556.           peg$currPos = s0;
  557.           s0 = peg$c2;
  558.         }
  559.       } else {
  560.         peg$currPos = s0;
  561.         s0 = peg$c2;
  562.       }
  563.  
  564.       return s0;
  565.     }
  566.  
  567.     function peg$parseelementFormat() {
  568.       var s0;
  569.  
  570.       s0 = peg$parsesimpleFormat();
  571.       if (s0 === peg$FAILED) {
  572.         s0 = peg$parsepluralFormat();
  573.         if (s0 === peg$FAILED) {
  574.           s0 = peg$parseselectOrdinalFormat();
  575.           if (s0 === peg$FAILED) {
  576.             s0 = peg$parseselectFormat();
  577.           }
  578.         }
  579.       }
  580.  
  581.       return s0;
  582.     }
  583.  
  584.     function peg$parsesimpleFormat() {
  585.       var s0, s1, s2, s3, s4, s5, s6;
  586.  
  587.       s0 = peg$currPos;
  588.       if (input.substr(peg$currPos, 6) === peg$c15) {
  589.         s1 = peg$c15;
  590.         peg$currPos += 6;
  591.       } else {
  592.         s1 = peg$FAILED;
  593.         if (peg$silentFails === 0) { peg$fail(peg$c16); }
  594.       }
  595.       if (s1 === peg$FAILED) {
  596.         if (input.substr(peg$currPos, 4) === peg$c17) {
  597.           s1 = peg$c17;
  598.           peg$currPos += 4;
  599.         } else {
  600.           s1 = peg$FAILED;
  601.           if (peg$silentFails === 0) { peg$fail(peg$c18); }
  602.         }
  603.         if (s1 === peg$FAILED) {
  604.           if (input.substr(peg$currPos, 4) === peg$c19) {
  605.             s1 = peg$c19;
  606.             peg$currPos += 4;
  607.           } else {
  608.             s1 = peg$FAILED;
  609.             if (peg$silentFails === 0) { peg$fail(peg$c20); }
  610.           }
  611.         }
  612.       }
  613.       if (s1 !== peg$FAILED) {
  614.         s2 = peg$parse_();
  615.         if (s2 !== peg$FAILED) {
  616.           s3 = peg$currPos;
  617.           if (input.charCodeAt(peg$currPos) === 44) {
  618.             s4 = peg$c10;
  619.             peg$currPos++;
  620.           } else {
  621.             s4 = peg$FAILED;
  622.             if (peg$silentFails === 0) { peg$fail(peg$c11); }
  623.           }
  624.           if (s4 !== peg$FAILED) {
  625.             s5 = peg$parse_();
  626.             if (s5 !== peg$FAILED) {
  627.               s6 = peg$parsechars();
  628.               if (s6 !== peg$FAILED) {
  629.                 s4 = [s4, s5, s6];
  630.                 s3 = s4;
  631.               } else {
  632.                 peg$currPos = s3;
  633.                 s3 = peg$c2;
  634.               }
  635.             } else {
  636.               peg$currPos = s3;
  637.               s3 = peg$c2;
  638.             }
  639.           } else {
  640.             peg$currPos = s3;
  641.             s3 = peg$c2;
  642.           }
  643.           if (s3 === peg$FAILED) {
  644.             s3 = peg$c9;
  645.           }
  646.           if (s3 !== peg$FAILED) {
  647.             peg$reportedPos = s0;
  648.             s1 = peg$c21(s1, s3);
  649.             s0 = s1;
  650.           } else {
  651.             peg$currPos = s0;
  652.             s0 = peg$c2;
  653.           }
  654.         } else {
  655.           peg$currPos = s0;
  656.           s0 = peg$c2;
  657.         }
  658.       } else {
  659.         peg$currPos = s0;
  660.         s0 = peg$c2;
  661.       }
  662.  
  663.       return s0;
  664.     }
  665.  
  666.     function peg$parsepluralFormat() {
  667.       var s0, s1, s2, s3, s4, s5;
  668.  
  669.       s0 = peg$currPos;
  670.       if (input.substr(peg$currPos, 6) === peg$c22) {
  671.         s1 = peg$c22;
  672.         peg$currPos += 6;
  673.       } else {
  674.         s1 = peg$FAILED;
  675.         if (peg$silentFails === 0) { peg$fail(peg$c23); }
  676.       }
  677.       if (s1 !== peg$FAILED) {
  678.         s2 = peg$parse_();
  679.         if (s2 !== peg$FAILED) {
  680.           if (input.charCodeAt(peg$currPos) === 44) {
  681.             s3 = peg$c10;
  682.             peg$currPos++;
  683.           } else {
  684.             s3 = peg$FAILED;
  685.             if (peg$silentFails === 0) { peg$fail(peg$c11); }
  686.           }
  687.           if (s3 !== peg$FAILED) {
  688.             s4 = peg$parse_();
  689.             if (s4 !== peg$FAILED) {
  690.               s5 = peg$parsepluralStyle();
  691.               if (s5 !== peg$FAILED) {
  692.                 peg$reportedPos = s0;
  693.                 s1 = peg$c24(s5);
  694.                 s0 = s1;
  695.               } else {
  696.                 peg$currPos = s0;
  697.                 s0 = peg$c2;
  698.               }
  699.             } else {
  700.               peg$currPos = s0;
  701.               s0 = peg$c2;
  702.             }
  703.           } else {
  704.             peg$currPos = s0;
  705.             s0 = peg$c2;
  706.           }
  707.         } else {
  708.           peg$currPos = s0;
  709.           s0 = peg$c2;
  710.         }
  711.       } else {
  712.         peg$currPos = s0;
  713.         s0 = peg$c2;
  714.       }
  715.  
  716.       return s0;
  717.     }
  718.  
  719.     function peg$parseselectOrdinalFormat() {
  720.       var s0, s1, s2, s3, s4, s5;
  721.  
  722.       s0 = peg$currPos;
  723.       if (input.substr(peg$currPos, 13) === peg$c25) {
  724.         s1 = peg$c25;
  725.         peg$currPos += 13;
  726.       } else {
  727.         s1 = peg$FAILED;
  728.         if (peg$silentFails === 0) { peg$fail(peg$c26); }
  729.       }
  730.       if (s1 !== peg$FAILED) {
  731.         s2 = peg$parse_();
  732.         if (s2 !== peg$FAILED) {
  733.           if (input.charCodeAt(peg$currPos) === 44) {
  734.             s3 = peg$c10;
  735.             peg$currPos++;
  736.           } else {
  737.             s3 = peg$FAILED;
  738.             if (peg$silentFails === 0) { peg$fail(peg$c11); }
  739.           }
  740.           if (s3 !== peg$FAILED) {
  741.             s4 = peg$parse_();
  742.             if (s4 !== peg$FAILED) {
  743.               s5 = peg$parsepluralStyle();
  744.               if (s5 !== peg$FAILED) {
  745.                 peg$reportedPos = s0;
  746.                 s1 = peg$c27(s5);
  747.                 s0 = s1;
  748.               } else {
  749.                 peg$currPos = s0;
  750.                 s0 = peg$c2;
  751.               }
  752.             } else {
  753.               peg$currPos = s0;
  754.               s0 = peg$c2;
  755.             }
  756.           } else {
  757.             peg$currPos = s0;
  758.             s0 = peg$c2;
  759.           }
  760.         } else {
  761.           peg$currPos = s0;
  762.           s0 = peg$c2;
  763.         }
  764.       } else {
  765.         peg$currPos = s0;
  766.         s0 = peg$c2;
  767.       }
  768.  
  769.       return s0;
  770.     }
  771.  
  772.     function peg$parseselectFormat() {
  773.       var s0, s1, s2, s3, s4, s5, s6;
  774.  
  775.       s0 = peg$currPos;
  776.       if (input.substr(peg$currPos, 6) === peg$c28) {
  777.         s1 = peg$c28;
  778.         peg$currPos += 6;
  779.       } else {
  780.         s1 = peg$FAILED;
  781.         if (peg$silentFails === 0) { peg$fail(peg$c29); }
  782.       }
  783.       if (s1 !== peg$FAILED) {
  784.         s2 = peg$parse_();
  785.         if (s2 !== peg$FAILED) {
  786.           if (input.charCodeAt(peg$currPos) === 44) {
  787.             s3 = peg$c10;
  788.             peg$currPos++;
  789.           } else {
  790.             s3 = peg$FAILED;
  791.             if (peg$silentFails === 0) { peg$fail(peg$c11); }
  792.           }
  793.           if (s3 !== peg$FAILED) {
  794.             s4 = peg$parse_();
  795.             if (s4 !== peg$FAILED) {
  796.               s5 = [];
  797.               s6 = peg$parseoptionalFormatPattern();
  798.               if (s6 !== peg$FAILED) {
  799.                 while (s6 !== peg$FAILED) {
  800.                   s5.push(s6);
  801.                   s6 = peg$parseoptionalFormatPattern();
  802.                 }
  803.               } else {
  804.                 s5 = peg$c2;
  805.               }
  806.               if (s5 !== peg$FAILED) {
  807.                 peg$reportedPos = s0;
  808.                 s1 = peg$c30(s5);
  809.                 s0 = s1;
  810.               } else {
  811.                 peg$currPos = s0;
  812.                 s0 = peg$c2;
  813.               }
  814.             } else {
  815.               peg$currPos = s0;
  816.               s0 = peg$c2;
  817.             }
  818.           } else {
  819.             peg$currPos = s0;
  820.             s0 = peg$c2;
  821.           }
  822.         } else {
  823.           peg$currPos = s0;
  824.           s0 = peg$c2;
  825.         }
  826.       } else {
  827.         peg$currPos = s0;
  828.         s0 = peg$c2;
  829.       }
  830.  
  831.       return s0;
  832.     }
  833.  
  834.     function peg$parseselector() {
  835.       var s0, s1, s2, s3;
  836.  
  837.       s0 = peg$currPos;
  838.       s1 = peg$currPos;
  839.       if (input.charCodeAt(peg$currPos) === 61) {
  840.         s2 = peg$c31;
  841.         peg$currPos++;
  842.       } else {
  843.         s2 = peg$FAILED;
  844.         if (peg$silentFails === 0) { peg$fail(peg$c32); }
  845.       }
  846.       if (s2 !== peg$FAILED) {
  847.         s3 = peg$parsenumber();
  848.         if (s3 !== peg$FAILED) {
  849.           s2 = [s2, s3];
  850.           s1 = s2;
  851.         } else {
  852.           peg$currPos = s1;
  853.           s1 = peg$c2;
  854.         }
  855.       } else {
  856.         peg$currPos = s1;
  857.         s1 = peg$c2;
  858.       }
  859.       if (s1 !== peg$FAILED) {
  860.         s1 = input.substring(s0, peg$currPos);
  861.       }
  862.       s0 = s1;
  863.       if (s0 === peg$FAILED) {
  864.         s0 = peg$parsechars();
  865.       }
  866.  
  867.       return s0;
  868.     }
  869.  
  870.     function peg$parseoptionalFormatPattern() {
  871.       var s0, s1, s2, s3, s4, s5, s6, s7, s8;
  872.  
  873.       s0 = peg$currPos;
  874.       s1 = peg$parse_();
  875.       if (s1 !== peg$FAILED) {
  876.         s2 = peg$parseselector();
  877.         if (s2 !== peg$FAILED) {
  878.           s3 = peg$parse_();
  879.           if (s3 !== peg$FAILED) {
  880.             if (input.charCodeAt(peg$currPos) === 123) {
  881.               s4 = peg$c7;
  882.               peg$currPos++;
  883.             } else {
  884.               s4 = peg$FAILED;
  885.               if (peg$silentFails === 0) { peg$fail(peg$c8); }
  886.             }
  887.             if (s4 !== peg$FAILED) {
  888.               s5 = peg$parse_();
  889.               if (s5 !== peg$FAILED) {
  890.                 s6 = peg$parsemessageFormatPattern();
  891.                 if (s6 !== peg$FAILED) {
  892.                   s7 = peg$parse_();
  893.                   if (s7 !== peg$FAILED) {
  894.                     if (input.charCodeAt(peg$currPos) === 125) {
  895.                       s8 = peg$c12;
  896.                       peg$currPos++;
  897.                     } else {
  898.                       s8 = peg$FAILED;
  899.                       if (peg$silentFails === 0) { peg$fail(peg$c13); }
  900.                     }
  901.                     if (s8 !== peg$FAILED) {
  902.                       peg$reportedPos = s0;
  903.                       s1 = peg$c33(s2, s6);
  904.                       s0 = s1;
  905.                     } else {
  906.                       peg$currPos = s0;
  907.                       s0 = peg$c2;
  908.                     }
  909.                   } else {
  910.                     peg$currPos = s0;
  911.                     s0 = peg$c2;
  912.                   }
  913.                 } else {
  914.                   peg$currPos = s0;
  915.                   s0 = peg$c2;
  916.                 }
  917.               } else {
  918.                 peg$currPos = s0;
  919.                 s0 = peg$c2;
  920.               }
  921.             } else {
  922.               peg$currPos = s0;
  923.               s0 = peg$c2;
  924.             }
  925.           } else {
  926.             peg$currPos = s0;
  927.             s0 = peg$c2;
  928.           }
  929.         } else {
  930.           peg$currPos = s0;
  931.           s0 = peg$c2;
  932.         }
  933.       } else {
  934.         peg$currPos = s0;
  935.         s0 = peg$c2;
  936.       }
  937.  
  938.       return s0;
  939.     }
  940.  
  941.     function peg$parseoffset() {
  942.       var s0, s1, s2, s3;
  943.  
  944.       s0 = peg$currPos;
  945.       if (input.substr(peg$currPos, 7) === peg$c34) {
  946.         s1 = peg$c34;
  947.         peg$currPos += 7;
  948.       } else {
  949.         s1 = peg$FAILED;
  950.         if (peg$silentFails === 0) { peg$fail(peg$c35); }
  951.       }
  952.       if (s1 !== peg$FAILED) {
  953.         s2 = peg$parse_();
  954.         if (s2 !== peg$FAILED) {
  955.           s3 = peg$parsenumber();
  956.           if (s3 !== peg$FAILED) {
  957.             peg$reportedPos = s0;
  958.             s1 = peg$c36(s3);
  959.             s0 = s1;
  960.           } else {
  961.             peg$currPos = s0;
  962.             s0 = peg$c2;
  963.           }
  964.         } else {
  965.           peg$currPos = s0;
  966.           s0 = peg$c2;
  967.         }
  968.       } else {
  969.         peg$currPos = s0;
  970.         s0 = peg$c2;
  971.       }
  972.  
  973.       return s0;
  974.     }
  975.  
  976.     function peg$parsepluralStyle() {
  977.       var s0, s1, s2, s3, s4;
  978.  
  979.       s0 = peg$currPos;
  980.       s1 = peg$parseoffset();
  981.       if (s1 === peg$FAILED) {
  982.         s1 = peg$c9;
  983.       }
  984.       if (s1 !== peg$FAILED) {
  985.         s2 = peg$parse_();
  986.         if (s2 !== peg$FAILED) {
  987.           s3 = [];
  988.           s4 = peg$parseoptionalFormatPattern();
  989.           if (s4 !== peg$FAILED) {
  990.             while (s4 !== peg$FAILED) {
  991.               s3.push(s4);
  992.               s4 = peg$parseoptionalFormatPattern();
  993.             }
  994.           } else {
  995.             s3 = peg$c2;
  996.           }
  997.           if (s3 !== peg$FAILED) {
  998.             peg$reportedPos = s0;
  999.             s1 = peg$c37(s1, s3);
  1000.             s0 = s1;
  1001.           } else {
  1002.             peg$currPos = s0;
  1003.             s0 = peg$c2;
  1004.           }
  1005.         } else {
  1006.           peg$currPos = s0;
  1007.           s0 = peg$c2;
  1008.         }
  1009.       } else {
  1010.         peg$currPos = s0;
  1011.         s0 = peg$c2;
  1012.       }
  1013.  
  1014.       return s0;
  1015.     }
  1016.  
  1017.     function peg$parsews() {
  1018.       var s0, s1;
  1019.  
  1020.       peg$silentFails++;
  1021.       s0 = [];
  1022.       if (peg$c39.test(input.charAt(peg$currPos))) {
  1023.         s1 = input.charAt(peg$currPos);
  1024.         peg$currPos++;
  1025.       } else {
  1026.         s1 = peg$FAILED;
  1027.         if (peg$silentFails === 0) { peg$fail(peg$c40); }
  1028.       }
  1029.       if (s1 !== peg$FAILED) {
  1030.         while (s1 !== peg$FAILED) {
  1031.           s0.push(s1);
  1032.           if (peg$c39.test(input.charAt(peg$currPos))) {
  1033.             s1 = input.charAt(peg$currPos);
  1034.             peg$currPos++;
  1035.           } else {
  1036.             s1 = peg$FAILED;
  1037.             if (peg$silentFails === 0) { peg$fail(peg$c40); }
  1038.           }
  1039.         }
  1040.       } else {
  1041.         s0 = peg$c2;
  1042.       }
  1043.       peg$silentFails--;
  1044.       if (s0 === peg$FAILED) {
  1045.         s1 = peg$FAILED;
  1046.         if (peg$silentFails === 0) { peg$fail(peg$c38); }
  1047.       }
  1048.  
  1049.       return s0;
  1050.     }
  1051.  
  1052.     function peg$parse_() {
  1053.       var s0, s1, s2;
  1054.  
  1055.       peg$silentFails++;
  1056.       s0 = peg$currPos;
  1057.       s1 = [];
  1058.       s2 = peg$parsews();
  1059.       while (s2 !== peg$FAILED) {
  1060.         s1.push(s2);
  1061.         s2 = peg$parsews();
  1062.       }
  1063.       if (s1 !== peg$FAILED) {
  1064.         s1 = input.substring(s0, peg$currPos);
  1065.       }
  1066.       s0 = s1;
  1067.       peg$silentFails--;
  1068.       if (s0 === peg$FAILED) {
  1069.         s1 = peg$FAILED;
  1070.         if (peg$silentFails === 0) { peg$fail(peg$c41); }
  1071.       }
  1072.  
  1073.       return s0;
  1074.     }
  1075.  
  1076.     function peg$parsedigit() {
  1077.       var s0;
  1078.  
  1079.       if (peg$c42.test(input.charAt(peg$currPos))) {
  1080.         s0 = input.charAt(peg$currPos);
  1081.         peg$currPos++;
  1082.       } else {
  1083.         s0 = peg$FAILED;
  1084.         if (peg$silentFails === 0) { peg$fail(peg$c43); }
  1085.       }
  1086.  
  1087.       return s0;
  1088.     }
  1089.  
  1090.     function peg$parsehexDigit() {
  1091.       var s0;
  1092.  
  1093.       if (peg$c44.test(input.charAt(peg$currPos))) {
  1094.         s0 = input.charAt(peg$currPos);
  1095.         peg$currPos++;
  1096.       } else {
  1097.         s0 = peg$FAILED;
  1098.         if (peg$silentFails === 0) { peg$fail(peg$c45); }
  1099.       }
  1100.  
  1101.       return s0;
  1102.     }
  1103.  
  1104.     function peg$parsenumber() {
  1105.       var s0, s1, s2, s3, s4, s5;
  1106.  
  1107.       s0 = peg$currPos;
  1108.       if (input.charCodeAt(peg$currPos) === 48) {
  1109.         s1 = peg$c46;
  1110.         peg$currPos++;
  1111.       } else {
  1112.         s1 = peg$FAILED;
  1113.         if (peg$silentFails === 0) { peg$fail(peg$c47); }
  1114.       }
  1115.       if (s1 === peg$FAILED) {
  1116.         s1 = peg$currPos;
  1117.         s2 = peg$currPos;
  1118.         if (peg$c48.test(input.charAt(peg$currPos))) {
  1119.           s3 = input.charAt(peg$currPos);
  1120.           peg$currPos++;
  1121.         } else {
  1122.           s3 = peg$FAILED;
  1123.           if (peg$silentFails === 0) { peg$fail(peg$c49); }
  1124.         }
  1125.         if (s3 !== peg$FAILED) {
  1126.           s4 = [];
  1127.           s5 = peg$parsedigit();
  1128.           while (s5 !== peg$FAILED) {
  1129.             s4.push(s5);
  1130.             s5 = peg$parsedigit();
  1131.           }
  1132.           if (s4 !== peg$FAILED) {
  1133.             s3 = [s3, s4];
  1134.             s2 = s3;
  1135.           } else {
  1136.             peg$currPos = s2;
  1137.             s2 = peg$c2;
  1138.           }
  1139.         } else {
  1140.           peg$currPos = s2;
  1141.           s2 = peg$c2;
  1142.         }
  1143.         if (s2 !== peg$FAILED) {
  1144.           s2 = input.substring(s1, peg$currPos);
  1145.         }
  1146.         s1 = s2;
  1147.       }
  1148.       if (s1 !== peg$FAILED) {
  1149.         peg$reportedPos = s0;
  1150.         s1 = peg$c50(s1);
  1151.       }
  1152.       s0 = s1;
  1153.  
  1154.       return s0;
  1155.     }
  1156.  
  1157.     function peg$parsechar() {
  1158.       var s0, s1, s2, s3, s4, s5, s6, s7;
  1159.  
  1160.       if (peg$c51.test(input.charAt(peg$currPos))) {
  1161.         s0 = input.charAt(peg$currPos);
  1162.         peg$currPos++;
  1163.       } else {
  1164.         s0 = peg$FAILED;
  1165.         if (peg$silentFails === 0) { peg$fail(peg$c52); }
  1166.       }
  1167.       if (s0 === peg$FAILED) {
  1168.         s0 = peg$currPos;
  1169.         if (input.substr(peg$currPos, 2) === peg$c53) {
  1170.           s1 = peg$c53;
  1171.           peg$currPos += 2;
  1172.         } else {
  1173.           s1 = peg$FAILED;
  1174.           if (peg$silentFails === 0) { peg$fail(peg$c54); }
  1175.         }
  1176.         if (s1 !== peg$FAILED) {
  1177.           peg$reportedPos = s0;
  1178.           s1 = peg$c55();
  1179.         }
  1180.         s0 = s1;
  1181.         if (s0 === peg$FAILED) {
  1182.           s0 = peg$currPos;
  1183.           if (input.substr(peg$currPos, 2) === peg$c56) {
  1184.             s1 = peg$c56;
  1185.             peg$currPos += 2;
  1186.           } else {
  1187.             s1 = peg$FAILED;
  1188.             if (peg$silentFails === 0) { peg$fail(peg$c57); }
  1189.           }
  1190.           if (s1 !== peg$FAILED) {
  1191.             peg$reportedPos = s0;
  1192.             s1 = peg$c58();
  1193.           }
  1194.           s0 = s1;
  1195.           if (s0 === peg$FAILED) {
  1196.             s0 = peg$currPos;
  1197.             if (input.substr(peg$currPos, 2) === peg$c59) {
  1198.               s1 = peg$c59;
  1199.               peg$currPos += 2;
  1200.             } else {
  1201.               s1 = peg$FAILED;
  1202.               if (peg$silentFails === 0) { peg$fail(peg$c60); }
  1203.             }
  1204.             if (s1 !== peg$FAILED) {
  1205.               peg$reportedPos = s0;
  1206.               s1 = peg$c61();
  1207.             }
  1208.             s0 = s1;
  1209.             if (s0 === peg$FAILED) {
  1210.               s0 = peg$currPos;
  1211.               if (input.substr(peg$currPos, 2) === peg$c62) {
  1212.                 s1 = peg$c62;
  1213.                 peg$currPos += 2;
  1214.               } else {
  1215.                 s1 = peg$FAILED;
  1216.                 if (peg$silentFails === 0) { peg$fail(peg$c63); }
  1217.               }
  1218.               if (s1 !== peg$FAILED) {
  1219.                 s2 = peg$currPos;
  1220.                 s3 = peg$currPos;
  1221.                 s4 = peg$parsehexDigit();
  1222.                 if (s4 !== peg$FAILED) {
  1223.                   s5 = peg$parsehexDigit();
  1224.                   if (s5 !== peg$FAILED) {
  1225.                     s6 = peg$parsehexDigit();
  1226.                     if (s6 !== peg$FAILED) {
  1227.                       s7 = peg$parsehexDigit();
  1228.                       if (s7 !== peg$FAILED) {
  1229.                         s4 = [s4, s5, s6, s7];
  1230.                         s3 = s4;
  1231.                       } else {
  1232.                         peg$currPos = s3;
  1233.                         s3 = peg$c2;
  1234.                       }
  1235.                     } else {
  1236.                       peg$currPos = s3;
  1237.                       s3 = peg$c2;
  1238.                     }
  1239.                   } else {
  1240.                     peg$currPos = s3;
  1241.                     s3 = peg$c2;
  1242.                   }
  1243.                 } else {
  1244.                   peg$currPos = s3;
  1245.                   s3 = peg$c2;
  1246.                 }
  1247.                 if (s3 !== peg$FAILED) {
  1248.                   s3 = input.substring(s2, peg$currPos);
  1249.                 }
  1250.                 s2 = s3;
  1251.                 if (s2 !== peg$FAILED) {
  1252.                   peg$reportedPos = s0;
  1253.                   s1 = peg$c64(s2);
  1254.                   s0 = s1;
  1255.                 } else {
  1256.                   peg$currPos = s0;
  1257.                   s0 = peg$c2;
  1258.                 }
  1259.               } else {
  1260.                 peg$currPos = s0;
  1261.                 s0 = peg$c2;
  1262.               }
  1263.             }
  1264.           }
  1265.         }
  1266.       }
  1267.  
  1268.       return s0;
  1269.     }
  1270.  
  1271.     function peg$parsechars() {
  1272.       var s0, s1, s2;
  1273.  
  1274.       s0 = peg$currPos;
  1275.       s1 = [];
  1276.       s2 = peg$parsechar();
  1277.       if (s2 !== peg$FAILED) {
  1278.         while (s2 !== peg$FAILED) {
  1279.           s1.push(s2);
  1280.           s2 = peg$parsechar();
  1281.         }
  1282.       } else {
  1283.         s1 = peg$c2;
  1284.       }
  1285.       if (s1 !== peg$FAILED) {
  1286.         peg$reportedPos = s0;
  1287.         s1 = peg$c65(s1);
  1288.       }
  1289.       s0 = s1;
  1290.  
  1291.       return s0;
  1292.     }
  1293.  
  1294.     peg$result = peg$startRuleFunction();
  1295.  
  1296.     if (peg$result !== peg$FAILED && peg$currPos === input.length) {
  1297.       return peg$result;
  1298.     } else {
  1299.       if (peg$result !== peg$FAILED && peg$currPos < input.length) {
  1300.         peg$fail({ type: "end", description: "end of input" });
  1301.       }
  1302.  
  1303.       throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
  1304.     }
  1305.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement