@echecs/pgn 2.1.4 → 3.0.4

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/package.json CHANGED
@@ -5,19 +5,21 @@
5
5
  },
6
6
  "description": "FIDE PGN Parser",
7
7
  "devDependencies": {
8
- "@types/jest": "^29.2.5",
9
- "@types/nearley": "^2.11.2",
10
- "@typescript-eslint/eslint-plugin": "^5.48.0",
11
- "@typescript-eslint/parser": "^5.48.0",
12
- "eslint": "^8.31.0",
13
- "eslint-config-prettier": "^8.6.0",
14
- "eslint-config-standard": "^17.0.0",
15
- "husky": "^8.0.3",
16
- "jest": "^29.3.1",
17
- "lint-staged": "^13.1.0",
18
- "prettier": "^2.8.2",
19
- "ts-jest": "^29.0.3",
20
- "typescript": "^4.9.4"
8
+ "@eslint/js": "^9.10.0",
9
+ "@types/nearley": "^2.11.5",
10
+ "@typescript-eslint/parser": "^8.5.0",
11
+ "@vitest/coverage-v8": "^2.0.5",
12
+ "eslint": "^9.10.0",
13
+ "eslint-config-prettier": "^9.1.0",
14
+ "eslint-import-resolver-typescript": "^3.6.3",
15
+ "eslint-plugin-import-x": "^4.2.1",
16
+ "husky": "^9.1.6",
17
+ "install": "^0.13.0",
18
+ "lint-staged": "^15.2.10",
19
+ "prettier": "^3.3.3",
20
+ "typescript": "^5.6.2",
21
+ "typescript-eslint": "^8.5.0",
22
+ "vitest": "^2.0.5"
21
23
  },
