@gmb/bitmark-parser-generator 1.5.11 → 1.5.13
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/browser/bitmark-parser-generator.min.js +1 -1
- package/dist/browser/bundle-report.html +2 -2
- package/dist/cjs/ast/Ast.js +13 -13
- package/dist/cjs/ast/Ast.js.map +1 -1
- package/dist/cjs/ast/Builder.js +1 -1
- package/dist/cjs/ast/Builder.js.map +1 -1
- package/dist/cjs/generated/build-info.js +1 -1
- package/dist/cjs/generated/parser/text/text-peggy-parser.js +1126 -651
- package/dist/cjs/generated/parser/text/text-peggy-parser.js.map +1 -1
- package/dist/cjs/generator/AstWalkerGenerator.js +83 -0
- package/dist/cjs/generator/AstWalkerGenerator.js.map +1 -0
- package/dist/cjs/generator/bitmark/BitmarkGenerator.js +144 -180
- package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
- package/dist/cjs/generator/json/JsonGenerator.js +84 -114
- package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
- package/dist/cjs/generator/text/TextGenerator.js +91 -124
- package/dist/cjs/generator/text/TextGenerator.js.map +1 -1
- package/dist/cjs/model/enum/TextMarkType.js +13 -2
- package/dist/cjs/model/enum/TextMarkType.js.map +1 -1
- package/dist/cjs/model/enum/TextNodeType.js +1 -0
- package/dist/cjs/model/enum/TextNodeType.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +20 -10
- package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
- package/dist/cjs/parser/json/JsonParser.js +1 -1
- package/dist/cjs/parser/json/JsonParser.js.map +1 -1
- package/dist/esm/ast/Ast.js +13 -13
- package/dist/esm/ast/Ast.js.map +1 -1
- package/dist/esm/ast/Builder.js +1 -1
- package/dist/esm/ast/Builder.js.map +1 -1
- package/dist/esm/generated/build-info.js +1 -1
- package/dist/esm/generated/parser/text/text-peggy-parser.js +1126 -651
- package/dist/esm/generated/parser/text/text-peggy-parser.js.map +1 -1
- package/dist/esm/generator/AstWalkerGenerator.js +80 -0
- package/dist/esm/generator/AstWalkerGenerator.js.map +1 -0
- package/dist/esm/generator/bitmark/BitmarkGenerator.js +144 -180
- package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
- package/dist/esm/generator/json/JsonGenerator.js +84 -114
- package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
- package/dist/esm/generator/text/TextGenerator.js +91 -124
- package/dist/esm/generator/text/TextGenerator.js.map +1 -1
- package/dist/esm/model/enum/TextMarkType.js +13 -2
- package/dist/esm/model/enum/TextMarkType.js.map +1 -1
- package/dist/esm/model/enum/TextNodeType.js +1 -0
- package/dist/esm/model/enum/TextNodeType.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +20 -10
- package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
- package/dist/esm/parser/json/JsonParser.js +1 -1
- package/dist/esm/parser/json/JsonParser.js.map +1 -1
- package/dist/types/ast/Ast.d.ts +4 -8
- package/dist/types/ast/Ast.d.ts.map +1 -1
- package/dist/types/generated/parser/text/text-peggy-parser.d.ts.map +1 -1
- package/dist/types/generator/AstWalkerGenerator.d.ts +32 -0
- package/dist/types/generator/AstWalkerGenerator.d.ts.map +1 -0
- package/dist/types/generator/Generator.d.ts +2 -2
- package/dist/types/generator/Generator.d.ts.map +1 -1
- package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +121 -127
- package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
- package/dist/types/generator/json/JsonGenerator.d.ts +43 -48
- package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
- package/dist/types/generator/text/TextGenerator.d.ts +13 -17
- package/dist/types/generator/text/TextGenerator.d.ts.map +1 -1
- package/dist/types/model/enum/TextMarkType.d.ts +26 -4
- package/dist/types/model/enum/TextMarkType.d.ts.map +1 -1
- package/dist/types/model/enum/TextNodeType.d.ts +2 -0
- package/dist/types/model/enum/TextNodeType.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
- package/package.json +13 -13
|
@@ -35,15 +35,16 @@ import { ArrayUtils } from '../../utils/ArrayUtils';
|
|
|
35
35
|
import { BooleanUtils } from '../../utils/BooleanUtils';
|
|
36
36
|
import { StringUtils } from '../../utils/StringUtils';
|
|
37
37
|
import { UrlUtils } from '../../utils/UrlUtils';
|
|
38
|
+
import { AstWalkerGenerator } from '../AstWalkerGenerator';
|
|
38
39
|
const DEFAULT_OPTIONS = {
|
|
39
40
|
// debugGenerationInline: true,
|
|
40
41
|
};
|
|
41
42
|
/**
|
|
42
43
|
* Generate bitmark JSON from a bitmark AST
|
|
43
44
|
*
|
|
44
|
-
*
|
|
45
|
+
*
|
|
45
46
|
*/
|
|
46
|
-
class JsonGenerator {
|
|
47
|
+
class JsonGenerator extends AstWalkerGenerator {
|
|
47
48
|
/**
|
|
48
49
|
* Generate bitmark JSON from a bitmark AST
|
|
49
50
|
*
|
|
@@ -51,7 +52,8 @@ class JsonGenerator {
|
|
|
51
52
|
* @param options - JSON generation options
|
|
52
53
|
*/
|
|
53
54
|
constructor(writer, options) {
|
|
54
|
-
var _a;
|
|
55
|
+
var _a, _b;
|
|
56
|
+
super();
|
|
55
57
|
this.ast = new Ast();
|
|
56
58
|
this.textParser = new TextParser();
|
|
57
59
|
// State
|
|
@@ -62,10 +64,9 @@ class JsonGenerator {
|
|
|
62
64
|
this.bodyDefault = Breakscape.EMPTY_STRING;
|
|
63
65
|
this.bodyJson = this.bodyDefault;
|
|
64
66
|
this.startPlaceholderIndex = 0;
|
|
65
|
-
// Debug
|
|
66
|
-
this.printed = false;
|
|
67
67
|
this.bitmarkVersion = (_a = BitmarkVersion.fromValue(options === null || options === void 0 ? void 0 : options.bitmarkVersion)) !== null && _a !== void 0 ? _a : DEFAULT_BITMARK_VERSION;
|
|
68
68
|
this.options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options === null || options === void 0 ? void 0 : options.jsonOptions);
|
|
69
|
+
this.debugGenerationInline = (_b = this.options.debugGenerationInline) !== null && _b !== void 0 ? _b : false;
|
|
69
70
|
this.jsonPrettifySpace = this.options.prettify === true ? 2 : this.options.prettify || undefined;
|
|
70
71
|
// Set defaults according to bitmark version
|
|
71
72
|
if (this.bitmarkVersion === BitmarkVersion.v2) {
|
|
@@ -133,55 +134,6 @@ class JsonGenerator {
|
|
|
133
134
|
// Walk the bitmark AST
|
|
134
135
|
this.ast.walk(ast, NodeType.bitmarkAst, this, undefined);
|
|
135
136
|
}
|
|
136
|
-
enter(node, parent, route) {
|
|
137
|
-
let res = void 0;
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
-
const gen = this;
|
|
140
|
-
const funcName = `enter_${node.key}`;
|
|
141
|
-
if (!this.printed) {
|
|
142
|
-
this.printed = true;
|
|
143
|
-
}
|
|
144
|
-
if (this.options.debugGenerationInline)
|
|
145
|
-
this.writeInlineDebug(node.key, { open: true });
|
|
146
|
-
if (typeof gen[funcName] === 'function') {
|
|
147
|
-
res = gen[funcName](node, parent, route);
|
|
148
|
-
}
|
|
149
|
-
return res;
|
|
150
|
-
}
|
|
151
|
-
between(node, left, right, parent, route) {
|
|
152
|
-
let res = void 0;
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
|
-
const gen = this;
|
|
155
|
-
const funcName = `between_${node.key}`;
|
|
156
|
-
if (this.options.debugGenerationInline)
|
|
157
|
-
this.writeInlineDebug(node.key, { single: true });
|
|
158
|
-
if (typeof gen[funcName] === 'function') {
|
|
159
|
-
res = gen[funcName](node, left, right, parent, route);
|
|
160
|
-
}
|
|
161
|
-
return res;
|
|
162
|
-
}
|
|
163
|
-
exit(node, parent, route) {
|
|
164
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
|
-
const gen = this;
|
|
166
|
-
const funcName = `exit_${node.key}`;
|
|
167
|
-
if (this.options.debugGenerationInline)
|
|
168
|
-
this.writeInlineDebug(node.key, { close: true });
|
|
169
|
-
if (typeof gen[funcName] === 'function') {
|
|
170
|
-
gen[funcName](node, parent, route);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
leaf(node, parent, route) {
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
|
-
const gen = this;
|
|
176
|
-
const funcName = `leaf_${node.key}`;
|
|
177
|
-
if (this.options.debugGenerationInline)
|
|
178
|
-
this.writeInlineDebug(node.key, { open: true });
|
|
179
|
-
if (typeof gen[funcName] === 'function') {
|
|
180
|
-
gen[funcName](node, parent, route);
|
|
181
|
-
}
|
|
182
|
-
if (this.options.debugGenerationInline)
|
|
183
|
-
this.writeInlineDebug(node.key, { close: true });
|
|
184
|
-
}
|
|
185
137
|
//
|
|
186
138
|
// NODE HANDLERS
|
|
187
139
|
//
|
|
@@ -189,13 +141,13 @@ class JsonGenerator {
|
|
|
189
141
|
// Non-Terminal nodes (branches)
|
|
190
142
|
//
|
|
191
143
|
// bitmark
|
|
192
|
-
enter_bitmarkAst(_node,
|
|
144
|
+
enter_bitmarkAst(_node, _route) {
|
|
193
145
|
// Reset the JSON
|
|
194
146
|
this.json = [];
|
|
195
147
|
}
|
|
196
148
|
// bitmarkAst -> bits
|
|
197
149
|
// bitmarkAst -> bits -> bitsValue
|
|
198
|
-
enter_bitsValue(node,
|
|
150
|
+
enter_bitsValue(node, _route) {
|
|
199
151
|
var _a, _b, _c;
|
|
200
152
|
const bit = node.value;
|
|
201
153
|
// Reset
|
|
@@ -239,14 +191,15 @@ class JsonGenerator {
|
|
|
239
191
|
this.bitJson.isExample = true;
|
|
240
192
|
}
|
|
241
193
|
}
|
|
242
|
-
exit_bitsValue(_node,
|
|
194
|
+
exit_bitsValue(_node, _route) {
|
|
243
195
|
// Clean up the bit JSON, removing any unwanted values
|
|
244
196
|
this.cleanAndSetDefaultsForBitJson(this.bitJson);
|
|
245
197
|
}
|
|
246
198
|
// bitmarkAst -> bits -> bitsValue -> imageSource
|
|
247
|
-
enter_imageSource(node,
|
|
199
|
+
enter_imageSource(node, route) {
|
|
248
200
|
const imageSource = node.value;
|
|
249
201
|
// Ignore values that are not at the bit level as they might be handled elsewhere
|
|
202
|
+
const parent = this.getParentNode(route);
|
|
250
203
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
|
|
251
204
|
return;
|
|
252
205
|
const { url, mockupId, size, format, trim } = imageSource;
|
|
@@ -259,10 +212,11 @@ class JsonGenerator {
|
|
|
259
212
|
this.bitJson.imageSource = imageSourceJson;
|
|
260
213
|
}
|
|
261
214
|
// bitmarkAst -> bits -> bitsValue -> partner
|
|
262
|
-
enter_partner(node,
|
|
215
|
+
enter_partner(node, route) {
|
|
263
216
|
const partner = node.value;
|
|
264
217
|
const bitType = this.getBitType(route);
|
|
265
218
|
// Ignore values that are not at the bit level as they might be handled elsewhere
|
|
219
|
+
const parent = this.getParentNode(route);
|
|
266
220
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue || !bitType)
|
|
267
221
|
return;
|
|
268
222
|
const { name, avatarImage } = partner;
|
|
@@ -277,9 +231,10 @@ class JsonGenerator {
|
|
|
277
231
|
this.bitJson.partner = partnerJson;
|
|
278
232
|
}
|
|
279
233
|
// bitmarkAst -> bits -> bitsValue -> markConfig -> markConfigValue
|
|
280
|
-
enter_markConfigValue(node,
|
|
234
|
+
enter_markConfigValue(node, route) {
|
|
281
235
|
const markConfig = node.value;
|
|
282
236
|
// Ignore example that is not at the correct level
|
|
237
|
+
const parent = this.getParentNode(route);
|
|
283
238
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.markConfig)
|
|
284
239
|
return;
|
|
285
240
|
const { mark, color, emphasis } = markConfig;
|
|
@@ -294,18 +249,20 @@ class JsonGenerator {
|
|
|
294
249
|
this.bitJson.marks.push(markJson);
|
|
295
250
|
}
|
|
296
251
|
// bitmarkAst -> bits -> bitsValue -> sampleSolution
|
|
297
|
-
leaf_sampleSolution(node,
|
|
252
|
+
leaf_sampleSolution(node, route) {
|
|
298
253
|
// Ignore example that is not at the correct level
|
|
254
|
+
const parent = this.getParentNode(route);
|
|
299
255
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
|
|
300
256
|
return;
|
|
301
257
|
if (node.value != null)
|
|
302
258
|
this.addProperty(this.bitJson, 'sampleSolution', node.value, true);
|
|
303
259
|
}
|
|
304
260
|
// bitmarkAst -> bits -> bitsValue -> itemLead
|
|
305
|
-
enter_itemLead(node,
|
|
261
|
+
enter_itemLead(node, route) {
|
|
306
262
|
const itemLead = node.value;
|
|
307
263
|
const { item, lead, pageNumber, marginNumber } = itemLead;
|
|
308
264
|
// Ignore item / lead that are not at the bit level as they are handled elsewhere
|
|
265
|
+
const parent = this.getParentNode(route);
|
|
309
266
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
|
|
310
267
|
return;
|
|
311
268
|
if (item != null) {
|
|
@@ -322,7 +279,7 @@ class JsonGenerator {
|
|
|
322
279
|
}
|
|
323
280
|
}
|
|
324
281
|
// bitmarkAst -> bits -> bitsValue -> extraProperties
|
|
325
|
-
enter_extraProperties(node,
|
|
282
|
+
enter_extraProperties(node, _route) {
|
|
326
283
|
const extraProperties = node.value;
|
|
327
284
|
if (!this.options.excludeUnknownProperties && extraProperties) {
|
|
328
285
|
for (const [key, values] of Object.entries(extraProperties)) {
|
|
@@ -335,7 +292,7 @@ class JsonGenerator {
|
|
|
335
292
|
}
|
|
336
293
|
}
|
|
337
294
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> cardBits -> cardBitsValue
|
|
338
|
-
enter_cardBitsValue(node,
|
|
295
|
+
enter_cardBitsValue(node, route) {
|
|
339
296
|
// How cardBits are handled depends on the bit type
|
|
340
297
|
const bitType = this.getBitType(route);
|
|
341
298
|
if (!bitType)
|
|
@@ -363,14 +320,15 @@ class JsonGenerator {
|
|
|
363
320
|
delete li.marginNumber;
|
|
364
321
|
listItems.push(this.listItem);
|
|
365
322
|
}
|
|
366
|
-
exit_cardBitsValue(_node,
|
|
323
|
+
exit_cardBitsValue(_node, _route) {
|
|
367
324
|
this.listItem = undefined;
|
|
368
325
|
}
|
|
369
326
|
// bitmarkAst -> bits -> bitsValue -> body
|
|
370
|
-
enter_body(_node,
|
|
327
|
+
enter_body(_node, _route) {
|
|
371
328
|
this.bodyJson = this.bodyDefault;
|
|
372
329
|
}
|
|
373
|
-
exit_body(_node,
|
|
330
|
+
exit_body(_node, route) {
|
|
331
|
+
const parent = this.getParentNode(route);
|
|
374
332
|
if (!parent)
|
|
375
333
|
return;
|
|
376
334
|
if (parent.key === NodeType.bitsValue) {
|
|
@@ -384,7 +342,7 @@ class JsonGenerator {
|
|
|
384
342
|
}
|
|
385
343
|
}
|
|
386
344
|
// bitmarkAst -> bits -> bitsValue -> * -> bodyParts (body, cardBody (e.g. cloze-list, page-footer))
|
|
387
|
-
enter_bodyParts(node,
|
|
345
|
+
enter_bodyParts(node, route) {
|
|
388
346
|
const bodyParts = node.value;
|
|
389
347
|
const plainText = this.options.textAsPlainText;
|
|
390
348
|
const textFormat = this.getTextFormat(route);
|
|
@@ -486,7 +444,7 @@ class JsonGenerator {
|
|
|
486
444
|
return false;
|
|
487
445
|
}
|
|
488
446
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> elements
|
|
489
|
-
enter_elements(node,
|
|
447
|
+
enter_elements(node, _route) {
|
|
490
448
|
const elements = node.value;
|
|
491
449
|
// Ignore elements that are not at the bit level as they are handled elsewhere as quizzes
|
|
492
450
|
// if (parent?.key !== NodeType.bitsValue) return;
|
|
@@ -495,10 +453,11 @@ class JsonGenerator {
|
|
|
495
453
|
}
|
|
496
454
|
}
|
|
497
455
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue
|
|
498
|
-
enter_flashcards(node,
|
|
456
|
+
enter_flashcards(node, route) {
|
|
499
457
|
var _a, _b, _c, _d, _e, _f;
|
|
500
458
|
const flashcards = node.value;
|
|
501
459
|
// Ignore responses that are not at the correct level as they are potentially handled elsewhere
|
|
460
|
+
const parent = this.getParentNode(route);
|
|
502
461
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
|
|
503
462
|
return;
|
|
504
463
|
const flashcardsJson = [];
|
|
@@ -524,10 +483,11 @@ class JsonGenerator {
|
|
|
524
483
|
}
|
|
525
484
|
}
|
|
526
485
|
// bitmarkAst -> bits -> bitsValue -> statement
|
|
527
|
-
enter_statement(node,
|
|
486
|
+
enter_statement(node, route) {
|
|
528
487
|
var _a, _b;
|
|
529
488
|
const statement = node.value;
|
|
530
489
|
// Ignore statement that is not at the cardNode level as it is handled elsewhere
|
|
490
|
+
const parent = this.getParentNode(route);
|
|
531
491
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
|
|
532
492
|
return;
|
|
533
493
|
if (statement) {
|
|
@@ -536,10 +496,11 @@ class JsonGenerator {
|
|
|
536
496
|
}
|
|
537
497
|
}
|
|
538
498
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> statements -> statementsValue
|
|
539
|
-
enter_statements(node,
|
|
499
|
+
enter_statements(node, route) {
|
|
540
500
|
var _a, _b, _c, _d, _e;
|
|
541
501
|
const statements = node.value;
|
|
542
502
|
// Ignore statements that are not at the card node level as they are handled elsewhere
|
|
503
|
+
const parent = this.getParentNode(route);
|
|
543
504
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
|
|
544
505
|
return;
|
|
545
506
|
const statementsJson = [];
|
|
@@ -572,10 +533,11 @@ class JsonGenerator {
|
|
|
572
533
|
}
|
|
573
534
|
// bitmarkAst -> bits -> bitsValue -> choices
|
|
574
535
|
// X bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices
|
|
575
|
-
enter_choices(node,
|
|
536
|
+
enter_choices(node, route) {
|
|
576
537
|
var _a, _b, _c, _d, _e;
|
|
577
538
|
const choices = node.value;
|
|
578
539
|
// Ignore choices that are not at the bit level as they are handled elsewhere as quizzes
|
|
540
|
+
const parent = this.getParentNode(route);
|
|
579
541
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
|
|
580
542
|
return;
|
|
581
543
|
const choicesJson = [];
|
|
@@ -602,10 +564,11 @@ class JsonGenerator {
|
|
|
602
564
|
}
|
|
603
565
|
// bitmarkAst -> bits -> bitsValue -> responses
|
|
604
566
|
// X bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses
|
|
605
|
-
enter_responses(node,
|
|
567
|
+
enter_responses(node, route) {
|
|
606
568
|
var _a, _b, _c, _d, _e;
|
|
607
569
|
const responses = node.value;
|
|
608
570
|
// Ignore responses that are not at the correct level as they are handled elsewhere as quizzes
|
|
571
|
+
const parent = this.getParentNode(route);
|
|
609
572
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
|
|
610
573
|
return;
|
|
611
574
|
const responsesJson = [];
|
|
@@ -631,7 +594,7 @@ class JsonGenerator {
|
|
|
631
594
|
}
|
|
632
595
|
}
|
|
633
596
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes
|
|
634
|
-
enter_quizzes(node,
|
|
597
|
+
enter_quizzes(node, _route) {
|
|
635
598
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
636
599
|
const quizzes = node.value;
|
|
637
600
|
const quizzesJson = [];
|
|
@@ -692,39 +655,38 @@ class JsonGenerator {
|
|
|
692
655
|
}
|
|
693
656
|
}
|
|
694
657
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> heading
|
|
695
|
-
enter_heading(node,
|
|
696
|
-
var _a
|
|
658
|
+
enter_heading(node, _route) {
|
|
659
|
+
var _a;
|
|
697
660
|
const heading = node.value;
|
|
698
|
-
//
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
valid = true;
|
|
702
|
-
}
|
|
703
|
-
if (!valid)
|
|
704
|
-
return false;
|
|
661
|
+
// Check if the heading is for a match or a match matrix
|
|
662
|
+
const bitType = this.getBitType(_route);
|
|
663
|
+
const isMatrix = Config.isOfBitType(bitType, BitType.matchMatrix);
|
|
705
664
|
// Create the heading
|
|
706
665
|
const headingJson = {
|
|
707
666
|
forKeys: (_a = Breakscape.unbreakscape(heading.forKeys)) !== null && _a !== void 0 ? _a : '',
|
|
708
667
|
};
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
headingJson.forValues = Breakscape.unbreakscape(heading.forValues);
|
|
668
|
+
if (isMatrix) {
|
|
669
|
+
// Matrix match, forValues is an array
|
|
670
|
+
headingJson.forValues = [];
|
|
671
|
+
if (Array.isArray(heading.forValues)) {
|
|
672
|
+
if (heading.forValues.length >= 1) {
|
|
673
|
+
headingJson.forValues = Breakscape.unbreakscape(heading.forValues);
|
|
674
|
+
}
|
|
719
675
|
}
|
|
720
676
|
}
|
|
721
677
|
else {
|
|
722
|
-
|
|
678
|
+
// Standard match, forValues is a string
|
|
679
|
+
headingJson.forValues = '';
|
|
680
|
+
if (Array.isArray(heading.forValues)) {
|
|
681
|
+
if (heading.forValues.length >= 1) {
|
|
682
|
+
headingJson.forValues = Breakscape.unbreakscape(heading.forValues[heading.forValues.length - 1]);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
723
685
|
}
|
|
724
686
|
this.bitJson.heading = headingJson;
|
|
725
687
|
}
|
|
726
688
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> pairs
|
|
727
|
-
enter_pairs(node,
|
|
689
|
+
enter_pairs(node, route) {
|
|
728
690
|
var _a, _b, _c, _d, _e, _f;
|
|
729
691
|
const pairs = node.value;
|
|
730
692
|
const pairsJson = [];
|
|
@@ -765,7 +727,7 @@ class JsonGenerator {
|
|
|
765
727
|
}
|
|
766
728
|
}
|
|
767
729
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> matrix
|
|
768
|
-
enter_matrix(node,
|
|
730
|
+
enter_matrix(node, _route) {
|
|
769
731
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
770
732
|
const matrix = node.value;
|
|
771
733
|
const matrixJsonArray = [];
|
|
@@ -815,7 +777,7 @@ class JsonGenerator {
|
|
|
815
777
|
}
|
|
816
778
|
}
|
|
817
779
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> questions
|
|
818
|
-
enter_questions(node,
|
|
780
|
+
enter_questions(node, _route) {
|
|
819
781
|
var _a, _b, _c, _d, _e, _f;
|
|
820
782
|
const questions = node.value;
|
|
821
783
|
const questionsJson = [];
|
|
@@ -841,10 +803,11 @@ class JsonGenerator {
|
|
|
841
803
|
}
|
|
842
804
|
}
|
|
843
805
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses
|
|
844
|
-
enter_botResponses(node,
|
|
806
|
+
enter_botResponses(node, route) {
|
|
845
807
|
var _a, _b, _c, _d, _e, _f;
|
|
846
808
|
const botResponses = node.value;
|
|
847
809
|
// Ignore responses that are not at the cardNode level as they are handled elsewhere
|
|
810
|
+
const parent = this.getParentNode(route);
|
|
848
811
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
|
|
849
812
|
return;
|
|
850
813
|
const responsesJson = [];
|
|
@@ -871,7 +834,7 @@ class JsonGenerator {
|
|
|
871
834
|
}
|
|
872
835
|
}
|
|
873
836
|
// bitmarkAst -> bits -> bitsValue -> resources
|
|
874
|
-
enter_resources(node,
|
|
837
|
+
enter_resources(node, route) {
|
|
875
838
|
var _a;
|
|
876
839
|
const resources = node.value;
|
|
877
840
|
const bitType = this.getBitType(route);
|
|
@@ -937,71 +900,74 @@ class JsonGenerator {
|
|
|
937
900
|
// Terminal nodes (leaves)
|
|
938
901
|
//
|
|
939
902
|
// bitmarkAst -> bits -> bitsValue -> title
|
|
940
|
-
leaf_title(node,
|
|
903
|
+
leaf_title(node, _route) {
|
|
941
904
|
this.bitJson.title = this.convertBreakscapedStringToJsonText(node.value, TextFormat.bitmarkMinusMinus);
|
|
942
905
|
}
|
|
943
906
|
// bitmarkAst -> bits -> bitsValue -> subtitle
|
|
944
|
-
leaf_subtitle(node,
|
|
907
|
+
leaf_subtitle(node, _route) {
|
|
945
908
|
this.bitJson.subtitle = this.convertBreakscapedStringToJsonText(node.value, TextFormat.bitmarkMinusMinus);
|
|
946
909
|
}
|
|
947
910
|
// // bitmarkAst -> bits -> bitsValue -> level
|
|
948
|
-
leaf_level(node,
|
|
911
|
+
leaf_level(node, _route) {
|
|
949
912
|
var _a;
|
|
950
913
|
if (node.value != null)
|
|
951
914
|
this.addProperty(this.bitJson, 'level', (_a = node.value) !== null && _a !== void 0 ? _a : 1, true);
|
|
952
915
|
}
|
|
953
916
|
// bitmarkAst -> bits -> bitsValue -> book
|
|
954
|
-
leaf_book(node,
|
|
917
|
+
leaf_book(node, _route) {
|
|
955
918
|
if (node.value != null)
|
|
956
919
|
this.addProperty(this.bitJson, 'book', node.value, true);
|
|
957
920
|
}
|
|
958
921
|
// bitmarkAst -> bits -> bitsValue -> anchor
|
|
959
|
-
leaf_anchor(node,
|
|
922
|
+
leaf_anchor(node, _route) {
|
|
960
923
|
if (node.value != null)
|
|
961
924
|
this.addProperty(this.bitJson, 'anchor', node.value, true);
|
|
962
925
|
}
|
|
963
926
|
// bitmarkAst -> bits -> bitsValue -> reference
|
|
964
|
-
leaf_reference(node,
|
|
927
|
+
leaf_reference(node, _route) {
|
|
965
928
|
if (node.value != null)
|
|
966
929
|
this.addProperty(this.bitJson, 'reference', node.value, true);
|
|
967
930
|
}
|
|
968
931
|
// bitmarkAst -> bits -> bitsValue -> referenceEnd
|
|
969
|
-
leaf_referenceEnd(node,
|
|
932
|
+
leaf_referenceEnd(node, _route) {
|
|
970
933
|
if (node.value != null)
|
|
971
934
|
this.addProperty(this.bitJson, 'referenceEnd', node.value, true);
|
|
972
935
|
}
|
|
973
936
|
// bitmarkAst -> bits -> bitsValue -> * -> hint
|
|
974
|
-
leaf_hint(node,
|
|
937
|
+
leaf_hint(node, route) {
|
|
975
938
|
const hint = node.value;
|
|
976
939
|
// Ignore hint that is not at the bit level as it are handled elsewhere
|
|
940
|
+
const parent = this.getParentNode(route);
|
|
977
941
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
|
|
978
942
|
return;
|
|
979
943
|
this.bitJson.hint = this.convertBreakscapedStringToJsonText(hint, TextFormat.bitmarkMinusMinus);
|
|
980
944
|
}
|
|
981
945
|
// bitmarkAst -> bits -> bitsValue -> * -> instruction
|
|
982
|
-
leaf_instruction(node,
|
|
946
|
+
leaf_instruction(node, route) {
|
|
983
947
|
const instruction = node.value;
|
|
984
948
|
// Ignore instruction that is not at the bit level as it are handled elsewhere
|
|
949
|
+
const parent = this.getParentNode(route);
|
|
985
950
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
|
|
986
951
|
return;
|
|
987
952
|
this.bitJson.instruction = this.convertBreakscapedStringToJsonText(instruction, TextFormat.bitmarkMinusMinus);
|
|
988
953
|
}
|
|
989
954
|
// bitmarkAst -> bits -> footer -> footerText
|
|
990
|
-
leaf_footerText(node,
|
|
955
|
+
leaf_footerText(node, _route) {
|
|
991
956
|
const footer = node.value;
|
|
992
957
|
this.bitJson.footer = this.convertBreakscapedStringToJsonText(footer, TextFormat.bitmarkMinusMinus);
|
|
993
958
|
}
|
|
994
959
|
// bitmarkAst -> bits -> bitsValue -> markup
|
|
995
|
-
leaf_markup(node,
|
|
960
|
+
leaf_markup(node, _route) {
|
|
996
961
|
const bitmark = node.value;
|
|
997
962
|
if (bitmark)
|
|
998
963
|
this.bitWrapperJson.bitmark = bitmark;
|
|
999
964
|
}
|
|
1000
965
|
// bitmarkAst -> bits -> bitsValue -> parser
|
|
1001
966
|
// bitmarkAst -> bits -> bitsValue -> * -> internalComment
|
|
1002
|
-
enter_parser(node,
|
|
967
|
+
enter_parser(node, route) {
|
|
1003
968
|
const parser = node.value;
|
|
1004
969
|
const bitType = this.getBitType(route);
|
|
970
|
+
const parent = this.getParentNode(route);
|
|
1005
971
|
if (parser && bitType) {
|
|
1006
972
|
const { version, excessResources: parserExcessResources, warnings, errors } = parser, parserRest = __rest(parser, ["version", "excessResources", "warnings", "errors"]);
|
|
1007
973
|
const bitmarkVersion = `${this.bitmarkVersion}`;
|
|
@@ -1039,7 +1005,7 @@ class JsonGenerator {
|
|
|
1039
1005
|
}
|
|
1040
1006
|
}
|
|
1041
1007
|
// bitmarkAst -> errors
|
|
1042
|
-
// protected enter_errors(node: NodeInfo,
|
|
1008
|
+
// protected enter_errors(node: NodeInfo, _route: NodeInfo[],
|
|
1043
1009
|
// context: Context): void {
|
|
1044
1010
|
// const errors = node.value as ParserError[] | undefined;
|
|
1045
1011
|
// if (errors && errors.length > 0) {
|
|
@@ -1074,13 +1040,14 @@ class JsonGenerator {
|
|
|
1074
1040
|
continue;
|
|
1075
1041
|
const funcName = `enter_${astKey}`;
|
|
1076
1042
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1077
|
-
this[funcName] = (node,
|
|
1043
|
+
this[funcName] = (node, route) => {
|
|
1078
1044
|
var _a;
|
|
1079
1045
|
const value = node.value;
|
|
1080
1046
|
if (value == null)
|
|
1081
1047
|
return;
|
|
1082
1048
|
// if (key === 'progress') debugger;
|
|
1083
1049
|
// Ignore any property that is not at the bit level as that will be handled by a different handler
|
|
1050
|
+
const parent = this.getParentNode(route);
|
|
1084
1051
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
|
|
1085
1052
|
return;
|
|
1086
1053
|
// Convert key as needed
|
|
@@ -1748,6 +1715,9 @@ class JsonGenerator {
|
|
|
1748
1715
|
// }
|
|
1749
1716
|
}
|
|
1750
1717
|
}
|
|
1718
|
+
//
|
|
1719
|
+
// Helper functions
|
|
1720
|
+
//
|
|
1751
1721
|
/**
|
|
1752
1722
|
* Get the value for the zoomDisabled property, setting the appropriate default value if no value is set.
|
|
1753
1723
|
*
|