@echecs/pgn 3.1.3 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/grammar.cjs CHANGED
@@ -1,144 +1,2718 @@
1
+ // @generated by Peggy 5.1.0.
2
+ //
3
+ // https://peggyjs.org/
1
4
  "use strict";
2
- // Generated automatically by nearley, version 2.20.1
3
- // http://github.com/Hardmath123/nearley
4
- (function () {
5
- function id(x) { return x[0]; }
6
- const lexer = require('./lexer.ts').default;
7
- var grammar = {
8
- Lexer: lexer,
9
- ParserRules: [
10
- { "name": "DATABASE$ebnf$1$subexpression$1", "symbols": [(lexer.has("__") ? { type: "__" } : __), "DATABASE"] },
11
- { "name": "DATABASE$ebnf$1", "symbols": ["DATABASE$ebnf$1$subexpression$1"], "postprocess": id },
12
- { "name": "DATABASE$ebnf$1", "symbols": [], "postprocess": function (d) { return null; } },
13
- { "name": "DATABASE", "symbols": ["GAME", "DATABASE$ebnf$1"], "postprocess": (d) => {
14
- const games = [d[0]];
15
- if (d[1]) {
16
- games.push(...d[1][1]);
17
- }
18
- return games;
19
- }
5
+ function pairMoves(moves, start) {
6
+ start = start ?? 0;
7
+ const acc = [];
8
+ for (let i = 0; i < moves.length; i++) {
9
+ const si = start + i;
10
+ const isWhite = si % 2 === 0;
11
+ const index = (si - (isWhite ? 0 : 1)) >> 1;
12
+ if (acc[index] === undefined) {
13
+ acc[index] = [index + 1, undefined];
14
+ }
15
+ const { number, long, ...move } = moves[i];
16
+ if (number !== undefined && number !== index + 1) {
17
+ console.warn(`Warning: Move number mismatch - ${number}`);
18
+ }
19
+ if (move.castling) {
20
+ move.to = isWhite
21
+ ? (long ? 'c1' : 'g1')
22
+ : (long ? 'c8' : 'g8');
23
+ }
24
+ if (move.variants) {
25
+ move.variants = move.variants.map((variant) => pairMoves(variant, si));
26
+ }
27
+ acc[index][isWhite ? 1 : 2] = move;
28
+ }
29
+ return start === 0 ? acc : acc.slice(start >> 1);
30
+ }
31
+ function mapResult(result) {
32
+ switch (result) {
33
+ case '1-0': return 1;
34
+ case '0-1': return 0;
35
+ case '1/2-1/2': return 0.5;
36
+ default: return '?';
37
+ }
38
+ }
39
+ class peg$SyntaxError extends SyntaxError {
40
+ constructor(message, expected, found, location) {
41
+ super(message);
42
+ this.expected = expected;
43
+ this.found = found;
44
+ this.location = location;
45
+ this.name = "SyntaxError";
46
+ }
47
+ format(sources) {
48
+ let str = "Error: " + this.message;
49
+ if (this.location) {
50
+ let src = null;
51
+ const st = sources.find(s => s.source === this.location.source);
52
+ if (st) {
53
+ src = st.text.split(/\r\n|\n|\r/g);
54
+ }
55
+ const s = this.location.start;
56
+ const offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
57
+ ? this.location.source.offset(s)
58
+ : s;
59
+ const loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
60
+ if (src) {
61
+ const e = this.location.end;
62
+ const filler = "".padEnd(offset_s.line.toString().length, " ");
63
+ const line = src[s.line - 1];
64
+ const last = s.line === e.line ? e.column : line.length + 1;
65
+ const hatLen = (last - s.column) || 1;
66
+ str += "\n --> " + loc + "\n"
67
+ + filler + " |\n"
68
+ + offset_s.line + " | " + line + "\n"
69
+ + filler + " | " + "".padEnd(s.column - 1, " ")
70
+ + "".padEnd(hatLen, "^");
71
+ }
72
+ else {
73
+ str += "\n at " + loc;
74
+ }
75
+ }
76
+ return str;
77
+ }
78
+ static buildMessage(expected, found) {
79
+ function hex(ch) {
80
+ return ch.codePointAt(0).toString(16).toUpperCase();
81
+ }
82
+ const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode")
83
+ ? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu")
84
+ : null;
85
+ function unicodeEscape(s) {
86
+ if (nonPrintable) {
87
+ return s.replace(nonPrintable, ch => "\\u{" + hex(ch) + "}");
88
+ }
89
+ return s;
90
+ }
91
+ function literalEscape(s) {
92
+ return unicodeEscape(s
93
+ .replace(/\\/g, "\\\\")
94
+ .replace(/"/g, "\\\"")
95
+ .replace(/\0/g, "\\0")
96
+ .replace(/\t/g, "\\t")
97
+ .replace(/\n/g, "\\n")
98
+ .replace(/\r/g, "\\r")
99
+ .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
100
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
101
+ }
102
+ function classEscape(s) {
103
+ return unicodeEscape(s
104
+ .replace(/\\/g, "\\\\")
105
+ .replace(/\]/g, "\\]")
106
+ .replace(/\^/g, "\\^")
107
+ .replace(/-/g, "\\-")
108
+ .replace(/\0/g, "\\0")
109
+ .replace(/\t/g, "\\t")
110
+ .replace(/\n/g, "\\n")
111
+ .replace(/\r/g, "\\r")
112
+ .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
113
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
114
+ }
115
+ const DESCRIBE_EXPECTATION_FNS = {
116
+ literal(expectation) {
117
+ return "\"" + literalEscape(expectation.text) + "\"";
20
118
  },
21
- { "name": "GAME", "symbols": ["TAGS", (lexer.has("__") ? { type: "__" } : __), "MOVES", (lexer.has("__") ? { type: "__" } : __), (lexer.has("result") ? { type: "result" } : result)], "postprocess": (d) => {
22
- function pair(moves, start = 0) {
23
- return moves.reduce((acc, move, i) => {
24
- const color = (start + i) % 2 === 0 ? 'white' : 'black';
25
- const index = Math.floor((start + i) / 2);
26
- if (acc[index] === undefined) {
27
- acc[index] = [index + 1, undefined];
28
- }
29
- if (move.number !== undefined && move.number.value !== index + 1) {
30
- console.warn(`Warning: Move number mismatch - ${move.number.value} at line ${move.number.line} col ${move.number.col}`);
31
- }
32
- delete move.number;
33
- if (move.castling) {
34
- move.to = color === 'white' ? move.long ? 'c1' : 'g1' : move.long ? 'c8' : 'g8';
35
- // Delete the temporary castling property
36
- delete move.long;
37
- }
38
- if (move.variants) {
39
- move.variants = move.variants.map((variant) => pair(variant, start + i));
40
- }
41
- acc[index][color === 'white' ? 1 : 2] = move;
42
- return acc;
43
- }, []).slice(Math.floor(start / 2));
44
- }
45
- //return ({ meta: d[0], moves, result: String(d[4]) });
46
- const result = d[4].value;
47
- let mappedResult;
48
- switch (result) {
49
- case '1-0':
50
- mappedResult = 1;
51
- break;
52
- case '0-1':
53
- mappedResult = 0;
54
- break;
55
- case '1/2-1/2':
56
- mappedResult = 0.5;
57
- break;
58
- default:
59
- mappedResult = '?';
60
- break;
61
- }
62
- return ({ meta: d[0], moves: pair(d[2]), result: mappedResult });
63
- }
119
+ class(expectation) {
120
+ const escapedParts = expectation.parts.map(part => (Array.isArray(part)
121
+ ? classEscape(part[0]) + "-" + classEscape(part[1])
122
+ : classEscape(part)));
123
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : "");
64
124
  },
65
- { "name": "TAGS$ebnf$1$subexpression$1", "symbols": [(lexer.has("__") ? { type: "__" } : __), "TAGS"] },
66
- { "name": "TAGS$ebnf$1", "symbols": ["TAGS$ebnf$1$subexpression$1"], "postprocess": id },
67
- { "name": "TAGS$ebnf$1", "symbols": [], "postprocess": function (d) { return null; } },
68
- { "name": "TAGS", "symbols": ["TAG", "TAGS$ebnf$1"], "postprocess": (d) => {
69
- const tag = d[0];
70
- const rest = d[1] ? d[1][1] : {};
71
- return { ...tag, ...rest };
72
- }
125
+ any() {
126
+ return "any character";
73
127
  },
74
- { "name": "TAG", "symbols": [{ "literal": "[" }, (lexer.has("identifier") ? { type: "identifier" } : identifier), (lexer.has("__") ? { type: "__" } : __), (lexer.has("value") ? { type: "value" } : value), { "literal": "]" }], "postprocess": (d) => ({ [d[1].value]: d[3].value })
128
+ end() {
129
+ return "end of input";
75
130
  },
76
- { "name": "MOVES$ebnf$1", "symbols": [] },
77
- { "name": "MOVES$ebnf$1$subexpression$1$ebnf$1", "symbols": [(lexer.has("__") ? { type: "__" } : __)], "postprocess": id },
78
- { "name": "MOVES$ebnf$1$subexpression$1$ebnf$1", "symbols": [], "postprocess": function (d) { return null; } },
79
- { "name": "MOVES$ebnf$1$subexpression$1", "symbols": ["MOVES$ebnf$1$subexpression$1$ebnf$1", "RAV"] },
80
- { "name": "MOVES$ebnf$1", "symbols": ["MOVES$ebnf$1", "MOVES$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) { return d[0].concat([d[1]]); } },
81
- { "name": "MOVES$ebnf$2$subexpression$1", "symbols": [(lexer.has("__") ? { type: "__" } : __), "MOVES"] },
82
- { "name": "MOVES$ebnf$2", "symbols": ["MOVES$ebnf$2$subexpression$1"], "postprocess": id },
83
- { "name": "MOVES$ebnf$2", "symbols": [], "postprocess": function (d) { return null; } },
84
- { "name": "MOVES", "symbols": ["MOVE", "MOVES$ebnf$1", "MOVES$ebnf$2"], "postprocess": (d) => {
85
- let moves = [d[0]];
86
- if (d[1].length > 0) {
87
- moves[0].variants = d[1].map(d1 => d1[1]);
88
- }
89
- if (d[2]) {
90
- moves.push(...d[2][1]);
91
- }
92
- return moves;
93
- }
131
+ other(expectation) {
132
+ return expectation.description;
94
133
  },
95
- { "name": "MOVE$ebnf$1", "symbols": [(lexer.has("number") ? { type: "number" } : number)], "postprocess": id },
96
- { "name": "MOVE$ebnf$1", "symbols": [], "postprocess": function (d) { return null; } },
97
- { "name": "MOVE$ebnf$2", "symbols": [(lexer.has("__") ? { type: "__" } : __)], "postprocess": id },
98
- { "name": "MOVE$ebnf$2", "symbols": [], "postprocess": function (d) { return null; } },
99
- { "name": "MOVE$ebnf$3", "symbols": [] },
100
- { "name": "MOVE$ebnf$3$subexpression$1$ebnf$1", "symbols": [(lexer.has("__") ? { type: "__" } : __)], "postprocess": id },
101
- { "name": "MOVE$ebnf$3$subexpression$1$ebnf$1", "symbols": [], "postprocess": function (d) { return null; } },
102
- { "name": "MOVE$ebnf$3$subexpression$1", "symbols": ["MOVE$ebnf$3$subexpression$1$ebnf$1", "NAG"] },
103
- { "name": "MOVE$ebnf$3", "symbols": ["MOVE$ebnf$3", "MOVE$ebnf$3$subexpression$1"], "postprocess": function arrpush(d) { return d[0].concat([d[1]]); } },
104
- { "name": "MOVE$ebnf$4", "symbols": [] },
105
- { "name": "MOVE$ebnf$4$subexpression$1$ebnf$1", "symbols": [(lexer.has("__") ? { type: "__" } : __)], "postprocess": id },
106
- { "name": "MOVE$ebnf$4$subexpression$1$ebnf$1", "symbols": [], "postprocess": function (d) { return null; } },
107
- { "name": "MOVE$ebnf$4$subexpression$1", "symbols": ["MOVE$ebnf$4$subexpression$1$ebnf$1", "COMMENT"] },
108
- { "name": "MOVE$ebnf$4", "symbols": ["MOVE$ebnf$4", "MOVE$ebnf$4$subexpression$1"], "postprocess": function arrpush(d) { return d[0].concat([d[1]]); } },
109
- { "name": "MOVE", "symbols": ["MOVE$ebnf$1", "MOVE$ebnf$2", (lexer.has("san") ? { type: "san" } : san), "MOVE$ebnf$3", "MOVE$ebnf$4"], "postprocess": (d) => {
110
- // We keep the token for number so we can warn about mismatches. Not really
111
- // useful as numbers could be out of order.
112
- const number = d[0] ?? undefined;
113
- const annotations = d[3].map(d3 => d3[1]);
114
- const comments = d[4].map(d4 => d4[1]).filter(Boolean);
115
- const san = d[2].value;
116
- return {
117
- number,
118
- ...(annotations.length > 0 && { annotations }),
119
- ...(comments.length > 0 && { comment: comments.join(' ').replace(/\n/g, '') }),
120
- ...san,
121
- };
134
+ };
135
+ function describeExpectation(expectation) {
136
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
137
+ }
138
+ function describeExpected(expected) {
139
+ const descriptions = expected.map(describeExpectation);
140
+ descriptions.sort();
141
+ if (descriptions.length > 0) {
142
+ let j = 1;
143
+ for (let i = 1; i < descriptions.length; i++) {
144
+ if (descriptions[i - 1] !== descriptions[i]) {
145
+ descriptions[j] = descriptions[i];
146
+ j++;
147
+ }
148
+ }
149
+ descriptions.length = j;
150
+ }
151
+ switch (descriptions.length) {
152
+ case 1:
153
+ return descriptions[0];
154
+ case 2:
155
+ return descriptions[0] + " or " + descriptions[1];
156
+ default:
157
+ return descriptions.slice(0, -1).join(", ")
158
+ + ", or "
159
+ + descriptions[descriptions.length - 1];
160
+ }
161
+ }
162
+ function describeFound(found) {
163
+ return found ? "\"" + literalEscape(found) + "\"" : "end of input";
164
+ }
165
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
166
+ }
167
+ }
168
+ function peg$parse(input, options) {
169
+ options = options !== undefined ? options : {};
170
+ const peg$FAILED = {};
171
+ const peg$source = options.grammarSource;
172
+ const peg$startRuleFunctions = {
173
+ DATABASE: peg$parseDATABASE,
174
+ };
175
+ let peg$startRuleFunction = peg$parseDATABASE;
176
+ const peg$c0 = "[";
177
+ const peg$c1 = "]";
178
+ const peg$c2 = "\"";
179
+ const peg$c3 = "1/2-1/2";
180
+ const peg$c4 = "1-0";
181
+ const peg$c5 = "0-1";
182
+ const peg$c6 = "*";
183
+ const peg$c7 = ".";
184
+ const peg$c8 = "O-O-O";
185
+ const peg$c9 = "O-O";
186
+ const peg$c10 = "x";
187
+ const peg$c11 = "=";
188
+ const peg$c12 = "(";
189
+ const peg$c13 = ")";
190
+ const peg$c14 = "$";
191
+ const peg$c15 = "!!";
192
+ const peg$c16 = "??";
193
+ const peg$c17 = "!?";
194
+ const peg$c18 = "?!";
195
+ const peg$c19 = "+ \u2212";
196
+ const peg$c20 = "\u2212 +";
197
+ const peg$c21 = "{";
198
+ const peg$c22 = "}";
199
+ const peg$c23 = ";";
200
+ const peg$c24 = "%";
201
+ const peg$r0 = /^[a-zA-Z0-9_]/;
202
+ const peg$r1 = /^[^"]/;
203
+ const peg$r2 = /^[0-9]/;
204
+ const peg$r3 = /^[+#]/;
205
+ const peg$r4 = /^[KQBNPR]/;
206
+ const peg$r5 = /^[a-h]/;
207
+ const peg$r6 = /^[1-8]/;
208
+ const peg$r7 = /^[NBRQ]/;
209
+ const peg$r8 = /^[!?\xB1\u2213\u221E\u25A1\u2A71-\u2A72]/;
210
+ const peg$r9 = /^[=\u2191-\u2192\u21C6\u25CB\u27F3\u2981\u2A00\u2BF9]/;
211
+ const peg$r10 = /^[^}]/;
212
+ const peg$r11 = /^[\n]/;
213
+ const peg$r12 = /^[ \t\n\r]/;
214
+ const peg$e0 = peg$literalExpectation("[", false);
215
+ const peg$e1 = peg$literalExpectation("]", false);
216
+ const peg$e2 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_"], false, false, false);
217
+ const peg$e3 = peg$literalExpectation("\"", false);
218
+ const peg$e4 = peg$classExpectation(["\""], true, false, false);
219
+ const peg$e5 = peg$literalExpectation("1/2-1/2", false);
220
+ const peg$e6 = peg$literalExpectation("1-0", false);
221
+ const peg$e7 = peg$literalExpectation("0-1", false);
222
+ const peg$e8 = peg$literalExpectation("*", false);
223
+ const peg$e9 = peg$classExpectation([["0", "9"]], false, false, false);
224
+ const peg$e10 = peg$literalExpectation(".", false);
225
+ const peg$e11 = peg$literalExpectation("O-O-O", false);
226
+ const peg$e12 = peg$classExpectation(["+", "#"], false, false, false);
227
+ const peg$e13 = peg$literalExpectation("O-O", false);
228
+ const peg$e14 = peg$classExpectation(["K", "Q", "B", "N", "P", "R"], false, false, false);
229
+ const peg$e15 = peg$classExpectation([["a", "h"]], false, false, false);
230
+ const peg$e16 = peg$classExpectation([["1", "8"]], false, false, false);
231
+ const peg$e17 = peg$literalExpectation("x", false);
232
+ const peg$e18 = peg$literalExpectation("=", false);
233
+ const peg$e19 = peg$classExpectation(["N", "B", "R", "Q"], false, false, false);
234
+ const peg$e20 = peg$literalExpectation("(", false);
235
+ const peg$e21 = peg$literalExpectation(")", false);
236
+ const peg$e22 = peg$literalExpectation("$", false);
237
+ const peg$e23 = peg$literalExpectation("!!", false);
238
+ const peg$e24 = peg$literalExpectation("??", false);
239
+ const peg$e25 = peg$literalExpectation("!?", false);
240
+ const peg$e26 = peg$literalExpectation("?!", false);
241
+ const peg$e27 = peg$classExpectation(["!", "?", "\xB1", "\u2213", "\u221E", "\u25A1", ["\u2A71", "\u2A72"]], false, false, false);
242
+ const peg$e28 = peg$literalExpectation("+ \u2212", false);
243
+ const peg$e29 = peg$literalExpectation("\u2212 +", false);
244
+ const peg$e30 = peg$classExpectation(["=", ["\u2191", "\u2192"], "\u21C6", "\u25CB", "\u27F3", "\u2981", "\u2A00", "\u2BF9"], false, false, false);
245
+ const peg$e31 = peg$literalExpectation("{", false);
246
+ const peg$e32 = peg$classExpectation(["}"], true, false, false);
247
+ const peg$e33 = peg$literalExpectation("}", false);
248
+ const peg$e34 = peg$literalExpectation(";", false);
249
+ const peg$e35 = peg$classExpectation(["\n"], false, false, false);
250
+ const peg$e36 = peg$anyExpectation();
251
+ const peg$e37 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false, false);
252
+ const peg$e38 = peg$literalExpectation("%", false);
253
+ function peg$f0(first, g) { return g; }
254
+ function peg$f1(first, rest) { return [first, ...rest]; }
255
+ function peg$f2(tags, moves, result) { return { meta: tags, moves: pairMoves(moves), result: mapResult(result) }; }
256
+ function peg$f3(head, t) { return t; }
257
+ function peg$f4(head, tail) { return Object.assign({}, head, ...tail); }
258
+ function peg$f5(id, val) { return { [id]: val }; }
259
+ function peg$f6(val) { return val.trim(); }
260
+ function peg$f7(head, r) { return r; }
261
+ function peg$f8(head, variants, m) { return m; }
262
+ function peg$f9(head, variants, tail) {
263
+ if (variants.length > 0) {
264
+ head.variants = variants;
265
+ }
266
+ return tail ? [head, ...tail] : [head];
267
+ }
268
+ function peg$f10(num, san, n) { return n; }
269
+ function peg$f11(num, san, nags, c) { return c; }
270
+ function peg$f12(num, san, nags, comments) {
271
+ const move = { ...san };
272
+ if (num !== null)
273
+ move.number = num;
274
+ if (nags.length > 0) {
275
+ const annotations = nags.filter(Boolean);
276
+ if (annotations.length > 0)
277
+ move.annotations = annotations;
278
+ }
279
+ if (comments.length > 0) {
280
+ const commentText = comments.filter(Boolean).join(' ').replace(/\n/g, '');
281
+ if (commentText.length > 0)
282
+ move.comment = commentText;
283
+ }
284
+ return move;
285
+ }
286
+ function peg$f13(n) { return parseInt(n.replace(/\./g, ''), 10); }
287
+ function peg$f14() { return { castling: true, long: true, piece: 'K', to: 'O-O-O' }; }
288
+ function peg$f15() { return { castling: true, long: false, piece: 'K', to: 'O-O' }; }
289
+ function peg$f16(piece, df, dr, file, rank, promo, ind) {
290
+ const to = file + rank;
291
+ const result = { capture: true, from: df + dr, piece, to };
292
+ if (promo)
293
+ result.promotion = promo;
294
+ if (ind === '+')
295
+ result.check = true;
296
+ if (ind === '#')
297
+ result.checkmate = true;
298
+ return result;
299
+ }
300
+ function peg$f17(piece, df, dr, file, rank, promo, ind) {
301
+ const to = file + rank;
302
+ const result = { from: df + dr, piece, to };
303
+ if (promo)
304
+ result.promotion = promo;
305
+ if (ind === '+')
306
+ result.check = true;
307
+ if (ind === '#')
308
+ result.checkmate = true;
309
+ return result;
310
+ }
311
+ function peg$f18(piece, df, file, rank, promo, ind) {
312
+ const to = file + rank;
313
+ const result = { capture: true, from: df, piece, to };
314
+ if (promo)
315
+ result.promotion = promo;
316
+ if (ind === '+')
317
+ result.check = true;
318
+ if (ind === '#')
319
+ result.checkmate = true;
320
+ return result;
321
+ }
322
+ function peg$f19(piece, dr, file, rank, promo, ind) {
323
+ const to = file + rank;
324
+ const result = { capture: true, from: dr, piece, to };
325
+ if (promo)
326
+ result.promotion = promo;
327
+ if (ind === '+')
328
+ result.check = true;
329
+ if (ind === '#')
330
+ result.checkmate = true;
331
+ return result;
332
+ }
333
+ function peg$f20(piece, df, file, rank, promo, ind) {
334
+ const to = file + rank;
335
+ const result = { from: df, piece, to };
336
+ if (promo)
337
+ result.promotion = promo;
338
+ if (ind === '+')
339
+ result.check = true;
340
+ if (ind === '#')
341
+ result.checkmate = true;
342
+ return result;
343
+ }
344
+ function peg$f21(piece, dr, file, rank, promo, ind) {
345
+ const to = file + rank;
346
+ const result = { from: dr, piece, to };
347
+ if (promo)
348
+ result.promotion = promo;
349
+ if (ind === '+')
350
+ result.check = true;
351
+ if (ind === '#')
352
+ result.checkmate = true;
353
+ return result;
354
+ }
355
+ function peg$f22(piece, file, rank, promo, ind) {
356
+ const to = file + rank;
357
+ const result = { capture: true, piece, to };
358
+ if (promo)
359
+ result.promotion = promo;
360
+ if (ind === '+')
361
+ result.check = true;
362
+ if (ind === '#')
363
+ result.checkmate = true;
364
+ return result;
365
+ }
366
+ function peg$f23(piece, file, rank, promo, ind) {
367
+ const to = file + rank;
368
+ const result = { piece, to };
369
+ if (promo)
370
+ result.promotion = promo;
371
+ if (ind === '+')
372
+ result.check = true;
373
+ if (ind === '#')
374
+ result.checkmate = true;
375
+ return result;
376
+ }
377
+ function peg$f24(from, file, rank, promo, ind) {
378
+ const to = file + rank;
379
+ const result = { capture: true, from, piece: 'P', to };
380
+ if (promo)
381
+ result.promotion = promo;
382
+ if (ind === '+')
383
+ result.check = true;
384
+ if (ind === '#')
385
+ result.checkmate = true;
386
+ return result;
387
+ }
388
+ function peg$f25(file, rank, promo, ind) {
389
+ const to = file + rank;
390
+ const result = { piece: 'P', to };
391
+ if (promo)
392
+ result.promotion = promo;
393
+ if (ind === '+')
394
+ result.check = true;
395
+ if (ind === '#')
396
+ result.checkmate = true;
397
+ return result;
398
+ }
399
+ function peg$f26(p) { return p; }
400
+ function peg$f27(moves) { return moves; }
401
+ function peg$f28(n) { return n; }
402
+ function peg$f29(text) { return text.replace(/[\n\t]/g, ' ').trim(); }
403
+ function peg$f30(text) { return text.trim(); }
404
+ let peg$currPos = options.peg$currPos | 0;
405
+ let peg$savedPos = peg$currPos;
406
+ const peg$posDetailsCache = [{ line: 1, column: 1 }];
407
+ let peg$maxFailPos = peg$currPos;
408
+ let peg$maxFailExpected = options.peg$maxFailExpected || [];
409
+ let peg$silentFails = options.peg$silentFails | 0;
410
+ let peg$result;
411
+ if (options.startRule) {
412
+ if (!(options.startRule in peg$startRuleFunctions)) {
413
+ throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
414
+ }
415
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
416
+ }
417
+ function text() {
418
+ return input.substring(peg$savedPos, peg$currPos);
419
+ }
420
+ function offset() {
421
+ return peg$savedPos;
422
+ }
423
+ function range() {
424
+ return {
425
+ source: peg$source,
426
+ start: peg$savedPos,
427
+ end: peg$currPos,
428
+ };
429
+ }
430
+ function location() {
431
+ return peg$computeLocation(peg$savedPos, peg$currPos);
432
+ }
433
+ function expected(description, location) {
434
+ location = location !== undefined
435
+ ? location
436
+ : peg$computeLocation(peg$savedPos, peg$currPos);
437
+ throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location);
438
+ }
439
+ function error(message, location) {
440
+ location = location !== undefined
441
+ ? location
442
+ : peg$computeLocation(peg$savedPos, peg$currPos);
443
+ throw peg$buildSimpleError(message, location);
444
+ }
445
+ function peg$getUnicode(pos = peg$currPos) {
446
+ const cp = input.codePointAt(pos);
447
+ if (cp === undefined) {
448
+ return "";
449
+ }
450
+ return String.fromCodePoint(cp);
451
+ }
452
+ function peg$literalExpectation(text, ignoreCase) {
453
+ return { type: "literal", text, ignoreCase };
454
+ }
455
+ function peg$classExpectation(parts, inverted, ignoreCase, unicode) {
456
+ return { type: "class", parts, inverted, ignoreCase, unicode };
457
+ }
458
+ function peg$anyExpectation() {
459
+ return { type: "any" };
460
+ }
461
+ function peg$endExpectation() {
462
+ return { type: "end" };
463
+ }
464
+ function peg$otherExpectation(description) {
465
+ return { type: "other", description };
466
+ }
467
+ function peg$computePosDetails(pos) {
468
+ let details = peg$posDetailsCache[pos];
469
+ let p;
470
+ if (details) {
471
+ return details;
472
+ }
473
+ else {
474
+ if (pos >= peg$posDetailsCache.length) {
475
+ p = peg$posDetailsCache.length - 1;
476
+ }
477
+ else {
478
+ p = pos;
479
+ while (!peg$posDetailsCache[--p]) { }
480
+ }
481
+ details = peg$posDetailsCache[p];
482
+ details = {
483
+ line: details.line,
484
+ column: details.column,
485
+ };
486
+ while (p < pos) {
487
+ if (input.charCodeAt(p) === 10) {
488
+ details.line++;
489
+ details.column = 1;
490
+ }
491
+ else {
492
+ details.column++;
122
493
  }
494
+ p++;
495
+ }
496
+ peg$posDetailsCache[pos] = details;
497
+ return details;
498
+ }
499
+ }
500
+ function peg$computeLocation(startPos, endPos, offset) {
501
+ const startPosDetails = peg$computePosDetails(startPos);
502
+ const endPosDetails = peg$computePosDetails(endPos);
503
+ const res = {
504
+ source: peg$source,
505
+ start: {
506
+ offset: startPos,
507
+ line: startPosDetails.line,
508
+ column: startPosDetails.column,
123
509
  },
124
- { "name": "RAV$ebnf$1", "symbols": [(lexer.has("__") ? { type: "__" } : __)], "postprocess": id },
125
- { "name": "RAV$ebnf$1", "symbols": [], "postprocess": function (d) { return null; } },
126
- { "name": "RAV$ebnf$2", "symbols": [(lexer.has("__") ? { type: "__" } : __)], "postprocess": id },
127
- { "name": "RAV$ebnf$2", "symbols": [], "postprocess": function (d) { return null; } },
128
- { "name": "RAV", "symbols": [{ "literal": "(" }, "RAV$ebnf$1", "MOVES", "RAV$ebnf$2", { "literal": ")" }], "postprocess": (d) => d[2]
510
+ end: {
511
+ offset: endPos,
512
+ line: endPosDetails.line,
513
+ column: endPosDetails.column,
129
514
  },
130
- { "name": "NAG", "symbols": [(lexer.has("nag_import") ? { type: "nag_import" } : nag_import)], "postprocess": (d) => d[0].value },
131
- { "name": "NAG", "symbols": [(lexer.has("nag_export") ? { type: "nag_export" } : nag_export)], "postprocess": id },
132
- { "name": "COMMENT", "symbols": [(lexer.has("comment_line") ? { type: "comment_line" } : comment_line)] },
133
- { "name": "COMMENT", "symbols": [(lexer.has("comment_multiline") ? { type: "comment_multiline" } : comment_multiline)] }
134
- ],
135
- ParserStart: "DATABASE"
136
- };
137
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
138
- module.exports = grammar;
515
+ };
516
+ if (offset && peg$source && (typeof peg$source.offset === "function")) {
517
+ res.start = peg$source.offset(res.start);
518
+ res.end = peg$source.offset(res.end);
519
+ }
520
+ return res;
521
+ }
522
+ function peg$fail(expected) {
523
+ if (peg$currPos < peg$maxFailPos) {
524
+ return;
525
+ }
526
+ if (peg$currPos > peg$maxFailPos) {
527
+ peg$maxFailPos = peg$currPos;
528
+ peg$maxFailExpected = [];
529
+ }
530
+ peg$maxFailExpected.push(expected);
531
+ }
532
+ function peg$buildSimpleError(message, location) {
533
+ return new peg$SyntaxError(message, null, null, location);
534
+ }
535
+ function peg$buildStructuredError(expected, found, location) {
536
+ return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
537
+ }
538
+ function peg$parseDATABASE() {
539
+ let s0, s1, s2, s3, s4, s5, s6;
540
+ s0 = peg$currPos;
541
+ s1 = peg$parse_();
542
+ s2 = peg$parseGAME();
543
+ if (s2 !== peg$FAILED) {
544
+ s3 = [];
545
+ s4 = peg$currPos;
546
+ s5 = peg$parse_();
547
+ s6 = peg$parseGAME();
548
+ if (s6 !== peg$FAILED) {
549
+ peg$savedPos = s4;
550
+ s4 = peg$f0(s2, s6);
551
+ }
552
+ else {
553
+ peg$currPos = s4;
554
+ s4 = peg$FAILED;
555
+ }
556
+ while (s4 !== peg$FAILED) {
557
+ s3.push(s4);
558
+ s4 = peg$currPos;
559
+ s5 = peg$parse_();
560
+ s6 = peg$parseGAME();
561
+ if (s6 !== peg$FAILED) {
562
+ peg$savedPos = s4;
563
+ s4 = peg$f0(s2, s6);
564
+ }
565
+ else {
566
+ peg$currPos = s4;
567
+ s4 = peg$FAILED;
568
+ }
569
+ }
570
+ s4 = peg$parse_();
571
+ peg$savedPos = s0;
572
+ s0 = peg$f1(s2, s3);
573
+ }
574
+ else {
575
+ peg$currPos = s0;
576
+ s0 = peg$FAILED;
577
+ }
578
+ return s0;
579
+ }
580
+ function peg$parseGAME() {
581
+ let s0, s1, s2, s3, s4, s5;
582
+ s0 = peg$currPos;
583
+ s1 = peg$parseTAGS();
584
+ if (s1 !== peg$FAILED) {
585
+ s2 = peg$parse_();
586
+ s3 = peg$parseMOVES();
587
+ if (s3 !== peg$FAILED) {
588
+ s4 = peg$parse_();
589
+ s5 = peg$parseRESULT();
590
+ if (s5 !== peg$FAILED) {
591
+ peg$savedPos = s0;
592
+ s0 = peg$f2(s1, s3, s5);
593
+ }
594
+ else {
595
+ peg$currPos = s0;
596
+ s0 = peg$FAILED;
597
+ }
598
+ }
599
+ else {
600
+ peg$currPos = s0;
601
+ s0 = peg$FAILED;
602
+ }
603
+ }
604
+ else {
605
+ peg$currPos = s0;
606
+ s0 = peg$FAILED;
607
+ }
608
+ return s0;
609
+ }
610
+ function peg$parseTAGS() {
611
+ let s0, s1, s2, s3, s4, s5;
612
+ s0 = peg$currPos;
613
+ s1 = peg$parseTAG();
614
+ if (s1 !== peg$FAILED) {
615
+ s2 = [];
616
+ s3 = peg$currPos;
617
+ s4 = peg$parse_();
618
+ s5 = peg$parseTAG();
619
+ if (s5 !== peg$FAILED) {
620
+ peg$savedPos = s3;
621
+ s3 = peg$f3(s1, s5);
622
+ }
623
+ else {
624
+ peg$currPos = s3;
625
+ s3 = peg$FAILED;
626
+ }
627
+ while (s3 !== peg$FAILED) {
628
+ s2.push(s3);
629
+ s3 = peg$currPos;
630
+ s4 = peg$parse_();
631
+ s5 = peg$parseTAG();
632
+ if (s5 !== peg$FAILED) {
633
+ peg$savedPos = s3;
634
+ s3 = peg$f3(s1, s5);
635
+ }
636
+ else {
637
+ peg$currPos = s3;
638
+ s3 = peg$FAILED;
639
+ }
640
+ }
641
+ peg$savedPos = s0;
642
+ s0 = peg$f4(s1, s2);
643
+ }
644
+ else {
645
+ peg$currPos = s0;
646
+ s0 = peg$FAILED;
647
+ }
648
+ return s0;
649
+ }
650
+ function peg$parseTAG() {
651
+ let s0, s1, s2, s3, s4, s5, s6, s7;
652
+ s0 = peg$currPos;
653
+ if (input.charCodeAt(peg$currPos) === 91) {
654
+ s1 = peg$c0;
655
+ peg$currPos++;
656
+ }
657
+ else {
658
+ s1 = peg$FAILED;
659
+ if (peg$silentFails === 0) {
660
+ peg$fail(peg$e0);
661
+ }
662
+ }
663
+ if (s1 !== peg$FAILED) {
664
+ s2 = peg$parse_();
665
+ s3 = peg$parseIDENTIFIER();
666
+ if (s3 !== peg$FAILED) {
667
+ s4 = peg$parse_();
668
+ s5 = peg$parseSTRING();
669
+ if (s5 !== peg$FAILED) {
670
+ s6 = peg$parse_();
671
+ if (input.charCodeAt(peg$currPos) === 93) {
672
+ s7 = peg$c1;
673
+ peg$currPos++;
674
+ }
675
+ else {
676
+ s7 = peg$FAILED;
677
+ if (peg$silentFails === 0) {
678
+ peg$fail(peg$e1);
679
+ }
680
+ }
681
+ if (s7 !== peg$FAILED) {
682
+ peg$savedPos = s0;
683
+ s0 = peg$f5(s3, s5);
684
+ }
685
+ else {
686
+ peg$currPos = s0;
687
+ s0 = peg$FAILED;
688
+ }
689
+ }
690
+ else {
691
+ peg$currPos = s0;
692
+ s0 = peg$FAILED;
693
+ }
694
+ }
695
+ else {
696
+ peg$currPos = s0;
697
+ s0 = peg$FAILED;
698
+ }
699
+ }
700
+ else {
701
+ peg$currPos = s0;
702
+ s0 = peg$FAILED;
703
+ }
704
+ return s0;
705
+ }
706
+ function peg$parseIDENTIFIER() {
707
+ let s0, s1, s2;
708
+ s0 = peg$currPos;
709
+ s1 = [];
710
+ s2 = input.charAt(peg$currPos);
711
+ if (peg$r0.test(s2)) {
712
+ peg$currPos++;
713
+ }
714
+ else {
715
+ s2 = peg$FAILED;
716
+ if (peg$silentFails === 0) {
717
+ peg$fail(peg$e2);
718
+ }
719
+ }
720
+ if (s2 !== peg$FAILED) {
721
+ while (s2 !== peg$FAILED) {
722
+ s1.push(s2);
723
+ s2 = input.charAt(peg$currPos);
724
+ if (peg$r0.test(s2)) {
725
+ peg$currPos++;
726
+ }
727
+ else {
728
+ s2 = peg$FAILED;
729
+ if (peg$silentFails === 0) {
730
+ peg$fail(peg$e2);
731
+ }
732
+ }
733
+ }
734
+ }
735
+ else {
736
+ s1 = peg$FAILED;
737
+ }
738
+ if (s1 !== peg$FAILED) {
739
+ s0 = input.substring(s0, peg$currPos);
740
+ }
741
+ else {
742
+ s0 = s1;
743
+ }
744
+ return s0;
745
+ }
746
+ function peg$parseSTRING() {
747
+ let s0, s1, s2, s3, s4;
748
+ s0 = peg$currPos;
749
+ if (input.charCodeAt(peg$currPos) === 34) {
750
+ s1 = peg$c2;
751
+ peg$currPos++;
752
+ }
753
+ else {
754
+ s1 = peg$FAILED;
755
+ if (peg$silentFails === 0) {
756
+ peg$fail(peg$e3);
757
+ }
758
+ }
759
+ if (s1 !== peg$FAILED) {
760
+ s2 = peg$currPos;
761
+ s3 = [];
762
+ s4 = input.charAt(peg$currPos);
763
+ if (peg$r1.test(s4)) {
764
+ peg$currPos++;
765
+ }
766
+ else {
767
+ s4 = peg$FAILED;
768
+ if (peg$silentFails === 0) {
769
+ peg$fail(peg$e4);
770
+ }
771
+ }
772
+ while (s4 !== peg$FAILED) {
773
+ s3.push(s4);
774
+ s4 = input.charAt(peg$currPos);
775
+ if (peg$r1.test(s4)) {
776
+ peg$currPos++;
777
+ }
778
+ else {
779
+ s4 = peg$FAILED;
780
+ if (peg$silentFails === 0) {
781
+ peg$fail(peg$e4);
782
+ }
783
+ }
784
+ }
785
+ s2 = input.substring(s2, peg$currPos);
786
+ if (input.charCodeAt(peg$currPos) === 34) {
787
+ s3 = peg$c2;
788
+ peg$currPos++;
789
+ }
790
+ else {
791
+ s3 = peg$FAILED;
792
+ if (peg$silentFails === 0) {
793
+ peg$fail(peg$e3);
794
+ }
795
+ }
796
+ if (s3 !== peg$FAILED) {
797
+ peg$savedPos = s0;
798
+ s0 = peg$f6(s2);
799
+ }
800
+ else {
801
+ peg$currPos = s0;
802
+ s0 = peg$FAILED;
803
+ }
804
+ }
805
+ else {
806
+ peg$currPos = s0;
807
+ s0 = peg$FAILED;
808
+ }
809
+ return s0;
810
+ }
811
+ function peg$parseRESULT() {
812
+ let s0;
813
+ if (input.substr(peg$currPos, 7) === peg$c3) {
814
+ s0 = peg$c3;
815
+ peg$currPos += 7;
816
+ }
817
+ else {
818
+ s0 = peg$FAILED;
819
+ if (peg$silentFails === 0) {
820
+ peg$fail(peg$e5);
821
+ }
822
+ }
823
+ if (s0 === peg$FAILED) {
824
+ if (input.substr(peg$currPos, 3) === peg$c4) {
825
+ s0 = peg$c4;
826
+ peg$currPos += 3;
827
+ }
828
+ else {
829
+ s0 = peg$FAILED;
830
+ if (peg$silentFails === 0) {
831
+ peg$fail(peg$e6);
832
+ }
833
+ }
834
+ if (s0 === peg$FAILED) {
835
+ if (input.substr(peg$currPos, 3) === peg$c5) {
836
+ s0 = peg$c5;
837
+ peg$currPos += 3;
838
+ }
839
+ else {
840
+ s0 = peg$FAILED;
841
+ if (peg$silentFails === 0) {
842
+ peg$fail(peg$e7);
843
+ }
844
+ }
845
+ if (s0 === peg$FAILED) {
846
+ if (input.charCodeAt(peg$currPos) === 42) {
847
+ s0 = peg$c6;
848
+ peg$currPos++;
849
+ }
850
+ else {
851
+ s0 = peg$FAILED;
852
+ if (peg$silentFails === 0) {
853
+ peg$fail(peg$e8);
854
+ }
855
+ }
856
+ }
857
+ }
858
+ }
859
+ return s0;
860
+ }
861
+ function peg$parseMOVES() {
862
+ let s0, s1, s2, s3, s4, s5;
863
+ s0 = peg$currPos;
864
+ s1 = peg$parseMOVE();
865
+ if (s1 !== peg$FAILED) {
866
+ s2 = [];
867
+ s3 = peg$currPos;
868
+ s4 = peg$parse_();
869
+ s5 = peg$parseRAV();
870
+ if (s5 !== peg$FAILED) {
871
+ peg$savedPos = s3;
872
+ s3 = peg$f7(s1, s5);
873
+ }
874
+ else {
875
+ peg$currPos = s3;
876
+ s3 = peg$FAILED;
877
+ }
878
+ while (s3 !== peg$FAILED) {
879
+ s2.push(s3);
880
+ s3 = peg$currPos;
881
+ s4 = peg$parse_();
882
+ s5 = peg$parseRAV();
883
+ if (s5 !== peg$FAILED) {
884
+ peg$savedPos = s3;
885
+ s3 = peg$f7(s1, s5);
886
+ }
887
+ else {
888
+ peg$currPos = s3;
889
+ s3 = peg$FAILED;
890
+ }
891
+ }
892
+ s3 = peg$currPos;
893
+ s4 = peg$parse_();
894
+ s5 = peg$parseMOVES();
895
+ if (s5 !== peg$FAILED) {
896
+ peg$savedPos = s3;
897
+ s3 = peg$f8(s1, s2, s5);
898
+ }
899
+ else {
900
+ peg$currPos = s3;
901
+ s3 = peg$FAILED;
902
+ }
903
+ if (s3 === peg$FAILED) {
904
+ s3 = null;
905
+ }
906
+ peg$savedPos = s0;
907
+ s0 = peg$f9(s1, s2, s3);
908
+ }
909
+ else {
910
+ peg$currPos = s0;
911
+ s0 = peg$FAILED;
912
+ }
913
+ return s0;
914
+ }
915
+ function peg$parseMOVE() {
916
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8;
917
+ s0 = peg$currPos;
918
+ s1 = peg$parseNUMBER();
919
+ if (s1 === peg$FAILED) {
920
+ s1 = null;
921
+ }
922
+ s2 = peg$parse_();
923
+ s3 = peg$parseSAN();
924
+ if (s3 !== peg$FAILED) {
925
+ s4 = [];
926
+ s5 = peg$currPos;
927
+ s6 = peg$parse_();
928
+ s7 = peg$parseNAG();
929
+ if (s7 !== peg$FAILED) {
930
+ peg$savedPos = s5;
931
+ s5 = peg$f10(s1, s3, s7);
932
+ }
933
+ else {
934
+ peg$currPos = s5;
935
+ s5 = peg$FAILED;
936
+ }
937
+ while (s5 !== peg$FAILED) {
938
+ s4.push(s5);
939
+ s5 = peg$currPos;
940
+ s6 = peg$parse_();
941
+ s7 = peg$parseNAG();
942
+ if (s7 !== peg$FAILED) {
943
+ peg$savedPos = s5;
944
+ s5 = peg$f10(s1, s3, s7);
945
+ }
946
+ else {
947
+ peg$currPos = s5;
948
+ s5 = peg$FAILED;
949
+ }
950
+ }
951
+ s5 = [];
952
+ s6 = peg$currPos;
953
+ s7 = peg$parse_();
954
+ s8 = peg$parseCOMMENT();
955
+ if (s8 !== peg$FAILED) {
956
+ peg$savedPos = s6;
957
+ s6 = peg$f11(s1, s3, s4, s8);
958
+ }
959
+ else {
960
+ peg$currPos = s6;
961
+ s6 = peg$FAILED;
962
+ }
963
+ while (s6 !== peg$FAILED) {
964
+ s5.push(s6);
965
+ s6 = peg$currPos;
966
+ s7 = peg$parse_();
967
+ s8 = peg$parseCOMMENT();
968
+ if (s8 !== peg$FAILED) {
969
+ peg$savedPos = s6;
970
+ s6 = peg$f11(s1, s3, s4, s8);
971
+ }
972
+ else {
973
+ peg$currPos = s6;
974
+ s6 = peg$FAILED;
975
+ }
976
+ }
977
+ peg$savedPos = s0;
978
+ s0 = peg$f12(s1, s3, s4, s5);
979
+ }
980
+ else {
981
+ peg$currPos = s0;
982
+ s0 = peg$FAILED;
983
+ }
984
+ return s0;
985
+ }
986
+ function peg$parseNUMBER() {
987
+ let s0, s1, s2, s3, s4, s5;
988
+ s0 = peg$currPos;
989
+ s1 = peg$currPos;
990
+ s2 = peg$currPos;
991
+ s3 = [];
992
+ s4 = input.charAt(peg$currPos);
993
+ if (peg$r2.test(s4)) {
994
+ peg$currPos++;
995
+ }
996
+ else {
997
+ s4 = peg$FAILED;
998
+ if (peg$silentFails === 0) {
999
+ peg$fail(peg$e9);
1000
+ }
1001
+ }
1002
+ if (s4 !== peg$FAILED) {
1003
+ while (s4 !== peg$FAILED) {
1004
+ s3.push(s4);
1005
+ s4 = input.charAt(peg$currPos);
1006
+ if (peg$r2.test(s4)) {
1007
+ peg$currPos++;
1008
+ }
1009
+ else {
1010
+ s4 = peg$FAILED;
1011
+ if (peg$silentFails === 0) {
1012
+ peg$fail(peg$e9);
1013
+ }
1014
+ }
1015
+ }
1016
+ }
1017
+ else {
1018
+ s3 = peg$FAILED;
1019
+ }
1020
+ if (s3 !== peg$FAILED) {
1021
+ s4 = [];
1022
+ if (input.charCodeAt(peg$currPos) === 46) {
1023
+ s5 = peg$c7;
1024
+ peg$currPos++;
1025
+ }
1026
+ else {
1027
+ s5 = peg$FAILED;
1028
+ if (peg$silentFails === 0) {
1029
+ peg$fail(peg$e10);
1030
+ }
1031
+ }
1032
+ while (s5 !== peg$FAILED) {
1033
+ s4.push(s5);
1034
+ if (input.charCodeAt(peg$currPos) === 46) {
1035
+ s5 = peg$c7;
1036
+ peg$currPos++;
1037
+ }
1038
+ else {
1039
+ s5 = peg$FAILED;
1040
+ if (peg$silentFails === 0) {
1041
+ peg$fail(peg$e10);
1042
+ }
1043
+ }
1044
+ }
1045
+ s3 = [s3, s4];
1046
+ s2 = s3;
1047
+ }
1048
+ else {
1049
+ peg$currPos = s2;
1050
+ s2 = peg$FAILED;
1051
+ }
1052
+ if (s2 !== peg$FAILED) {
1053
+ s1 = input.substring(s1, peg$currPos);
1054
+ }
1055
+ else {
1056
+ s1 = s2;
1057
+ }
1058
+ if (s1 !== peg$FAILED) {
1059
+ peg$savedPos = s0;
1060
+ s1 = peg$f13(s1);
1061
+ }
1062
+ s0 = s1;
1063
+ return s0;
1064
+ }
1065
+ function peg$parseSAN() {
1066
+ let s0;
1067
+ s0 = peg$parseCASTLING();
1068
+ if (s0 === peg$FAILED) {
1069
+ s0 = peg$parsePIECE_MOVE();
1070
+ if (s0 === peg$FAILED) {
1071
+ s0 = peg$parsePAWN_CAPTURE();
1072
+ if (s0 === peg$FAILED) {
1073
+ s0 = peg$parsePAWN_PUSH();
1074
+ }
1075
+ }
1076
+ }
1077
+ return s0;
1078
+ }
1079
+ function peg$parseCASTLING() {
1080
+ let s0, s1, s2, s3;
1081
+ s0 = peg$currPos;
1082
+ if (input.substr(peg$currPos, 5) === peg$c8) {
1083
+ s1 = peg$c8;
1084
+ peg$currPos += 5;
1085
+ }
1086
+ else {
1087
+ s1 = peg$FAILED;
1088
+ if (peg$silentFails === 0) {
1089
+ peg$fail(peg$e11);
1090
+ }
1091
+ }
1092
+ if (s1 !== peg$FAILED) {
1093
+ s2 = peg$currPos;
1094
+ s3 = input.charAt(peg$currPos);
1095
+ if (peg$r3.test(s3)) {
1096
+ peg$currPos++;
1097
+ }
1098
+ else {
1099
+ s3 = peg$FAILED;
1100
+ if (peg$silentFails === 0) {
1101
+ peg$fail(peg$e12);
1102
+ }
1103
+ }
1104
+ if (s3 === peg$FAILED) {
1105
+ s3 = null;
1106
+ }
1107
+ s2 = input.substring(s2, peg$currPos);
1108
+ peg$savedPos = s0;
1109
+ s0 = peg$f14();
1110
+ }
1111
+ else {
1112
+ peg$currPos = s0;
1113
+ s0 = peg$FAILED;
1114
+ }
1115
+ if (s0 === peg$FAILED) {
1116
+ s0 = peg$currPos;
1117
+ if (input.substr(peg$currPos, 3) === peg$c9) {
1118
+ s1 = peg$c9;
1119
+ peg$currPos += 3;
1120
+ }
1121
+ else {
1122
+ s1 = peg$FAILED;
1123
+ if (peg$silentFails === 0) {
1124
+ peg$fail(peg$e13);
1125
+ }
1126
+ }
1127
+ if (s1 !== peg$FAILED) {
1128
+ s2 = peg$currPos;
1129
+ s3 = input.charAt(peg$currPos);
1130
+ if (peg$r3.test(s3)) {
1131
+ peg$currPos++;
1132
+ }
1133
+ else {
1134
+ s3 = peg$FAILED;
1135
+ if (peg$silentFails === 0) {
1136
+ peg$fail(peg$e12);
1137
+ }
1138
+ }
1139
+ if (s3 === peg$FAILED) {
1140
+ s3 = null;
1141
+ }
1142
+ s2 = input.substring(s2, peg$currPos);
1143
+ peg$savedPos = s0;
1144
+ s0 = peg$f15();
1145
+ }
1146
+ else {
1147
+ peg$currPos = s0;
1148
+ s0 = peg$FAILED;
1149
+ }
1150
+ }
1151
+ return s0;
1152
+ }
1153
+ function peg$parsePIECE_MOVE() {
1154
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
1155
+ s0 = peg$currPos;
1156
+ s1 = input.charAt(peg$currPos);
1157
+ if (peg$r4.test(s1)) {
1158
+ peg$currPos++;
1159
+ }
1160
+ else {
1161
+ s1 = peg$FAILED;
1162
+ if (peg$silentFails === 0) {
1163
+ peg$fail(peg$e14);
1164
+ }
1165
+ }
1166
+ if (s1 !== peg$FAILED) {
1167
+ s2 = input.charAt(peg$currPos);
1168
+ if (peg$r5.test(s2)) {
1169
+ peg$currPos++;
1170
+ }
1171
+ else {
1172
+ s2 = peg$FAILED;
1173
+ if (peg$silentFails === 0) {
1174
+ peg$fail(peg$e15);
1175
+ }
1176
+ }
1177
+ if (s2 !== peg$FAILED) {
1178
+ s3 = input.charAt(peg$currPos);
1179
+ if (peg$r6.test(s3)) {
1180
+ peg$currPos++;
1181
+ }
1182
+ else {
1183
+ s3 = peg$FAILED;
1184
+ if (peg$silentFails === 0) {
1185
+ peg$fail(peg$e16);
1186
+ }
1187
+ }
1188
+ if (s3 !== peg$FAILED) {
1189
+ if (input.charCodeAt(peg$currPos) === 120) {
1190
+ s4 = peg$c10;
1191
+ peg$currPos++;
1192
+ }
1193
+ else {
1194
+ s4 = peg$FAILED;
1195
+ if (peg$silentFails === 0) {
1196
+ peg$fail(peg$e17);
1197
+ }
1198
+ }
1199
+ if (s4 !== peg$FAILED) {
1200
+ s5 = input.charAt(peg$currPos);
1201
+ if (peg$r5.test(s5)) {
1202
+ peg$currPos++;
1203
+ }
1204
+ else {
1205
+ s5 = peg$FAILED;
1206
+ if (peg$silentFails === 0) {
1207
+ peg$fail(peg$e15);
1208
+ }
1209
+ }
1210
+ if (s5 !== peg$FAILED) {
1211
+ s6 = input.charAt(peg$currPos);
1212
+ if (peg$r6.test(s6)) {
1213
+ peg$currPos++;
1214
+ }
1215
+ else {
1216
+ s6 = peg$FAILED;
1217
+ if (peg$silentFails === 0) {
1218
+ peg$fail(peg$e16);
1219
+ }
1220
+ }
1221
+ if (s6 !== peg$FAILED) {
1222
+ s7 = peg$parsePROMO();
1223
+ if (s7 === peg$FAILED) {
1224
+ s7 = null;
1225
+ }
1226
+ s8 = peg$currPos;
1227
+ s9 = input.charAt(peg$currPos);
1228
+ if (peg$r3.test(s9)) {
1229
+ peg$currPos++;
1230
+ }
1231
+ else {
1232
+ s9 = peg$FAILED;
1233
+ if (peg$silentFails === 0) {
1234
+ peg$fail(peg$e12);
1235
+ }
1236
+ }
1237
+ if (s9 === peg$FAILED) {
1238
+ s9 = null;
1239
+ }
1240
+ s8 = input.substring(s8, peg$currPos);
1241
+ peg$savedPos = s0;
1242
+ s0 = peg$f16(s1, s2, s3, s5, s6, s7, s8);
1243
+ }
1244
+ else {
1245
+ peg$currPos = s0;
1246
+ s0 = peg$FAILED;
1247
+ }
1248
+ }
1249
+ else {
1250
+ peg$currPos = s0;
1251
+ s0 = peg$FAILED;
1252
+ }
1253
+ }
1254
+ else {
1255
+ peg$currPos = s0;
1256
+ s0 = peg$FAILED;
1257
+ }
1258
+ }
1259
+ else {
1260
+ peg$currPos = s0;
1261
+ s0 = peg$FAILED;
1262
+ }
1263
+ }
1264
+ else {
1265
+ peg$currPos = s0;
1266
+ s0 = peg$FAILED;
1267
+ }
1268
+ }
1269
+ else {
1270
+ peg$currPos = s0;
1271
+ s0 = peg$FAILED;
1272
+ }
1273
+ if (s0 === peg$FAILED) {
1274
+ s0 = peg$currPos;
1275
+ s1 = input.charAt(peg$currPos);
1276
+ if (peg$r4.test(s1)) {
1277
+ peg$currPos++;
1278
+ }
1279
+ else {
1280
+ s1 = peg$FAILED;
1281
+ if (peg$silentFails === 0) {
1282
+ peg$fail(peg$e14);
1283
+ }
1284
+ }
1285
+ if (s1 !== peg$FAILED) {
1286
+ s2 = input.charAt(peg$currPos);
1287
+ if (peg$r5.test(s2)) {
1288
+ peg$currPos++;
1289
+ }
1290
+ else {
1291
+ s2 = peg$FAILED;
1292
+ if (peg$silentFails === 0) {
1293
+ peg$fail(peg$e15);
1294
+ }
1295
+ }
1296
+ if (s2 !== peg$FAILED) {
1297
+ s3 = input.charAt(peg$currPos);
1298
+ if (peg$r6.test(s3)) {
1299
+ peg$currPos++;
1300
+ }
1301
+ else {
1302
+ s3 = peg$FAILED;
1303
+ if (peg$silentFails === 0) {
1304
+ peg$fail(peg$e16);
1305
+ }
1306
+ }
1307
+ if (s3 !== peg$FAILED) {
1308
+ s4 = input.charAt(peg$currPos);
1309
+ if (peg$r5.test(s4)) {
1310
+ peg$currPos++;
1311
+ }
1312
+ else {
1313
+ s4 = peg$FAILED;
1314
+ if (peg$silentFails === 0) {
1315
+ peg$fail(peg$e15);
1316
+ }
1317
+ }
1318
+ if (s4 !== peg$FAILED) {
1319
+ s5 = input.charAt(peg$currPos);
1320
+ if (peg$r6.test(s5)) {
1321
+ peg$currPos++;
1322
+ }
1323
+ else {
1324
+ s5 = peg$FAILED;
1325
+ if (peg$silentFails === 0) {
1326
+ peg$fail(peg$e16);
1327
+ }
1328
+ }
1329
+ if (s5 !== peg$FAILED) {
1330
+ s6 = peg$parsePROMO();
1331
+ if (s6 === peg$FAILED) {
1332
+ s6 = null;
1333
+ }
1334
+ s7 = peg$currPos;
1335
+ s8 = input.charAt(peg$currPos);
1336
+ if (peg$r3.test(s8)) {
1337
+ peg$currPos++;
1338
+ }
1339
+ else {
1340
+ s8 = peg$FAILED;
1341
+ if (peg$silentFails === 0) {
1342
+ peg$fail(peg$e12);
1343
+ }
1344
+ }
1345
+ if (s8 === peg$FAILED) {
1346
+ s8 = null;
1347
+ }
1348
+ s7 = input.substring(s7, peg$currPos);
1349
+ peg$savedPos = s0;
1350
+ s0 = peg$f17(s1, s2, s3, s4, s5, s6, s7);
1351
+ }
1352
+ else {
1353
+ peg$currPos = s0;
1354
+ s0 = peg$FAILED;
1355
+ }
1356
+ }
1357
+ else {
1358
+ peg$currPos = s0;
1359
+ s0 = peg$FAILED;
1360
+ }
1361
+ }
1362
+ else {
1363
+ peg$currPos = s0;
1364
+ s0 = peg$FAILED;
1365
+ }
1366
+ }
1367
+ else {
1368
+ peg$currPos = s0;
1369
+ s0 = peg$FAILED;
1370
+ }
1371
+ }
1372
+ else {
1373
+ peg$currPos = s0;
1374
+ s0 = peg$FAILED;
1375
+ }
1376
+ if (s0 === peg$FAILED) {
1377
+ s0 = peg$currPos;
1378
+ s1 = input.charAt(peg$currPos);
1379
+ if (peg$r4.test(s1)) {
1380
+ peg$currPos++;
1381
+ }
1382
+ else {
1383
+ s1 = peg$FAILED;
1384
+ if (peg$silentFails === 0) {
1385
+ peg$fail(peg$e14);
1386
+ }
1387
+ }
1388
+ if (s1 !== peg$FAILED) {
1389
+ s2 = input.charAt(peg$currPos);
1390
+ if (peg$r5.test(s2)) {
1391
+ peg$currPos++;
1392
+ }
1393
+ else {
1394
+ s2 = peg$FAILED;
1395
+ if (peg$silentFails === 0) {
1396
+ peg$fail(peg$e15);
1397
+ }
1398
+ }
1399
+ if (s2 !== peg$FAILED) {
1400
+ if (input.charCodeAt(peg$currPos) === 120) {
1401
+ s3 = peg$c10;
1402
+ peg$currPos++;
1403
+ }
1404
+ else {
1405
+ s3 = peg$FAILED;
1406
+ if (peg$silentFails === 0) {
1407
+ peg$fail(peg$e17);
1408
+ }
1409
+ }
1410
+ if (s3 !== peg$FAILED) {
1411
+ s4 = input.charAt(peg$currPos);
1412
+ if (peg$r5.test(s4)) {
1413
+ peg$currPos++;
1414
+ }
1415
+ else {
1416
+ s4 = peg$FAILED;
1417
+ if (peg$silentFails === 0) {
1418
+ peg$fail(peg$e15);
1419
+ }
1420
+ }
1421
+ if (s4 !== peg$FAILED) {
1422
+ s5 = input.charAt(peg$currPos);
1423
+ if (peg$r6.test(s5)) {
1424
+ peg$currPos++;
1425
+ }
1426
+ else {
1427
+ s5 = peg$FAILED;
1428
+ if (peg$silentFails === 0) {
1429
+ peg$fail(peg$e16);
1430
+ }
1431
+ }
1432
+ if (s5 !== peg$FAILED) {
1433
+ s6 = peg$parsePROMO();
1434
+ if (s6 === peg$FAILED) {
1435
+ s6 = null;
1436
+ }
1437
+ s7 = peg$currPos;
1438
+ s8 = input.charAt(peg$currPos);
1439
+ if (peg$r3.test(s8)) {
1440
+ peg$currPos++;
1441
+ }
1442
+ else {
1443
+ s8 = peg$FAILED;
1444
+ if (peg$silentFails === 0) {
1445
+ peg$fail(peg$e12);
1446
+ }
1447
+ }
1448
+ if (s8 === peg$FAILED) {
1449
+ s8 = null;
1450
+ }
1451
+ s7 = input.substring(s7, peg$currPos);
1452
+ peg$savedPos = s0;
1453
+ s0 = peg$f18(s1, s2, s4, s5, s6, s7);
1454
+ }
1455
+ else {
1456
+ peg$currPos = s0;
1457
+ s0 = peg$FAILED;
1458
+ }
1459
+ }
1460
+ else {
1461
+ peg$currPos = s0;
1462
+ s0 = peg$FAILED;
1463
+ }
1464
+ }
1465
+ else {
1466
+ peg$currPos = s0;
1467
+ s0 = peg$FAILED;
1468
+ }
1469
+ }
1470
+ else {
1471
+ peg$currPos = s0;
1472
+ s0 = peg$FAILED;
1473
+ }
1474
+ }
1475
+ else {
1476
+ peg$currPos = s0;
1477
+ s0 = peg$FAILED;
1478
+ }
1479
+ if (s0 === peg$FAILED) {
1480
+ s0 = peg$currPos;
1481
+ s1 = input.charAt(peg$currPos);
1482
+ if (peg$r4.test(s1)) {
1483
+ peg$currPos++;
1484
+ }
1485
+ else {
1486
+ s1 = peg$FAILED;
1487
+ if (peg$silentFails === 0) {
1488
+ peg$fail(peg$e14);
1489
+ }
1490
+ }
1491
+ if (s1 !== peg$FAILED) {
1492
+ s2 = input.charAt(peg$currPos);
1493
+ if (peg$r6.test(s2)) {
1494
+ peg$currPos++;
1495
+ }
1496
+ else {
1497
+ s2 = peg$FAILED;
1498
+ if (peg$silentFails === 0) {
1499
+ peg$fail(peg$e16);
1500
+ }
1501
+ }
1502
+ if (s2 !== peg$FAILED) {
1503
+ if (input.charCodeAt(peg$currPos) === 120) {
1504
+ s3 = peg$c10;
1505
+ peg$currPos++;
1506
+ }
1507
+ else {
1508
+ s3 = peg$FAILED;
1509
+ if (peg$silentFails === 0) {
1510
+ peg$fail(peg$e17);
1511
+ }
1512
+ }
1513
+ if (s3 !== peg$FAILED) {
1514
+ s4 = input.charAt(peg$currPos);
1515
+ if (peg$r5.test(s4)) {
1516
+ peg$currPos++;
1517
+ }
1518
+ else {
1519
+ s4 = peg$FAILED;
1520
+ if (peg$silentFails === 0) {
1521
+ peg$fail(peg$e15);
1522
+ }
1523
+ }
1524
+ if (s4 !== peg$FAILED) {
1525
+ s5 = input.charAt(peg$currPos);
1526
+ if (peg$r6.test(s5)) {
1527
+ peg$currPos++;
1528
+ }
1529
+ else {
1530
+ s5 = peg$FAILED;
1531
+ if (peg$silentFails === 0) {
1532
+ peg$fail(peg$e16);
1533
+ }
1534
+ }
1535
+ if (s5 !== peg$FAILED) {
1536
+ s6 = peg$parsePROMO();
1537
+ if (s6 === peg$FAILED) {
1538
+ s6 = null;
1539
+ }
1540
+ s7 = peg$currPos;
1541
+ s8 = input.charAt(peg$currPos);
1542
+ if (peg$r3.test(s8)) {
1543
+ peg$currPos++;
1544
+ }
1545
+ else {
1546
+ s8 = peg$FAILED;
1547
+ if (peg$silentFails === 0) {
1548
+ peg$fail(peg$e12);
1549
+ }
1550
+ }
1551
+ if (s8 === peg$FAILED) {
1552
+ s8 = null;
1553
+ }
1554
+ s7 = input.substring(s7, peg$currPos);
1555
+ peg$savedPos = s0;
1556
+ s0 = peg$f19(s1, s2, s4, s5, s6, s7);
1557
+ }
1558
+ else {
1559
+ peg$currPos = s0;
1560
+ s0 = peg$FAILED;
1561
+ }
1562
+ }
1563
+ else {
1564
+ peg$currPos = s0;
1565
+ s0 = peg$FAILED;
1566
+ }
1567
+ }
1568
+ else {
1569
+ peg$currPos = s0;
1570
+ s0 = peg$FAILED;
1571
+ }
1572
+ }
1573
+ else {
1574
+ peg$currPos = s0;
1575
+ s0 = peg$FAILED;
1576
+ }
1577
+ }
1578
+ else {
1579
+ peg$currPos = s0;
1580
+ s0 = peg$FAILED;
1581
+ }
1582
+ if (s0 === peg$FAILED) {
1583
+ s0 = peg$currPos;
1584
+ s1 = input.charAt(peg$currPos);
1585
+ if (peg$r4.test(s1)) {
1586
+ peg$currPos++;
1587
+ }
1588
+ else {
1589
+ s1 = peg$FAILED;
1590
+ if (peg$silentFails === 0) {
1591
+ peg$fail(peg$e14);
1592
+ }
1593
+ }
1594
+ if (s1 !== peg$FAILED) {
1595
+ s2 = input.charAt(peg$currPos);
1596
+ if (peg$r5.test(s2)) {
1597
+ peg$currPos++;
1598
+ }
1599
+ else {
1600
+ s2 = peg$FAILED;
1601
+ if (peg$silentFails === 0) {
1602
+ peg$fail(peg$e15);
1603
+ }
1604
+ }
1605
+ if (s2 !== peg$FAILED) {
1606
+ s3 = input.charAt(peg$currPos);
1607
+ if (peg$r5.test(s3)) {
1608
+ peg$currPos++;
1609
+ }
1610
+ else {
1611
+ s3 = peg$FAILED;
1612
+ if (peg$silentFails === 0) {
1613
+ peg$fail(peg$e15);
1614
+ }
1615
+ }
1616
+ if (s3 !== peg$FAILED) {
1617
+ s4 = input.charAt(peg$currPos);
1618
+ if (peg$r6.test(s4)) {
1619
+ peg$currPos++;
1620
+ }
1621
+ else {
1622
+ s4 = peg$FAILED;
1623
+ if (peg$silentFails === 0) {
1624
+ peg$fail(peg$e16);
1625
+ }
1626
+ }
1627
+ if (s4 !== peg$FAILED) {
1628
+ s5 = peg$parsePROMO();
1629
+ if (s5 === peg$FAILED) {
1630
+ s5 = null;
1631
+ }
1632
+ s6 = peg$currPos;
1633
+ s7 = input.charAt(peg$currPos);
1634
+ if (peg$r3.test(s7)) {
1635
+ peg$currPos++;
1636
+ }
1637
+ else {
1638
+ s7 = peg$FAILED;
1639
+ if (peg$silentFails === 0) {
1640
+ peg$fail(peg$e12);
1641
+ }
1642
+ }
1643
+ if (s7 === peg$FAILED) {
1644
+ s7 = null;
1645
+ }
1646
+ s6 = input.substring(s6, peg$currPos);
1647
+ peg$savedPos = s0;
1648
+ s0 = peg$f20(s1, s2, s3, s4, s5, s6);
1649
+ }
1650
+ else {
1651
+ peg$currPos = s0;
1652
+ s0 = peg$FAILED;
1653
+ }
1654
+ }
1655
+ else {
1656
+ peg$currPos = s0;
1657
+ s0 = peg$FAILED;
1658
+ }
1659
+ }
1660
+ else {
1661
+ peg$currPos = s0;
1662
+ s0 = peg$FAILED;
1663
+ }
1664
+ }
1665
+ else {
1666
+ peg$currPos = s0;
1667
+ s0 = peg$FAILED;
1668
+ }
1669
+ if (s0 === peg$FAILED) {
1670
+ s0 = peg$currPos;
1671
+ s1 = input.charAt(peg$currPos);
1672
+ if (peg$r4.test(s1)) {
1673
+ peg$currPos++;
1674
+ }
1675
+ else {
1676
+ s1 = peg$FAILED;
1677
+ if (peg$silentFails === 0) {
1678
+ peg$fail(peg$e14);
1679
+ }
1680
+ }
1681
+ if (s1 !== peg$FAILED) {
1682
+ s2 = input.charAt(peg$currPos);
1683
+ if (peg$r6.test(s2)) {
1684
+ peg$currPos++;
1685
+ }
1686
+ else {
1687
+ s2 = peg$FAILED;
1688
+ if (peg$silentFails === 0) {
1689
+ peg$fail(peg$e16);
1690
+ }
1691
+ }
1692
+ if (s2 !== peg$FAILED) {
1693
+ s3 = input.charAt(peg$currPos);
1694
+ if (peg$r5.test(s3)) {
1695
+ peg$currPos++;
1696
+ }
1697
+ else {
1698
+ s3 = peg$FAILED;
1699
+ if (peg$silentFails === 0) {
1700
+ peg$fail(peg$e15);
1701
+ }
1702
+ }
1703
+ if (s3 !== peg$FAILED) {
1704
+ s4 = input.charAt(peg$currPos);
1705
+ if (peg$r6.test(s4)) {
1706
+ peg$currPos++;
1707
+ }
1708
+ else {
1709
+ s4 = peg$FAILED;
1710
+ if (peg$silentFails === 0) {
1711
+ peg$fail(peg$e16);
1712
+ }
1713
+ }
1714
+ if (s4 !== peg$FAILED) {
1715
+ s5 = peg$parsePROMO();
1716
+ if (s5 === peg$FAILED) {
1717
+ s5 = null;
1718
+ }
1719
+ s6 = peg$currPos;
1720
+ s7 = input.charAt(peg$currPos);
1721
+ if (peg$r3.test(s7)) {
1722
+ peg$currPos++;
1723
+ }
1724
+ else {
1725
+ s7 = peg$FAILED;
1726
+ if (peg$silentFails === 0) {
1727
+ peg$fail(peg$e12);
1728
+ }
1729
+ }
1730
+ if (s7 === peg$FAILED) {
1731
+ s7 = null;
1732
+ }
1733
+ s6 = input.substring(s6, peg$currPos);
1734
+ peg$savedPos = s0;
1735
+ s0 = peg$f21(s1, s2, s3, s4, s5, s6);
1736
+ }
1737
+ else {
1738
+ peg$currPos = s0;
1739
+ s0 = peg$FAILED;
1740
+ }
1741
+ }
1742
+ else {
1743
+ peg$currPos = s0;
1744
+ s0 = peg$FAILED;
1745
+ }
1746
+ }
1747
+ else {
1748
+ peg$currPos = s0;
1749
+ s0 = peg$FAILED;
1750
+ }
1751
+ }
1752
+ else {
1753
+ peg$currPos = s0;
1754
+ s0 = peg$FAILED;
1755
+ }
1756
+ if (s0 === peg$FAILED) {
1757
+ s0 = peg$currPos;
1758
+ s1 = input.charAt(peg$currPos);
1759
+ if (peg$r4.test(s1)) {
1760
+ peg$currPos++;
1761
+ }
1762
+ else {
1763
+ s1 = peg$FAILED;
1764
+ if (peg$silentFails === 0) {
1765
+ peg$fail(peg$e14);
1766
+ }
1767
+ }
1768
+ if (s1 !== peg$FAILED) {
1769
+ if (input.charCodeAt(peg$currPos) === 120) {
1770
+ s2 = peg$c10;
1771
+ peg$currPos++;
1772
+ }
1773
+ else {
1774
+ s2 = peg$FAILED;
1775
+ if (peg$silentFails === 0) {
1776
+ peg$fail(peg$e17);
1777
+ }
1778
+ }
1779
+ if (s2 !== peg$FAILED) {
1780
+ s3 = input.charAt(peg$currPos);
1781
+ if (peg$r5.test(s3)) {
1782
+ peg$currPos++;
1783
+ }
1784
+ else {
1785
+ s3 = peg$FAILED;
1786
+ if (peg$silentFails === 0) {
1787
+ peg$fail(peg$e15);
1788
+ }
1789
+ }
1790
+ if (s3 !== peg$FAILED) {
1791
+ s4 = input.charAt(peg$currPos);
1792
+ if (peg$r6.test(s4)) {
1793
+ peg$currPos++;
1794
+ }
1795
+ else {
1796
+ s4 = peg$FAILED;
1797
+ if (peg$silentFails === 0) {
1798
+ peg$fail(peg$e16);
1799
+ }
1800
+ }
1801
+ if (s4 !== peg$FAILED) {
1802
+ s5 = peg$parsePROMO();
1803
+ if (s5 === peg$FAILED) {
1804
+ s5 = null;
1805
+ }
1806
+ s6 = peg$currPos;
1807
+ s7 = input.charAt(peg$currPos);
1808
+ if (peg$r3.test(s7)) {
1809
+ peg$currPos++;
1810
+ }
1811
+ else {
1812
+ s7 = peg$FAILED;
1813
+ if (peg$silentFails === 0) {
1814
+ peg$fail(peg$e12);
1815
+ }
1816
+ }
1817
+ if (s7 === peg$FAILED) {
1818
+ s7 = null;
1819
+ }
1820
+ s6 = input.substring(s6, peg$currPos);
1821
+ peg$savedPos = s0;
1822
+ s0 = peg$f22(s1, s3, s4, s5, s6);
1823
+ }
1824
+ else {
1825
+ peg$currPos = s0;
1826
+ s0 = peg$FAILED;
1827
+ }
1828
+ }
1829
+ else {
1830
+ peg$currPos = s0;
1831
+ s0 = peg$FAILED;
1832
+ }
1833
+ }
1834
+ else {
1835
+ peg$currPos = s0;
1836
+ s0 = peg$FAILED;
1837
+ }
1838
+ }
1839
+ else {
1840
+ peg$currPos = s0;
1841
+ s0 = peg$FAILED;
1842
+ }
1843
+ if (s0 === peg$FAILED) {
1844
+ s0 = peg$currPos;
1845
+ s1 = input.charAt(peg$currPos);
1846
+ if (peg$r4.test(s1)) {
1847
+ peg$currPos++;
1848
+ }
1849
+ else {
1850
+ s1 = peg$FAILED;
1851
+ if (peg$silentFails === 0) {
1852
+ peg$fail(peg$e14);
1853
+ }
1854
+ }
1855
+ if (s1 !== peg$FAILED) {
1856
+ s2 = input.charAt(peg$currPos);
1857
+ if (peg$r5.test(s2)) {
1858
+ peg$currPos++;
1859
+ }
1860
+ else {
1861
+ s2 = peg$FAILED;
1862
+ if (peg$silentFails === 0) {
1863
+ peg$fail(peg$e15);
1864
+ }
1865
+ }
1866
+ if (s2 !== peg$FAILED) {
1867
+ s3 = input.charAt(peg$currPos);
1868
+ if (peg$r6.test(s3)) {
1869
+ peg$currPos++;
1870
+ }
1871
+ else {
1872
+ s3 = peg$FAILED;
1873
+ if (peg$silentFails === 0) {
1874
+ peg$fail(peg$e16);
1875
+ }
1876
+ }
1877
+ if (s3 !== peg$FAILED) {
1878
+ s4 = peg$parsePROMO();
1879
+ if (s4 === peg$FAILED) {
1880
+ s4 = null;
1881
+ }
1882
+ s5 = peg$currPos;
1883
+ s6 = input.charAt(peg$currPos);
1884
+ if (peg$r3.test(s6)) {
1885
+ peg$currPos++;
1886
+ }
1887
+ else {
1888
+ s6 = peg$FAILED;
1889
+ if (peg$silentFails === 0) {
1890
+ peg$fail(peg$e12);
1891
+ }
1892
+ }
1893
+ if (s6 === peg$FAILED) {
1894
+ s6 = null;
1895
+ }
1896
+ s5 = input.substring(s5, peg$currPos);
1897
+ peg$savedPos = s0;
1898
+ s0 = peg$f23(s1, s2, s3, s4, s5);
1899
+ }
1900
+ else {
1901
+ peg$currPos = s0;
1902
+ s0 = peg$FAILED;
1903
+ }
1904
+ }
1905
+ else {
1906
+ peg$currPos = s0;
1907
+ s0 = peg$FAILED;
1908
+ }
1909
+ }
1910
+ else {
1911
+ peg$currPos = s0;
1912
+ s0 = peg$FAILED;
1913
+ }
1914
+ }
1915
+ }
1916
+ }
1917
+ }
1918
+ }
1919
+ }
1920
+ }
1921
+ return s0;
1922
+ }
1923
+ function peg$parsePAWN_CAPTURE() {
1924
+ let s0, s1, s2, s3, s4, s5, s6, s7;
1925
+ s0 = peg$currPos;
1926
+ s1 = input.charAt(peg$currPos);
1927
+ if (peg$r5.test(s1)) {
1928
+ peg$currPos++;
1929
+ }
1930
+ else {
1931
+ s1 = peg$FAILED;
1932
+ if (peg$silentFails === 0) {
1933
+ peg$fail(peg$e15);
1934
+ }
1935
+ }
1936
+ if (s1 !== peg$FAILED) {
1937
+ if (input.charCodeAt(peg$currPos) === 120) {
1938
+ s2 = peg$c10;
1939
+ peg$currPos++;
1940
+ }
1941
+ else {
1942
+ s2 = peg$FAILED;
1943
+ if (peg$silentFails === 0) {
1944
+ peg$fail(peg$e17);
1945
+ }
1946
+ }
1947
+ if (s2 !== peg$FAILED) {
1948
+ s3 = input.charAt(peg$currPos);
1949
+ if (peg$r5.test(s3)) {
1950
+ peg$currPos++;
1951
+ }
1952
+ else {
1953
+ s3 = peg$FAILED;
1954
+ if (peg$silentFails === 0) {
1955
+ peg$fail(peg$e15);
1956
+ }
1957
+ }
1958
+ if (s3 !== peg$FAILED) {
1959
+ s4 = input.charAt(peg$currPos);
1960
+ if (peg$r6.test(s4)) {
1961
+ peg$currPos++;
1962
+ }
1963
+ else {
1964
+ s4 = peg$FAILED;
1965
+ if (peg$silentFails === 0) {
1966
+ peg$fail(peg$e16);
1967
+ }
1968
+ }
1969
+ if (s4 !== peg$FAILED) {
1970
+ s5 = peg$parsePROMO();
1971
+ if (s5 === peg$FAILED) {
1972
+ s5 = null;
1973
+ }
1974
+ s6 = peg$currPos;
1975
+ s7 = input.charAt(peg$currPos);
1976
+ if (peg$r3.test(s7)) {
1977
+ peg$currPos++;
1978
+ }
1979
+ else {
1980
+ s7 = peg$FAILED;
1981
+ if (peg$silentFails === 0) {
1982
+ peg$fail(peg$e12);
1983
+ }
1984
+ }
1985
+ if (s7 === peg$FAILED) {
1986
+ s7 = null;
1987
+ }
1988
+ s6 = input.substring(s6, peg$currPos);
1989
+ peg$savedPos = s0;
1990
+ s0 = peg$f24(s1, s3, s4, s5, s6);
1991
+ }
1992
+ else {
1993
+ peg$currPos = s0;
1994
+ s0 = peg$FAILED;
1995
+ }
1996
+ }
1997
+ else {
1998
+ peg$currPos = s0;
1999
+ s0 = peg$FAILED;
2000
+ }
2001
+ }
2002
+ else {
2003
+ peg$currPos = s0;
2004
+ s0 = peg$FAILED;
2005
+ }
2006
+ }
2007
+ else {
2008
+ peg$currPos = s0;
2009
+ s0 = peg$FAILED;
2010
+ }
2011
+ return s0;
2012
+ }
2013
+ function peg$parsePAWN_PUSH() {
2014
+ let s0, s1, s2, s3, s4, s5;
2015
+ s0 = peg$currPos;
2016
+ s1 = input.charAt(peg$currPos);
2017
+ if (peg$r5.test(s1)) {
2018
+ peg$currPos++;
2019
+ }
2020
+ else {
2021
+ s1 = peg$FAILED;
2022
+ if (peg$silentFails === 0) {
2023
+ peg$fail(peg$e15);
2024
+ }
2025
+ }
2026
+ if (s1 !== peg$FAILED) {
2027
+ s2 = input.charAt(peg$currPos);
2028
+ if (peg$r6.test(s2)) {
2029
+ peg$currPos++;
2030
+ }
2031
+ else {
2032
+ s2 = peg$FAILED;
2033
+ if (peg$silentFails === 0) {
2034
+ peg$fail(peg$e16);
2035
+ }
2036
+ }
2037
+ if (s2 !== peg$FAILED) {
2038
+ s3 = peg$parsePROMO();
2039
+ if (s3 === peg$FAILED) {
2040
+ s3 = null;
2041
+ }
2042
+ s4 = peg$currPos;
2043
+ s5 = input.charAt(peg$currPos);
2044
+ if (peg$r3.test(s5)) {
2045
+ peg$currPos++;
2046
+ }
2047
+ else {
2048
+ s5 = peg$FAILED;
2049
+ if (peg$silentFails === 0) {
2050
+ peg$fail(peg$e12);
2051
+ }
2052
+ }
2053
+ if (s5 === peg$FAILED) {
2054
+ s5 = null;
2055
+ }
2056
+ s4 = input.substring(s4, peg$currPos);
2057
+ peg$savedPos = s0;
2058
+ s0 = peg$f25(s1, s2, s3, s4);
2059
+ }
2060
+ else {
2061
+ peg$currPos = s0;
2062
+ s0 = peg$FAILED;
2063
+ }
2064
+ }
2065
+ else {
2066
+ peg$currPos = s0;
2067
+ s0 = peg$FAILED;
2068
+ }
2069
+ return s0;
2070
+ }
2071
+ function peg$parsePROMO() {
2072
+ let s0, s1, s2;
2073
+ s0 = peg$currPos;
2074
+ if (input.charCodeAt(peg$currPos) === 61) {
2075
+ s1 = peg$c11;
2076
+ peg$currPos++;
2077
+ }
2078
+ else {
2079
+ s1 = peg$FAILED;
2080
+ if (peg$silentFails === 0) {
2081
+ peg$fail(peg$e18);
2082
+ }
2083
+ }
2084
+ if (s1 !== peg$FAILED) {
2085
+ s2 = input.charAt(peg$currPos);
2086
+ if (peg$r7.test(s2)) {
2087
+ peg$currPos++;
2088
+ }
2089
+ else {
2090
+ s2 = peg$FAILED;
2091
+ if (peg$silentFails === 0) {
2092
+ peg$fail(peg$e19);
2093
+ }
2094
+ }
2095
+ if (s2 !== peg$FAILED) {
2096
+ peg$savedPos = s0;
2097
+ s0 = peg$f26(s2);
2098
+ }
2099
+ else {
2100
+ peg$currPos = s0;
2101
+ s0 = peg$FAILED;
2102
+ }
2103
+ }
2104
+ else {
2105
+ peg$currPos = s0;
2106
+ s0 = peg$FAILED;
2107
+ }
2108
+ return s0;
2109
+ }
2110
+ function peg$parseRAV() {
2111
+ let s0, s1, s2, s3, s4, s5;
2112
+ s0 = peg$currPos;
2113
+ if (input.charCodeAt(peg$currPos) === 40) {
2114
+ s1 = peg$c12;
2115
+ peg$currPos++;
2116
+ }
2117
+ else {
2118
+ s1 = peg$FAILED;
2119
+ if (peg$silentFails === 0) {
2120
+ peg$fail(peg$e20);
2121
+ }
2122
+ }
2123
+ if (s1 !== peg$FAILED) {
2124
+ s2 = peg$parse_();
2125
+ s3 = peg$parseMOVES();
2126
+ if (s3 !== peg$FAILED) {
2127
+ s4 = peg$parse_();
2128
+ if (input.charCodeAt(peg$currPos) === 41) {
2129
+ s5 = peg$c13;
2130
+ peg$currPos++;
2131
+ }
2132
+ else {
2133
+ s5 = peg$FAILED;
2134
+ if (peg$silentFails === 0) {
2135
+ peg$fail(peg$e21);
2136
+ }
2137
+ }
2138
+ if (s5 !== peg$FAILED) {
2139
+ peg$savedPos = s0;
2140
+ s0 = peg$f27(s3);
2141
+ }
2142
+ else {
2143
+ peg$currPos = s0;
2144
+ s0 = peg$FAILED;
2145
+ }
2146
+ }
2147
+ else {
2148
+ peg$currPos = s0;
2149
+ s0 = peg$FAILED;
2150
+ }
2151
+ }
2152
+ else {
2153
+ peg$currPos = s0;
2154
+ s0 = peg$FAILED;
2155
+ }
2156
+ return s0;
2157
+ }
2158
+ function peg$parseNAG() {
2159
+ let s0;
2160
+ s0 = peg$parsenag_export();
2161
+ if (s0 === peg$FAILED) {
2162
+ s0 = peg$parsenag_import();
2163
+ }
2164
+ return s0;
2165
+ }
2166
+ function peg$parsenag_export() {
2167
+ let s0, s1, s2, s3, s4;
2168
+ s0 = peg$currPos;
2169
+ if (input.charCodeAt(peg$currPos) === 36) {
2170
+ s1 = peg$c14;
2171
+ peg$currPos++;
2172
+ }
2173
+ else {
2174
+ s1 = peg$FAILED;
2175
+ if (peg$silentFails === 0) {
2176
+ peg$fail(peg$e22);
2177
+ }
2178
+ }
2179
+ if (s1 !== peg$FAILED) {
2180
+ s2 = peg$currPos;
2181
+ s3 = [];
2182
+ s4 = input.charAt(peg$currPos);
2183
+ if (peg$r2.test(s4)) {
2184
+ peg$currPos++;
2185
+ }
2186
+ else {
2187
+ s4 = peg$FAILED;
2188
+ if (peg$silentFails === 0) {
2189
+ peg$fail(peg$e9);
2190
+ }
2191
+ }
2192
+ if (s4 !== peg$FAILED) {
2193
+ while (s4 !== peg$FAILED) {
2194
+ s3.push(s4);
2195
+ s4 = input.charAt(peg$currPos);
2196
+ if (peg$r2.test(s4)) {
2197
+ peg$currPos++;
2198
+ }
2199
+ else {
2200
+ s4 = peg$FAILED;
2201
+ if (peg$silentFails === 0) {
2202
+ peg$fail(peg$e9);
2203
+ }
2204
+ }
2205
+ }
2206
+ }
2207
+ else {
2208
+ s3 = peg$FAILED;
2209
+ }
2210
+ if (s3 !== peg$FAILED) {
2211
+ s2 = input.substring(s2, peg$currPos);
2212
+ }
2213
+ else {
2214
+ s2 = s3;
2215
+ }
2216
+ if (s2 !== peg$FAILED) {
2217
+ peg$savedPos = s0;
2218
+ s0 = peg$f28(s2);
2219
+ }
2220
+ else {
2221
+ peg$currPos = s0;
2222
+ s0 = peg$FAILED;
2223
+ }
2224
+ }
2225
+ else {
2226
+ peg$currPos = s0;
2227
+ s0 = peg$FAILED;
2228
+ }
2229
+ return s0;
2230
+ }
2231
+ function peg$parsenag_import() {
2232
+ let s0;
2233
+ if (input.substr(peg$currPos, 2) === peg$c15) {
2234
+ s0 = peg$c15;
2235
+ peg$currPos += 2;
2236
+ }
2237
+ else {
2238
+ s0 = peg$FAILED;
2239
+ if (peg$silentFails === 0) {
2240
+ peg$fail(peg$e23);
2241
+ }
2242
+ }
2243
+ if (s0 === peg$FAILED) {
2244
+ if (input.substr(peg$currPos, 2) === peg$c16) {
2245
+ s0 = peg$c16;
2246
+ peg$currPos += 2;
2247
+ }
2248
+ else {
2249
+ s0 = peg$FAILED;
2250
+ if (peg$silentFails === 0) {
2251
+ peg$fail(peg$e24);
2252
+ }
2253
+ }
2254
+ if (s0 === peg$FAILED) {
2255
+ if (input.substr(peg$currPos, 2) === peg$c17) {
2256
+ s0 = peg$c17;
2257
+ peg$currPos += 2;
2258
+ }
2259
+ else {
2260
+ s0 = peg$FAILED;
2261
+ if (peg$silentFails === 0) {
2262
+ peg$fail(peg$e25);
2263
+ }
2264
+ }
2265
+ if (s0 === peg$FAILED) {
2266
+ if (input.substr(peg$currPos, 2) === peg$c18) {
2267
+ s0 = peg$c18;
2268
+ peg$currPos += 2;
2269
+ }
2270
+ else {
2271
+ s0 = peg$FAILED;
2272
+ if (peg$silentFails === 0) {
2273
+ peg$fail(peg$e26);
2274
+ }
2275
+ }
2276
+ if (s0 === peg$FAILED) {
2277
+ s0 = input.charAt(peg$currPos);
2278
+ if (peg$r8.test(s0)) {
2279
+ peg$currPos++;
2280
+ }
2281
+ else {
2282
+ s0 = peg$FAILED;
2283
+ if (peg$silentFails === 0) {
2284
+ peg$fail(peg$e27);
2285
+ }
2286
+ }
2287
+ if (s0 === peg$FAILED) {
2288
+ if (input.substr(peg$currPos, 3) === peg$c19) {
2289
+ s0 = peg$c19;
2290
+ peg$currPos += 3;
2291
+ }
2292
+ else {
2293
+ s0 = peg$FAILED;
2294
+ if (peg$silentFails === 0) {
2295
+ peg$fail(peg$e28);
2296
+ }
2297
+ }
2298
+ if (s0 === peg$FAILED) {
2299
+ if (input.substr(peg$currPos, 3) === peg$c20) {
2300
+ s0 = peg$c20;
2301
+ peg$currPos += 3;
2302
+ }
2303
+ else {
2304
+ s0 = peg$FAILED;
2305
+ if (peg$silentFails === 0) {
2306
+ peg$fail(peg$e29);
2307
+ }
2308
+ }
2309
+ if (s0 === peg$FAILED) {
2310
+ s0 = input.charAt(peg$currPos);
2311
+ if (peg$r9.test(s0)) {
2312
+ peg$currPos++;
2313
+ }
2314
+ else {
2315
+ s0 = peg$FAILED;
2316
+ if (peg$silentFails === 0) {
2317
+ peg$fail(peg$e30);
2318
+ }
2319
+ }
2320
+ }
2321
+ }
2322
+ }
2323
+ }
2324
+ }
2325
+ }
2326
+ }
2327
+ return s0;
2328
+ }
2329
+ function peg$parseCOMMENT() {
2330
+ let s0;
2331
+ s0 = peg$parsecomment_multiline();
2332
+ if (s0 === peg$FAILED) {
2333
+ s0 = peg$parsecomment_line();
2334
+ }
2335
+ return s0;
2336
+ }
2337
+ function peg$parsecomment_multiline() {
2338
+ let s0, s1, s2, s3, s4;
2339
+ s0 = peg$currPos;
2340
+ if (input.charCodeAt(peg$currPos) === 123) {
2341
+ s1 = peg$c21;
2342
+ peg$currPos++;
2343
+ }
2344
+ else {
2345
+ s1 = peg$FAILED;
2346
+ if (peg$silentFails === 0) {
2347
+ peg$fail(peg$e31);
2348
+ }
2349
+ }
2350
+ if (s1 !== peg$FAILED) {
2351
+ s2 = peg$currPos;
2352
+ s3 = [];
2353
+ s4 = input.charAt(peg$currPos);
2354
+ if (peg$r10.test(s4)) {
2355
+ peg$currPos++;
2356
+ }
2357
+ else {
2358
+ s4 = peg$FAILED;
2359
+ if (peg$silentFails === 0) {
2360
+ peg$fail(peg$e32);
2361
+ }
2362
+ }
2363
+ while (s4 !== peg$FAILED) {
2364
+ s3.push(s4);
2365
+ s4 = input.charAt(peg$currPos);
2366
+ if (peg$r10.test(s4)) {
2367
+ peg$currPos++;
2368
+ }
2369
+ else {
2370
+ s4 = peg$FAILED;
2371
+ if (peg$silentFails === 0) {
2372
+ peg$fail(peg$e32);
2373
+ }
2374
+ }
2375
+ }
2376
+ s2 = input.substring(s2, peg$currPos);
2377
+ if (input.charCodeAt(peg$currPos) === 125) {
2378
+ s3 = peg$c22;
2379
+ peg$currPos++;
2380
+ }
2381
+ else {
2382
+ s3 = peg$FAILED;
2383
+ if (peg$silentFails === 0) {
2384
+ peg$fail(peg$e33);
2385
+ }
2386
+ }
2387
+ if (s3 !== peg$FAILED) {
2388
+ peg$savedPos = s0;
2389
+ s0 = peg$f29(s2);
2390
+ }
2391
+ else {
2392
+ peg$currPos = s0;
2393
+ s0 = peg$FAILED;
2394
+ }
2395
+ }
2396
+ else {
2397
+ peg$currPos = s0;
2398
+ s0 = peg$FAILED;
2399
+ }
2400
+ return s0;
2401
+ }
2402
+ function peg$parsecomment_line() {
2403
+ let s0, s1, s2, s3, s4, s5, s6;
2404
+ s0 = peg$currPos;
2405
+ if (input.charCodeAt(peg$currPos) === 59) {
2406
+ s1 = peg$c23;
2407
+ peg$currPos++;
2408
+ }
2409
+ else {
2410
+ s1 = peg$FAILED;
2411
+ if (peg$silentFails === 0) {
2412
+ peg$fail(peg$e34);
2413
+ }
2414
+ }
2415
+ if (s1 !== peg$FAILED) {
2416
+ s2 = peg$currPos;
2417
+ s3 = [];
2418
+ s4 = peg$currPos;
2419
+ s5 = peg$currPos;
2420
+ peg$silentFails++;
2421
+ s6 = input.charAt(peg$currPos);
2422
+ if (peg$r11.test(s6)) {
2423
+ peg$currPos++;
2424
+ }
2425
+ else {
2426
+ s6 = peg$FAILED;
2427
+ if (peg$silentFails === 0) {
2428
+ peg$fail(peg$e35);
2429
+ }
2430
+ }
2431
+ peg$silentFails--;
2432
+ if (s6 === peg$FAILED) {
2433
+ s5 = undefined;
2434
+ }
2435
+ else {
2436
+ peg$currPos = s5;
2437
+ s5 = peg$FAILED;
2438
+ }
2439
+ if (s5 !== peg$FAILED) {
2440
+ if (input.length > peg$currPos) {
2441
+ s6 = input.charAt(peg$currPos);
2442
+ peg$currPos++;
2443
+ }
2444
+ else {
2445
+ s6 = peg$FAILED;
2446
+ if (peg$silentFails === 0) {
2447
+ peg$fail(peg$e36);
2448
+ }
2449
+ }
2450
+ if (s6 !== peg$FAILED) {
2451
+ s5 = [s5, s6];
2452
+ s4 = s5;
2453
+ }
2454
+ else {
2455
+ peg$currPos = s4;
2456
+ s4 = peg$FAILED;
2457
+ }
2458
+ }
2459
+ else {
2460
+ peg$currPos = s4;
2461
+ s4 = peg$FAILED;
2462
+ }
2463
+ while (s4 !== peg$FAILED) {
2464
+ s3.push(s4);
2465
+ s4 = peg$currPos;
2466
+ s5 = peg$currPos;
2467
+ peg$silentFails++;
2468
+ s6 = input.charAt(peg$currPos);
2469
+ if (peg$r11.test(s6)) {
2470
+ peg$currPos++;
2471
+ }
2472
+ else {
2473
+ s6 = peg$FAILED;
2474
+ if (peg$silentFails === 0) {
2475
+ peg$fail(peg$e35);
2476
+ }
2477
+ }
2478
+ peg$silentFails--;
2479
+ if (s6 === peg$FAILED) {
2480
+ s5 = undefined;
2481
+ }
2482
+ else {
2483
+ peg$currPos = s5;
2484
+ s5 = peg$FAILED;
2485
+ }
2486
+ if (s5 !== peg$FAILED) {
2487
+ if (input.length > peg$currPos) {
2488
+ s6 = input.charAt(peg$currPos);
2489
+ peg$currPos++;
2490
+ }
2491
+ else {
2492
+ s6 = peg$FAILED;
2493
+ if (peg$silentFails === 0) {
2494
+ peg$fail(peg$e36);
2495
+ }
2496
+ }
2497
+ if (s6 !== peg$FAILED) {
2498
+ s5 = [s5, s6];
2499
+ s4 = s5;
2500
+ }
2501
+ else {
2502
+ peg$currPos = s4;
2503
+ s4 = peg$FAILED;
2504
+ }
2505
+ }
2506
+ else {
2507
+ peg$currPos = s4;
2508
+ s4 = peg$FAILED;
2509
+ }
2510
+ }
2511
+ s2 = input.substring(s2, peg$currPos);
2512
+ peg$savedPos = s0;
2513
+ s0 = peg$f30(s2);
2514
+ }
2515
+ else {
2516
+ peg$currPos = s0;
2517
+ s0 = peg$FAILED;
2518
+ }
2519
+ return s0;
2520
+ }
2521
+ function peg$parse_() {
2522
+ let s0, s1;
2523
+ s0 = [];
2524
+ s1 = input.charAt(peg$currPos);
2525
+ if (peg$r12.test(s1)) {
2526
+ peg$currPos++;
2527
+ }
2528
+ else {
2529
+ s1 = peg$FAILED;
2530
+ if (peg$silentFails === 0) {
2531
+ peg$fail(peg$e37);
2532
+ }
2533
+ }
2534
+ if (s1 === peg$FAILED) {
2535
+ s1 = peg$parseESCAPE();
2536
+ }
2537
+ while (s1 !== peg$FAILED) {
2538
+ s0.push(s1);
2539
+ s1 = input.charAt(peg$currPos);
2540
+ if (peg$r12.test(s1)) {
2541
+ peg$currPos++;
2542
+ }
2543
+ else {
2544
+ s1 = peg$FAILED;
2545
+ if (peg$silentFails === 0) {
2546
+ peg$fail(peg$e37);
2547
+ }
2548
+ }
2549
+ if (s1 === peg$FAILED) {
2550
+ s1 = peg$parseESCAPE();
2551
+ }
2552
+ }
2553
+ return s0;
2554
+ }
2555
+ function peg$parseESCAPE() {
2556
+ let s0, s1, s2, s3, s4, s5;
2557
+ s0 = peg$currPos;
2558
+ if (input.charCodeAt(peg$currPos) === 37) {
2559
+ s1 = peg$c24;
2560
+ peg$currPos++;
2561
+ }
2562
+ else {
2563
+ s1 = peg$FAILED;
2564
+ if (peg$silentFails === 0) {
2565
+ peg$fail(peg$e38);
2566
+ }
2567
+ }
2568
+ if (s1 !== peg$FAILED) {
2569
+ s2 = [];
2570
+ s3 = peg$currPos;
2571
+ s4 = peg$currPos;
2572
+ peg$silentFails++;
2573
+ s5 = input.charAt(peg$currPos);
2574
+ if (peg$r11.test(s5)) {
2575
+ peg$currPos++;
2576
+ }
2577
+ else {
2578
+ s5 = peg$FAILED;
2579
+ if (peg$silentFails === 0) {
2580
+ peg$fail(peg$e35);
2581
+ }
2582
+ }
2583
+ peg$silentFails--;
2584
+ if (s5 === peg$FAILED) {
2585
+ s4 = undefined;
2586
+ }
2587
+ else {
2588
+ peg$currPos = s4;
2589
+ s4 = peg$FAILED;
2590
+ }
2591
+ if (s4 !== peg$FAILED) {
2592
+ if (input.length > peg$currPos) {
2593
+ s5 = input.charAt(peg$currPos);
2594
+ peg$currPos++;
2595
+ }
2596
+ else {
2597
+ s5 = peg$FAILED;
2598
+ if (peg$silentFails === 0) {
2599
+ peg$fail(peg$e36);
2600
+ }
2601
+ }
2602
+ if (s5 !== peg$FAILED) {
2603
+ s4 = [s4, s5];
2604
+ s3 = s4;
2605
+ }
2606
+ else {
2607
+ peg$currPos = s3;
2608
+ s3 = peg$FAILED;
2609
+ }
2610
+ }
2611
+ else {
2612
+ peg$currPos = s3;
2613
+ s3 = peg$FAILED;
2614
+ }
2615
+ while (s3 !== peg$FAILED) {
2616
+ s2.push(s3);
2617
+ s3 = peg$currPos;
2618
+ s4 = peg$currPos;
2619
+ peg$silentFails++;
2620
+ s5 = input.charAt(peg$currPos);
2621
+ if (peg$r11.test(s5)) {
2622
+ peg$currPos++;
2623
+ }
2624
+ else {
2625
+ s5 = peg$FAILED;
2626
+ if (peg$silentFails === 0) {
2627
+ peg$fail(peg$e35);
2628
+ }
2629
+ }
2630
+ peg$silentFails--;
2631
+ if (s5 === peg$FAILED) {
2632
+ s4 = undefined;
2633
+ }
2634
+ else {
2635
+ peg$currPos = s4;
2636
+ s4 = peg$FAILED;
2637
+ }
2638
+ if (s4 !== peg$FAILED) {
2639
+ if (input.length > peg$currPos) {
2640
+ s5 = input.charAt(peg$currPos);
2641
+ peg$currPos++;
2642
+ }
2643
+ else {
2644
+ s5 = peg$FAILED;
2645
+ if (peg$silentFails === 0) {
2646
+ peg$fail(peg$e36);
2647
+ }
2648
+ }
2649
+ if (s5 !== peg$FAILED) {
2650
+ s4 = [s4, s5];
2651
+ s3 = s4;
2652
+ }
2653
+ else {
2654
+ peg$currPos = s3;
2655
+ s3 = peg$FAILED;
2656
+ }
2657
+ }
2658
+ else {
2659
+ peg$currPos = s3;
2660
+ s3 = peg$FAILED;
2661
+ }
2662
+ }
2663
+ s3 = input.charAt(peg$currPos);
2664
+ if (peg$r11.test(s3)) {
2665
+ peg$currPos++;
2666
+ }
2667
+ else {
2668
+ s3 = peg$FAILED;
2669
+ if (peg$silentFails === 0) {
2670
+ peg$fail(peg$e35);
2671
+ }
2672
+ }
2673
+ if (s3 === peg$FAILED) {
2674
+ s3 = null;
2675
+ }
2676
+ s1 = [s1, s2, s3];
2677
+ s0 = s1;
2678
+ }
2679
+ else {
2680
+ peg$currPos = s0;
2681
+ s0 = peg$FAILED;
2682
+ }
2683
+ return s0;
2684
+ }
2685
+ peg$result = peg$startRuleFunction();
2686
+ const peg$success = (peg$result !== peg$FAILED && peg$currPos === input.length);
2687
+ function peg$throw() {
2688
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
2689
+ peg$fail(peg$endExpectation());
2690
+ }
2691
+ throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? peg$getUnicode(peg$maxFailPos) : null, peg$maxFailPos < input.length
2692
+ ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
2693
+ : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
2694
+ }
2695
+ if (options.peg$library) {
2696
+ return /** @type {any} */ ({
2697
+ peg$result,
2698
+ peg$currPos,
2699
+ peg$FAILED,
2700
+ peg$maxFailExpected,
2701
+ peg$maxFailPos,
2702
+ peg$success,
2703
+ peg$throw: peg$success ? undefined : peg$throw,
2704
+ });
2705
+ }
2706
+ if (peg$success) {
2707
+ return peg$result;
139
2708
  }
140
2709
  else {
141
- window.grammar = grammar;
2710
+ peg$throw();
142
2711
  }
143
- })();
2712
+ }
2713
+ module.exports = {
2714
+ StartRules: ["DATABASE"],
2715
+ SyntaxError: peg$SyntaxError,
2716
+ parse: peg$parse,
2717
+ };
144
2718
  //# sourceMappingURL=grammar.cjs.map