yini-parser 1.0.0-alpha.7x → 1.0.1-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.
- package/CHANGELOG.md +11 -1
- package/README.md +15 -1
- package/dist/YINI.js +17 -19
- package/dist/core/ErrorDataHandler.js +15 -15
- package/dist/core/YINIVisitor.d.ts +7 -1
- package/dist/core/YINIVisitor.js +184 -175
- package/dist/core/objectBuilder.js +39 -39
- package/dist/grammar/YiniLexer.d.ts +1 -0
- package/dist/grammar/YiniLexer.js +236 -228
- package/dist/grammar/YiniParser.d.ts +18 -1
- package/dist/grammar/YiniParser.js +480 -305
- package/dist/grammar/YiniParserVisitor.d.ts +7 -0
- package/dist/grammar/YiniParserVisitor.js +1 -1
- package/dist/index.js +24 -44
- package/dist/parseEntry.js +47 -27
- package/dist/parsers/extractHeaderParts.js +14 -14
- package/dist/parsers/extractSignificantYiniLine.js +18 -18
- package/dist/parsers/parseBoolean.js +2 -2
- package/dist/parsers/parseNull.js +2 -2
- package/dist/parsers/parseNumber.js +8 -8
- package/dist/parsers/parseSectionHeader.js +19 -19
- package/dist/parsers/parseString.js +9 -9
- package/dist/utils/string.js +3 -3
- package/dist/yiniHelpers.js +3 -3
- package/examples/basic-output.js +15 -0
- package/examples/nested-output.js +18 -0
- package/package.json +5 -1
- /package/dist/utils/{system.d.ts → print.d.ts} +0 -0
- /package/dist/utils/{system.js → print.js} +0 -0
|
@@ -2,34 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.constructFinalObject = void 0;
|
|
4
4
|
const env_1 = require("../config/env");
|
|
5
|
-
const
|
|
5
|
+
const print_1 = require("../utils/print");
|
|
6
6
|
/**
|
|
7
7
|
* Construct the final result of a JavaScript Object.
|
|
8
8
|
*/
|
|
9
9
|
const constructFinalObject = (syntaxTreeC, errorHandler) => {
|
|
10
|
-
(0,
|
|
10
|
+
(0, print_1.debugPrint)('-> constructFinalObject(..)');
|
|
11
11
|
const bulder = new Builder(syntaxTreeC, errorHandler);
|
|
12
12
|
if ((0, env_1.isDebug)()) {
|
|
13
13
|
console.log('Argument, syntaxTreeC:');
|
|
14
|
-
(0,
|
|
14
|
+
(0, print_1.printObject)(syntaxTreeC);
|
|
15
15
|
}
|
|
16
16
|
const jsObject = bulder.doCheckAndBuild();
|
|
17
|
-
(0,
|
|
17
|
+
(0, print_1.debugPrint)('<- About to leave constructFinalObject(..)');
|
|
18
18
|
if ((0, env_1.isDebug)()) {
|
|
19
19
|
console.log('Returning, jsObject:');
|
|
20
|
-
(0,
|
|
20
|
+
(0, print_1.printObject)(syntaxTreeC);
|
|
21
21
|
}
|
|
22
22
|
return jsObject;
|
|
23
23
|
};
|
|
24
24
|
exports.constructFinalObject = constructFinalObject;
|
|
25
25
|
class Builder {
|
|
26
26
|
constructor(syntaxTreeC, errorHandler) {
|
|
27
|
-
(0,
|
|
27
|
+
(0, print_1.debugPrint)('-> Builder: constructor(..)');
|
|
28
28
|
this.syntaxTreeC = syntaxTreeC;
|
|
29
29
|
this.errorHandler = errorHandler;
|
|
30
30
|
}
|
|
31
31
|
doCheckAndBuild() {
|
|
32
|
-
(0,
|
|
32
|
+
(0, print_1.debugPrint)('-> Builder: doCheckAndBuild(..)');
|
|
33
33
|
if (!this.syntaxTreeC) {
|
|
34
34
|
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
35
35
|
this.errorHandler.pushOrBail(null, 'Fatal-Error', 'SyntaxTreeC is undefined', 'This is most likely caused by an internal error somewhere. The process cannot recover fully from this, sorry.');
|
|
@@ -39,46 +39,46 @@ class Builder {
|
|
|
39
39
|
return jsObject;
|
|
40
40
|
}
|
|
41
41
|
buildFullSubTrees(syntaxTreeC) {
|
|
42
|
-
(0,
|
|
42
|
+
(0, print_1.debugPrint)('-> Builder: buildFullSubTrees(..)');
|
|
43
43
|
(0, env_1.isDebug)() && console.log();
|
|
44
44
|
const fullSubTreeList = []; // List of FULL sub-trees.
|
|
45
45
|
// Current Working Full Sub-Tree (starting at level 1).
|
|
46
46
|
let workingFullSubTree = syntaxTreeC._syntaxTree[0]; // (!) Any tree MUST START at level 1.
|
|
47
|
-
(0,
|
|
47
|
+
(0, print_1.debugPrint)(`Setted new workingFullSubTree, from syntaxTreeC._syntaxTree[0]`);
|
|
48
48
|
const len = syntaxTreeC._syntaxTree.length;
|
|
49
49
|
for (let i = 1; i < len; i++) {
|
|
50
50
|
const currentChainC = syntaxTreeC._syntaxTree[i];
|
|
51
51
|
const level = currentChainC.originLevel;
|
|
52
52
|
const nestingIndex = level - 1; // For debugging purposes.
|
|
53
53
|
const chain = currentChainC.chain; // For debugging purposes.
|
|
54
|
-
(0,
|
|
55
|
-
(0,
|
|
54
|
+
(0, print_1.debugPrint)(`Got new chain from syntaxTreeC._syntaxTree[${i}] to be mounted onto parent...`);
|
|
55
|
+
(0, print_1.debugPrint)('* level: ' + level + ' (i=' + i + '), chain: ' + chain);
|
|
56
56
|
if (level === 1) {
|
|
57
|
-
(0,
|
|
57
|
+
(0, print_1.debugPrint)('HIT - Detected that currentChain starts with level 1');
|
|
58
58
|
fullSubTreeList.push(workingFullSubTree);
|
|
59
|
-
(0,
|
|
59
|
+
(0, print_1.debugPrint)('The workingFullSubTree is finished, pushed it to the list.');
|
|
60
60
|
workingFullSubTree = syntaxTreeC._syntaxTree[i]; // (!) The tree MUST START at level 1.
|
|
61
|
-
(0,
|
|
61
|
+
(0, print_1.debugPrint)(`Setted new workingFullSubTree, from syntaxTreeC._syntaxTree[${i}]`);
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
64
|
-
(0,
|
|
64
|
+
(0, print_1.debugPrint)('About to mount currentChain onto workingFullSubTree at correct level...');
|
|
65
65
|
workingFullSubTree = this.mountChainOntoLevel(currentChainC, workingFullSubTree);
|
|
66
66
|
}
|
|
67
|
-
(0,
|
|
67
|
+
(0, print_1.debugPrint)();
|
|
68
68
|
}
|
|
69
69
|
fullSubTreeList.push(workingFullSubTree);
|
|
70
70
|
if ((0, env_1.isDebug)()) {
|
|
71
71
|
console.log();
|
|
72
72
|
console.log('--- fullSubTreeList: (list of FULL sub-trees.) -------');
|
|
73
|
-
(0,
|
|
73
|
+
(0, print_1.printObject)(fullSubTreeList);
|
|
74
74
|
console.log();
|
|
75
75
|
}
|
|
76
76
|
return fullSubTreeList;
|
|
77
77
|
}
|
|
78
78
|
mountChainOntoLevel(chainC, workingSubTree) {
|
|
79
|
-
(0,
|
|
79
|
+
(0, print_1.debugPrint)('-> Builder: mountChainOntoLevel(..)');
|
|
80
80
|
if ((0, env_1.isDebug)()) {
|
|
81
|
-
(0,
|
|
81
|
+
(0, print_1.printObject)(chainC);
|
|
82
82
|
}
|
|
83
83
|
if (chainC.originLevel > 1) {
|
|
84
84
|
// NOP
|
|
@@ -86,36 +86,36 @@ class Builder {
|
|
|
86
86
|
else {
|
|
87
87
|
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
88
88
|
this.errorHandler.pushOrBail(null, 'Fatal-Error', 'Internal-Error: Detected incorrect chain in mountChainOntoLevel(..), start section has level: ' +
|
|
89
|
-
chainC.originLevel, 'The (chain) must start with a section level higher than 1', '' + (0,
|
|
89
|
+
chainC.originLevel, 'The (chain) must start with a section level higher than 1', '' + (0, print_1.printObject)(chainC));
|
|
90
90
|
}
|
|
91
91
|
if (workingSubTree.originLevel != 1) {
|
|
92
92
|
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
93
93
|
this.errorHandler.pushOrBail(null, 'Fatal-Error', 'Internal-Error: Detected incorrect full sub-tree in mountChainOntoLevel(..), start section has level: ' +
|
|
94
|
-
chainC.originLevel, 'A full sub-tree (chain) must start with a section at level 1', '' + (0,
|
|
94
|
+
chainC.originLevel, 'A full sub-tree (chain) must start with a section at level 1', '' + (0, print_1.printObject)(chainC));
|
|
95
95
|
}
|
|
96
96
|
const chain = chainC.chain;
|
|
97
97
|
const targetLevel = chainC.originLevel;
|
|
98
98
|
if ((0, env_1.isDebug)()) {
|
|
99
|
-
(0,
|
|
100
|
-
(0,
|
|
101
|
-
(0,
|
|
102
|
-
(0,
|
|
103
|
-
(0,
|
|
104
|
-
(0,
|
|
99
|
+
(0, print_1.debugPrint)('Target level = ' + targetLevel);
|
|
100
|
+
(0, print_1.debugPrint)(`The chain to mount: (onto level: ${targetLevel})`);
|
|
101
|
+
(0, print_1.printObject)(chain);
|
|
102
|
+
(0, print_1.debugPrint)('--- workingFullSubTree: -------');
|
|
103
|
+
(0, print_1.debugPrint)('Before mounting onto workingSubTree.chain:');
|
|
104
|
+
(0, print_1.printObject)(workingSubTree.chain);
|
|
105
105
|
}
|
|
106
|
-
(0,
|
|
106
|
+
(0, print_1.debugPrint)('Mount currentChain onto workingFullSubTree.');
|
|
107
107
|
workingSubTree.chain = mountObjectAtLevel(workingSubTree.chain, chain, targetLevel, this.errorHandler);
|
|
108
108
|
if ((0, env_1.isDebug)()) {
|
|
109
|
-
(0,
|
|
110
|
-
(0,
|
|
111
|
-
(0,
|
|
109
|
+
(0, print_1.debugPrint)('After mounting onto workingSubTree.chain:');
|
|
110
|
+
(0, print_1.printObject)(workingSubTree.chain);
|
|
111
|
+
(0, print_1.debugPrint)('----------');
|
|
112
112
|
}
|
|
113
|
-
(0,
|
|
113
|
+
(0, print_1.debugPrint)('<- Builder: mountChainOntoLevel(..)');
|
|
114
114
|
return workingSubTree;
|
|
115
115
|
}
|
|
116
116
|
// Contruct the final JS object from the list of full sub-trees.
|
|
117
117
|
buildObjectFromList(fullSubTreeList) {
|
|
118
|
-
(0,
|
|
118
|
+
(0, print_1.debugPrint)('-> Builder: buildObjectFromList(..)');
|
|
119
119
|
const jsObject = {};
|
|
120
120
|
for (const chainC of fullSubTreeList) {
|
|
121
121
|
if (chainC.originLevel === 1) {
|
|
@@ -132,7 +132,7 @@ class Builder {
|
|
|
132
132
|
else {
|
|
133
133
|
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
134
134
|
this.errorHandler.pushOrBail(null, 'Fatal-Error', 'Internal-Error: Detected incorrect full sub-tree in buildObjectFromList(..), start section has level: ' +
|
|
135
|
-
chainC.originLevel, 'A full sub-tree (chain) must start with a section at level 1', '' + (0,
|
|
135
|
+
chainC.originLevel, 'A full sub-tree (chain) must start with a section at level 1', '' + (0, print_1.printObject)(chainC));
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
return jsObject;
|
|
@@ -163,14 +163,14 @@ const mountObjectAtLevel = (objectSrc, objectDest, level, errorHandler) => {
|
|
|
163
163
|
current = current[nextKey];
|
|
164
164
|
currentLevel++;
|
|
165
165
|
}
|
|
166
|
-
(0,
|
|
167
|
-
(0,
|
|
166
|
+
(0, print_1.debugPrint)('--------');
|
|
167
|
+
(0, print_1.debugPrint)(' current = ' + (0, print_1.toPrettyJSON)(current));
|
|
168
168
|
const [firstKey] = Object.keys(objectDest);
|
|
169
|
-
(0,
|
|
169
|
+
(0, print_1.debugPrint)('objectDest = ' + firstKey);
|
|
170
170
|
if (Object.prototype.hasOwnProperty.call(current, firstKey)) {
|
|
171
171
|
//@todo Add metadata with line number, onto chainC, so can use line number in error reporting
|
|
172
|
-
(0,
|
|
173
|
-
(0,
|
|
172
|
+
(0, print_1.debugPrint)(`(!) sectionName already exist, name: "${firstKey}", in: `);
|
|
173
|
+
(0, print_1.debugPrint)((0, print_1.toPrettyJSON)(current));
|
|
174
174
|
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
175
175
|
errorHandler.pushOrBail(null, 'Syntax-Error', 'Section name already exists', 'Cannot redefine section name: "' +
|
|
176
176
|
firstKey +
|
|
@@ -46,6 +46,7 @@ export default class YiniLexer extends Lexer {
|
|
|
46
46
|
static readonly LINE_COMMENT = 44;
|
|
47
47
|
static readonly INLINE_COMMENT = 45;
|
|
48
48
|
static readonly IDENT_INVALID = 46;
|
|
49
|
+
static readonly REST = 47;
|
|
49
50
|
static readonly EOF: number;
|
|
50
51
|
static readonly channelNames: string[];
|
|
51
52
|
static readonly literalNames: (string | null)[];
|