text: /* eslint-disable */
  /*
   * 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 = { start: peg$parsestart },
        peg$startRuleFunction  = peg$parsestart,
  
        peg$c0 = function(gs) { return gs.map(g => g[0]) },
        peg$c1 = function(h, m, r) { return [m, r] },
        peg$c2 = function(h, r) { return [null, r] },
        peg$c3 = function(h, mr) { return make_game(h, mr[0], mr[1]) },
        peg$c4 = peg$anyExpectation(),
        peg$c5 = "\"",
        peg$c6 = peg$literalExpectation("\"", false),
        peg$c7 = peg$otherExpectation("semi-colon"),
        peg$c8 = ";",
        peg$c9 = peg$literalExpectation(";", false),
        peg$c10 = /^[^"]/,
        peg$c11 = peg$classExpectation(["\""], true, false),
        peg$c12 = function(str) { return str.join('') },
        peg$c13 = peg$otherExpectation("integer"),
        peg$c14 = /^[1-9]/,
        peg$c15 = peg$classExpectation([["1", "9"]], false, false),
        peg$c16 = /^[0-9]/,
        peg$c17 = peg$classExpectation([["0", "9"]], false, false),
        peg$c18 = function(a, b) { return parseInt(a+b.join(''), 10) },
        peg$c19 = /^[A-Za-z0-9_\-]/,
        peg$c20 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "-"], false, false),
        peg$c21 = function(chars) { return chars.join('') },
        peg$c22 = " ",
        peg$c23 = peg$literalExpectation(" ", false),
        peg$c24 = "\f",
        peg$c25 = peg$literalExpectation("\f", false),
        peg$c26 = "\t",
        peg$c27 = peg$literalExpectation("\t", false),
        peg$c28 = peg$otherExpectation("whitespace"),
        peg$c29 = peg$otherExpectation("newline"),
        peg$c30 = "\r\n",
        peg$c31 = peg$literalExpectation("\r\n", false),
        peg$c32 = "\r",
        peg$c33 = peg$literalExpectation("\r", false),
        peg$c34 = "\n",
        peg$c35 = peg$literalExpectation("\n", false),
        peg$c36 = "\u2028",
        peg$c37 = peg$literalExpectation("\u2028", false),
        peg$c38 = "\u2029",
        peg$c39 = peg$literalExpectation("\u2029", false),
        peg$c40 = peg$otherExpectation("not newline"),
        peg$c41 = /^[^\r\n\u2028\u2029]/,
        peg$c42 = peg$classExpectation(["\r", "\n", "\u2028", "\u2029"], true, false),
        peg$c43 = peg$otherExpectation("header"),
        peg$c44 = "[",
        peg$c45 = peg$literalExpectation("[", false),
        peg$c46 = function(hn, hv) { return make_header(hn.trim(), hv.trim()) },
        peg$c47 = function(hs) { return hs },
        peg$c48 = peg$otherExpectation("piece"),
        peg$c49 = /^[NKQRB]/,
        peg$c50 = peg$classExpectation(["N", "K", "Q", "R", "B"], false, false),
        peg$c51 = peg$otherExpectation("rank"),
        peg$c52 = /^[a-h]/,
        peg$c53 = peg$classExpectation([["a", "h"]], false, false),
        peg$c54 = peg$otherExpectation("file"),
        peg$c55 = /^[1-8]/,
        peg$c56 = peg$classExpectation([["1", "8"]], false, false),
        peg$c57 = peg$otherExpectation("check"),
        peg$c58 = "+",
        peg$c59 = peg$literalExpectation("+", false),
        peg$c60 = peg$otherExpectation("checkmate"),
        peg$c61 = "#",
        peg$c62 = peg$literalExpectation("#", false),
        peg$c63 = peg$otherExpectation("capture"),
        peg$c64 = "x",
        peg$c65 = peg$literalExpectation("x", false),
        peg$c66 = peg$otherExpectation("period"),
        peg$c67 = ".",
        peg$c68 = peg$literalExpectation(".", false),
        peg$c69 = peg$otherExpectation("result"),
        peg$c70 = "1-0",
        peg$c71 = peg$literalExpectation("1-0", false),
        peg$c72 = "0-1",
        peg$c73 = peg$literalExpectation("0-1", false),
        peg$c74 = "*",
        peg$c75 = peg$literalExpectation("*", false),
        peg$c76 = "1/2-1/2",
        peg$c77 = peg$literalExpectation("1/2-1/2", false),
        peg$c78 = "1/2",
        peg$c79 = peg$literalExpectation("1/2", false),
        peg$c80 = function() { return "1/2-1/2" },
        peg$c81 = "0.5",
        peg$c82 = peg$literalExpectation("0.5", false),
        peg$c83 = "0.5-0.5",
        peg$c84 = peg$literalExpectation("0.5-0.5", false),
        peg$c85 = function(mn) { return mn },
        peg$c86 = function(r, f) { return r+f },
        peg$c87 = "=",
        peg$c88 = peg$literalExpectation("=", false),
        peg$c89 = /^[QRBN]/,
        peg$c90 = peg$classExpectation(["Q", "R", "B", "N"], false, false),
        peg$c91 = peg$otherExpectation("nag"),
        peg$c92 = "$",
        peg$c93 = peg$literalExpectation("$", false),
        peg$c94 = peg$otherExpectation("nag_alt"),
        peg$c95 = "!",
        peg$c96 = peg$literalExpectation("!", false),
        peg$c97 = function() { return '$1' },
        peg$c98 = "?",
        peg$c99 = peg$literalExpectation("?", false),
        peg$c100 = function() { return '$2' },
        peg$c101 = "!!",
        peg$c102 = peg$literalExpectation("!!", false),
        peg$c103 = function() { return '$3' },
        peg$c104 = "??",
        peg$c105 = peg$literalExpectation("??", false),
        peg$c106 = function() { return '$4' },
        peg$c107 = "!?",
        peg$c108 = peg$literalExpectation("!?", false),
        peg$c109 = function() { return '$5' },
        peg$c110 = "?!",
        peg$c111 = peg$literalExpectation("?!", false),
        peg$c112 = function() { return '$6' },
        peg$c113 = "\u25A1",
        peg$c114 = peg$literalExpectation("\u25A1", false),
        peg$c115 = function() { return '$7' },
        peg$c116 = function() { return '$10' },
        peg$c117 = function() { return '$11' },
        peg$c118 = function() { return '$12' },
        peg$c119 = "\u221E",
        peg$c120 = peg$literalExpectation("\u221E", false),
        peg$c121 = function() { return '$13' },
        peg$c122 = "\u2A72",
        peg$c123 = peg$literalExpectation("\u2A72", false),
        peg$c124 = function() { return '$14' },
        peg$c125 = "\u2A71",
        peg$c126 = peg$literalExpectation("\u2A71", false),
        peg$c127 = function() { return '$15' },
        peg$c128 = "\xB1",
        peg$c129 = peg$literalExpectation("\xB1", false),
        peg$c130 = function() { return '$16' },
        peg$c131 = "\u2213",
        peg$c132 = peg$literalExpectation("\u2213", false),
        peg$c133 = function() { return '$17' },
        peg$c134 = "+-",
        peg$c135 = peg$literalExpectation("+-", false),
        peg$c136 = function() { return '$18' },
        peg$c137 = "-+",
        peg$c138 = peg$literalExpectation("-+", false),
        peg$c139 = function() { return '$19' },
        peg$c140 = function() { return '$20' },
        peg$c141 = function() { return '$21' },
        peg$c142 = "\u2A00",
        peg$c143 = peg$literalExpectation("\u2A00", false),
        peg$c144 = function() { return '$22' },
        peg$c145 = function() { return '$23' },
        peg$c146 = "\u27F3",
        peg$c147 = peg$literalExpectation("\u27F3", false),
        peg$c148 = function() { return '$32' },
        peg$c149 = function() { return '$33' },
        peg$c150 = "\u2192",
        peg$c151 = peg$literalExpectation("\u2192", false),
        peg$c152 = function() { return '$36' },
        peg$c153 = function() { return '$37' },
        peg$c154 = "\u2191",
        peg$c155 = peg$literalExpectation("\u2191", false),
        peg$c156 = function() { return '$40' },
        peg$c157 = function() { return '$41' },
        peg$c158 = "\u21C6",
        peg$c159 = peg$literalExpectation("\u21C6", false),
        peg$c160 = function() { return '$132' },
        peg$c161 = function() { return '$133' },
        peg$c162 = "D",
        peg$c163 = peg$literalExpectation("D", false),
        peg$c164 = function() { return '$220' },
        peg$c165 = function(cc) { return cc.join('').trim() },
        peg$c166 = peg$otherExpectation("open comment"),
        peg$c167 = "{",
        peg$c168 = peg$literalExpectation("{", false),
        peg$c169 = peg$otherExpectation("close comment"),
        peg$c170 = "}",
        peg$c171 = peg$literalExpectation("}", false),
        peg$c172 = /^[^}]/,
        peg$c173 = peg$classExpectation(["}"], true, false),
        peg$c174 = function(cc, n) { return n },
        peg$c175 = function(cc, nags) { return cc.join('').trim() + nags.join('').trim() },
        peg$c176 = function(comments) { return comments.join('').trim() },
        peg$c177 = peg$otherExpectation("castles"),
        peg$c178 = "O-O-O",
        peg$c179 = peg$literalExpectation("O-O-O", false),
        peg$c180 = "O-O",
        peg$c181 = peg$literalExpectation("O-O", false),
        peg$c182 = peg$otherExpectation("null move"),
        peg$c183 = "--",
        peg$c184 = peg$literalExpectation("--", false),
        peg$c185 = function(m) { return flatten(m).join('').trim() },
        peg$c186 = function(commentBefore, mn, m, n) { return n },
        peg$c187 = function(commentBefore, mn, m, nags, commentAfter, r) { return r },
        peg$c188 = function(commentBefore, mn, m, nags, commentAfter, ravs) { return { mn, m, nags, commentAfter, ravs } },
        peg$c189 = function(commentBefore, notation) {
            if (!notation) notation = {}
            const { mn, m, nags, commentAfter, ravs } = notation
            return make_move(mn, m, nags, ravs, commentBefore, commentAfter)
          },
        peg$c190 = function(first, rest) { return first ? [first].concat(rest.map(function(m) { return m[1] })) : [] },
        peg$c191 = "(",
        peg$c192 = peg$literalExpectation("(", false),
        peg$c193 = ")",
        peg$c194 = peg$literalExpectation(")", false),
        peg$c195 = function(m, r) { return make_rav(m, r) },
  
        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$parsestart() {
      var s0, s1, s2, s3, s4, s5, s6;
  
      s0 = peg$currPos;
      s1 = [];
      s2 = peg$parsenewline();
      while (s2 !== peg$FAILED) {
        s1.push(s2);
        s2 = peg$parsenewline();
      }
      if (s1 !== peg$FAILED) {
        s2 = [];
        s3 = peg$currPos;
        s4 = peg$parsegame();
        if (s4 !== peg$FAILED) {
          s5 = [];
          s6 = peg$parsenewline();
          while (s6 !== peg$FAILED) {
            s5.push(s6);
            s6 = peg$parsenewline();
          }
          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$parsegame();
          if (s4 !== peg$FAILED) {
            s5 = [];
            s6 = peg$parsenewline();
            while (s6 !== peg$FAILED) {
              s5.push(s6);
              s6 = peg$parsenewline();
            }
            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) {
          s3 = peg$parseEOF();
          if (s3 !== peg$FAILED) {
            peg$savedPos = s0;
            s1 = peg$c0(s2);
            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$parsegame() {
      var s0, s1, s2, s3, s4, s5, s6;
  
      s0 = peg$currPos;
      s1 = peg$parseheaders();
      if (s1 === peg$FAILED) {
        s1 = null;
      }
      if (s1 !== peg$FAILED) {
        s2 = [];
        s3 = peg$parsewhitespace();
        while (s3 !== peg$FAILED) {
          s2.push(s3);
          s3 = peg$parsewhitespace();
        }
        if (s2 !== peg$FAILED) {
          s3 = peg$currPos;
          s4 = peg$parsemovetext();
          if (s4 !== peg$FAILED) {
            s5 = [];
            s6 = peg$parsewhitespace();
            while (s6 !== peg$FAILED) {
              s5.push(s6);
              s6 = peg$parsewhitespace();
            }
            if (s5 !== peg$FAILED) {
              s6 = peg$parseresult();
              if (s6 !== peg$FAILED) {
                peg$savedPos = s3;
                s4 = peg$c1(s1, s4, s6);
                s3 = s4;
              } else {
                peg$currPos = s3;
                s3 = peg$FAILED;
              }
            } else {
              peg$currPos = s3;
              s3 = peg$FAILED;
            }
          } else {
            peg$currPos = s3;
            s3 = peg$FAILED;
          }
          if (s3 === peg$FAILED) {
            s3 = peg$currPos;
            s4 = peg$parseresult();
            if (s4 !== peg$FAILED) {
              peg$savedPos = s3;
              s4 = peg$c2(s1, s4);
            }
            s3 = s4;
          }
          if (s3 !== peg$FAILED) {
            s4 = [];
            s5 = peg$parsewhitespace();
            while (s5 !== peg$FAILED) {
              s4.push(s5);
              s5 = peg$parsewhitespace();
            }
            if (s4 !== peg$FAILED) {
              peg$savedPos = s0;
              s1 = peg$c3(s1, 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;
      }
  
      return s0;
    }
  
    function peg$parseEOF() {
      var s0, s1;
  
      s0 = peg$currPos;
      peg$silentFails++;
      if (input.length > peg$currPos) {
        s1 = input.charAt(peg$currPos);
        peg$currPos++;
      } else {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c4); }
      }
      peg$silentFails--;
      if (s1 === peg$FAILED) {
        s0 = void 0;
      } else {
        peg$currPos = s0;
        s0 = peg$FAILED;
      }
  
      return s0;
    }
  
    function peg$parsedouble_quote() {
      var s0;
  
      if (input.charCodeAt(peg$currPos) === 34) {
        s0 = peg$c5;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c6); }
      }
  
      return s0;
    }
  
    function peg$parsesemi_colon() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.charCodeAt(peg$currPos) === 59) {
        s0 = peg$c8;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c9); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c7); }
      }
  
      return s0;
    }
  
    function peg$parsestring() {
      var s0, s1, s2, s3;
  
      s0 = peg$currPos;
      s1 = peg$parsedouble_quote();
      if (s1 !== peg$FAILED) {
        s2 = [];
        if (peg$c10.test(input.charAt(peg$currPos))) {
          s3 = input.charAt(peg$currPos);
          peg$currPos++;
        } else {
          s3 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c11); }
        }
        while (s3 !== peg$FAILED) {
          s2.push(s3);
          if (peg$c10.test(input.charAt(peg$currPos))) {
            s3 = input.charAt(peg$currPos);
            peg$currPos++;
          } else {
            s3 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c11); }
          }
        }
        if (s2 !== peg$FAILED) {
          s3 = peg$parsedouble_quote();
          if (s3 !== peg$FAILED) {
            peg$savedPos = s0;
            s1 = peg$c12(s2);
            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$parseinteger() {
      var s0, s1, s2, s3;
  
      peg$silentFails++;
      s0 = peg$currPos;
      if (peg$c14.test(input.charAt(peg$currPos))) {
        s1 = input.charAt(peg$currPos);
        peg$currPos++;
      } else {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c15); }
      }
      if (s1 !== peg$FAILED) {
        s2 = [];
        if (peg$c16.test(input.charAt(peg$currPos))) {
          s3 = input.charAt(peg$currPos);
          peg$currPos++;
        } else {
          s3 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c17); }
        }
        while (s3 !== peg$FAILED) {
          s2.push(s3);
          if (peg$c16.test(input.charAt(peg$currPos))) {
            s3 = input.charAt(peg$currPos);
            peg$currPos++;
          } else {
            s3 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c17); }
          }
        }
        if (s2 !== peg$FAILED) {
          peg$savedPos = s0;
          s1 = peg$c18(s1, s2);
          s0 = s1;
        } else {
          peg$currPos = s0;
          s0 = peg$FAILED;
        }
      } else {
        peg$currPos = s0;
        s0 = peg$FAILED;
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c13); }
      }
  
      return s0;
    }
  
    function peg$parsesymbol() {
      var s0, s1, s2;
  
      s0 = peg$currPos;
      s1 = [];
      if (peg$c19.test(input.charAt(peg$currPos))) {
        s2 = input.charAt(peg$currPos);
        peg$currPos++;
      } else {
        s2 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c20); }
      }
      if (s2 !== peg$FAILED) {
        while (s2 !== peg$FAILED) {
          s1.push(s2);
          if (peg$c19.test(input.charAt(peg$currPos))) {
            s2 = input.charAt(peg$currPos);
            peg$currPos++;
          } else {
            s2 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c20); }
          }
        }
      } else {
        s1 = peg$FAILED;
      }
      if (s1 !== peg$FAILED) {
        peg$savedPos = s0;
        s1 = peg$c21(s1);
      }
      s0 = s1;
  
      return s0;
    }
  
    function peg$parsews() {
      var s0;
  
      if (input.charCodeAt(peg$currPos) === 32) {
        s0 = peg$c22;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c23); }
      }
      if (s0 === peg$FAILED) {
        if (input.charCodeAt(peg$currPos) === 12) {
          s0 = peg$c24;
          peg$currPos++;
        } else {
          s0 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c25); }
        }
        if (s0 === peg$FAILED) {
          if (input.charCodeAt(peg$currPos) === 9) {
            s0 = peg$c26;
            peg$currPos++;
          } else {
            s0 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c27); }
          }
        }
      }
  
      return s0;
    }
  
    function peg$parsewhitespace() {
      var s0, s1;
  
      peg$silentFails++;
      s0 = peg$parsews();
      if (s0 === peg$FAILED) {
        s0 = peg$parsenewline();
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c28); }
      }
  
      return s0;
    }
  
    function peg$parsenewline() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.substr(peg$currPos, 2) === peg$c30) {
        s0 = peg$c30;
        peg$currPos += 2;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c31); }
      }
      if (s0 === peg$FAILED) {
        if (input.charCodeAt(peg$currPos) === 13) {
          s0 = peg$c32;
          peg$currPos++;
        } else {
          s0 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c33); }
        }
        if (s0 === peg$FAILED) {
          if (input.charCodeAt(peg$currPos) === 10) {
            s0 = peg$c34;
            peg$currPos++;
          } else {
            s0 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c35); }
          }
          if (s0 === peg$FAILED) {
            if (input.charCodeAt(peg$currPos) === 8232) {
              s0 = peg$c36;
              peg$currPos++;
            } else {
              s0 = peg$FAILED;
              if (peg$silentFails === 0) { peg$fail(peg$c37); }
            }
            if (s0 === peg$FAILED) {
              if (input.charCodeAt(peg$currPos) === 8233) {
                s0 = peg$c38;
                peg$currPos++;
              } else {
                s0 = peg$FAILED;
                if (peg$silentFails === 0) { peg$fail(peg$c39); }
              }
            }
          }
        }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c29); }
      }
  
      return s0;
    }
  
    function peg$parsenot_newline() {
      var s0, s1;
  
      peg$silentFails++;
      if (peg$c41.test(input.charAt(peg$currPos))) {
        s0 = input.charAt(peg$currPos);
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c42); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c40); }
      }
  
      return s0;
    }
  
    function peg$parseheader() {
      var s0, s1, s2, s3, s4, s5, s6, s7, s8;
  
      peg$silentFails++;
      s0 = peg$currPos;
      s1 = [];
      s2 = peg$parsewhitespace();
      while (s2 !== peg$FAILED) {
        s1.push(s2);
        s2 = peg$parsewhitespace();
      }
      if (s1 !== peg$FAILED) {
        if (input.charCodeAt(peg$currPos) === 91) {
          s2 = peg$c44;
          peg$currPos++;
        } else {
          s2 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c45); }
        }
        if (s2 !== peg$FAILED) {
          s3 = peg$parsesymbol();
          if (s3 !== peg$FAILED) {
            s4 = [];
            s5 = peg$parsews();
            if (s5 !== peg$FAILED) {
              while (s5 !== peg$FAILED) {
                s4.push(s5);
                s5 = peg$parsews();
              }
            } else {
              s4 = peg$FAILED;
            }
            if (s4 !== peg$FAILED) {
              s5 = peg$parsestring();
              if (s5 !== peg$FAILED) {
                s6 = [];
                s7 = peg$parsenot_newline();
                while (s7 !== peg$FAILED) {
                  s6.push(s7);
                  s7 = peg$parsenot_newline();
                }
                if (s6 !== peg$FAILED) {
                  s7 = [];
                  s8 = peg$parsenewline();
                  while (s8 !== peg$FAILED) {
                    s7.push(s8);
                    s8 = peg$parsenewline();
                  }
                  if (s7 !== peg$FAILED) {
                    peg$savedPos = s0;
                    s1 = peg$c46(s3, 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;
          }
        } else {
          peg$currPos = s0;
          s0 = peg$FAILED;
        }
      } else {
        peg$currPos = s0;
        s0 = peg$FAILED;
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c43); }
      }
  
      return s0;
    }
  
    function peg$parseheaders() {
      var s0, s1, s2;
  
      s0 = peg$currPos;
      s1 = [];
      s2 = peg$parseheader();
      if (s2 !== peg$FAILED) {
        while (s2 !== peg$FAILED) {
          s1.push(s2);
          s2 = peg$parseheader();
        }
      } else {
        s1 = peg$FAILED;
      }
      if (s1 !== peg$FAILED) {
        peg$savedPos = s0;
        s1 = peg$c47(s1);
      }
      s0 = s1;
  
      return s0;
    }
  
    function peg$parsepiece() {
      var s0, s1;
  
      peg$silentFails++;
      if (peg$c49.test(input.charAt(peg$currPos))) {
        s0 = input.charAt(peg$currPos);
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c50); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c48); }
      }
  
      return s0;
    }
  
    function peg$parserank() {
      var s0, s1;
  
      peg$silentFails++;
      if (peg$c52.test(input.charAt(peg$currPos))) {
        s0 = input.charAt(peg$currPos);
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c53); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c51); }
      }
  
      return s0;
    }
  
    function peg$parsefile() {
      var s0, s1;
  
      peg$silentFails++;
      if (peg$c55.test(input.charAt(peg$currPos))) {
        s0 = input.charAt(peg$currPos);
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c56); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c54); }
      }
  
      return s0;
    }
  
    function peg$parsecheck() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.charCodeAt(peg$currPos) === 43) {
        s0 = peg$c58;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c59); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c57); }
      }
  
      return s0;
    }
  
    function peg$parsecheckmate() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.charCodeAt(peg$currPos) === 35) {
        s0 = peg$c61;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c62); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c60); }
      }
  
      return s0;
    }
  
    function peg$parsecapture() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.charCodeAt(peg$currPos) === 120) {
        s0 = peg$c64;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c65); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c63); }
      }
  
      return s0;
    }
  
    function peg$parseperiod() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.charCodeAt(peg$currPos) === 46) {
        s0 = peg$c67;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c68); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c66); }
      }
  
      return s0;
    }
  
    function peg$parseresult() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.substr(peg$currPos, 3) === peg$c70) {
        s0 = peg$c70;
        peg$currPos += 3;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c71); }
      }
      if (s0 === peg$FAILED) {
        if (input.substr(peg$currPos, 3) === peg$c72) {
          s0 = peg$c72;
          peg$currPos += 3;
        } else {
          s0 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c73); }
        }
        if (s0 === peg$FAILED) {
          if (input.charCodeAt(peg$currPos) === 42) {
            s0 = peg$c74;
            peg$currPos++;
          } else {
            s0 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c75); }
          }
          if (s0 === peg$FAILED) {
            if (input.substr(peg$currPos, 7) === peg$c76) {
              s0 = peg$c76;
              peg$currPos += 7;
            } else {
              s0 = peg$FAILED;
              if (peg$silentFails === 0) { peg$fail(peg$c77); }
            }
            if (s0 === peg$FAILED) {
              s0 = peg$currPos;
              if (input.substr(peg$currPos, 3) === peg$c78) {
                s1 = peg$c78;
                peg$currPos += 3;
              } else {
                s1 = peg$FAILED;
                if (peg$silentFails === 0) { peg$fail(peg$c79); }
              }
              if (s1 !== peg$FAILED) {
                peg$savedPos = s0;
                s1 = peg$c80();
              }
              s0 = s1;
              if (s0 === peg$FAILED) {
                s0 = peg$currPos;
                if (input.substr(peg$currPos, 3) === peg$c81) {
                  s1 = peg$c81;
                  peg$currPos += 3;
                } else {
                  s1 = peg$FAILED;
                  if (peg$silentFails === 0) { peg$fail(peg$c82); }
                }
                if (s1 !== peg$FAILED) {
                  peg$savedPos = s0;
                  s1 = peg$c80();
                }
                s0 = s1;
                if (s0 === peg$FAILED) {
                  s0 = peg$currPos;
                  if (input.substr(peg$currPos, 7) === peg$c83) {
                    s1 = peg$c83;
                    peg$currPos += 7;
                  } else {
                    s1 = peg$FAILED;
                    if (peg$silentFails === 0) { peg$fail(peg$c84); }
                  }
                  if (s1 !== peg$FAILED) {
                    peg$savedPos = s0;
                    s1 = peg$c80();
                  }
                  s0 = s1;
                }
              }
            }
          }
        }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c69); }
      }
  
      return s0;
    }
  
    function peg$parsemove_number() {
      var s0, s1, s2, s3, s4, s5;
  
      s0 = peg$currPos;
      s1 = peg$parseinteger();
      if (s1 !== peg$FAILED) {
        s2 = peg$parseperiod();
        if (s2 !== peg$FAILED) {
          s3 = peg$currPos;
          s4 = peg$parseperiod();
          if (s4 !== peg$FAILED) {
            s5 = peg$parseperiod();
            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$c85(s1);
            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$parsesquare() {
      var s0, s1, s2;
  
      s0 = peg$currPos;
      s1 = peg$parserank();
      if (s1 !== peg$FAILED) {
        s2 = peg$parsefile();
        if (s2 !== peg$FAILED) {
          peg$savedPos = s0;
          s1 = peg$c86(s1, s2);
          s0 = s1;
        } else {
          peg$currPos = s0;
          s0 = peg$FAILED;
        }
      } else {
        peg$currPos = s0;
        s0 = peg$FAILED;
      }
  
      return s0;
    }
  
    function peg$parsepromotion() {
      var s0, s1, s2;
  
      s0 = peg$currPos;
      if (input.charCodeAt(peg$currPos) === 61) {
        s1 = peg$c87;
        peg$currPos++;
      } else {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c88); }
      }
      if (s1 !== peg$FAILED) {
        if (peg$c89.test(input.charAt(peg$currPos))) {
          s2 = input.charAt(peg$currPos);
          peg$currPos++;
        } else {
          s2 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c90); }
        }
        if (s2 !== peg$FAILED) {
          s1 = [s1, s2];
          s0 = s1;
        } else {
          peg$currPos = s0;
          s0 = peg$FAILED;
        }
      } else {
        peg$currPos = s0;
        s0 = peg$FAILED;
      }
  
      return s0;
    }
  
    function peg$parsenag() {
      var s0, s1, s2, s3;
  
      peg$silentFails++;
      s0 = peg$currPos;
      s1 = peg$currPos;
      if (input.charCodeAt(peg$currPos) === 36) {
        s2 = peg$c92;
        peg$currPos++;
      } else {
        s2 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c93); }
      }
      if (s2 !== peg$FAILED) {
        s3 = peg$parseinteger();
        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) {
        peg$savedPos = s0;
        s1 = peg$c21(s1);
      }
      s0 = s1;
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c91); }
      }
  
      return s0;
    }
  
    function peg$parsenag_alts() {
      var s0, s1;
  
      peg$silentFails++;
      s0 = peg$currPos;
      if (input.charCodeAt(peg$currPos) === 33) {
        s1 = peg$c95;
        peg$currPos++;
      } else {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c96); }
      }
      if (s1 !== peg$FAILED) {
        peg$savedPos = s0;
        s1 = peg$c97();
      }
      s0 = s1;
      if (s0 === peg$FAILED) {
        s0 = peg$currPos;
        if (input.charCodeAt(peg$currPos) === 63) {
          s1 = peg$c98;
          peg$currPos++;
        } else {
          s1 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c99); }
        }
        if (s1 !== peg$FAILED) {
          peg$savedPos = s0;
          s1 = peg$c100();
        }
        s0 = s1;
        if (s0 === peg$FAILED) {
          s0 = peg$currPos;
          if (input.substr(peg$currPos, 2) === peg$c101) {
            s1 = peg$c101;
            peg$currPos += 2;
          } else {
            s1 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c102); }
          }
          if (s1 !== peg$FAILED) {
            peg$savedPos = s0;
            s1 = peg$c103();
          }
          s0 = s1;
          if (s0 === peg$FAILED) {
            s0 = peg$currPos;
            if (input.substr(peg$currPos, 2) === peg$c104) {
              s1 = peg$c104;
              peg$currPos += 2;
            } else {
              s1 = peg$FAILED;
              if (peg$silentFails === 0) { peg$fail(peg$c105); }
            }
            if (s1 !== peg$FAILED) {
              peg$savedPos = s0;
              s1 = peg$c106();
            }
            s0 = s1;
            if (s0 === peg$FAILED) {
              s0 = peg$currPos;
              if (input.substr(peg$currPos, 2) === peg$c107) {
                s1 = peg$c107;
                peg$currPos += 2;
              } else {
                s1 = peg$FAILED;
                if (peg$silentFails === 0) { peg$fail(peg$c108); }
              }
              if (s1 !== peg$FAILED) {
                peg$savedPos = s0;
                s1 = peg$c109();
              }
              s0 = s1;
              if (s0 === peg$FAILED) {
                s0 = peg$currPos;
                if (input.substr(peg$currPos, 2) === peg$c110) {
                  s1 = peg$c110;
                  peg$currPos += 2;
                } else {
                  s1 = peg$FAILED;
                  if (peg$silentFails === 0) { peg$fail(peg$c111); }
                }
                if (s1 !== peg$FAILED) {
                  peg$savedPos = s0;
                  s1 = peg$c112();
                }
                s0 = s1;
                if (s0 === peg$FAILED) {
                  s0 = peg$currPos;
                  if (input.charCodeAt(peg$currPos) === 9633) {
                    s1 = peg$c113;
                    peg$currPos++;
                  } else {
                    s1 = peg$FAILED;
                    if (peg$silentFails === 0) { peg$fail(peg$c114); }
                  }
                  if (s1 !== peg$FAILED) {
                    peg$savedPos = s0;
                    s1 = peg$c115();
                  }
                  s0 = s1;
                  if (s0 === peg$FAILED) {
                    s0 = peg$currPos;
                    if (input.charCodeAt(peg$currPos) === 61) {
                      s1 = peg$c87;
                      peg$currPos++;
                    } else {
                      s1 = peg$FAILED;
                      if (peg$silentFails === 0) { peg$fail(peg$c88); }
                    }
                    if (s1 !== peg$FAILED) {
                      peg$savedPos = s0;
                      s1 = peg$c116();
                    }
                    s0 = s1;
                    if (s0 === peg$FAILED) {
                      s0 = peg$currPos;
                      if (input.charCodeAt(peg$currPos) === 61) {
                        s1 = peg$c87;
                        peg$currPos++;
                      } else {
                        s1 = peg$FAILED;
                        if (peg$silentFails === 0) { peg$fail(peg$c88); }
                      }
                      if (s1 !== peg$FAILED) {
                        peg$savedPos = s0;
                        s1 = peg$c117();
                      }
                      s0 = s1;
                      if (s0 === peg$FAILED) {
                        s0 = peg$currPos;
                        if (input.charCodeAt(peg$currPos) === 61) {
                          s1 = peg$c87;
                          peg$currPos++;
                        } else {
                          s1 = peg$FAILED;
                          if (peg$silentFails === 0) { peg$fail(peg$c88); }
                        }
                        if (s1 !== peg$FAILED) {
                          peg$savedPos = s0;
                          s1 = peg$c118();
                        }
                        s0 = s1;
                        if (s0 === peg$FAILED) {
                          s0 = peg$currPos;
                          if (input.charCodeAt(peg$currPos) === 8734) {
                            s1 = peg$c119;
                            peg$currPos++;
                          } else {
                            s1 = peg$FAILED;
                            if (peg$silentFails === 0) { peg$fail(peg$c120); }
                          }
                          if (s1 !== peg$FAILED) {
                            peg$savedPos = s0;
                            s1 = peg$c121();
                          }
                          s0 = s1;
                          if (s0 === peg$FAILED) {
                            s0 = peg$currPos;
                            if (input.charCodeAt(peg$currPos) === 10866) {
                              s1 = peg$c122;
                              peg$currPos++;
                            } else {
                              s1 = peg$FAILED;
                              if (peg$silentFails === 0) { peg$fail(peg$c123); }
                            }
                            if (s1 !== peg$FAILED) {
                              peg$savedPos = s0;
                              s1 = peg$c124();
                            }
                            s0 = s1;
                            if (s0 === peg$FAILED) {
                              s0 = peg$currPos;
                              if (input.charCodeAt(peg$currPos) === 10865) {
                                s1 = peg$c125;
                                peg$currPos++;
                              } else {
                                s1 = peg$FAILED;
                                if (peg$silentFails === 0) { peg$fail(peg$c126); }
                              }
                              if (s1 !== peg$FAILED) {
                                peg$savedPos = s0;
                                s1 = peg$c127();
                              }
                              s0 = s1;
                              if (s0 === peg$FAILED) {
                                s0 = peg$currPos;
                                if (input.charCodeAt(peg$currPos) === 177) {
                                  s1 = peg$c128;
                                  peg$currPos++;
                                } else {
                                  s1 = peg$FAILED;
                                  if (peg$silentFails === 0) { peg$fail(peg$c129); }
                                }
                                if (s1 !== peg$FAILED) {
                                  peg$savedPos = s0;
                                  s1 = peg$c130();
                                }
                                s0 = s1;
                                if (s0 === peg$FAILED) {
                                  s0 = peg$currPos;
                                  if (input.charCodeAt(peg$currPos) === 8723) {
                                    s1 = peg$c131;
                                    peg$currPos++;
                                  } else {
                                    s1 = peg$FAILED;
                                    if (peg$silentFails === 0) { peg$fail(peg$c132); }
                                  }
                                  if (s1 !== peg$FAILED) {
                                    peg$savedPos = s0;
                                    s1 = peg$c133();
                                  }
                                  s0 = s1;
                                  if (s0 === peg$FAILED) {
                                    s0 = peg$currPos;
                                    if (input.substr(peg$currPos, 2) === peg$c134) {
                                      s1 = peg$c134;
                                      peg$currPos += 2;
                                    } else {
                                      s1 = peg$FAILED;
                                      if (peg$silentFails === 0) { peg$fail(peg$c135); }
                                    }
                                    if (s1 !== peg$FAILED) {
                                      peg$savedPos = s0;
                                      s1 = peg$c136();
                                    }
                                    s0 = s1;
                                    if (s0 === peg$FAILED) {
                                      s0 = peg$currPos;
                                      if (input.substr(peg$currPos, 2) === peg$c137) {
                                        s1 = peg$c137;
                                        peg$currPos += 2;
                                      } else {
                                        s1 = peg$FAILED;
                                        if (peg$silentFails === 0) { peg$fail(peg$c138); }
                                      }
                                      if (s1 !== peg$FAILED) {
                                        peg$savedPos = s0;
                                        s1 = peg$c139();
                                      }
                                      s0 = s1;
                                      if (s0 === peg$FAILED) {
                                        s0 = peg$currPos;
                                        if (input.substr(peg$currPos, 2) === peg$c134) {
                                          s1 = peg$c134;
                                          peg$currPos += 2;
                                        } else {
                                          s1 = peg$FAILED;
                                          if (peg$silentFails === 0) { peg$fail(peg$c135); }
                                        }
                                        if (s1 !== peg$FAILED) {
                                          peg$savedPos = s0;
                                          s1 = peg$c140();
                                        }
                                        s0 = s1;
                                        if (s0 === peg$FAILED) {
                                          s0 = peg$currPos;
                                          if (input.substr(peg$currPos, 2) === peg$c137) {
                                            s1 = peg$c137;
                                            peg$currPos += 2;
                                          } else {
                                            s1 = peg$FAILED;
                                            if (peg$silentFails === 0) { peg$fail(peg$c138); }
                                          }
                                          if (s1 !== peg$FAILED) {
                                            peg$savedPos = s0;
                                            s1 = peg$c141();
                                          }
                                          s0 = s1;
                                          if (s0 === peg$FAILED) {
                                            s0 = peg$currPos;
                                            if (input.charCodeAt(peg$currPos) === 10752) {
                                              s1 = peg$c142;
                                              peg$currPos++;
                                            } else {
                                              s1 = peg$FAILED;
                                              if (peg$silentFails === 0) { peg$fail(peg$c143); }
                                            }
                                            if (s1 !== peg$FAILED) {
                                              peg$savedPos = s0;
                                              s1 = peg$c144();
                                            }
                                            s0 = s1;
                                            if (s0 === peg$FAILED) {
                                              s0 = peg$currPos;
                                              if (input.charCodeAt(peg$currPos) === 10752) {
                                                s1 = peg$c142;
                                                peg$currPos++;
                                              } else {
                                                s1 = peg$FAILED;
                                                if (peg$silentFails === 0) { peg$fail(peg$c143); }
                                              }
                                              if (s1 !== peg$FAILED) {
                                                peg$savedPos = s0;
                                                s1 = peg$c145();
                                              }
                                              s0 = s1;
                                              if (s0 === peg$FAILED) {
                                                s0 = peg$currPos;
                                                if (input.charCodeAt(peg$currPos) === 10227) {
                                                  s1 = peg$c146;
                                                  peg$currPos++;
                                                } else {
                                                  s1 = peg$FAILED;
                                                  if (peg$silentFails === 0) { peg$fail(peg$c147); }
                                                }
                                                if (s1 !== peg$FAILED) {
                                                  peg$savedPos = s0;
                                                  s1 = peg$c148();
                                                }
                                                s0 = s1;
                                                if (s0 === peg$FAILED) {
                                                  s0 = peg$currPos;
                                                  if (input.charCodeAt(peg$currPos) === 10227) {
                                                    s1 = peg$c146;
                                                    peg$currPos++;
                                                  } else {
                                                    s1 = peg$FAILED;
                                                    if (peg$silentFails === 0) { peg$fail(peg$c147); }
                                                  }
                                                  if (s1 !== peg$FAILED) {
                                                    peg$savedPos = s0;
                                                    s1 = peg$c149();
                                                  }
                                                  s0 = s1;
                                                  if (s0 === peg$FAILED) {
                                                    s0 = peg$currPos;
                                                    if (input.charCodeAt(peg$currPos) === 8594) {
                                                      s1 = peg$c150;
                                                      peg$currPos++;
                                                    } else {
                                                      s1 = peg$FAILED;
                                                      if (peg$silentFails === 0) { peg$fail(peg$c151); }
                                                    }
                                                    if (s1 !== peg$FAILED) {
                                                      peg$savedPos = s0;
                                                      s1 = peg$c152();
                                                    }
                                                    s0 = s1;
                                                    if (s0 === peg$FAILED) {
                                                      s0 = peg$currPos;
                                                      if (input.charCodeAt(peg$currPos) === 8594) {
                                                        s1 = peg$c150;
                                                        peg$currPos++;
                                                      } else {
                                                        s1 = peg$FAILED;
                                                        if (peg$silentFails === 0) { peg$fail(peg$c151); }
                                                      }
                                                      if (s1 !== peg$FAILED) {
                                                        peg$savedPos = s0;
                                                        s1 = peg$c153();
                                                      }
                                                      s0 = s1;
                                                      if (s0 === peg$FAILED) {
                                                        s0 = peg$currPos;
                                                        if (input.charCodeAt(peg$currPos) === 8593) {
                                                          s1 = peg$c154;
                                                          peg$currPos++;
                                                        } else {
                                                          s1 = peg$FAILED;
                                                          if (peg$silentFails === 0) { peg$fail(peg$c155); }
                                                        }
                                                        if (s1 !== peg$FAILED) {
                                                          peg$savedPos = s0;
                                                          s1 = peg$c156();
                                                        }
                                                        s0 = s1;
                                                        if (s0 === peg$FAILED) {
                                                          s0 = peg$currPos;
                                                          if (input.charCodeAt(peg$currPos) === 8593) {
                                                            s1 = peg$c154;
                                                            peg$currPos++;
                                                          } else {
                                                            s1 = peg$FAILED;
                                                            if (peg$silentFails === 0) { peg$fail(peg$c155); }
                                                          }
                                                          if (s1 !== peg$FAILED) {
                                                            peg$savedPos = s0;
                                                            s1 = peg$c157();
                                                          }
                                                          s0 = s1;
                                                          if (s0 === peg$FAILED) {
                                                            s0 = peg$currPos;
                                                            if (input.charCodeAt(peg$currPos) === 8646) {
                                                              s1 = peg$c158;
                                                              peg$currPos++;
                                                            } else {
                                                              s1 = peg$FAILED;
                                                              if (peg$silentFails === 0) { peg$fail(peg$c159); }
                                                            }
                                                            if (s1 !== peg$FAILED) {
                                                              peg$savedPos = s0;
                                                              s1 = peg$c160();
                                                            }
                                                            s0 = s1;
                                                            if (s0 === peg$FAILED) {
                                                              s0 = peg$currPos;
                                                              if (input.charCodeAt(peg$currPos) === 8646) {
                                                                s1 = peg$c158;
                                                                peg$currPos++;
                                                              } else {
                                                                s1 = peg$FAILED;
                                                                if (peg$silentFails === 0) { peg$fail(peg$c159); }
                                                              }
                                                              if (s1 !== peg$FAILED) {
                                                                peg$savedPos = s0;
                                                                s1 = peg$c161();
                                                              }
                                                              s0 = s1;
                                                              if (s0 === peg$FAILED) {
                                                                s0 = peg$currPos;
                                                                if (input.charCodeAt(peg$currPos) === 68) {
                                                                  s1 = peg$c162;
                                                                  peg$currPos++;
                                                                } else {
                                                                  s1 = peg$FAILED;
                                                                  if (peg$silentFails === 0) { peg$fail(peg$c163); }
                                                                }
                                                                if (s1 !== peg$FAILED) {
                                                                  peg$savedPos = s0;
                                                                  s1 = peg$c164();
                                                                }
                                                                s0 = s1;
                                                              }
                                                            }
                                                          }
                                                        }
                                                      }
                                                    }
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c94); }
      }
  
      return s0;
    }
  
    function peg$parsecontinuation() {
      var s0, s1, s2, s3;
  
      s0 = peg$currPos;
      s1 = peg$parseperiod();
      if (s1 !== peg$FAILED) {
        s2 = peg$parseperiod();
        if (s2 !== peg$FAILED) {
          s3 = peg$parseperiod();
          if (s3 !== peg$FAILED) {
            s1 = [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$parserol_comment() {
      var s0, s1, s2, s3, s4, s5;
  
      s0 = peg$currPos;
      s1 = [];
      s2 = peg$parsewhitespace();
      while (s2 !== peg$FAILED) {
        s1.push(s2);
        s2 = peg$parsewhitespace();
      }
      if (s1 !== peg$FAILED) {
        s2 = peg$parsesemi_colon();
        if (s2 !== peg$FAILED) {
          s3 = [];
          s4 = peg$parsewhitespace();
          while (s4 !== peg$FAILED) {
            s3.push(s4);
            s4 = peg$parsewhitespace();
          }
          if (s3 !== peg$FAILED) {
            s4 = [];
            s5 = peg$parsenot_newline();
            while (s5 !== peg$FAILED) {
              s4.push(s5);
              s5 = peg$parsenot_newline();
            }
            if (s4 !== peg$FAILED) {
              s5 = peg$parsenewline();
              if (s5 !== peg$FAILED) {
                peg$savedPos = s0;
                s1 = peg$c165(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$parsecomment_open() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.charCodeAt(peg$currPos) === 123) {
        s0 = peg$c167;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c168); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c166); }
      }
  
      return s0;
    }
  
    function peg$parsecomment_close() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.charCodeAt(peg$currPos) === 125) {
        s0 = peg$c170;
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c171); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c169); }
      }
  
      return s0;
    }
  
    function peg$parsecomment_chars() {
      var s0;
  
      if (peg$c172.test(input.charAt(peg$currPos))) {
        s0 = input.charAt(peg$currPos);
        peg$currPos++;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c173); }
      }
  
      return s0;
    }
  
    function peg$parsecomment() {
      var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
  
      s0 = peg$parserol_comment();
      if (s0 === peg$FAILED) {
        s0 = peg$currPos;
        s1 = [];
        s2 = peg$currPos;
        s3 = [];
        s4 = peg$parsewhitespace();
        while (s4 !== peg$FAILED) {
          s3.push(s4);
          s4 = peg$parsewhitespace();
        }
        if (s3 !== peg$FAILED) {
          s4 = peg$parsecomment_open();
          if (s4 !== peg$FAILED) {
            s5 = [];
            s6 = peg$parsecomment_chars();
            while (s6 !== peg$FAILED) {
              s5.push(s6);
              s6 = peg$parsecomment_chars();
            }
            if (s5 !== peg$FAILED) {
              s6 = peg$parsecomment_close();
              if (s6 !== peg$FAILED) {
                s7 = [];
                s8 = peg$currPos;
                s9 = [];
                s10 = peg$parsewhitespace();
                if (s10 !== peg$FAILED) {
                  while (s10 !== peg$FAILED) {
                    s9.push(s10);
                    s10 = peg$parsewhitespace();
                  }
                } else {
                  s9 = peg$FAILED;
                }
                if (s9 !== peg$FAILED) {
                  s10 = peg$parsenag();
                  if (s10 !== peg$FAILED) {
                    peg$savedPos = s8;
                    s9 = peg$c174(s5, s10);
                    s8 = s9;
                  } else {
                    peg$currPos = s8;
                    s8 = peg$FAILED;
                  }
                } else {
                  peg$currPos = s8;
                  s8 = peg$FAILED;
                }
                while (s8 !== peg$FAILED) {
                  s7.push(s8);
                  s8 = peg$currPos;
                  s9 = [];
                  s10 = peg$parsewhitespace();
                  if (s10 !== peg$FAILED) {
                    while (s10 !== peg$FAILED) {
                      s9.push(s10);
                      s10 = peg$parsewhitespace();
                    }
                  } else {
                    s9 = peg$FAILED;
                  }
                  if (s9 !== peg$FAILED) {
                    s10 = peg$parsenag();
                    if (s10 !== peg$FAILED) {
                      peg$savedPos = s8;
                      s9 = peg$c174(s5, s10);
                      s8 = s9;
                    } else {
                      peg$currPos = s8;
                      s8 = peg$FAILED;
                    }
                  } else {
                    peg$currPos = s8;
                    s8 = peg$FAILED;
                  }
                }
                if (s7 !== peg$FAILED) {
                  peg$savedPos = s2;
                  s3 = peg$c175(s5, s7);
                  s2 = s3;
                } else {
                  peg$currPos = s2;
                  s2 = peg$FAILED;
                }
              } else {
                peg$currPos = s2;
                s2 = peg$FAILED;
              }
            } else {
              peg$currPos = s2;
              s2 = peg$FAILED;
            }
          } else {
            peg$currPos = s2;
            s2 = peg$FAILED;
          }
        } else {
          peg$currPos = s2;
          s2 = peg$FAILED;
        }
        while (s2 !== peg$FAILED) {
          s1.push(s2);
          s2 = peg$currPos;
          s3 = [];
          s4 = peg$parsewhitespace();
          while (s4 !== peg$FAILED) {
            s3.push(s4);
            s4 = peg$parsewhitespace();
          }
          if (s3 !== peg$FAILED) {
            s4 = peg$parsecomment_open();
            if (s4 !== peg$FAILED) {
              s5 = [];
              s6 = peg$parsecomment_chars();
              while (s6 !== peg$FAILED) {
                s5.push(s6);
                s6 = peg$parsecomment_chars();
              }
              if (s5 !== peg$FAILED) {
                s6 = peg$parsecomment_close();
                if (s6 !== peg$FAILED) {
                  s7 = [];
                  s8 = peg$currPos;
                  s9 = [];
                  s10 = peg$parsewhitespace();
                  if (s10 !== peg$FAILED) {
                    while (s10 !== peg$FAILED) {
                      s9.push(s10);
                      s10 = peg$parsewhitespace();
                    }
                  } else {
                    s9 = peg$FAILED;
                  }
                  if (s9 !== peg$FAILED) {
                    s10 = peg$parsenag();
                    if (s10 !== peg$FAILED) {
                      peg$savedPos = s8;
                      s9 = peg$c174(s5, s10);
                      s8 = s9;
                    } else {
                      peg$currPos = s8;
                      s8 = peg$FAILED;
                    }
                  } else {
                    peg$currPos = s8;
                    s8 = peg$FAILED;
                  }
                  while (s8 !== peg$FAILED) {
                    s7.push(s8);
                    s8 = peg$currPos;
                    s9 = [];
                    s10 = peg$parsewhitespace();
                    if (s10 !== peg$FAILED) {
                      while (s10 !== peg$FAILED) {
                        s9.push(s10);
                        s10 = peg$parsewhitespace();
                      }
                    } else {
                      s9 = peg$FAILED;
                    }
                    if (s9 !== peg$FAILED) {
                      s10 = peg$parsenag();
                      if (s10 !== peg$FAILED) {
                        peg$savedPos = s8;
                        s9 = peg$c174(s5, s10);
                        s8 = s9;
                      } else {
                        peg$currPos = s8;
                        s8 = peg$FAILED;
                      }
                    } else {
                      peg$currPos = s8;
                      s8 = peg$FAILED;
                    }
                  }
                  if (s7 !== peg$FAILED) {
                    peg$savedPos = s2;
                    s3 = peg$c175(s5, s7);
                    s2 = s3;
                  } else {
                    peg$currPos = s2;
                    s2 = peg$FAILED;
                  }
                } else {
                  peg$currPos = s2;
                  s2 = peg$FAILED;
                }
              } else {
                peg$currPos = s2;
                s2 = peg$FAILED;
              }
            } else {
              peg$currPos = s2;
              s2 = peg$FAILED;
            }
          } else {
            peg$currPos = s2;
            s2 = peg$FAILED;
          }
        }
        if (s1 !== peg$FAILED) {
          peg$savedPos = s0;
          s1 = peg$c176(s1);
        }
        s0 = s1;
      }
  
      return s0;
    }
  
    function peg$parsepawn_half_move() {
      var s0, s1, s2, s3;
  
      s0 = peg$currPos;
      s1 = peg$currPos;
      s2 = peg$parserank();
      if (s2 !== peg$FAILED) {
        s3 = peg$parsecapture();
        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$parsesquare();
        if (s2 !== peg$FAILED) {
          s3 = peg$parsepromotion();
          if (s3 === peg$FAILED) {
            s3 = null;
          }
          if (s3 !== peg$FAILED) {
            s1 = [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$parsepiece_half_move() {
      var s0, s1, s2, s3;
  
      s0 = peg$currPos;
      s1 = peg$parsepiece();
      if (s1 !== peg$FAILED) {
        s2 = peg$parsecapture();
        if (s2 === peg$FAILED) {
          s2 = null;
        }
        if (s2 !== peg$FAILED) {
          s3 = peg$parsesquare();
          if (s3 !== peg$FAILED) {
            s1 = [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$parsepiece_disambiguation_half_move() {
      var s0, s1, s2, s3, s4;
  
      s0 = peg$currPos;
      s1 = peg$parsepiece();
      if (s1 !== peg$FAILED) {
        s2 = peg$parserank();
        if (s2 === peg$FAILED) {
          s2 = peg$parsefile();
        }
        if (s2 !== peg$FAILED) {
          s3 = peg$parsecapture();
          if (s3 === peg$FAILED) {
            s3 = null;
          }
          if (s3 !== peg$FAILED) {
            s4 = peg$parsesquare();
            if (s4 !== peg$FAILED) {
              s1 = [s1, s2, 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;
      }
  
      return s0;
    }
  
    function peg$parsecastle_half_move() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.substr(peg$currPos, 5) === peg$c178) {
        s0 = peg$c178;
        peg$currPos += 5;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c179); }
      }
      if (s0 === peg$FAILED) {
        if (input.substr(peg$currPos, 3) === peg$c180) {
          s0 = peg$c180;
          peg$currPos += 3;
        } else {
          s0 = peg$FAILED;
          if (peg$silentFails === 0) { peg$fail(peg$c181); }
        }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c177); }
      }
  
      return s0;
    }
  
    function peg$parsenull_move() {
      var s0, s1;
  
      peg$silentFails++;
      if (input.substr(peg$currPos, 2) === peg$c183) {
        s0 = peg$c183;
        peg$currPos += 2;
      } else {
        s0 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c184); }
      }
      peg$silentFails--;
      if (s0 === peg$FAILED) {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c182); }
      }
  
      return s0;
    }
  
    function peg$parsehalf_move() {
      var s0, s1, s2, s3, s4, s5;
  
      s0 = peg$currPos;
      s1 = peg$currPos;
      s2 = peg$parsecontinuation();
      if (s2 === peg$FAILED) {
        s2 = null;
      }
      if (s2 !== peg$FAILED) {
        s3 = peg$parsecastle_half_move();
        if (s3 === peg$FAILED) {
          s3 = peg$parsepiece_disambiguation_half_move();
          if (s3 === peg$FAILED) {
            s3 = peg$parsepiece_half_move();
            if (s3 === peg$FAILED) {
              s3 = peg$parsepawn_half_move();
              if (s3 === peg$FAILED) {
                s3 = peg$parsenull_move();
              }
            }
          }
        }
        if (s3 !== peg$FAILED) {
          s4 = peg$parsecheck();
          if (s4 === peg$FAILED) {
            s4 = peg$parsecheckmate();
          }
          if (s4 === peg$FAILED) {
            s4 = null;
          }
          if (s4 !== peg$FAILED) {
            s5 = peg$parsenag_alts();
            if (s5 === peg$FAILED) {
              s5 = null;
            }
            if (s5 !== peg$FAILED) {
              s2 = [s2, s3, s4, 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$c185(s1);
      }
      s0 = s1;
  
      return s0;
    }
  
    function peg$parsemove() {
      var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12;
  
      s0 = peg$currPos;
      s1 = peg$parsecomment();
      if (s1 !== peg$FAILED) {
        s2 = [];
        s3 = peg$parsewhitespace();
        while (s3 !== peg$FAILED) {
          s2.push(s3);
          s3 = peg$parsewhitespace();
        }
        if (s2 !== peg$FAILED) {
          s3 = peg$currPos;
          s4 = peg$parsemove_number();
          if (s4 === peg$FAILED) {
            s4 = null;
          }
          if (s4 !== peg$FAILED) {
            s5 = [];
            s6 = peg$parsewhitespace();
            while (s6 !== peg$FAILED) {
              s5.push(s6);
              s6 = peg$parsewhitespace();
            }
            if (s5 !== peg$FAILED) {
              s6 = peg$parsehalf_move();
              if (s6 === peg$FAILED) {
                s6 = null;
              }
              if (s6 !== peg$FAILED) {
                s7 = [];
                s8 = peg$currPos;
                s9 = [];
                s10 = peg$parsewhitespace();
                if (s10 !== peg$FAILED) {
                  while (s10 !== peg$FAILED) {
                    s9.push(s10);
                    s10 = peg$parsewhitespace();
                  }
                } else {
                  s9 = peg$FAILED;
                }
                if (s9 !== peg$FAILED) {
                  s10 = peg$parsenag();
                  if (s10 !== peg$FAILED) {
                    peg$savedPos = s8;
                    s9 = peg$c186(s1, s4, s6, s10);
                    s8 = s9;
                  } else {
                    peg$currPos = s8;
                    s8 = peg$FAILED;
                  }
                } else {
                  peg$currPos = s8;
                  s8 = peg$FAILED;
                }
                while (s8 !== peg$FAILED) {
                  s7.push(s8);
                  s8 = peg$currPos;
                  s9 = [];
                  s10 = peg$parsewhitespace();
                  if (s10 !== peg$FAILED) {
                    while (s10 !== peg$FAILED) {
                      s9.push(s10);
                      s10 = peg$parsewhitespace();
                    }
                  } else {
                    s9 = peg$FAILED;
                  }
                  if (s9 !== peg$FAILED) {
                    s10 = peg$parsenag();
                    if (s10 !== peg$FAILED) {
                      peg$savedPos = s8;
                      s9 = peg$c186(s1, s4, s6, s10);
                      s8 = s9;
                    } else {
                      peg$currPos = s8;
                      s8 = peg$FAILED;
                    }
                  } else {
                    peg$currPos = s8;
                    s8 = peg$FAILED;
                  }
                }
                if (s7 !== peg$FAILED) {
                  s8 = peg$parsecomment();
                  if (s8 !== peg$FAILED) {
                    s9 = [];
                    s10 = peg$currPos;
                    s11 = [];
                    s12 = peg$parsewhitespace();
                    if (s12 !== peg$FAILED) {
                      while (s12 !== peg$FAILED) {
                        s11.push(s12);
                        s12 = peg$parsewhitespace();
                      }
                    } else {
                      s11 = peg$FAILED;
                    }
                    if (s11 !== peg$FAILED) {
                      s12 = peg$parserav();
                      if (s12 !== peg$FAILED) {
                        peg$savedPos = s10;
                        s11 = peg$c187(s1, s4, s6, s7, s8, s12);
                        s10 = s11;
                      } else {
                        peg$currPos = s10;
                        s10 = peg$FAILED;
                      }
                    } else {
                      peg$currPos = s10;
                      s10 = peg$FAILED;
                    }
                    while (s10 !== peg$FAILED) {
                      s9.push(s10);
                      s10 = peg$currPos;
                      s11 = [];
                      s12 = peg$parsewhitespace();
                      if (s12 !== peg$FAILED) {
                        while (s12 !== peg$FAILED) {
                          s11.push(s12);
                          s12 = peg$parsewhitespace();
                        }
                      } else {
                        s11 = peg$FAILED;
                      }
                      if (s11 !== peg$FAILED) {
                        s12 = peg$parserav();
                        if (s12 !== peg$FAILED) {
                          peg$savedPos = s10;
                          s11 = peg$c187(s1, s4, s6, s7, s8, s12);
                          s10 = s11;
                        } else {
                          peg$currPos = s10;
                          s10 = peg$FAILED;
                        }
                      } else {
                        peg$currPos = s10;
                        s10 = peg$FAILED;
                      }
                    }
                    if (s9 !== peg$FAILED) {
                      peg$savedPos = s3;
                      s4 = peg$c188(s1, s4, s6, s7, s8, s9);
                      s3 = s4;
                    } else {
                      peg$currPos = s3;
                      s3 = peg$FAILED;
                    }
                  } else {
                    peg$currPos = s3;
                    s3 = peg$FAILED;
                  }
                } else {
                  peg$currPos = s3;
                  s3 = peg$FAILED;
                }
              } else {
                peg$currPos = s3;
                s3 = peg$FAILED;
              }
            } 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$c189(s1, 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$parsemovetext() {
      var s0, s1, s2, s3, s4, s5;
  
      s0 = peg$currPos;
      s1 = peg$parsemove();
      if (s1 !== peg$FAILED) {
        s2 = [];
        s3 = peg$currPos;
        s4 = [];
        s5 = peg$parsewhitespace();
        if (s5 !== peg$FAILED) {
          while (s5 !== peg$FAILED) {
            s4.push(s5);
            s5 = peg$parsewhitespace();
          }
        } else {
          s4 = peg$FAILED;
        }
        if (s4 !== peg$FAILED) {
          s5 = peg$parsemove();
          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 = [];
          s5 = peg$parsewhitespace();
          if (s5 !== peg$FAILED) {
            while (s5 !== peg$FAILED) {
              s4.push(s5);
              s5 = peg$parsewhitespace();
            }
          } else {
            s4 = peg$FAILED;
          }
          if (s4 !== peg$FAILED) {
            s5 = peg$parsemove();
            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$c190(s1, s2);
          s0 = s1;
        } else {
          peg$currPos = s0;
          s0 = peg$FAILED;
        }
      } else {
        peg$currPos = s0;
        s0 = peg$FAILED;
      }
  
      return s0;
    }
  
    function peg$parserav() {
      var s0, s1, s2, s3, s4, s5, s6, s7;
  
      s0 = peg$currPos;
      if (input.charCodeAt(peg$currPos) === 40) {
        s1 = peg$c191;
        peg$currPos++;
      } else {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c192); }
      }
      if (s1 !== peg$FAILED) {
        s2 = [];
        s3 = peg$parsewhitespace();
        while (s3 !== peg$FAILED) {
          s2.push(s3);
          s3 = peg$parsewhitespace();
        }
        if (s2 !== peg$FAILED) {
          s3 = peg$parsemovetext();
          if (s3 !== peg$FAILED) {
            s4 = [];
            s5 = peg$parsewhitespace();
            while (s5 !== peg$FAILED) {
              s4.push(s5);
              s5 = peg$parsewhitespace();
            }
            if (s4 !== peg$FAILED) {
              s5 = peg$parseresult();
              if (s5 === peg$FAILED) {
                s5 = null;
              }
              if (s5 !== peg$FAILED) {
                s6 = [];
                s7 = peg$parsewhitespace();
                while (s7 !== peg$FAILED) {
                  s6.push(s7);
                  s7 = peg$parsewhitespace();
                }
                if (s6 !== peg$FAILED) {
                  if (input.charCodeAt(peg$currPos) === 41) {
                    s7 = peg$c193;
                    peg$currPos++;
                  } else {
                    s7 = peg$FAILED;
                    if (peg$silentFails === 0) { peg$fail(peg$c194); }
                  }
                  if (s7 !== peg$FAILED) {
                    peg$savedPos = s0;
                    s1 = peg$c195(s3, 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;
          }
        } else {
          peg$currPos = s0;
          s0 = peg$FAILED;
        }
      } else {
        peg$currPos = s0;
        s0 = peg$FAILED;
      }
  
      return s0;
    }
  
  
      function flatten(a, acc = []) {
        for (var i = 0; i < a.length; i++) {
          if (Array.isArray(a[i])) {
            flatten(a[i], acc)
          } else {
            acc.push(a[i])
          }
        }
        return acc
      }
  
      function make_header(hn,hv) {
        var m = {}
        m[hn] = hv
        return m
      }
  
      function make_move(move_number, move, nags, ravs, commentBefore, commentAfter) {
        var m = {}
        if (move_number) m.move_number = move_number
        if (move) m.move = move
        if (nags && nags.length) m.nags = nags
        if (ravs && ravs.length) m.ravs = ravs
        if (commentBefore) m.commentBefore = commentBefore
        if (commentAfter) m.commentAfter = commentAfter
        return m
      }
  
      function make_rav(moves, result) {
        return {
          moves,
          result,
        }
      }
  
      function make_game(h, m, r) {
        h = h || []
        return {
          headers: h.reduce((acc, x) => Object.assign(acc, x), {}),
          moves: m || [],
          result: r,
        }
      }
  
  
    peg$result = peg$startRuleFunction();
  
    if (peg$result !== peg$FAILED && peg$currPos === input.length) {
      return peg$result;
    } else {
      if (peg$result !== peg$FAILED && peg$currPos < input.length) {
        peg$fail(peg$endExpectation());
      }
  
      throw peg$buildStructuredError(
        peg$maxFailExpected,
        peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
        peg$maxFailPos < input.length
          ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
          : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
      );
    }
  }
  
  export default {
    SyntaxError: peg$SyntaxError,
    parse:       peg$parse
  };
  