22
24
  "files": [
23
25
  "/dist/",
@@ -34,19 +36,24 @@
34
36
  "main": "dist/index.js",
35
37
  "name": "@echecs/pgn",
36
38
  "repository": "mormubis/pgn",
39
+ "type": "module",
40
+ "types": "dist/index.d.ts",
41
+ "version": "3.0.4",
37
42
  "scripts": {
38
- "build": "npm run grammar:compile && npm run compile && cp src/grammar.js dist/grammar.js",
39
- "compile": "tsc",
40
- "format": "prettier --ignore-path .gitignore \"src/**/*.+(js|json|md|yml)\" --write",
41
- "grammar:compile": "nearleyc src/grammar.ne -o src/grammar.js",
43
+ "build": "pnpm run build:grammar && pnpm run build:entry",
44
+ "build:grammar": "pnpm run grammar:compile",
45
+ "build:entry": "tsc --project tsconfig.build.json",
46
+ "format": "pnpm run format:ci --write",
47
+ "format:ci": "prettier -l \"**/*.+(css|js|json|jsx|md|mjs|mts|ts|tsx|yml|yaml)\"",
48
+ "grammar:compile": "nearleyc src/grammar.ne -o src/grammar.cjs",
42
49
  "grammar:diagram": "nearley-railroad src/grammar.ne -o diagram.html",
43
50
  "grammar:test": "nearley-test -s DATABASE src/grammar.js < ./test.pgn",
44
- "lint": "eslint \"src/**/*.ts\" --fix",
45
- "prepare": "npm run build",
46
- "test": "jest",
47
- "test:coverage": "npm run test -- --coverage",
48
- "test:watch": "npm run test -- --watch"
49
- },
50
- "types": "dist/index.d.ts",
51
- "version": "2.1.4"
52
- }
51
+ "lint": "pnpm run lint:style && pnpm run lint:types",
52
+ "lint:ci": "pnpm run lint:style --max-warnings 0 && pnpm run lint:types",
53
+ "lint:style": "eslint \"src/**/*.{ts,tsx}\" --fix",
54
+ "lint:types": "tsc --noEmit --project tsconfig.json",
55
+ "test": "vitest run",
56
+ "test:coverage": "pnpm run test --coverage",
57
+ "test:watch": "pnpm run test --watch"
58
+ }
59
+ }
package/dist/grammar.js DELETED
@@ -1,428 +0,0 @@
1
- // Generated automatically by nearley, version 2.20.1
2
- // http://github.com/Hardmath123/nearley
3
- (function () {
4
- function id(x) { return x[0]; }
5
- var grammar = {
6
- Lexer: undefined,
7
- ParserRules: [
8
- {"name": "unsigned_int$ebnf$1", "symbols": [/[0-9]/]},
9
- {"name": "unsigned_int$ebnf$1", "symbols": ["unsigned_int$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
10
- {"name": "unsigned_int", "symbols": ["unsigned_int$ebnf$1"], "postprocess":
11
- function(d) {
12
- return parseInt(d[0].join(""));
13
- }
14
- },
15
- {"name": "int$ebnf$1$subexpression$1", "symbols": [{"literal":"-"}]},
16
- {"name": "int$ebnf$1$subexpression$1", "symbols": [{"literal":"+"}]},
17
- {"name": "int$ebnf$1", "symbols": ["int$ebnf$1$subexpression$1"], "postprocess": id},
18
- {"name": "int$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
19
- {"name": "int$ebnf$2", "symbols": [/[0-9]/]},
20
- {"name": "int$ebnf$2", "symbols": ["int$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
21
- {"name": "int", "symbols": ["int$ebnf$1", "int$ebnf$2"], "postprocess":
22
- function(d) {
23
- if (d[0]) {
24
- return parseInt(d[0][0]+d[1].join(""));
25
- } else {
26
- return parseInt(d[1].join(""));
27
- }
28
- }
29
- },
30
- {"name": "unsigned_decimal$ebnf$1", "symbols": [/[0-9]/]},
31
- {"name": "unsigned_decimal$ebnf$1", "symbols": ["unsigned_decimal$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
32
- {"name": "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", "symbols": [/[0-9]/]},
33
- {"name": "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", "symbols": ["unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
34
- {"name": "unsigned_decimal$ebnf$2$subexpression$1", "symbols": [{"literal":"."}, "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1"]},
35
- {"name": "unsigned_decimal$ebnf$2", "symbols": ["unsigned_decimal$ebnf$2$subexpression$1"], "postprocess": id},
36
- {"name": "unsigned_decimal$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
37
- {"name": "unsigned_decimal", "symbols": ["unsigned_decimal$ebnf$1", "unsigned_decimal$ebnf$2"], "postprocess":
38
- function(d) {
39
- return parseFloat(
40
- d[0].join("") +
41
- (d[1] ? "."+d[1][1].join("") : "")
42
- );
43
- }
44
- },
45
- {"name": "decimal$ebnf$1", "symbols": [{"literal":"-"}], "postprocess": id},
46
- {"name": "decimal$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
47
- {"name": "decimal$ebnf$2", "symbols": [/[0-9]/]},
48
- {"name": "decimal$ebnf$2", "symbols": ["decimal$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
49
- {"name": "decimal$ebnf$3$subexpression$1$ebnf$1", "symbols": [/[0-9]/]},
50
- {"name": "decimal$ebnf$3$subexpression$1$ebnf$1", "symbols": ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
51
- {"name": "decimal$ebnf$3$subexpression$1", "symbols": [{"literal":"."}, "decimal$ebnf$3$subexpression$1$ebnf$1"]},
52
- {"name": "decimal$ebnf$3", "symbols": ["decimal$ebnf$3$subexpression$1"], "postprocess": id},
53
- {"name": "decimal$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
54
- {"name": "decimal", "symbols": ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"], "postprocess":
55
- function(d) {
56
- return parseFloat(
57
- (d[0] || "") +
58
- d[1].join("") +
59
- (d[2] ? "."+d[2][1].join("") : "")
60
- );
61
- }
62
- },
63
- {"name": "percentage", "symbols": ["decimal", {"literal":"%"}], "postprocess":
64
- function(d) {
65
- return d[0]/100;
66
- }
67
- },
68
- {"name": "jsonfloat$ebnf$1", "symbols": [{"literal":"-"}], "postprocess": id},
69
- {"name": "jsonfloat$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
70
- {"name": "jsonfloat$ebnf$2", "symbols": [/[0-9]/]},
71
- {"name": "jsonfloat$ebnf$2", "symbols": ["jsonfloat$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
72
- {"name": "jsonfloat$ebnf$3$subexpression$1$ebnf$1", "symbols": [/[0-9]/]},
73
- {"name": "jsonfloat$ebnf$3$subexpression$1$ebnf$1", "symbols": ["jsonfloat$ebnf$3$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
74
- {"name": "jsonfloat$ebnf$3$subexpression$1", "symbols": [{"literal":"."}, "jsonfloat$ebnf$3$subexpression$1$ebnf$1"]},
75
- {"name": "jsonfloat$ebnf$3", "symbols": ["jsonfloat$ebnf$3$subexpression$1"], "postprocess": id},
76
- {"name": "jsonfloat$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
77
- {"name": "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "symbols": [/[+-]/], "postprocess": id},
78
- {"name": "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
79
- {"name": "jsonfloat$ebnf$4$subexpression$1$ebnf$2", "symbols": [/[0-9]/]},
80
- {"name": "jsonfloat$ebnf$4$subexpression$1$ebnf$2", "symbols": ["jsonfloat$ebnf$4$subexpression$1$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
81
- {"name": "jsonfloat$ebnf$4$subexpression$1", "symbols": [/[eE]/, "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "jsonfloat$ebnf$4$subexpression$1$ebnf$2"]},
82
- {"name": "jsonfloat$ebnf$4", "symbols": ["jsonfloat$ebnf$4$subexpression$1"], "postprocess": id},
83
- {"name": "jsonfloat$ebnf$4", "symbols": [], "postprocess": function(d) {return null;}},
84
- {"name": "jsonfloat", "symbols": ["jsonfloat$ebnf$1", "jsonfloat$ebnf$2", "jsonfloat$ebnf$3", "jsonfloat$ebnf$4"], "postprocess":
85
- function(d) {
86
- return parseFloat(
87
- (d[0] || "") +
88
- d[1].join("") +
89
- (d[2] ? "."+d[2][1].join("") : "") +
90
- (d[3] ? "e" + (d[3][1] || "+") + d[3][2].join("") : "")
91
- );
92
- }
93
- },
94
- {"name": "dqstring$ebnf$1", "symbols": []},
95
- {"name": "dqstring$ebnf$1", "symbols": ["dqstring$ebnf$1", "dstrchar"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
96
- {"name": "dqstring", "symbols": [{"literal":"\""}, "dqstring$ebnf$1", {"literal":"\""}], "postprocess": function(d) {return d[1].join(""); }},
97
- {"name": "sqstring$ebnf$1", "symbols": []},
98
- {"name": "sqstring$ebnf$1", "symbols": ["sqstring$ebnf$1", "sstrchar"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
99
- {"name": "sqstring", "symbols": [{"literal":"'"}, "sqstring$ebnf$1", {"literal":"'"}], "postprocess": function(d) {return d[1].join(""); }},
100
- {"name": "btstring$ebnf$1", "symbols": []},
101
- {"name": "btstring$ebnf$1", "symbols": ["btstring$ebnf$1", /[^`]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
102
- {"name": "btstring", "symbols": [{"literal":"`"}, "btstring$ebnf$1", {"literal":"`"}], "postprocess": function(d) {return d[1].join(""); }},
103
- {"name": "dstrchar", "symbols": [/[^\\"\n]/], "postprocess": id},
104
- {"name": "dstrchar", "symbols": [{"literal":"\\"}, "strescape"], "postprocess":
105
- function(d) {
106
- return JSON.parse("\""+d.join("")+"\"");
107
- }
108
- },
109
- {"name": "sstrchar", "symbols": [/[^\\'\n]/], "postprocess": id},
110
- {"name": "sstrchar", "symbols": [{"literal":"\\"}, "strescape"], "postprocess": function(d) { return JSON.parse("\""+d.join("")+"\""); }},
111
- {"name": "sstrchar$string$1", "symbols": [{"literal":"\\"}, {"literal":"'"}], "postprocess": function joiner(d) {return d.join('');}},
112
- {"name": "sstrchar", "symbols": ["sstrchar$string$1"], "postprocess": function(d) {return "'"; }},
113
- {"name": "strescape", "symbols": [/["\\/bfnrt]/], "postprocess": id},
114
- {"name": "strescape", "symbols": [{"literal":"u"}, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/], "postprocess":
115
- function(d) {
116
- return d.join("");
117
- }
118
- },
119
- {"name": "_$ebnf$1", "symbols": []},
120
- {"name": "_$ebnf$1", "symbols": ["_$ebnf$1", "wschar"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
121
- {"name": "_", "symbols": ["_$ebnf$1"], "postprocess": function(d) {return null;}},
122
- {"name": "__$ebnf$1", "symbols": ["wschar"]},
123
- {"name": "__$ebnf$1", "symbols": ["__$ebnf$1", "wschar"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
124
- {"name": "__", "symbols": ["__$ebnf$1"], "postprocess": function(d) {return null;}},
125
- {"name": "wschar", "symbols": [/[ \t\n\v\f]/], "postprocess": id},
126
- {"name": "DATABASE$ebnf$1", "symbols": ["GAME"]},
127
- {"name": "DATABASE$ebnf$1", "symbols": ["DATABASE$ebnf$1", "GAME"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
128
- {"name": "DATABASE", "symbols": ["DATABASE$ebnf$1"], "postprocess": id},
129
- {"name": "GAME", "symbols": ["TAGS", "MOVE_SECTION", "__", "result", "__"], "postprocess":
130
- (d) => ({ meta: d[0], moves: d[1], result: d[3] })
131
- },
132
- {"name": "TAGS$ebnf$1$subexpression$1", "symbols": ["TAG", "__"]},
133
- {"name": "TAGS$ebnf$1", "symbols": ["TAGS$ebnf$1$subexpression$1"]},
134
- {"name": "TAGS$ebnf$1$subexpression$2", "symbols": ["TAG", "__"]},
135
- {"name": "TAGS$ebnf$1", "symbols": ["TAGS$ebnf$1", "TAGS$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
136
- {"name": "TAGS", "symbols": ["TAGS$ebnf$1"], "postprocess": (d) => d[0].map(d0 => d0[0]).reduce((acc, item) => ({ ...acc, ...item }), {})},
137
- {"name": "TAG", "symbols": [{"literal":"["}, "NAME", "__", "VALUE", {"literal":"]"}], "postprocess": (d) => ({ [d[1]]: d[3] })},
138
- {"name": "NAME", "symbols": ["string"]},
139
- {"name": "VALUE", "symbols": ["dqstring"], "postprocess": id},
140
- {"name": "MOVE_SECTION$ebnf$1", "symbols": []},
141
- {"name": "MOVE_SECTION$ebnf$1$subexpression$1", "symbols": ["_", "MOVE"]},
142
- {"name": "MOVE_SECTION$ebnf$1", "symbols": ["MOVE_SECTION$ebnf$1", "MOVE_SECTION$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
143
- {"name": "MOVE_SECTION$ebnf$2$subexpression$1", "symbols": ["_", "HM_WHITE"]},
144
- {"name": "MOVE_SECTION$ebnf$2", "symbols": ["MOVE_SECTION$ebnf$2$subexpression$1"], "postprocess": id},
145
- {"name": "MOVE_SECTION$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
146
- {"name": "MOVE_SECTION", "symbols": ["MOVE", "MOVE_SECTION$ebnf$1", "MOVE_SECTION$ebnf$2"], "postprocess":
147
- (d) => {
148
- const moves = [d[0]];
149
-
150
- if (d[1].length > 0) {
151
- const d1 = d[1];
152
-
153
- moves.push(...d1.map(d => d[1]));
154
- }
155
-
156
- if (d[2]) {
157
- const d2 = d[2];
158
-
159
- moves.push(d2[1]);
160
- }
161
-
162
- return moves;
163
- }
164
- },
165
- {"name": "MOVE_SECTION", "symbols": ["HM_WHITE"], "postprocess": d => [d[0]]},
166
- {"name": "MOVES$ebnf$1", "symbols": []},
167
- {"name": "MOVES$ebnf$1$subexpression$1", "symbols": ["_", "MOVE"]},
168
- {"name": "MOVES$ebnf$1", "symbols": ["MOVES$ebnf$1", "MOVES$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
169
- {"name": "MOVES$ebnf$2$subexpression$1", "symbols": ["_", "HM_WHITE"]},
170
- {"name": "MOVES$ebnf$2", "symbols": ["MOVES$ebnf$2$subexpression$1"], "postprocess": id},
171
- {"name": "MOVES$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
172
- {"name": "MOVES", "symbols": ["MOVES$ebnf$1", "MOVES$ebnf$2"], "postprocess":
173
- (d) => {
174
- const moves = [];
175
-
176
- if (d[0]) {
177
- d[0].map(d0 => d0[1]).map(d01 => moves.push(d01));
178
- }
179
-
180
- if (d[1]) {
181
- moves.push(d[1][1]);
182
- }
183
-
184
- return moves;
185
- }
186
- },
187
- {"name": "HM_WHITE$ebnf$1", "symbols": []},
188
- {"name": "HM_WHITE$ebnf$1$subexpression$1", "symbols": ["_", "VARIANT"]},
189
- {"name": "HM_WHITE$ebnf$1", "symbols": ["HM_WHITE$ebnf$1", "HM_WHITE$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
190
- {"name": "HM_WHITE", "symbols": ["NUMBER", "_", "SAN", "HM_WHITE$ebnf$1"], "postprocess":
191
- (d) => {
192
- const move = [d[0], {...d[2], ...(d[3].length > 0 && { variants: d[3].map(d3 => d3[1]) }), }];
193
-
194
- if (move[1].castling) {
195
- move[1].to = move[1].castling === 'K' ? 'g1' : 'c1';
196
- move[1].castling = true;
197
- }
198
-
199
- return move;
200
- }
201
- },
202
- {"name": "HM_BLACK$ebnf$1", "symbols": []},
203
- {"name": "HM_BLACK$ebnf$1$subexpression$1", "symbols": ["_", "VARIANT"]},
204
- {"name": "HM_BLACK$ebnf$1", "symbols": ["HM_BLACK$ebnf$1", "HM_BLACK$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
205
- {"name": "HM_BLACK", "symbols": ["_", "NUMBER", "continuation", "_", "SAN", "HM_BLACK$ebnf$1"], "postprocess":
206
- (d) => {
207
- const move = [d[1], undefined, {...d[4], ...(d[5].length > 0 && { variants: d[5].map(d5 => d5[1]) }) }];
208
-
209
- if (move[2].castling) {
210
- move[2].to = move[2].castling === 'K' ? 'g8' : 'c8';
211
- move[2].castling = true;
212
- }
213
-
214
- return move;
215
- }
216
- },
217
- {"name": "MOVE$ebnf$1", "symbols": []},
218
- {"name": "MOVE$ebnf$1$subexpression$1", "symbols": ["_", "VARIANT"]},
219
- {"name": "MOVE$ebnf$1", "symbols": ["MOVE$ebnf$1", "MOVE$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
220
- {"name": "MOVE", "symbols": ["NUMBER", "_", "SAN", "__", "SAN", "MOVE$ebnf$1"], "postprocess":
221
- (d) => {
222
- const move = [d[0], d[2], d[4]];
223
-
224
- if (move[1].castling) {
225
- move[1].to = move[1].castling === 'K' ? 'g1' : 'c1';
226
- move[1].castling = true;
227
- }
228
-
229
- if (move[2].castling) {
230
- move[2].to = move[2].castling === 'K' ? 'g8' : 'c8';
231
- move[2].castling = true;
232
- }
233
-
234
- if (d[5]) {
235
- const variants = d[5].map(d5 => d5[1]);
236
-
237
- const white = variants.filter(variant => variant[0][1]);
238
- const black = variants.filter(variant => !variant[0][1]);
239
-
240
- if (white.length > 0) {
241
- move[1].variants = white;
242
- }
243
-
244
- if (black.length > 0) {
245
- move[2].variants = black;
246
- }
247
- }
248
-
249
- return move;
250
- }
251
- },
252
- {"name": "MOVE", "symbols": ["HM_WHITE", "__", "HM_BLACK"], "postprocess":
253
- d => [d[0][0], d[0][1], d[2][2]]
254
- },
255
- {"name": "NUMBER$ebnf$1", "symbols": [{"literal":"."}], "postprocess": id},
256
- {"name": "NUMBER$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
257
- {"name": "NUMBER", "symbols": ["unsigned_int", "NUMBER$ebnf$1"], "postprocess": (d) => d[0]},
258
- {"name": "VARIANT", "symbols": [{"literal":"("}, "MOVES", "_", {"literal":")"}], "postprocess":
259
- (d) => d[1]
260
- },
261
- {"name": "VARIANT", "symbols": [{"literal":"("}, "HM_BLACK", "MOVES", "_", {"literal":")"}], "postprocess":
262
- (d) => [d[1], ...d[2]]
263
- },
264
- {"name": "SAN$ebnf$1", "symbols": ["piece"], "postprocess": id},
265
- {"name": "SAN$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
266
- {"name": "SAN$ebnf$2", "symbols": ["DISAMBIGUATION"], "postprocess": id},
267
- {"name": "SAN$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
268
- {"name": "SAN$ebnf$3", "symbols": ["capture"], "postprocess": id},
269
- {"name": "SAN$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
270
- {"name": "SAN$ebnf$4", "symbols": ["PROMOTION"], "postprocess": id},
271
- {"name": "SAN$ebnf$4", "symbols": [], "postprocess": function(d) {return null;}},
272
- {"name": "SAN$ebnf$5$subexpression$1", "symbols": ["_", "SUFFIX"]},
273
- {"name": "SAN$ebnf$5", "symbols": ["SAN$ebnf$5$subexpression$1"], "postprocess": id},
274
- {"name": "SAN$ebnf$5", "symbols": [], "postprocess": function(d) {return null;}},
275
- {"name": "SAN$ebnf$6", "symbols": []},
276
- {"name": "SAN$ebnf$6$subexpression$1", "symbols": ["_", "COMMENT"]},
277
- {"name": "SAN$ebnf$6", "symbols": ["SAN$ebnf$6", "SAN$ebnf$6$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
278
- {"name": "SAN", "symbols": ["SAN$ebnf$1", "SAN$ebnf$2", "SAN$ebnf$3", "file", "rank", "SAN$ebnf$4", "SAN$ebnf$5", "SAN$ebnf$6"], "postprocess":
279
- (d) => {
280
- const comments = d[7].map(d7 => d7[1]).filter(Boolean);
281
-
282
- return ({
283
- ...(d[6] && d[6][1]),
284
- ...(comments.length > 0 && { comment: comments.reduce((acc, item) => `${acc} ${item}`, '') }),
285
- ...(d[2] && { capture: true }),
286
- ...(d[1] && { from: d[1][0] }),
287
- piece: d[0] ? d[0][0] : 'P',
288
- ...(d[5] && { promotion: d[5] }),
289
- to: `${d[3]}${d[4]}`,
290
- });
291
- }
292
- },
293
- {"name": "SAN$ebnf$7", "symbols": []},
294
- {"name": "SAN$ebnf$7$subexpression$1", "symbols": ["_", "SUFFIX"]},
295
- {"name": "SAN$ebnf$7", "symbols": ["SAN$ebnf$7", "SAN$ebnf$7$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
296
- {"name": "SAN$ebnf$8", "symbols": []},
297
- {"name": "SAN$ebnf$8$subexpression$1", "symbols": ["_", "COMMENT"]},
298
- {"name": "SAN$ebnf$8", "symbols": ["SAN$ebnf$8", "SAN$ebnf$8$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
299
- {"name": "SAN", "symbols": ["castling", "SAN$ebnf$7", "SAN$ebnf$8"], "postprocess":
300
- (d) => {
301
- const comments = d[2].map(d2 => d2[1]).filter(Boolean);
302
-
303
- return ({
304
- ...(d[1]),
305
- ...(comments.length > 0 && { comment: comments.reduce((acc, item) => `${acc} ${item}`, '') }),
306
- castling: d[0],
307
- piece: 'K'
308
- })
309
- }
310
- },
311
- {"name": "DISAMBIGUATION", "symbols": ["file"], "postprocess": id},
312
- {"name": "DISAMBIGUATION", "symbols": ["rank"], "postprocess": id},
313
- {"name": "PROMOTION", "symbols": [{"literal":"="}, /[QBNR]/], "postprocess": (d) => d[1]},
314
- {"name": "SUFFIX$subexpression$1", "symbols": ["check"]},
315
- {"name": "SUFFIX$subexpression$1", "symbols": ["checkmate"]},
316
- {"name": "SUFFIX$ebnf$1", "symbols": ["annotation"], "postprocess": id},
317
- {"name": "SUFFIX$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
318
- {"name": "SUFFIX$ebnf$2", "symbols": []},
319
- {"name": "SUFFIX$ebnf$2$subexpression$1", "symbols": ["_", "NAG"]},
320
- {"name": "SUFFIX$ebnf$2", "symbols": ["SUFFIX$ebnf$2", "SUFFIX$ebnf$2$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
321
- {"name": "SUFFIX", "symbols": ["SUFFIX$subexpression$1", "SUFFIX$ebnf$1", "SUFFIX$ebnf$2"], "postprocess":
322
- (d) => ({
323
- ...(d[0] && { [d[0]]: true }),
324
- ...((d[1] || d[2].length > 0) && { annotations: [...(d[1] ? [d[1]] : []), ...d[2].map(d2 => d2[1])] }),
325
- })
326
- },
327
- {"name": "SUFFIX$ebnf$3$subexpression$1", "symbols": ["check"]},
328
- {"name": "SUFFIX$ebnf$3$subexpression$1", "symbols": ["checkmate"]},
329
- {"name": "SUFFIX$ebnf$3", "symbols": ["SUFFIX$ebnf$3$subexpression$1"], "postprocess": id},
330
- {"name": "SUFFIX$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
331
- {"name": "SUFFIX$ebnf$4", "symbols": []},
332
- {"name": "SUFFIX$ebnf$4$subexpression$1", "symbols": ["_", "NAG"]},
333
- {"name": "SUFFIX$ebnf$4", "symbols": ["SUFFIX$ebnf$4", "SUFFIX$ebnf$4$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
334
- {"name": "SUFFIX", "symbols": ["SUFFIX$ebnf$3", "annotation", "SUFFIX$ebnf$4"], "postprocess":
335
- (d) => ({
336
- ...(d[0] && { [d[0]]: true }),
337
- ...((d[1] || d[2].length > 0) && { annotations: [...(d[1] ? [d[1]] : []), ...d[2].map(d2 => d2[1])] }),
338
- })
339
- },
340
- {"name": "SUFFIX$ebnf$5$subexpression$1", "symbols": ["check"]},
341
- {"name": "SUFFIX$ebnf$5$subexpression$1", "symbols": ["checkmate"]},
342
- {"name": "SUFFIX$ebnf$5", "symbols": ["SUFFIX$ebnf$5$subexpression$1"], "postprocess": id},
343
- {"name": "SUFFIX$ebnf$5", "symbols": [], "postprocess": function(d) {return null;}},
344
- {"name": "SUFFIX$ebnf$6", "symbols": ["annotation"], "postprocess": id},
345
- {"name": "SUFFIX$ebnf$6", "symbols": [], "postprocess": function(d) {return null;}},
346
- {"name": "SUFFIX$ebnf$7$subexpression$1", "symbols": ["_", "NAG"]},
347
- {"name": "SUFFIX$ebnf$7", "symbols": ["SUFFIX$ebnf$7$subexpression$1"]},
348
- {"name": "SUFFIX$ebnf$7$subexpression$2", "symbols": ["_", "NAG"]},
349
- {"name": "SUFFIX$ebnf$7", "symbols": ["SUFFIX$ebnf$7", "SUFFIX$ebnf$7$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
350
- {"name": "SUFFIX", "symbols": ["SUFFIX$ebnf$5", "SUFFIX$ebnf$6", "SUFFIX$ebnf$7"], "postprocess":
351
- (d) => ({
352
- ...(d[0] && { [d[0]]: true }),
353
- ...((d[1] || d[2].length > 0) && { annotations: [...(d[1] ? [d[1]] : []), ...d[2].map(d2 => d2[1])] }),
354
- })
355
- },
356
- {"name": "NAG$subexpression$1$string$1", "symbols": [{"literal":"2"}, {"literal":"5"}], "postprocess": function joiner(d) {return d.join('');}},
357
- {"name": "NAG$subexpression$1", "symbols": ["NAG$subexpression$1$string$1", /[0-5]/]},
358
- {"name": "NAG$subexpression$1", "symbols": [{"literal":"2"}, /[0-4]/, /[0-9]/]},
359
- {"name": "NAG$subexpression$1", "symbols": [{"literal":"1"}, /[0-9]/, /[0-9]/]},
360
- {"name": "NAG$subexpression$1", "symbols": [/[1-9]/, /[0-9]/]},
361
- {"name": "NAG$subexpression$1", "symbols": [/[0-9]/]},
362
- {"name": "NAG", "symbols": [{"literal":"$"}, "NAG$subexpression$1"], "postprocess":
363
- (d) => d[1]
364
- },
365
- {"name": "COMMENT", "symbols": ["bstring"]},
366
- {"name": "COMMENT$ebnf$1", "symbols": []},
367
- {"name": "COMMENT$ebnf$1", "symbols": ["COMMENT$ebnf$1", /[^\n]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
368
- {"name": "COMMENT", "symbols": [{"literal":";"}, "COMMENT$ebnf$1"]},
369
- {"name": "annotation$string$1", "symbols": [{"literal":"!"}, {"literal":"!"}], "postprocess": function joiner(d) {return d.join('');}},
370
- {"name": "annotation", "symbols": ["annotation$string$1"], "postprocess": id},
371
- {"name": "annotation", "symbols": [{"literal":"!"}], "postprocess": id},
372
- {"name": "annotation$string$2", "symbols": [{"literal":"!"}, {"literal":"?"}], "postprocess": function joiner(d) {return d.join('');}},
373
- {"name": "annotation", "symbols": ["annotation$string$2"], "postprocess": id},
374
- {"name": "annotation$string$3", "symbols": [{"literal":"?"}, {"literal":"!"}], "postprocess": function joiner(d) {return d.join('');}},
375
- {"name": "annotation", "symbols": ["annotation$string$3"], "postprocess": id},
376
- {"name": "annotation", "symbols": [{"literal":"?"}], "postprocess": id},
377
- {"name": "annotation$string$4", "symbols": [{"literal":"?"}, {"literal":"?"}], "postprocess": function joiner(d) {return d.join('');}},
378
- {"name": "annotation", "symbols": ["annotation$string$4"], "postprocess": id},
379
- {"name": "annotation$string$5", "symbols": [{"literal":"+"}, {"literal":"-"}], "postprocess": function joiner(d) {return d.join('');}},
380
- {"name": "annotation", "symbols": ["annotation$string$5"], "postprocess": id},
381
- {"name": "annotation$string$6", "symbols": [{"literal":"-"}, {"literal":"+"}], "postprocess": function joiner(d) {return d.join('');}},
382
- {"name": "annotation", "symbols": ["annotation$string$6"], "postprocess": id},
383
- {"name": "annotation", "symbols": [{"literal":"="}], "postprocess": id},
384
- {"name": "annotation$string$7", "symbols": [{"literal":"?"}, {"literal":"!"}], "postprocess": function joiner(d) {return d.join('');}},
385
- {"name": "annotation", "symbols": ["annotation$string$7"], "postprocess": id},
386
- {"name": "annotation", "symbols": [{"literal":"?"}], "postprocess": id},
387
- {"name": "annotation$string$8", "symbols": [{"literal":"?"}, {"literal":"?"}], "postprocess": function joiner(d) {return d.join('');}},
388
- {"name": "annotation", "symbols": ["annotation$string$8"], "postprocess": id},
389
- {"name": "annotation", "symbols": [{"literal":"±"}], "postprocess": id},
390
- {"name": "annotation", "symbols": [{"literal":"∓"}], "postprocess": id},
391
- {"name": "annotation", "symbols": [{"literal":"∞"}], "postprocess": id},
392
- {"name": "annotation", "symbols": [{"literal":"⨀"}], "postprocess": id},
393
- {"name": "annotation", "symbols": [{"literal":"⩱"}], "postprocess": id},
394
- {"name": "annotation", "symbols": [{"literal":"⩲"}], "postprocess": id},
395
- {"name": "check", "symbols": [{"literal":"+"}], "postprocess": () => 'check'},
396
- {"name": "checkmate", "symbols": [{"literal":"#"}], "postprocess": () => 'checkmate'},
397
- {"name": "bstring$ebnf$1", "symbols": []},
398
- {"name": "bstring$ebnf$1", "symbols": ["bstring$ebnf$1", /[^}]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
399
- {"name": "bstring", "symbols": [{"literal":"{"}, "bstring$ebnf$1", {"literal":"}"}], "postprocess": (d) => d[1].join('')},
400
- {"name": "capture", "symbols": [{"literal":"x"}]},
401
- {"name": "castling$string$1", "symbols": [{"literal":"O"}, {"literal":"-"}, {"literal":"O"}], "postprocess": function joiner(d) {return d.join('');}},
402
- {"name": "castling", "symbols": ["castling$string$1"], "postprocess": () => 'K'},
403
- {"name": "castling$string$2", "symbols": [{"literal":"O"}, {"literal":"-"}, {"literal":"O"}, {"literal":"-"}, {"literal":"O"}], "postprocess": function joiner(d) {return d.join('');}},
404
- {"name": "castling", "symbols": ["castling$string$2"], "postprocess": () => 'Q'},
405
- {"name": "continuation$string$1", "symbols": [{"literal":"."}, {"literal":"."}, {"literal":"."}], "postprocess": function joiner(d) {return d.join('');}},
406
- {"name": "continuation", "symbols": ["continuation$string$1"]},
407
- {"name": "file", "symbols": [/[a-h]/]},
408
- {"name": "piece", "symbols": [/[KQBNR]/]},
409
- {"name": "rank", "symbols": [/[1-8]/]},
410
- {"name": "result$string$1", "symbols": [{"literal":"1"}, {"literal":"-"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
411
- {"name": "result", "symbols": ["result$string$1"], "postprocess": () => 1},
412
- {"name": "result$string$2", "symbols": [{"literal":"0"}, {"literal":"-"}, {"literal":"1"}], "postprocess": function joiner(d) {return d.join('');}},
413
- {"name": "result", "symbols": ["result$string$2"], "postprocess": () => 0},
414
- {"name": "result$string$3", "symbols": [{"literal":"1"}, {"literal":"/"}, {"literal":"2"}, {"literal":"-"}, {"literal":"1"}, {"literal":"/"}, {"literal":"2"}], "postprocess": function joiner(d) {return d.join('');}},
415
- {"name": "result", "symbols": ["result$string$3"], "postprocess": () => 0.5},
416
- {"name": "result", "symbols": [{"literal":"*"}], "postprocess": () => '?'},
417
- {"name": "string$ebnf$1", "symbols": [/[^\s]/]},
418
- {"name": "string$ebnf$1", "symbols": ["string$ebnf$1", /[^\s]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
419
- {"name": "string", "symbols": ["string$ebnf$1"], "postprocess": (d) => d[0].join('')}
420
- ]
421
- , ParserStart: "DATABASE"
422
- }
423
- if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') {
424
- module.exports = grammar;
425
- } else {
426
- window.grammar = grammar;
427
- }
428
- })();