yini-parser 1.0.0-alpha.5 → 1.0.0-alpha.7
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/CHANGELOG.md +20 -0
- package/README.md +260 -28
- package/dist/YINI.d.ts +27 -5
- package/dist/YINI.js +27 -5
- package/dist/core/ErrorDataHandler.js +34 -38
- package/dist/core/YINIVisitor.d.ts +3 -0
- package/dist/core/YINIVisitor.js +55 -4
- package/dist/core/objectBuilder.js +21 -2
- package/dist/grammar/YiniLexer.d.ts +40 -41
- package/dist/grammar/YiniLexer.js +283 -287
- package/dist/grammar/YiniParser.d.ts +40 -41
- package/dist/grammar/YiniParser.js +138 -141
- package/dist/index.js +11 -13
- package/dist/parsers/extractHeaderParts.js +1 -1
- package/dist/utils/system.d.ts +10 -5
- package/dist/utils/system.js +21 -3
- package/dist/yiniHelpers.js +1 -1
- package/package.json +1 -1
package/dist/core/YINIVisitor.js
CHANGED
|
@@ -38,13 +38,47 @@ class YINIVisitor extends YiniParserVisitor_1.default {
|
|
|
38
38
|
this.meta_numOfMembers = 0; // For stats.
|
|
39
39
|
this.meta_numOfChains = 0; // For stats.
|
|
40
40
|
this.meta_maxLevelSection = 0; // For stats.
|
|
41
|
-
|
|
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) => {
|
|
42
56
|
if ((0, env_1.isDebug)()) {
|
|
43
57
|
console.log();
|
|
44
58
|
(0, system_1.debugPrint)('--- In pushOnTree(..) --------');
|
|
45
59
|
(0, system_1.debugPrint)('sReslult:');
|
|
46
60
|
(0, system_1.printObject)(sReslult);
|
|
47
61
|
}
|
|
62
|
+
const key = sReslult.level + '-' + sReslult.name;
|
|
63
|
+
(0, system_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, system_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
|
+
}
|
|
48
82
|
// if (
|
|
49
83
|
// sReslult.level === 0 &&
|
|
50
84
|
// (!sReslult.name || sReslult.name === 'undefined')
|
|
@@ -115,7 +149,7 @@ class YINIVisitor extends YiniParserVisitor_1.default {
|
|
|
115
149
|
// ctx?.section_list()?.forEach((section: any) => {
|
|
116
150
|
(0, system_1.debugPrint)('\nStart of each element in forEeach(..) of section_list():');
|
|
117
151
|
const topSectionResult = this.visitSection(section);
|
|
118
|
-
this.pushOnTree(topSectionResult);
|
|
152
|
+
this.pushOnTree(ctx, topSectionResult);
|
|
119
153
|
const topSectionName = topSectionResult === null || topSectionResult === void 0 ? void 0 : topSectionResult.name;
|
|
120
154
|
const topSectionMembers = topSectionResult === null || topSectionResult === void 0 ? void 0 : topSectionResult.members;
|
|
121
155
|
const topSectionLevel = topSectionResult === null || topSectionResult === void 0 ? void 0 : topSectionResult.level; // This must have a value of 1.
|
|
@@ -386,7 +420,7 @@ class YINIVisitor extends YiniParserVisitor_1.default {
|
|
|
386
420
|
this.lastActiveSectionAtLevels[this.level - 1] = {
|
|
387
421
|
[sectionName]: Object.assign({}, members),
|
|
388
422
|
};
|
|
389
|
-
this.pushOnTree({
|
|
423
|
+
this.pushOnTree(ctx, {
|
|
390
424
|
level: sectionLevel,
|
|
391
425
|
name: sectionName,
|
|
392
426
|
members,
|
|
@@ -499,7 +533,8 @@ class YINIVisitor extends YiniParserVisitor_1.default {
|
|
|
499
533
|
}
|
|
500
534
|
else {
|
|
501
535
|
this.meta_numOfMembers++;
|
|
502
|
-
if ((value
|
|
536
|
+
// if ((value?.type as TDataType) === 'Null') {
|
|
537
|
+
if (type === 'Null') {
|
|
503
538
|
members[key] = null;
|
|
504
539
|
}
|
|
505
540
|
else {
|
|
@@ -507,6 +542,22 @@ class YINIVisitor extends YiniParserVisitor_1.default {
|
|
|
507
542
|
// NOTE: (!) Only if nested section.
|
|
508
543
|
(0, system_1.debugPrint)('About to mount a single member or section onto members...');
|
|
509
544
|
(0, env_1.isDebug)() && console.log({ [key]: value });
|
|
545
|
+
// if ((type as TDataType) === 'Object') {
|
|
546
|
+
// const isExistingSectionName =
|
|
547
|
+
// this.hasDefinedSectionTitle(key, this.level)
|
|
548
|
+
// debugPrint(' type = "' + type + '"')
|
|
549
|
+
// debugPrint('this.level = "' + this.level + '"')
|
|
550
|
+
// debugPrint(
|
|
551
|
+
// 'DDDDDDDD: sectionName / objectKey: ' + key,
|
|
552
|
+
// )
|
|
553
|
+
// debugPrint(
|
|
554
|
+
// 'Is already defined at this level? ' +
|
|
555
|
+
// isExistingSectionName,
|
|
556
|
+
// )
|
|
557
|
+
// if (!isExistingSectionName) {
|
|
558
|
+
// this.setDefineSectionTitle(key, this.level)
|
|
559
|
+
// }
|
|
560
|
+
// }
|
|
510
561
|
Object.assign(members, { [key]: value });
|
|
511
562
|
(0, system_1.debugPrint)('+ Added member or section onto members: "' +
|
|
512
563
|
key +
|
|
@@ -77,6 +77,9 @@ class Builder {
|
|
|
77
77
|
}
|
|
78
78
|
mountChainOntoLevel(chainC, workingSubTree) {
|
|
79
79
|
(0, system_1.debugPrint)('-> Builder: mountChainOntoLevel(..)');
|
|
80
|
+
if ((0, env_1.isDebug)()) {
|
|
81
|
+
(0, system_1.printObject)(chainC);
|
|
82
|
+
}
|
|
80
83
|
if (chainC.originLevel > 1) {
|
|
81
84
|
// NOP
|
|
82
85
|
}
|
|
@@ -101,7 +104,7 @@ class Builder {
|
|
|
101
104
|
(0, system_1.printObject)(workingSubTree.chain);
|
|
102
105
|
}
|
|
103
106
|
(0, system_1.debugPrint)('Mount currentChain onto workingFullSubTree.');
|
|
104
|
-
workingSubTree.chain = mountObjectAtLevel(workingSubTree.chain, chain, targetLevel);
|
|
107
|
+
workingSubTree.chain = mountObjectAtLevel(workingSubTree.chain, chain, targetLevel, this.errorHandler);
|
|
105
108
|
if ((0, env_1.isDebug)()) {
|
|
106
109
|
(0, system_1.debugPrint)('After mounting onto workingSubTree.chain:');
|
|
107
110
|
(0, system_1.printObject)(workingSubTree.chain);
|
|
@@ -140,7 +143,7 @@ class Builder {
|
|
|
140
143
|
* 1-based) in objectSrc.
|
|
141
144
|
* @return Returns a new object without mutating input objects.
|
|
142
145
|
*/
|
|
143
|
-
const mountObjectAtLevel = (objectSrc, objectDest, level) => {
|
|
146
|
+
const mountObjectAtLevel = (objectSrc, objectDest, level, errorHandler) => {
|
|
144
147
|
// Deep copy to avoid mutating the input.
|
|
145
148
|
const result = JSON.parse(JSON.stringify(objectSrc));
|
|
146
149
|
let current = result;
|
|
@@ -160,6 +163,22 @@ const mountObjectAtLevel = (objectSrc, objectDest, level) => {
|
|
|
160
163
|
current = current[nextKey];
|
|
161
164
|
currentLevel++;
|
|
162
165
|
}
|
|
166
|
+
(0, system_1.debugPrint)('--------');
|
|
167
|
+
(0, system_1.debugPrint)(' current = ' + (0, system_1.toPrettyJSON)(current));
|
|
168
|
+
const [firstKey] = Object.keys(objectDest);
|
|
169
|
+
(0, system_1.debugPrint)('objectDest = ' + firstKey);
|
|
170
|
+
if (Object.prototype.hasOwnProperty.call(current, firstKey)) {
|
|
171
|
+
//@todo Add metadata with line number, onto chainC, so can use line number in error reporting
|
|
172
|
+
(0, system_1.debugPrint)(`(!) sectionName already exist, name: "${firstKey}", in: `);
|
|
173
|
+
(0, system_1.debugPrint)((0, system_1.toPrettyJSON)(current));
|
|
174
|
+
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
175
|
+
errorHandler.pushOrBail(null, 'Syntax-Error', 'Section name already exists', 'Cannot redefine section name: "' +
|
|
176
|
+
firstKey +
|
|
177
|
+
'" at level ' +
|
|
178
|
+
currentLevel +
|
|
179
|
+
'.');
|
|
180
|
+
return current;
|
|
181
|
+
}
|
|
163
182
|
// Mount objectDest onto the object at the required level.
|
|
164
183
|
Object.assign(current, objectDest);
|
|
165
184
|
return result;
|
|
@@ -6,47 +6,46 @@ export default class YiniLexer extends Lexer {
|
|
|
6
6
|
static readonly SS = 4;
|
|
7
7
|
static readonly EUR = 5;
|
|
8
8
|
static readonly CARET = 6;
|
|
9
|
-
static readonly
|
|
10
|
-
static readonly
|
|
11
|
-
static readonly
|
|
12
|
-
static readonly
|
|
13
|
-
static readonly
|
|
14
|
-
static readonly
|
|
15
|
-
static readonly
|
|
16
|
-
static readonly
|
|
17
|
-
static readonly
|
|
18
|
-
static readonly
|
|
19
|
-
static readonly
|
|
20
|
-
static readonly
|
|
21
|
-
static readonly
|
|
22
|
-
static readonly
|
|
23
|
-
static readonly
|
|
24
|
-
static readonly
|
|
25
|
-
static readonly
|
|
26
|
-
static readonly
|
|
27
|
-
static readonly
|
|
28
|
-
static readonly
|
|
29
|
-
static readonly
|
|
30
|
-
static readonly
|
|
31
|
-
static readonly
|
|
32
|
-
static readonly
|
|
33
|
-
static readonly
|
|
34
|
-
static readonly
|
|
35
|
-
static readonly
|
|
36
|
-
static readonly
|
|
37
|
-
static readonly
|
|
38
|
-
static readonly
|
|
39
|
-
static readonly
|
|
40
|
-
static readonly
|
|
41
|
-
static readonly
|
|
42
|
-
static readonly
|
|
43
|
-
static readonly
|
|
44
|
-
static readonly
|
|
45
|
-
static readonly
|
|
46
|
-
static readonly
|
|
47
|
-
static readonly
|
|
48
|
-
static readonly
|
|
49
|
-
static readonly IDENT_INVALID = 47;
|
|
9
|
+
static readonly GT = 7;
|
|
10
|
+
static readonly LT = 8;
|
|
11
|
+
static readonly EQ = 9;
|
|
12
|
+
static readonly HASH = 10;
|
|
13
|
+
static readonly COMMA = 11;
|
|
14
|
+
static readonly COLON = 12;
|
|
15
|
+
static readonly OB = 13;
|
|
16
|
+
static readonly CB = 14;
|
|
17
|
+
static readonly OC = 15;
|
|
18
|
+
static readonly CC = 16;
|
|
19
|
+
static readonly PLUS = 17;
|
|
20
|
+
static readonly DOLLAR = 18;
|
|
21
|
+
static readonly PC = 19;
|
|
22
|
+
static readonly AT = 20;
|
|
23
|
+
static readonly SEMICOLON = 21;
|
|
24
|
+
static readonly BOOLEAN_FALSE = 22;
|
|
25
|
+
static readonly BOOLEAN_TRUE = 23;
|
|
26
|
+
static readonly NULL = 24;
|
|
27
|
+
static readonly EMPTY_OBJECT = 25;
|
|
28
|
+
static readonly EMPTY_LIST = 26;
|
|
29
|
+
static readonly SHEBANG = 27;
|
|
30
|
+
static readonly NUMBER = 28;
|
|
31
|
+
static readonly KEY = 29;
|
|
32
|
+
static readonly IDENT = 30;
|
|
33
|
+
static readonly IDENT_BACKTICKED = 31;
|
|
34
|
+
static readonly STRING = 32;
|
|
35
|
+
static readonly TRIPLE_QUOTED_STRING = 33;
|
|
36
|
+
static readonly SINGLE_OR_DOUBLE = 34;
|
|
37
|
+
static readonly R_AND_C_STRING = 35;
|
|
38
|
+
static readonly HYPER_STRING = 36;
|
|
39
|
+
static readonly ESC_SEQ = 37;
|
|
40
|
+
static readonly ESC_SEQ_BASE = 38;
|
|
41
|
+
static readonly NL = 39;
|
|
42
|
+
static readonly SINGLE_NL = 40;
|
|
43
|
+
static readonly WS = 41;
|
|
44
|
+
static readonly BLOCK_COMMENT = 42;
|
|
45
|
+
static readonly COMMENT = 43;
|
|
46
|
+
static readonly LINE_COMMENT = 44;
|
|
47
|
+
static readonly INLINE_COMMENT = 45;
|
|
48
|
+
static readonly IDENT_INVALID = 46;
|
|
50
49
|
static readonly EOF: number;
|
|
51
50
|
static readonly channelNames: string[];
|
|
52
51
|
static readonly literalNames: (string | null)[];
|