@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
|
@@ -38,15 +38,16 @@ const ArrayUtils_1 = require("../../utils/ArrayUtils");
|
|
|
38
38
|
const BooleanUtils_1 = require("../../utils/BooleanUtils");
|
|
39
39
|
const StringUtils_1 = require("../../utils/StringUtils");
|
|
40
40
|
const UrlUtils_1 = require("../../utils/UrlUtils");
|
|
41
|
+
const AstWalkerGenerator_1 = require("../AstWalkerGenerator");
|
|
41
42
|
const DEFAULT_OPTIONS = {
|
|
42
43
|
// debugGenerationInline: true,
|
|
43
44
|
};
|
|
44
45
|
/**
|
|
45
46
|
* Generate bitmark JSON from a bitmark AST
|
|
46
47
|
*
|
|
47
|
-
*
|
|
48
|
+
*
|
|
48
49
|
*/
|
|
49
|
-
class JsonGenerator {
|
|
50
|
+
class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
|
|
50
51
|
/**
|
|
51
52
|
* Generate bitmark JSON from a bitmark AST
|
|
52
53
|
*
|
|
@@ -54,7 +55,8 @@ class JsonGenerator {
|
|
|
54
55
|
* @param options - JSON generation options
|
|
55
56
|
*/
|
|
56
57
|
constructor(writer, options) {
|
|
57
|
-
var _a;
|
|
58
|
+
var _a, _b;
|
|
59
|
+
super();
|
|
58
60
|
this.ast = new Ast_1.Ast();
|
|
59
61
|
this.textParser = new TextParser_1.TextParser();
|
|
60
62
|
// State
|
|
@@ -65,10 +67,9 @@ class JsonGenerator {
|
|
|
65
67
|
this.bodyDefault = Breakscape_1.Breakscape.EMPTY_STRING;
|
|
66
68
|
this.bodyJson = this.bodyDefault;
|
|
67
69
|
this.startPlaceholderIndex = 0;
|
|
68
|
-
// Debug
|
|
69
|
-
this.printed = false;
|
|
70
70
|
this.bitmarkVersion = (_a = BitmarkVersion_1.BitmarkVersion.fromValue(options === null || options === void 0 ? void 0 : options.bitmarkVersion)) !== null && _a !== void 0 ? _a : BitmarkVersion_1.DEFAULT_BITMARK_VERSION;
|
|
71
71
|
this.options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options === null || options === void 0 ? void 0 : options.jsonOptions);
|
|
72
|
+
this.debugGenerationInline = (_b = this.options.debugGenerationInline) !== null && _b !== void 0 ? _b : false;
|
|
72
73
|
this.jsonPrettifySpace = this.options.prettify === true ? 2 : this.options.prettify || undefined;
|
|
73
74
|
// Set defaults according to bitmark version
|
|
74
75
|
if (this.bitmarkVersion === BitmarkVersion_1.BitmarkVersion.v2) {
|
|
@@ -136,55 +137,6 @@ class JsonGenerator {
|
|
|
136
137
|
// Walk the bitmark AST
|
|
137
138
|
this.ast.walk(ast, NodeType_1.NodeType.bitmarkAst, this, undefined);
|
|
138
139
|
}
|
|
139
|
-
enter(node, parent, route) {
|
|
140
|
-
let res = void 0;
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
|
-
const gen = this;
|
|
143
|
-
const funcName = `enter_${node.key}`;
|
|
144
|
-
if (!this.printed) {
|
|
145
|
-
this.printed = true;
|
|
146
|
-
}
|
|
147
|
-
if (this.options.debugGenerationInline)
|
|
148
|
-
this.writeInlineDebug(node.key, { open: true });
|
|
149
|
-
if (typeof gen[funcName] === 'function') {
|
|
150
|
-
res = gen[funcName](node, parent, route);
|
|
151
|
-
}
|
|
152
|
-
return res;
|
|
153
|
-
}
|
|
154
|
-
between(node, left, right, parent, route) {
|
|
155
|
-
let res = void 0;
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
|
-
const gen = this;
|
|
158
|
-
const funcName = `between_${node.key}`;
|
|
159
|
-
if (this.options.debugGenerationInline)
|
|
160
|
-
this.writeInlineDebug(node.key, { single: true });
|
|
161
|
-
if (typeof gen[funcName] === 'function') {
|
|
162
|
-
res = gen[funcName](node, left, right, parent, route);
|
|
163
|
-
}
|
|
164
|
-
return res;
|
|
165
|
-
}
|
|
166
|
-
exit(node, parent, route) {
|
|
167
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
|
-
const gen = this;
|
|
169
|
-
const funcName = `exit_${node.key}`;
|
|
170
|
-
if (this.options.debugGenerationInline)
|
|
171
|
-
this.writeInlineDebug(node.key, { close: true });
|
|
172
|
-
if (typeof gen[funcName] === 'function') {
|
|
173
|
-
gen[funcName](node, parent, route);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
leaf(node, parent, route) {
|
|
177
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
-
const gen = this;
|
|
179
|
-
const funcName = `leaf_${node.key}`;
|
|
180
|
-
if (this.options.debugGenerationInline)
|
|
181
|
-
this.writeInlineDebug(node.key, { open: true });
|
|
182
|
-
if (typeof gen[funcName] === 'function') {
|
|
183
|
-
gen[funcName](node, parent, route);
|
|
184
|
-
}
|
|
185
|
-
if (this.options.debugGenerationInline)
|
|
186
|
-
this.writeInlineDebug(node.key, { close: true });
|
|
187
|
-
}
|
|
188
140
|
//
|
|
189
141
|
// NODE HANDLERS
|
|
190
142
|
//
|
|
@@ -192,13 +144,13 @@ class JsonGenerator {
|
|
|
192
144
|
// Non-Terminal nodes (branches)
|
|
193
145
|
//
|
|
194
146
|
// bitmark
|
|
195
|
-
enter_bitmarkAst(_node,
|
|
147
|
+
enter_bitmarkAst(_node, _route) {
|
|
196
148
|
// Reset the JSON
|
|
197
149
|
this.json = [];
|
|
198
150
|
}
|
|
199
151
|
// bitmarkAst -> bits
|
|
200
152
|
// bitmarkAst -> bits -> bitsValue
|
|
201
|
-
enter_bitsValue(node,
|
|
153
|
+
enter_bitsValue(node, _route) {
|
|
202
154
|
var _a, _b, _c;
|
|
203
155
|
const bit = node.value;
|
|
204
156
|
// Reset
|
|
@@ -242,14 +194,15 @@ class JsonGenerator {
|
|
|
242
194
|
this.bitJson.isExample = true;
|
|
243
195
|
}
|
|
244
196
|
}
|
|
245
|
-
exit_bitsValue(_node,
|
|
197
|
+
exit_bitsValue(_node, _route) {
|
|
246
198
|
// Clean up the bit JSON, removing any unwanted values
|
|
247
199
|
this.cleanAndSetDefaultsForBitJson(this.bitJson);
|
|
248
200
|
}
|
|
249
201
|
// bitmarkAst -> bits -> bitsValue -> imageSource
|
|
250
|
-
enter_imageSource(node,
|
|
202
|
+
enter_imageSource(node, route) {
|
|
251
203
|
const imageSource = node.value;
|
|
252
204
|
// Ignore values that are not at the bit level as they might be handled elsewhere
|
|
205
|
+
const parent = this.getParentNode(route);
|
|
253
206
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
|
|
254
207
|
return;
|
|
255
208
|
const { url, mockupId, size, format, trim } = imageSource;
|
|
@@ -262,10 +215,11 @@ class JsonGenerator {
|
|
|
262
215
|
this.bitJson.imageSource = imageSourceJson;
|
|
263
216
|
}
|
|
264
217
|
// bitmarkAst -> bits -> bitsValue -> partner
|
|
265
|
-
enter_partner(node,
|
|
218
|
+
enter_partner(node, route) {
|
|
266
219
|
const partner = node.value;
|
|
267
220
|
const bitType = this.getBitType(route);
|
|
268
221
|
// Ignore values that are not at the bit level as they might be handled elsewhere
|
|
222
|
+
const parent = this.getParentNode(route);
|
|
269
223
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue || !bitType)
|
|
270
224
|
return;
|
|
271
225
|
const { name, avatarImage } = partner;
|
|
@@ -280,9 +234,10 @@ class JsonGenerator {
|
|
|
280
234
|
this.bitJson.partner = partnerJson;
|
|
281
235
|
}
|
|
282
236
|
// bitmarkAst -> bits -> bitsValue -> markConfig -> markConfigValue
|
|
283
|
-
enter_markConfigValue(node,
|
|
237
|
+
enter_markConfigValue(node, route) {
|
|
284
238
|
const markConfig = node.value;
|
|
285
239
|
// Ignore example that is not at the correct level
|
|
240
|
+
const parent = this.getParentNode(route);
|
|
286
241
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.markConfig)
|
|
287
242
|
return;
|
|
288
243
|
const { mark, color, emphasis } = markConfig;
|
|
@@ -297,18 +252,20 @@ class JsonGenerator {
|
|
|
297
252
|
this.bitJson.marks.push(markJson);
|
|
298
253
|
}
|
|
299
254
|
// bitmarkAst -> bits -> bitsValue -> sampleSolution
|
|
300
|
-
leaf_sampleSolution(node,
|
|
255
|
+
leaf_sampleSolution(node, route) {
|
|
301
256
|
// Ignore example that is not at the correct level
|
|
257
|
+
const parent = this.getParentNode(route);
|
|
302
258
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
|
|
303
259
|
return;
|
|
304
260
|
if (node.value != null)
|
|
305
261
|
this.addProperty(this.bitJson, 'sampleSolution', node.value, true);
|
|
306
262
|
}
|
|
307
263
|
// bitmarkAst -> bits -> bitsValue -> itemLead
|
|
308
|
-
enter_itemLead(node,
|
|
264
|
+
enter_itemLead(node, route) {
|
|
309
265
|
const itemLead = node.value;
|
|
310
266
|
const { item, lead, pageNumber, marginNumber } = itemLead;
|
|
311
267
|
// Ignore item / lead that are not at the bit level as they are handled elsewhere
|
|
268
|
+
const parent = this.getParentNode(route);
|
|
312
269
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
|
|
313
270
|
return;
|
|
314
271
|
if (item != null) {
|
|
@@ -325,7 +282,7 @@ class JsonGenerator {
|
|
|
325
282
|
}
|
|
326
283
|
}
|
|
327
284
|
// bitmarkAst -> bits -> bitsValue -> extraProperties
|
|
328
|
-
enter_extraProperties(node,
|
|
285
|
+
enter_extraProperties(node, _route) {
|
|
329
286
|
const extraProperties = node.value;
|
|
330
287
|
if (!this.options.excludeUnknownProperties && extraProperties) {
|
|
331
288
|
for (const [key, values] of Object.entries(extraProperties)) {
|
|
@@ -338,7 +295,7 @@ class JsonGenerator {
|
|
|
338
295
|
}
|
|
339
296
|
}
|
|
340
297
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> cardBits -> cardBitsValue
|
|
341
|
-
enter_cardBitsValue(node,
|
|
298
|
+
enter_cardBitsValue(node, route) {
|
|
342
299
|
// How cardBits are handled depends on the bit type
|
|
343
300
|
const bitType = this.getBitType(route);
|
|
344
301
|
if (!bitType)
|
|
@@ -366,14 +323,15 @@ class JsonGenerator {
|
|
|
366
323
|
delete li.marginNumber;
|
|
367
324
|
listItems.push(this.listItem);
|
|
368
325
|
}
|
|
369
|
-
exit_cardBitsValue(_node,
|
|
326
|
+
exit_cardBitsValue(_node, _route) {
|
|
370
327
|
this.listItem = undefined;
|
|
371
328
|
}
|
|
372
329
|
// bitmarkAst -> bits -> bitsValue -> body
|
|
373
|
-
enter_body(_node,
|
|
330
|
+
enter_body(_node, _route) {
|
|
374
331
|
this.bodyJson = this.bodyDefault;
|
|
375
332
|
}
|
|
376
|
-
exit_body(_node,
|
|
333
|
+
exit_body(_node, route) {
|
|
334
|
+
const parent = this.getParentNode(route);
|
|
377
335
|
if (!parent)
|
|
378
336
|
return;
|
|
379
337
|
if (parent.key === NodeType_1.NodeType.bitsValue) {
|
|
@@ -387,7 +345,7 @@ class JsonGenerator {
|
|
|
387
345
|
}
|
|
388
346
|
}
|
|
389
347
|
// bitmarkAst -> bits -> bitsValue -> * -> bodyParts (body, cardBody (e.g. cloze-list, page-footer))
|
|
390
|
-
enter_bodyParts(node,
|
|
348
|
+
enter_bodyParts(node, route) {
|
|
391
349
|
const bodyParts = node.value;
|
|
392
350
|
const plainText = this.options.textAsPlainText;
|
|
393
351
|
const textFormat = this.getTextFormat(route);
|
|
@@ -489,7 +447,7 @@ class JsonGenerator {
|
|
|
489
447
|
return false;
|
|
490
448
|
}
|
|
491
449
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> elements
|
|
492
|
-
enter_elements(node,
|
|
450
|
+
enter_elements(node, _route) {
|
|
493
451
|
const elements = node.value;
|
|
494
452
|
// Ignore elements that are not at the bit level as they are handled elsewhere as quizzes
|
|
495
453
|
// if (parent?.key !== NodeType.bitsValue) return;
|
|
@@ -498,10 +456,11 @@ class JsonGenerator {
|
|
|
498
456
|
}
|
|
499
457
|
}
|
|
500
458
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue
|
|
501
|
-
enter_flashcards(node,
|
|
459
|
+
enter_flashcards(node, route) {
|
|
502
460
|
var _a, _b, _c, _d, _e, _f;
|
|
503
461
|
const flashcards = node.value;
|
|
504
462
|
// Ignore responses that are not at the correct level as they are potentially handled elsewhere
|
|
463
|
+
const parent = this.getParentNode(route);
|
|
505
464
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
|
|
506
465
|
return;
|
|
507
466
|
const flashcardsJson = [];
|
|
@@ -527,10 +486,11 @@ class JsonGenerator {
|
|
|
527
486
|
}
|
|
528
487
|
}
|
|
529
488
|
// bitmarkAst -> bits -> bitsValue -> statement
|
|
530
|
-
enter_statement(node,
|
|
489
|
+
enter_statement(node, route) {
|
|
531
490
|
var _a, _b;
|
|
532
491
|
const statement = node.value;
|
|
533
492
|
// Ignore statement that is not at the cardNode level as it is handled elsewhere
|
|
493
|
+
const parent = this.getParentNode(route);
|
|
534
494
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
|
|
535
495
|
return;
|
|
536
496
|
if (statement) {
|
|
@@ -539,10 +499,11 @@ class JsonGenerator {
|
|
|
539
499
|
}
|
|
540
500
|
}
|
|
541
501
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> statements -> statementsValue
|
|
542
|
-
enter_statements(node,
|
|
502
|
+
enter_statements(node, route) {
|
|
543
503
|
var _a, _b, _c, _d, _e;
|
|
544
504
|
const statements = node.value;
|
|
545
505
|
// Ignore statements that are not at the card node level as they are handled elsewhere
|
|
506
|
+
const parent = this.getParentNode(route);
|
|
546
507
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
|
|
547
508
|
return;
|
|
548
509
|
const statementsJson = [];
|
|
@@ -575,10 +536,11 @@ class JsonGenerator {
|
|
|
575
536
|
}
|
|
576
537
|
// bitmarkAst -> bits -> bitsValue -> choices
|
|
577
538
|
// X bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices
|
|
578
|
-
enter_choices(node,
|
|
539
|
+
enter_choices(node, route) {
|
|
579
540
|
var _a, _b, _c, _d, _e;
|
|
580
541
|
const choices = node.value;
|
|
581
542
|
// Ignore choices that are not at the bit level as they are handled elsewhere as quizzes
|
|
543
|
+
const parent = this.getParentNode(route);
|
|
582
544
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
|
|
583
545
|
return;
|
|
584
546
|
const choicesJson = [];
|
|
@@ -605,10 +567,11 @@ class JsonGenerator {
|
|
|
605
567
|
}
|
|
606
568
|
// bitmarkAst -> bits -> bitsValue -> responses
|
|
607
569
|
// X bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses
|
|
608
|
-
enter_responses(node,
|
|
570
|
+
enter_responses(node, route) {
|
|
609
571
|
var _a, _b, _c, _d, _e;
|
|
610
572
|
const responses = node.value;
|
|
611
573
|
// Ignore responses that are not at the correct level as they are handled elsewhere as quizzes
|
|
574
|
+
const parent = this.getParentNode(route);
|
|
612
575
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
|
|
613
576
|
return;
|
|
614
577
|
const responsesJson = [];
|
|
@@ -634,7 +597,7 @@ class JsonGenerator {
|
|
|
634
597
|
}
|
|
635
598
|
}
|
|
636
599
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes
|
|
637
|
-
enter_quizzes(node,
|
|
600
|
+
enter_quizzes(node, _route) {
|
|
638
601
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
639
602
|
const quizzes = node.value;
|
|
640
603
|
const quizzesJson = [];
|
|
@@ -695,39 +658,38 @@ class JsonGenerator {
|
|
|
695
658
|
}
|
|
696
659
|
}
|
|
697
660
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> heading
|
|
698
|
-
enter_heading(node,
|
|
699
|
-
var _a
|
|
661
|
+
enter_heading(node, _route) {
|
|
662
|
+
var _a;
|
|
700
663
|
const heading = node.value;
|
|
701
|
-
//
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
valid = true;
|
|
705
|
-
}
|
|
706
|
-
if (!valid)
|
|
707
|
-
return false;
|
|
664
|
+
// Check if the heading is for a match or a match matrix
|
|
665
|
+
const bitType = this.getBitType(_route);
|
|
666
|
+
const isMatrix = Config_1.Config.isOfBitType(bitType, BitType_1.BitType.matchMatrix);
|
|
708
667
|
// Create the heading
|
|
709
668
|
const headingJson = {
|
|
710
669
|
forKeys: (_a = Breakscape_1.Breakscape.unbreakscape(heading.forKeys)) !== null && _a !== void 0 ? _a : '',
|
|
711
670
|
};
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
}
|
|
720
|
-
else {
|
|
721
|
-
headingJson.forValues = Breakscape_1.Breakscape.unbreakscape(heading.forValues);
|
|
671
|
+
if (isMatrix) {
|
|
672
|
+
// Matrix match, forValues is an array
|
|
673
|
+
headingJson.forValues = [];
|
|
674
|
+
if (Array.isArray(heading.forValues)) {
|
|
675
|
+
if (heading.forValues.length >= 1) {
|
|
676
|
+
headingJson.forValues = Breakscape_1.Breakscape.unbreakscape(heading.forValues);
|
|
677
|
+
}
|
|
722
678
|
}
|
|
723
679
|
}
|
|
724
680
|
else {
|
|
725
|
-
|
|
681
|
+
// Standard match, forValues is a string
|
|
682
|
+
headingJson.forValues = '';
|
|
683
|
+
if (Array.isArray(heading.forValues)) {
|
|
684
|
+
if (heading.forValues.length >= 1) {
|
|
685
|
+
headingJson.forValues = Breakscape_1.Breakscape.unbreakscape(heading.forValues[heading.forValues.length - 1]);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
726
688
|
}
|
|
727
689
|
this.bitJson.heading = headingJson;
|
|
728
690
|
}
|
|
729
691
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> pairs
|
|
730
|
-
enter_pairs(node,
|
|
692
|
+
enter_pairs(node, route) {
|
|
731
693
|
var _a, _b, _c, _d, _e, _f;
|
|
732
694
|
const pairs = node.value;
|
|
733
695
|
const pairsJson = [];
|
|
@@ -768,7 +730,7 @@ class JsonGenerator {
|
|
|
768
730
|
}
|
|
769
731
|
}
|
|
770
732
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> matrix
|
|
771
|
-
enter_matrix(node,
|
|
733
|
+
enter_matrix(node, _route) {
|
|
772
734
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
773
735
|
const matrix = node.value;
|
|
774
736
|
const matrixJsonArray = [];
|
|
@@ -818,7 +780,7 @@ class JsonGenerator {
|
|
|
818
780
|
}
|
|
819
781
|
}
|
|
820
782
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> questions
|
|
821
|
-
enter_questions(node,
|
|
783
|
+
enter_questions(node, _route) {
|
|
822
784
|
var _a, _b, _c, _d, _e, _f;
|
|
823
785
|
const questions = node.value;
|
|
824
786
|
const questionsJson = [];
|
|
@@ -844,10 +806,11 @@ class JsonGenerator {
|
|
|
844
806
|
}
|
|
845
807
|
}
|
|
846
808
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses
|
|
847
|
-
enter_botResponses(node,
|
|
809
|
+
enter_botResponses(node, route) {
|
|
848
810
|
var _a, _b, _c, _d, _e, _f;
|
|
849
811
|
const botResponses = node.value;
|
|
850
812
|
// Ignore responses that are not at the cardNode level as they are handled elsewhere
|
|
813
|
+
const parent = this.getParentNode(route);
|
|
851
814
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
|
|
852
815
|
return;
|
|
853
816
|
const responsesJson = [];
|
|
@@ -874,7 +837,7 @@ class JsonGenerator {
|
|
|
874
837
|
}
|
|
875
838
|
}
|
|
876
839
|
// bitmarkAst -> bits -> bitsValue -> resources
|
|
877
|
-
enter_resources(node,
|
|
840
|
+
enter_resources(node, route) {
|
|
878
841
|
var _a;
|
|
879
842
|
const resources = node.value;
|
|
880
843
|
const bitType = this.getBitType(route);
|
|
@@ -940,71 +903,74 @@ class JsonGenerator {
|
|
|
940
903
|
// Terminal nodes (leaves)
|
|
941
904
|
//
|
|
942
905
|
// bitmarkAst -> bits -> bitsValue -> title
|
|
943
|
-
leaf_title(node,
|
|
906
|
+
leaf_title(node, _route) {
|
|
944
907
|
this.bitJson.title = this.convertBreakscapedStringToJsonText(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
|
|
945
908
|
}
|
|
946
909
|
// bitmarkAst -> bits -> bitsValue -> subtitle
|
|
947
|
-
leaf_subtitle(node,
|
|
910
|
+
leaf_subtitle(node, _route) {
|
|
948
911
|
this.bitJson.subtitle = this.convertBreakscapedStringToJsonText(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
|
|
949
912
|
}
|
|
950
913
|
// // bitmarkAst -> bits -> bitsValue -> level
|
|
951
|
-
leaf_level(node,
|
|
914
|
+
leaf_level(node, _route) {
|
|
952
915
|
var _a;
|
|
953
916
|
if (node.value != null)
|
|
954
917
|
this.addProperty(this.bitJson, 'level', (_a = node.value) !== null && _a !== void 0 ? _a : 1, true);
|
|
955
918
|
}
|
|
956
919
|
// bitmarkAst -> bits -> bitsValue -> book
|
|
957
|
-
leaf_book(node,
|
|
920
|
+
leaf_book(node, _route) {
|
|
958
921
|
if (node.value != null)
|
|
959
922
|
this.addProperty(this.bitJson, 'book', node.value, true);
|
|
960
923
|
}
|
|
961
924
|
// bitmarkAst -> bits -> bitsValue -> anchor
|
|
962
|
-
leaf_anchor(node,
|
|
925
|
+
leaf_anchor(node, _route) {
|
|
963
926
|
if (node.value != null)
|
|
964
927
|
this.addProperty(this.bitJson, 'anchor', node.value, true);
|
|
965
928
|
}
|
|
966
929
|
// bitmarkAst -> bits -> bitsValue -> reference
|
|
967
|
-
leaf_reference(node,
|
|
930
|
+
leaf_reference(node, _route) {
|
|
968
931
|
if (node.value != null)
|
|
969
932
|
this.addProperty(this.bitJson, 'reference', node.value, true);
|
|
970
933
|
}
|
|
971
934
|
// bitmarkAst -> bits -> bitsValue -> referenceEnd
|
|
972
|
-
leaf_referenceEnd(node,
|
|
935
|
+
leaf_referenceEnd(node, _route) {
|
|
973
936
|
if (node.value != null)
|
|
974
937
|
this.addProperty(this.bitJson, 'referenceEnd', node.value, true);
|
|
975
938
|
}
|
|
976
939
|
// bitmarkAst -> bits -> bitsValue -> * -> hint
|
|
977
|
-
leaf_hint(node,
|
|
940
|
+
leaf_hint(node, route) {
|
|
978
941
|
const hint = node.value;
|
|
979
942
|
// Ignore hint that is not at the bit level as it are handled elsewhere
|
|
943
|
+
const parent = this.getParentNode(route);
|
|
980
944
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
|
|
981
945
|
return;
|
|
982
946
|
this.bitJson.hint = this.convertBreakscapedStringToJsonText(hint, TextFormat_1.TextFormat.bitmarkMinusMinus);
|
|
983
947
|
}
|
|
984
948
|
// bitmarkAst -> bits -> bitsValue -> * -> instruction
|
|
985
|
-
leaf_instruction(node,
|
|
949
|
+
leaf_instruction(node, route) {
|
|
986
950
|
const instruction = node.value;
|
|
987
951
|
// Ignore instruction that is not at the bit level as it are handled elsewhere
|
|
952
|
+
const parent = this.getParentNode(route);
|
|
988
953
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
|
|
989
954
|
return;
|
|
990
955
|
this.bitJson.instruction = this.convertBreakscapedStringToJsonText(instruction, TextFormat_1.TextFormat.bitmarkMinusMinus);
|
|
991
956
|
}
|
|
992
957
|
// bitmarkAst -> bits -> footer -> footerText
|
|
993
|
-
leaf_footerText(node,
|
|
958
|
+
leaf_footerText(node, _route) {
|
|
994
959
|
const footer = node.value;
|
|
995
960
|
this.bitJson.footer = this.convertBreakscapedStringToJsonText(footer, TextFormat_1.TextFormat.bitmarkMinusMinus);
|
|
996
961
|
}
|
|
997
962
|
// bitmarkAst -> bits -> bitsValue -> markup
|
|
998
|
-
leaf_markup(node,
|
|
963
|
+
leaf_markup(node, _route) {
|
|
999
964
|
const bitmark = node.value;
|
|
1000
965
|
if (bitmark)
|
|
1001
966
|
this.bitWrapperJson.bitmark = bitmark;
|
|
1002
967
|
}
|
|
1003
968
|
// bitmarkAst -> bits -> bitsValue -> parser
|
|
1004
969
|
// bitmarkAst -> bits -> bitsValue -> * -> internalComment
|
|
1005
|
-
enter_parser(node,
|
|
970
|
+
enter_parser(node, route) {
|
|
1006
971
|
const parser = node.value;
|
|
1007
972
|
const bitType = this.getBitType(route);
|
|
973
|
+
const parent = this.getParentNode(route);
|
|
1008
974
|
if (parser && bitType) {
|
|
1009
975
|
const { version, excessResources: parserExcessResources, warnings, errors } = parser, parserRest = __rest(parser, ["version", "excessResources", "warnings", "errors"]);
|
|
1010
976
|
const bitmarkVersion = `${this.bitmarkVersion}`;
|
|
@@ -1042,7 +1008,7 @@ class JsonGenerator {
|
|
|
1042
1008
|
}
|
|
1043
1009
|
}
|
|
1044
1010
|
// bitmarkAst -> errors
|
|
1045
|
-
// protected enter_errors(node: NodeInfo,
|
|
1011
|
+
// protected enter_errors(node: NodeInfo, _route: NodeInfo[],
|
|
1046
1012
|
// context: Context): void {
|
|
1047
1013
|
// const errors = node.value as ParserError[] | undefined;
|
|
1048
1014
|
// if (errors && errors.length > 0) {
|
|
@@ -1077,13 +1043,14 @@ class JsonGenerator {
|
|
|
1077
1043
|
continue;
|
|
1078
1044
|
const funcName = `enter_${astKey}`;
|
|
1079
1045
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1080
|
-
this[funcName] = (node,
|
|
1046
|
+
this[funcName] = (node, route) => {
|
|
1081
1047
|
var _a;
|
|
1082
1048
|
const value = node.value;
|
|
1083
1049
|
if (value == null)
|
|
1084
1050
|
return;
|
|
1085
1051
|
// if (key === 'progress') debugger;
|
|
1086
1052
|
// Ignore any property that is not at the bit level as that will be handled by a different handler
|
|
1053
|
+
const parent = this.getParentNode(route);
|
|
1087
1054
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
|
|
1088
1055
|
return;
|
|
1089
1056
|
// Convert key as needed
|
|
@@ -1751,6 +1718,9 @@ class JsonGenerator {
|
|
|
1751
1718
|
// }
|
|
1752
1719
|
}
|
|
1753
1720
|
}
|
|
1721
|
+
//
|
|
1722
|
+
// Helper functions
|
|
1723
|
+
//
|
|
1754
1724
|
/**
|
|
1755
1725
|
* Get the value for the zoomDisabled property, setting the appropriate default value if no value is set.
|
|
1756
1726
|
*
|