yini-parser 1.0.2-beta → 1.1.0-beta

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +83 -98
  3. package/dist/YINI.d.ts +34 -11
  4. package/dist/YINI.js +206 -93
  5. package/dist/core/ASTBuilder.d.ts +191 -0
  6. package/dist/core/ASTBuilder.js +827 -0
  7. package/dist/core/ErrorDataHandler.d.ts +19 -19
  8. package/dist/core/ErrorDataHandler.js +258 -150
  9. package/dist/core/objectBuilder.d.ts +9 -3
  10. package/dist/core/objectBuilder.js +126 -163
  11. package/dist/core/types.d.ts +234 -44
  12. package/dist/core/types.js +7 -33
  13. package/dist/grammar/YiniLexer.d.ts +54 -48
  14. package/dist/grammar/YiniLexer.js +324 -289
  15. package/dist/grammar/YiniParser.d.ts +167 -150
  16. package/dist/grammar/YiniParser.js +1241 -1202
  17. package/dist/grammar/YiniParserVisitor.d.ts +59 -45
  18. package/dist/grammar/YiniParserVisitor.js +1 -1
  19. package/dist/index.d.ts +4 -2
  20. package/dist/index.js +286 -26
  21. package/dist/parseEntry.d.ts +3 -2
  22. package/dist/parseEntry.js +352 -81
  23. package/dist/parsers/extractHeaderParts.d.ts +3 -2
  24. package/dist/parsers/extractHeaderParts.js +1 -0
  25. package/dist/parsers/parseBoolean.d.ts +1 -1
  26. package/dist/parsers/parseBoolean.js +2 -1
  27. package/dist/parsers/parseNumber.d.ts +8 -3
  28. package/dist/parsers/parseNumber.js +21 -7
  29. package/dist/parsers/parseSectionHeader.d.ts +3 -2
  30. package/dist/parsers/parseSectionHeader.js +1 -0
  31. package/dist/utils/number.d.ts +3 -0
  32. package/dist/utils/number.js +18 -0
  33. package/dist/utils/object.d.ts +55 -0
  34. package/dist/utils/object.js +85 -0
  35. package/dist/utils/string.d.ts +21 -1
  36. package/dist/utils/string.js +39 -4
  37. package/dist/utils/system.d.ts +15 -0
  38. package/dist/utils/system.js +21 -0
  39. package/dist/yiniHelpers.d.ts +3 -0
  40. package/dist/yiniHelpers.js +43 -7
  41. package/package.json +1 -1
  42. package/dist/core/YINIVisitor.d.ts +0 -158
  43. package/dist/core/YINIVisitor.js +0 -1008
@@ -1,1008 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const env_1 = require("../config/env");
7
- const YiniParserVisitor_1 = __importDefault(require("../grammar/YiniParserVisitor"));
8
- const extractSignificantYiniLine_1 = require("../parsers/extractSignificantYiniLine");
9
- const parseBoolean_1 = __importDefault(require("../parsers/parseBoolean"));
10
- const parseNull_1 = __importDefault(require("../parsers/parseNull"));
11
- const parseNumber_1 = __importDefault(require("../parsers/parseNumber"));
12
- const parseSectionHeader_1 = __importDefault(require("../parsers/parseSectionHeader"));
13
- const parseString_1 = __importDefault(require("../parsers/parseString"));
14
- const print_1 = require("../utils/print");
15
- const string_1 = require("../utils/string");
16
- const yiniHelpers_1 = require("../yiniHelpers");
17
- const ErrorDataHandler_1 = require("./ErrorDataHandler");
18
- /**
19
- * This interface defines a complete generic visitor for a parse tree produced
20
- * by `YiniParser`.
21
- *
22
- * @param <IResult> The return type of the visit operation. Use `void` for
23
- * operations with no return type.
24
- */
25
- class YINIVisitor extends YiniParserVisitor_1.default {
26
- constructor(errorHandler, isStrict) {
27
- super();
28
- //export default class YINIVisitor extends YiniParserVisitor<any> {
29
- this.reversedTree = [];
30
- this.errorHandler = null;
31
- this.lastActiveSectionAtLevels = [];
32
- this.lastActiveSectionNameAtLevels = []; // Last active section name at each level.
33
- this.numOfLevelOnes = 0; // Num of Level-1 sections.
34
- this.level = 0;
35
- this.prevLevel = 0;
36
- this.prevSectionName = ''; // For error reporting purposes.
37
- this.meta_numOfSections = 0; // For stats.
38
- this.meta_numOfMembers = 0; // For stats.
39
- this.meta_numOfChains = 0; // For stats.
40
- this.meta_maxLevelSection = 0; // For stats.
41
- // private existingSectionTitles: Map<string, boolean> = new Map()
42
- this.existingSectionTitlesAtLevels = [];
43
- this.hasDefinedSectionTitle = (sectionName, level) => {
44
- const mapAtCurrentLevel = this.existingSectionTitlesAtLevels[level - 1];
45
- return mapAtCurrentLevel === null || mapAtCurrentLevel === void 0 ? void 0 : mapAtCurrentLevel.has(sectionName);
46
- };
47
- this.setDefineSectionTitle = (sectionName, level) => {
48
- let mapAtCurrentLevel = this.existingSectionTitlesAtLevels[level - 1];
49
- if (!mapAtCurrentLevel) {
50
- mapAtCurrentLevel = new Map();
51
- this.existingSectionTitlesAtLevels[level - 1] = mapAtCurrentLevel;
52
- }
53
- mapAtCurrentLevel.set(sectionName, true);
54
- };
55
- this.pushOnTree = (ctx, sReslult) => {
56
- if ((0, env_1.isDebug)()) {
57
- console.log();
58
- (0, print_1.debugPrint)('--- In pushOnTree(..) --------');
59
- (0, print_1.debugPrint)('sReslult:');
60
- (0, print_1.printObject)(sReslult);
61
- }
62
- const key = sReslult.level + '-' + sReslult.name;
63
- (0, print_1.debugPrint)('KKKKKK, key = ' + key);
64
- // if (this.existingSectionTitles.has(key)) {
65
- if (this.hasDefinedSectionTitle(key, sReslult.level)) {
66
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Section name already exists', 'Cannot redefine section name: "' +
67
- sReslult.name +
68
- '" at level ' +
69
- sReslult.level +
70
- '.');
71
- }
72
- else {
73
- if (sReslult.members === undefined) {
74
- (0, print_1.debugPrint)('This sReslult does not hold any valid members (=undefined)');
75
- }
76
- else {
77
- // this.existingSectionTitles.set(key, true)
78
- this.setDefineSectionTitle(key, sReslult.level);
79
- // printObject(this.existingSectionTitles)
80
- }
81
- }
82
- // if (
83
- // sReslult.level === 0 &&
84
- // (!sReslult.name || sReslult.name === 'undefined')
85
- // ) {
86
- // // NOTE: This is a nasty fix, should try to do another way!
87
- // debugPrint('HIT, Doing NASTY fix!!')
88
- // // A memberless section, e.g. `^ Section` and then input ends.
89
- // // Lift up the member in "members" to top.
90
- // // --- Get the key-name of the entry in "members" ----------
91
- // // "members": {
92
- // // "Title": {}
93
- // // }
94
- // const sectionName = Object.keys(sReslult.members)[0]
95
- // // ---------------------------------------------------------
96
- // debugPrint('sectionName = ' + sectionName)
97
- // const chain: IChainContainer = {
98
- // originLevel: 1,
99
- // chain: { [sectionName]: {} },
100
- // }
101
- // this.reversedTree.push(chain)
102
- // } else {
103
- const chain = {
104
- originLevel: sReslult.level,
105
- chain: { [(0, string_1.trimBackticks)(sReslult.name)]: sReslult.members },
106
- };
107
- this.reversedTree.push(chain);
108
- // }
109
- this.meta_numOfChains++;
110
- (0, print_1.debugPrint)('this.reversedTree: [list]');
111
- (0, print_1.printObject)(this.reversedTree);
112
- (0, print_1.debugPrint)('--- /end of pushOnTree(..) --------');
113
- };
114
- this.getDepthOfLevels = () => {
115
- return this.lastActiveSectionNameAtLevels.length;
116
- };
117
- this.setLastActiveSection = (atLevel, sectionName) => {
118
- if (atLevel >= 1) {
119
- this.lastActiveSectionNameAtLevels[atLevel - 1] = sectionName;
120
- }
121
- else {
122
- // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
123
- this.errorHandler.pushOrBail(null, 'Internal-Error', 'Invalid section level (<1), level: ' +
124
- atLevel +
125
- ', sectionName: "' +
126
- sectionName +
127
- '"');
128
- }
129
- };
130
- /**
131
- * Visit a parse tree produced by `YiniParser.yini`.
132
- * @param ctx the parse tree
133
- * @return the visitor result
134
- */
135
- // visitYini?: (ctx: YiniContext) => IResult;
136
- // visitYini = (ctx: YiniContext): IResult => {
137
- this.visitYini = (ctx, isStrict = false) => {
138
- var _a;
139
- if (!this.errorHandler) {
140
- // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
141
- new ErrorDataHandler_1.ErrorDataHandler().pushOrBail(null, 'Fatal-Error', 'Has no ErrorDataHandler instance when calling visitYini(..)', 'Something in the code is done incorrectly in order for this to happen... :S');
142
- }
143
- (0, print_1.debugPrint)();
144
- (0, print_1.debugPrint)('abcde99');
145
- (0, env_1.isDebug)() && console.log();
146
- (0, print_1.debugPrint)('-> Entered visitYini(..) in YINIVisitor');
147
- (0, print_1.debugPrint)('QQQQ');
148
- (_a = ctx.section_list()) === null || _a === void 0 ? void 0 : _a.forEach((section) => {
149
- // ctx?.section_list()?.forEach((section: any) => {
150
- (0, print_1.debugPrint)('\nStart of each element in forEeach(..) of section_list():');
151
- const topSectionResult = this.visitSection(section);
152
- this.pushOnTree(ctx, topSectionResult);
153
- const topSectionName = topSectionResult === null || topSectionResult === void 0 ? void 0 : topSectionResult.name;
154
- const topSectionMembers = topSectionResult === null || topSectionResult === void 0 ? void 0 : topSectionResult.members;
155
- const topSectionLevel = topSectionResult === null || topSectionResult === void 0 ? void 0 : topSectionResult.level; // This must have a value of 1.
156
- (0, print_1.debugPrint)('\ntopSectionResult (visitSection(..)):');
157
- if ((0, env_1.isDebug)()) {
158
- console.log(topSectionResult);
159
- }
160
- (0, print_1.debugPrint)('Found section head, topSectionName = "' + topSectionName + '"');
161
- topSectionMembers &&
162
- (0, print_1.debugPrint)('Num of Props of topSectionResult?.members: ' +
163
- Object.keys(topSectionResult === null || topSectionResult === void 0 ? void 0 : topSectionResult.members).length);
164
- (0, print_1.debugPrint)('topSectionMembers:');
165
- if ((0, env_1.isDebug)()) {
166
- console.log(topSectionMembers);
167
- }
168
- if (topSectionName) {
169
- (0, print_1.debugPrint)();
170
- (0, print_1.debugPrint)('-- Just extracted TOP/FIRST section info ---------------------------');
171
- (0, print_1.debugPrint)(' TOP/FIRST topSectionName = ' + topSectionName);
172
- (0, print_1.debugPrint)(' topSectionLevel = ' + topSectionLevel);
173
- (0, print_1.debugPrint)(' this.level = ' + this.level);
174
- (0, print_1.debugPrint)('Mounted/assigned section onto resultSections...');
175
- }
176
- (0, print_1.debugPrint)('\n=== resultSections: =====================================');
177
- if ((0, env_1.isDebug)()) {
178
- console.log('2222222222222');
179
- console.log(`lastActiveSectionAtLevels[${this.level - 1}]`);
180
- (0, print_1.printObject)(this.lastActiveSectionAtLevels[this.level - 1]);
181
- }
182
- (0, print_1.debugPrint)('==============================================\n');
183
- (0, print_1.debugPrint)('End of each element in forEeach(..) of section_list().');
184
- (0, print_1.debugPrint)();
185
- });
186
- const syntaxTree = this.reversedTree.reverse();
187
- if ((0, env_1.isDebug)()) {
188
- console.log();
189
- console.log('=========================================================================');
190
- console.log('=== syntaxTree: ==========================================================');
191
- (0, print_1.printObject)(syntaxTree);
192
- console.log('=========================================================================');
193
- console.log('=========================================================================');
194
- console.log();
195
- }
196
- const hasTerminal = !!ctx.terminal_line();
197
- // Returns an Intermediate Tree (could even be an AST).
198
- const syntaxTreeC = {
199
- // _base: this.resultSections,
200
- _syntaxTree: syntaxTree, // The Intermediate Tree, or AST.
201
- _hasTerminal: hasTerminal,
202
- _meta_numOfSections: this.meta_numOfSections,
203
- _meta_numOfMembers: this.meta_numOfMembers,
204
- _meta_numOfChains: this.meta_numOfChains,
205
- };
206
- return syntaxTreeC;
207
- };
208
- /**
209
- * Will visit here on EVERY section.
210
- * @param ctx the parse tree
211
- * @returns { [sectionName]: sectionObj }
212
- */
213
- // visitSection?: (ctx: SectionContext) => IResult;
214
- this.visitSection = (ctx) => {
215
- // let headMarkerType: TSectionHeaderType =
216
- // 'Classic-Header-Marker'
217
- var _a, _b, _c;
218
- (0, env_1.isDebug)() && console.log();
219
- (0, print_1.debugPrint)('-> Entered visitSection(..)');
220
- const res = {};
221
- (0, print_1.debugPrint)('start');
222
- (0, print_1.debugPrint)('XXXX0:ctx.getText() = ' + ctx.getText());
223
- (0, print_1.debugPrint)('XXXX1:ctx.SECTION_HEAD() = ' + ctx.SECTION_HEAD());
224
- (0, print_1.debugPrint)('XXXX1:SECTION_HEAD().getText() = ' +
225
- ((_a = ctx.SECTION_HEAD()) === null || _a === void 0 ? void 0 : _a.getText().trim()));
226
- (0, print_1.debugPrint)('end\n');
227
- let line = '';
228
- try {
229
- (0, print_1.debugPrint)('S1');
230
- line = ((_b = ctx.SECTION_HEAD()) === null || _b === void 0 ? void 0 : _b.getText().trim()) || '';
231
- (0, print_1.debugPrint)('S2, line: >>>' + line + '<<<');
232
- }
233
- catch (error) {
234
- const msgWhat = `Unexpected syntax while parsing a member or section head`;
235
- const msgWhy = `Found unexpected syntax while trying to read a key-value pair or a section header (such as a section marker or section name).`;
236
- // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
237
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', msgWhat, msgWhy);
238
- }
239
- // If no section head can be found in the above SECTION_HEAD(),
240
- // try alternative method of reading the section content.
241
- (0, print_1.debugPrint)('S3, line: >>>' + line + '<<<');
242
- if (!line) {
243
- (0, print_1.debugPrint)();
244
- (0, print_1.debugPrint)('Nothing in SECTION_HEAD() is found, trying to read the section content directly...');
245
- (0, print_1.debugPrint)('--- Start: parse line from section content-----------------');
246
- // const sectionContent = '' + ctx.getText().trim()
247
- const sectionContent = ctx.getText().trim();
248
- (0, print_1.debugPrint)('Section content: ' + ctx.getText());
249
- line = (0, extractSignificantYiniLine_1.extractYiniLine)(sectionContent);
250
- // const contentLines = splitLines(sectionContent)
251
- // if (isDebug()) {
252
- // console.log('contentLines:')
253
- // printObject(contentLines)
254
- // }
255
- // // contentLines.forEach((row: string) => {
256
- // for (let row of contentLines) {
257
- // debugPrint('---')
258
- // debugPrint('row (a): >>>' + row + '<<<')
259
- // row = stripNLAndAfter(row)
260
- // debugPrint('row (b): >>>' + row + '<<<')
261
- // row = stripCommentsAndAfter(row)
262
- // debugPrint('row (c): >>>' + row + '<<<')
263
- // row = row.trim()
264
- // debugPrint('row (d): >>>' + row + '<<<')
265
- // if (row) {
266
- // debugPrint(
267
- // 'Found some content in split row (non-comments).',
268
- // )
269
- // debugPrint('Split row: >>>' + row + '<<<')
270
- // // Use this as input in line.
271
- // line = row
272
- // debugPrint('Will use row as line input')
273
- // break
274
- // }
275
- // }
276
- // debugPrint(
277
- // '--- End: parse line from section content-----------------',
278
- // )
279
- // debugPrint()
280
- }
281
- (0, print_1.debugPrint)('S4, line: >>>' + line + '<<<');
282
- if (!line) {
283
- (0, print_1.debugPrint)('*** ERROR: Nothing to parse in section line');
284
- }
285
- this.prevLevel = this.level;
286
- let { sectionName, sectionLevel } = (0, parseSectionHeader_1.default)(line, this.errorHandler, ctx);
287
- this.level = sectionLevel;
288
- this.meta_numOfSections++;
289
- // ---------------------------------------------------------------
290
- let nestDirection;
291
- if (this.level === this.prevLevel) {
292
- nestDirection = 'same';
293
- }
294
- else if (this.level < this.prevLevel) {
295
- nestDirection = 'lower';
296
- }
297
- else {
298
- nestDirection = 'higher';
299
- }
300
- (0, print_1.debugPrint)('-- In visitSection(..) ---------------------------');
301
- (0, print_1.debugPrint)(' sectionName = ' + sectionName);
302
- (0, print_1.debugPrint)(' sectionLevel = ' + sectionLevel);
303
- (0, print_1.debugPrint)(' this.level = ' + this.level);
304
- (0, print_1.debugPrint)(' this.prevLevel = ' + this.prevLevel);
305
- (0, print_1.debugPrint)(' this.prevSectionName = ' + this.prevSectionName);
306
- (0, print_1.debugPrint)(' nestDirection = ' + nestDirection);
307
- (0, print_1.debugPrint)(' this.numOfLevelOnes = ' + this.numOfLevelOnes);
308
- (0, print_1.debugPrint)('this.getDepthOfLevels() = ' + this.getDepthOfLevels());
309
- (0, print_1.debugPrint)();
310
- if (nestDirection === 'higher') {
311
- (0, print_1.debugPrint)(`Is level skipping: ${this.level - this.prevLevel} >= 2?`);
312
- // if (Math.abs(this.prevLevel - this.level) >= 2) {
313
- if (this.level - this.prevLevel >= 2) {
314
- if (this.level === 2) {
315
- // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
316
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Invalid section header level ' +
317
- this.level +
318
- ', with section name "' +
319
- sectionName, 'A section header may not start directly at level ' +
320
- this.level +
321
- ', skipping previous section levels. Please start with one level further down.');
322
- }
323
- else {
324
- // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
325
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Invalid section level jump of section header "' +
326
- sectionName +
327
- '"', 'Section header name "' +
328
- sectionName +
329
- '" with level ' +
330
- this.level +
331
- ' may not jump over (skip) intermediate section levels, from section header name "' +
332
- this.prevSectionName +
333
- '" with level ' +
334
- this.prevLevel +
335
- '. Section levels should increase one at a time. Please adjust your section headers accordingly.');
336
- }
337
- }
338
- }
339
- this.prevSectionName = sectionName;
340
- (0, print_1.debugPrint)('About to visit members of section...');
341
- let members;
342
- if (!ctx.section_members()) {
343
- (0, print_1.debugPrint)('(!) Section has no members!');
344
- }
345
- else {
346
- members = this.visitSection_members(ctx.section_members());
347
- }
348
- // ---------------------------------------------------------------
349
- (_c = ctx.children) === null || _c === void 0 ? void 0 : _c.forEach((child) => {
350
- (0, print_1.debugPrint)('* child: ' + child);
351
- });
352
- if (this.level === 1) {
353
- this.numOfLevelOnes++;
354
- }
355
- //------------------------
356
- // if (nestDirection === 'higher') {
357
- // debugPrint(
358
- // `Is level skipping: ${this.level - this.prevLevel} >= 2?`,
359
- // )
360
- // // if (Math.abs(this.prevLevel - this.level) >= 2) {
361
- // if (this.level - this.prevLevel >= 2) {
362
- // // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
363
- // this.errorHandler!.pushOrBail(
364
- // ctx,
365
- // 'Syntax-Error',
366
- // 'Invalid section level jump of section header "' +
367
- // sectionName +
368
- // '"',
369
- // 'Section header name "' +
370
- // sectionName +
371
- // '" with level ' +
372
- // this.prevLevel +
373
- // ' may not jump over previous section levels, from a section with level ' +
374
- // this.level +
375
- // ' (section name: "' +
376
- // this.prevSectionName +
377
- // '").',
378
- // )
379
- // }
380
- // }
381
- // this.prevSectionName = sectionName
382
- if (nestDirection !== 'higher') {
383
- (0, print_1.debugPrint)('About to reset result');
384
- (0, print_1.printObject)({ [sectionName]: members });
385
- (0, print_1.debugPrint)(`Current lastActiveSectionAtLevels[${this.level - 1}]`);
386
- (0, print_1.printObject)(this.lastActiveSectionAtLevels[this.level - 1]);
387
- if (
388
- // (level === 0 && !sectionName) ||
389
- // (sectionName === 'undefined' && !!members)
390
- sectionLevel === 0 &&
391
- sectionName === 'undefined' &&
392
- !!members) {
393
- (0, print_1.debugPrint)('HIT2!!!!');
394
- (0, print_1.debugPrint)('(!) Detected a member (that does not have a sectionName), but a memberless object in "members"');
395
- sectionName = Object.keys(members)[0];
396
- (0, print_1.debugPrint)('sectionName = ' + sectionName);
397
- members = {};
398
- // this.lastActiveSectionAtLevels[0] = { [sectionName]: {} }
399
- // this.pushOnTree({ level: 1, name: sectionName, members: {} })
400
- (0, print_1.debugPrint)('(!) Skipping mounted since this is actually a memberless section');
401
- (0, print_1.debugPrint)();
402
- (0, print_1.debugPrint)('<- Leaving visitSection(..) EARLY');
403
- if ((0, env_1.isDebug)()) {
404
- console.log('returning (a memberless section):');
405
- console.log({
406
- level: 1,
407
- name: sectionName,
408
- members: members,
409
- });
410
- console.log();
411
- }
412
- return {
413
- level: 1,
414
- name: sectionName,
415
- members: members,
416
- };
417
- }
418
- else {
419
- // Mount as append
420
- this.lastActiveSectionAtLevels[this.level - 1] = {
421
- [sectionName]: Object.assign({}, members),
422
- };
423
- this.pushOnTree(ctx, {
424
- level: sectionLevel,
425
- name: sectionName,
426
- members,
427
- });
428
- // this.lastActiveSectionNameAtLevels.push(sectionName)
429
- (0, print_1.debugPrint)('Mounted as append');
430
- }
431
- (0, print_1.debugPrint)(`After: lastActiveSectionAtLevels[${this.level - 1}]`);
432
- (0, print_1.printObject)(this.lastActiveSectionAtLevels[this.level - 1]);
433
- if ((0, env_1.isDebug)()) {
434
- console.log(`After append lastActiveSectionAtLevels[${this.level - 1}]`);
435
- (0, print_1.printObject)(this.lastActiveSectionAtLevels[this.level - 1]);
436
- (0, print_1.debugPrint)('Before this.lastActiveSectionNameAtLevels:');
437
- (0, print_1.printObject)(this.lastActiveSectionNameAtLevels);
438
- // Reset.
439
- let i = this.level;
440
- while (this.lastActiveSectionNameAtLevels[i]) {
441
- this.lastActiveSectionNameAtLevels[i++] = undefined;
442
- }
443
- (0, print_1.debugPrint)('After this.lastActiveSectionNameAtLevels:');
444
- (0, print_1.printObject)(this.lastActiveSectionNameAtLevels);
445
- }
446
- (0, print_1.debugPrint)('HIT!!! - Just a lower or same level section, a continues full (nested) section,');
447
- (0, print_1.debugPrint)(`Has above in lastActiveSectionAtLevels[${this.level - 1}]`);
448
- (0, print_1.debugPrint)(' this.level: ' + this.level);
449
- (0, print_1.debugPrint)('this.prevLevel: ' + this.prevLevel);
450
- (0, print_1.debugPrint)(' this.level: ' + this.level);
451
- (0, print_1.debugPrint)();
452
- (0, print_1.debugPrint)(' HERE.... Should mount section to correct section at this.level: ' +
453
- this.level);
454
- //this.lastActiveSectionNameAtLevels[this.level - 1] = sectionName
455
- (0, print_1.debugPrint)();
456
- (0, print_1.debugPrint)('Resetted local result');
457
- sectionName = '';
458
- members = undefined;
459
- }
460
- //------------------------
461
- (0, print_1.debugPrint)();
462
- if ((0, env_1.isDebug)()) {
463
- if (members) {
464
- (0, print_1.printObject)({ [sectionName]: members });
465
- this.lastActiveSectionAtLevels[this.level - 1] = Object.assign({}, members);
466
- // this.lastActiveSectionNameAtLevels[this.level - 1] = sectionName
467
- (0, print_1.debugPrint)('Mounted as assigned');
468
- (0, print_1.debugPrint)(`lastActiveSectionAtLevels[${this.level - 1}]`);
469
- (0, print_1.printObject)(this.lastActiveSectionAtLevels[this.level - 1]);
470
- }
471
- }
472
- (0, print_1.debugPrint)('-----------------------');
473
- if ((0, env_1.isDebug)()) {
474
- console.log('At end of visitSection(..), this.lastActiveSectionNameAtLevels:');
475
- (0, print_1.printObject)(this.lastActiveSectionNameAtLevels);
476
- (0, print_1.debugPrint)(' this.level: ' + this.level);
477
- (0, print_1.debugPrint)('this.prevLevel: ' + this.prevLevel);
478
- (0, print_1.debugPrint)(' this.level: ' + this.level);
479
- (0, print_1.debugPrint)('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
480
- (0, print_1.debugPrint)('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
481
- console.log();
482
- }
483
- (0, print_1.debugPrint)('<- Leaving visitSection(..)');
484
- if ((0, env_1.isDebug)()) {
485
- console.log('returning:');
486
- console.log({
487
- sectionLevel: sectionLevel,
488
- name: sectionName,
489
- members: members,
490
- });
491
- console.log();
492
- }
493
- return {
494
- level: sectionLevel,
495
- name: sectionName,
496
- members: members,
497
- };
498
- };
499
- /**
500
- * Visit a parse tree produced by `YiniParser.bad_member`.
501
- * @param ctx the parse tree
502
- * @return the visitor result
503
- */
504
- this.visitBad_member = (ctx) => {
505
- ctx.REST;
506
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Invalid or malformed member found.', `Offending text: ${ctx.getText()}`);
507
- };
508
- /**
509
- * Visit a parse tree produced by `YiniParser.section_members`.
510
- * In here will mount object onto members object.
511
- * @param ctx the parse tree
512
- * @returns { key: value, ... }
513
- */
514
- // visitSection_members = (ctx: Section_membersContext): Record<string, any> => {
515
- // visitSection_members = (ctx: Section_membersContext): any => {
516
- this.visitSection_members = (ctx) => {
517
- (0, env_1.isDebug)() && console.log();
518
- (0, print_1.debugPrint)('************************************************************');
519
- (0, print_1.debugPrint)('-> Entered visitSection_members(..)');
520
- const members = {};
521
- (0, print_1.debugPrint)('Will loop through each member (or section head)...');
522
- ctx.member_list().forEach((member) => {
523
- const { type, key, value } = this.visitMember(member);
524
- (0, print_1.debugPrint)('+++++++++++++++++++++++++++++++++++++++++++++++++++++');
525
- (0, print_1.debugPrint)('* Item of member_list:');
526
- if ((0, env_1.isDebug)()) {
527
- console.log(value);
528
- }
529
- (0, print_1.debugPrint)(' type = >>>' + type + '<<<');
530
- (0, print_1.debugPrint)(' key = >>>' + key + '<<<');
531
- (0, print_1.debugPrint)('value = >>>' + value + '<<<');
532
- (0, print_1.debugPrint)('value[key] = >>>' + (value === null || value === void 0 ? void 0 : value[key]) + '<<<');
533
- (0, print_1.debugPrint)('--');
534
- if (key === '') {
535
- (0, print_1.debugPrint)('Skipping this member, due to key = ""');
536
- }
537
- else {
538
- if (members[key] !== undefined) {
539
- // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
540
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Key already exists in this section scope (in this main section), key name: ' +
541
- key);
542
- }
543
- else {
544
- this.meta_numOfMembers++;
545
- // if ((value?.type as TDataType) === 'Null') {
546
- if (type === 'Null') {
547
- members[key] = null;
548
- }
549
- else {
550
- (0, env_1.isDebug)() && console.log();
551
- // NOTE: (!) Only if nested section.
552
- (0, print_1.debugPrint)('About to mount a single member or section onto members...');
553
- (0, env_1.isDebug)() && console.log({ [key]: value });
554
- // if ((type as TDataType) === 'Object') {
555
- // const isExistingSectionName =
556
- // this.hasDefinedSectionTitle(key, this.level)
557
- // debugPrint(' type = "' + type + '"')
558
- // debugPrint('this.level = "' + this.level + '"')
559
- // debugPrint(
560
- // 'DDDDDDDD: sectionName / objectKey: ' + key,
561
- // )
562
- // debugPrint(
563
- // 'Is already defined at this level? ' +
564
- // isExistingSectionName,
565
- // )
566
- // if (!isExistingSectionName) {
567
- // this.setDefineSectionTitle(key, this.level)
568
- // }
569
- // }
570
- Object.assign(members, { [key]: value });
571
- (0, print_1.debugPrint)('+ Added member or section onto members: "' +
572
- key +
573
- '"');
574
- }
575
- }
576
- }
577
- });
578
- if ((0, env_1.isDebug)()) {
579
- (0, print_1.debugPrint)('~~~ After mounting in visitSection_members(..) ~~~~~~~~~~');
580
- (0, print_1.debugPrint)('this.resultSections:');
581
- (0, print_1.debugPrint)('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
582
- }
583
- //@todo handle member colon list
584
- // ctx..member_colon_list().forEach((mcl) => {
585
- // const { key, value } = this.visit(mcl)
586
- // members[key] = value
587
- // })
588
- (0, print_1.debugPrint)();
589
- (0, print_1.debugPrint)('<- Leaving visitSection_members(..)');
590
- if ((0, env_1.isDebug)()) {
591
- console.log('returning:');
592
- console.log(members);
593
- console.log();
594
- }
595
- return members;
596
- };
597
- /**
598
- * Visit every single section or member (any key-value pair such as
599
- * key=value or key=[...] etc.).
600
- * @returns {
601
- type: resultType,
602
- key: resultKey,
603
- value: resultValue,
604
- }: IResult
605
- */
606
- // visitMember?: (ctx: MemberContext) => IResult;
607
- this.visitMember = (ctx) => {
608
- var _a, _b, _c, _d;
609
- (0, env_1.isDebug)() && console.log();
610
- (0, print_1.debugPrint)('-> Entered visitMember(..)');
611
- (0, print_1.debugPrint)(' key = ' + ((_a = ctx.KEY()) === null || _a === void 0 ? void 0 : _a.getText().trim()));
612
- (0, print_1.debugPrint)('Or, section head = ' +
613
- ((_b = ctx.SECTION_HEAD()) === null || _b === void 0 ? void 0 : _b.getText().trim()) +
614
- ' (head WITHOUT any members (ONLY detected here))');
615
- (0, print_1.debugPrint)(' ctx.value() = ' + ctx.value());
616
- // For logging and debugging purposes.
617
- let entityType = 'Unknown';
618
- let resultType = undefined;
619
- let resultKey = '';
620
- let resultValue = {};
621
- let followingSection = null;
622
- // NOTE: (!) It can never be both a key and section head.
623
- if ((_c = ctx.KEY()) === null || _c === void 0 ? void 0 : _c.getText().trim()) {
624
- entityType = 'Member-Key';
625
- try {
626
- resultKey = ctx.KEY().getText();
627
- }
628
- catch (error) {
629
- (0, print_1.debugPrint)('in catch..');
630
- const msg = `Unexpected syntax while parsing a member (key-value pair)`;
631
- // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
632
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', msg);
633
- }
634
- const result = ctx.value()
635
- ? this.visitValue(ctx.value())
636
- : null;
637
- resultType = result === null || result === void 0 ? void 0 : result.type;
638
- resultValue = result === null || result === void 0 ? void 0 : result.value;
639
- (0, print_1.debugPrint)(' type = ' + resultType + ' @visitValue(..)');
640
- (0, print_1.debugPrint)('value = ' + resultValue + ' @visitValue(..)');
641
- }
642
- else if ((_d = ctx.SECTION_HEAD()) === null || _d === void 0 ? void 0 : _d.getText().trim()) {
643
- entityType = 'Section-Head';
644
- //NOTE: There might be an issue here that some subsection gets missing!!
645
- // const line = '' + ctx.SECTION_HEAD().getText().trim()
646
- const line = ctx.SECTION_HEAD().getText().trim();
647
- (0, print_1.debugPrint)('(!) Detected a section head instead: ' + line);
648
- followingSection = this.visitSection(ctx);
649
- // Object.assign(members, sectionObj)
650
- (0, print_1.debugPrint)('Got constructed object of builtSection (visitSection(..):');
651
- if ((0, env_1.isDebug)()) {
652
- console.log(followingSection);
653
- }
654
- //@todo (Is this fixed now? 2025-07-10) Mount the nested object correctly!
655
- resultType = 'Object';
656
- // resultValue[nestedSection?.name] = nestedSection?.members
657
- resultValue = (followingSection === null || followingSection === void 0 ? void 0 : followingSection.members) || {};
658
- resultKey = followingSection.name;
659
- (0, print_1.debugPrint)("resultKey = '" + resultKey + "'");
660
- (0, print_1.debugPrint)('resultValue:');
661
- if ((0, env_1.isDebug)()) {
662
- (0, print_1.printObject)(resultValue);
663
- }
664
- (0, print_1.debugPrint)('Mounted/assigned a section onto resultValue...');
665
- // Object.assign(value, { dummy: 6767 })
666
- // Object.assign(resultValue, {
667
- // dummy: 'That was detected a section head instead!',
668
- // })
669
- (0, print_1.debugPrint)();
670
- }
671
- (0, print_1.debugPrint)();
672
- (0, print_1.debugPrint)("entity = '" + entityType + "'");
673
- (0, print_1.debugPrint)("resultType = '" + resultType + "'");
674
- (0, print_1.debugPrint)("resultKey = '" + resultKey + "'");
675
- if (resultKey) {
676
- (0, print_1.debugPrint)();
677
- (0, print_1.debugPrint)('Has a key... Validate it either as a simple or a backticked ident...');
678
- if ((0, string_1.isEnclosedInBackticks)(resultKey)) {
679
- if (!(0, yiniHelpers_1.isValidBacktickedIdent)(resultKey)) {
680
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Invalid key name of this member, backticked key/identifier: "' +
681
- resultKey +
682
- '"', 'Section name should be backticked like e.g. `My section name`.');
683
- }
684
- resultKey = (0, string_1.trimBackticks)(resultKey);
685
- (0, print_1.debugPrint)("resultKey = '" + resultKey + "' (trimBackticks)");
686
- }
687
- else {
688
- if (!(0, yiniHelpers_1.isValidSimpleIdent)(resultKey)) {
689
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Invalid key name of this member, key/identifier: "' +
690
- resultKey +
691
- '"', 'Section name must start with: A-Z, a-z, or _, unless enclosed in backticks e.g. `' +
692
- resultKey +
693
- '`, `My key name`.');
694
- }
695
- }
696
- }
697
- if (resultValue === undefined) {
698
- (0, print_1.debugPrint)('Detected value as undefined');
699
- if (!this.isStrict) {
700
- (0, print_1.debugPrint)('Overloading undefined value with null');
701
- resultValue = null;
702
- }
703
- else {
704
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Encountered an empty/missing value in strict mode', 'Expected a value but found nothing, strict mode does not allow implicit null.', 'If you intend to have a null value, please specify "null" explicitly as the value.');
705
- }
706
- }
707
- (0, print_1.debugPrint)('*** Constructed JS object ***');
708
- (0, print_1.debugPrint)('resultValue:');
709
- if ((0, env_1.isDebug)()) {
710
- console.log(resultValue);
711
- }
712
- (0, print_1.debugPrint)();
713
- (0, print_1.debugPrint)('<- About to leave visitMember(..)');
714
- if ((0, env_1.isDebug)()) {
715
- console.log('returning:');
716
- console.log({
717
- type: resultType,
718
- key: resultKey,
719
- value: resultValue,
720
- });
721
- console.log();
722
- }
723
- if (!resultType && !resultKey) {
724
- // Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
725
- this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Unknown input');
726
- }
727
- // if (!isValidSimpleIdent(resultKey)) {
728
- // if (resultType !== 'Object' && !isValidSimpleIdent(resultKey)) {
729
- // this.errorHandler!.pushOrBail(
730
- // ctx,
731
- // 'Syntax-Error',
732
- // 'Invalid name of this key of a member, key name: "' +
733
- // resultKey +
734
- // '"',
735
- // 'Key name must start with: A-Z, a-z, or _, unless enclosed in backticks e.g. `' +
736
- // resultKey +
737
- // '`, `My key name`.',
738
- // )
739
- // }
740
- (0, print_1.debugPrint)();
741
- (0, print_1.debugPrint)('<- Leaving visitMember(..)');
742
- if ((0, env_1.isDebug)()) {
743
- console.log('returning:');
744
- console.log({
745
- type: resultType,
746
- key: resultKey,
747
- value: resultValue,
748
- });
749
- console.log();
750
- }
751
- return {
752
- type: resultType,
753
- key: resultKey,
754
- value: resultValue,
755
- };
756
- };
757
- /**
758
- * Visit a parse tree produced by `YiniParser.member_colon_list`.
759
- * @param ctx the parse tree
760
- * @return the visitor result
761
- */
762
- //visitMember_colon_list?: (ctx: Member_colon_listContext) => IResult
763
- this.visitMember_colon_list = (ctx) => {
764
- (0, env_1.isDebug)() && console.log();
765
- (0, print_1.debugPrint)('-> Entered visitMember_colon_list(..)');
766
- const key = ctx.KEY().getText();
767
- const values = this.visit(ctx.elements());
768
- return { key, value: values };
769
- };
770
- /**
771
- * Visit a parse tree produced by `YiniParser.value`.
772
- * @param ctx the parse tree
773
- * @return the visitor result
774
- */
775
- // visitValue?: (ctx: ValueContext) => IResult
776
- this.visitValue = (ctx) => {
777
- (0, env_1.isDebug)() && console.log();
778
- (0, print_1.debugPrint)('-> Entered visitValue(..)');
779
- if (ctx.string_literal())
780
- return this.visit(ctx.string_literal());
781
- if (ctx.number_literal())
782
- return this.visit(ctx.number_literal());
783
- if (ctx.boolean_literal())
784
- return this.visit(ctx.boolean_literal());
785
- if (ctx.null_literal())
786
- return this.visit(ctx.null_literal());
787
- if (ctx.object_literal())
788
- return this.visit(ctx.object_literal());
789
- if (ctx.list_in_brackets())
790
- return this.visit(ctx.list_in_brackets());
791
- // if (ctx.string_concat()) return this.visit(ctx.string_concat())
792
- return null;
793
- };
794
- /**
795
- * Visit a parse tree produced by `YiniParser.string_literal`.
796
- * @param ctx the parse tree
797
- * @return the visitor result
798
- */
799
- // visitString_literal?: (ctx: String_literalContext) => Result
800
- this.visitString_literal = (ctx) => {
801
- (0, print_1.debugPrint)('-> Entered visitString_literal(..)');
802
- const raw = ctx.getText();
803
- (0, print_1.debugPrint)('raw = >>>' + raw + '<<<');
804
- const value = (0, parseString_1.default)(raw);
805
- return { type: 'String', value };
806
- };
807
- /**
808
- * Visit a parse tree produced by `YiniParser.number_literal`.
809
- * @param ctx the parse tree
810
- * @return the visitor result
811
- */
812
- // visitNumber_literal?: (ctx: Number_literalContext) => IResult
813
- this.visitNumber_literal = (ctx) => {
814
- (0, print_1.debugPrint)('-> Entered visitNumber_literal(..)');
815
- const txt = ctx.getText();
816
- const { type, value } = (0, parseNumber_1.default)(txt);
817
- return { type, value };
818
- };
819
- /**
820
- * Visit a parse tree produced by `YiniParser.boolean_literal`.
821
- * @param ctx the parse tree
822
- * @return the visitor result
823
- */
824
- //visitBoolean_literal?: (ctx: Boolean_literalContext) => IResult
825
- this.visitBoolean_literal = (ctx) => {
826
- (0, print_1.debugPrint)('-> Entered visitBoolean_literal(..)');
827
- const txt = ctx.getText().toLowerCase();
828
- // return ['true', 'yes', 'on'].includes(text) as IResult
829
- const value = (0, parseBoolean_1.default)(txt);
830
- return { type: 'Boolean', value };
831
- };
832
- /**
833
- * Visit a parse tree produced by `YiniParser.null_literal`.
834
- * @param ctx the parse tree
835
- * @return the visitor result
836
- */
837
- this.visitNull_literal = (ctx) => {
838
- (0, print_1.debugPrint)('-> Entered visitNull_literal(..)');
839
- const txt = ctx.getText();
840
- const value = (0, parseNull_1.default)(txt);
841
- return { type: 'Null', value };
842
- };
843
- /**
844
- * Visit a parse tree produced by `YiniParser.object_literal`.
845
- * @param ctx the parse tree
846
- * @return the visitor result
847
- */
848
- // visitObject_literal?: (ctx: Object_literalContext) => IResult
849
- this.visitObject_literal = (ctx) => {
850
- const members = ctx.objectMemberList()
851
- ? this.visit(ctx.objectMemberList())
852
- : {};
853
- return { type: 'Object', value: members };
854
- };
855
- /**
856
- * Visit a parse tree produced by `YiniParser.objectMemberList`.
857
- * @param ctx the parse tree
858
- * @return the visitor result
859
- */
860
- //visitObjectMemberList?: (ctx: ObjectMemberListContext) => IResult
861
- this.visitObjectMemberList = (ctx) => {
862
- const obj = {};
863
- ctx.objectMember_list().forEach((member) => {
864
- const { key, value } = this.visit(member);
865
- obj[key] = value;
866
- });
867
- return obj;
868
- };
869
- /**
870
- * Visit a parse tree produced by `YiniParser.objectMember`.
871
- * @param ctx the parse tree
872
- * @return the visitor result
873
- */
874
- // visitObjectMember?: (ctx: ObjectMemberContext) => IResult
875
- this.visitObjectMember = (ctx) => {
876
- const key = ctx.KEY().getText();
877
- const value = ctx.value() ? this.visit(ctx.value()) : null;
878
- return { key, value };
879
- };
880
- /**
881
- * Visit a parse tree produced by `YiniParser.list`.
882
- * @param ctx the parse tree
883
- * @return the visitor result
884
- */
885
- // visitList?: (ctx: ListContext) => IResult
886
- this.visitList = (ctx) => this.visit(ctx.list_in_brackets());
887
- /**
888
- * Visit a parse tree produced by `YiniParser.list_in_brackets`.
889
- * @param ctx the parse tree
890
- * @return the visitor result
891
- */
892
- // visitList_in_brackets?: (ctx: List_in_bracketsContext) => IResult
893
- this.visitList_in_brackets = (ctx) => {
894
- (0, print_1.debugPrint)('-> Entered visitList_in_brackets(..)');
895
- let elements = [];
896
- if (!ctx.elements()) {
897
- (0, print_1.debugPrint)('Detected elements() is [], in list brackets');
898
- // elements = []
899
- return { type: 'List', value: [] };
900
- }
901
- else {
902
- (0, print_1.debugPrint)('Detected elements() has items, in list brackets');
903
- elements = this.visit(ctx.elements());
904
- }
905
- (0, print_1.debugPrint)('<- Leaving visitList_in_brackets(..)');
906
- if ((0, env_1.isDebug)()) {
907
- console.log('returning:');
908
- console.log({ type: 'List', value: elements.value });
909
- console.log();
910
- }
911
- return { type: 'List', value: elements.value };
912
- };
913
- /**
914
- * Visit a parse tree produced by `YiniParser.elements`.
915
- * @param ctx the parse tree
916
- * @return the visitor result
917
- */
918
- this.visitElements = (ctx) => {
919
- (0, print_1.debugPrint)('-> Entered visitElements(..)');
920
- const firstElem = ctx.element();
921
- let elements = [];
922
- (0, print_1.debugPrint)(' element = ' + firstElem);
923
- (0, print_1.debugPrint)(' element.getText() = ' + firstElem.getText());
924
- (0, print_1.debugPrint)(' elements = ' + !!ctx.elements());
925
- const resultElem = ctx.element()
926
- ? this.visitElement(ctx.element())
927
- : null;
928
- const resultTypeElem = resultElem === null || resultElem === void 0 ? void 0 : resultElem.type;
929
- const resultValueElem = resultElem === null || resultElem === void 0 ? void 0 : resultElem.value;
930
- (0, print_1.debugPrint)(' elem type = ' + resultTypeElem + ' @visitElements(..)');
931
- (0, print_1.debugPrint)(' elem value = ' + resultValueElem + ' @visitElements(..)');
932
- const resultElems = ctx.elements()
933
- ? this.visitElements(ctx.elements())
934
- : null;
935
- const resultTypeElems = resultElems === null || resultElems === void 0 ? void 0 : resultElems.type;
936
- const resultValueElems = resultElems === null || resultElems === void 0 ? void 0 : resultElems.value;
937
- (0, print_1.debugPrint)(' elems type = ' +
938
- resultTypeElems +
939
- ' @visitElements(..)');
940
- (0, print_1.debugPrint)(' elems value = ' +
941
- resultValueElems +
942
- ' @visitElements(..)');
943
- if (!ctx.elements()) {
944
- (0, print_1.debugPrint)('In visitElements(..) detected that elements() has no elements');
945
- elements = undefined;
946
- }
947
- else {
948
- (0, print_1.debugPrint)('In visitElements(..) detected elements in elements()');
949
- elements = this.visit(ctx.elements());
950
- if ((0, env_1.isDebug)()) {
951
- console.log('result of visited elements:');
952
- (0, print_1.printObject)(elements);
953
- }
954
- }
955
- const returnValues = elements
956
- ? [resultElem].concat(elements.value)
957
- : [resultElem];
958
- (0, print_1.debugPrint)('<- Leaving visitElements(..)');
959
- if ((0, env_1.isDebug)()) {
960
- console.log('returnValues:');
961
- (0, print_1.printObject)(returnValues);
962
- }
963
- return {
964
- type: 'List',
965
- // value: [resultElem].concat(elements.value),
966
- value: returnValues,
967
- };
968
- };
969
- /**
970
- * Visit a parse tree produced by `YiniParser.element`.
971
- * @param ctx the parse tree
972
- * @return the visitor result
973
- */
974
- // visitElement?: (ctx: ElementContext) => IResult
975
- // visitElement = (ctx: ElementContext): IResult => {
976
- this.visitElement = (ctx) => {
977
- (0, print_1.debugPrint)('-> Entered visitElement(..)');
978
- // if (ctx.value()) {
979
- // return this.visit(ctx.value())
980
- // } else {
981
- // return { type: 'Null', value: null } as IResult
982
- // }
983
- let result;
984
- if (ctx.value()) {
985
- result = this.visit(ctx.value());
986
- }
987
- else {
988
- result = { type: 'Null', value: null };
989
- }
990
- (0, print_1.debugPrint)('<- Leaving visitElement(..)');
991
- if ((0, env_1.isDebug)()) {
992
- console.log('returning:');
993
- (0, print_1.printObject)(result);
994
- console.log();
995
- }
996
- //return 'value'
997
- switch (result.type) {
998
- case 'String':
999
- return `${result.value}`;
1000
- default:
1001
- return result.value;
1002
- }
1003
- };
1004
- this.errorHandler = errorHandler;
1005
- this.isStrict = isStrict;
1006
- }
1007
- }
1008
- exports.default = YINIVisitor;