yini-parser 1.0.0-alpha.7 → 1.0.0-beta.1
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 +8 -0
- package/README.md +254 -151
- package/dist/YINI.js +15 -15
- package/dist/core/ErrorDataHandler.js +15 -15
- package/dist/core/YINIVisitor.d.ts +2 -2
- package/dist/core/YINIVisitor.js +254 -160
- package/dist/core/objectBuilder.js +39 -39
- package/dist/grammar/YiniLexer.js +5 -2
- package/dist/grammar/YiniParser.d.ts +28 -4
- package/dist/grammar/YiniParser.js +548 -298
- package/dist/grammar/YiniParserVisitor.d.ts +14 -0
- package/dist/grammar/YiniParserVisitor.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +17 -18
- package/dist/parseEntry.js +21 -21
- package/dist/parsers/extractHeaderParts.js +14 -14
- package/dist/parsers/extractSignificantYiniLine.js +18 -16
- 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/basic-with-comments.yini +15 -0
- package/examples/basic.yini +11 -0
- package/examples/compare-formats.md +89 -0
- package/examples/nested-output.js +18 -0
- package/examples/nested.yini +26 -0
- package/examples/parse-example.ts +22 -0
- package/package.json +3 -2
- /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 +
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Generated from grammar/v1.0.0-
|
|
3
|
+
// Generated from grammar/v1.0.0-rc.1/YiniLexer.g4 by ANTLR 4.13.2
|
|
4
4
|
// noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols
|
|
5
5
|
const antlr4_1 = require("antlr4");
|
|
6
6
|
class YiniLexer extends antlr4_1.Lexer {
|
|
@@ -81,7 +81,10 @@ YiniLexer.literalNames = [null, null,
|
|
|
81
81
|
"']'", "'{'",
|
|
82
82
|
"'}'", "'+'",
|
|
83
83
|
"'$'", "'%'",
|
|
84
|
-
"'@'", "';'"
|
|
84
|
+
"'@'", "';'",
|
|
85
|
+
null, null,
|
|
86
|
+
null, "'{}'",
|
|
87
|
+
"'[]'"];
|
|
85
88
|
YiniLexer.symbolicNames = [null, "YINI_MARKER",
|
|
86
89
|
"SECTION_HEAD",
|
|
87
90
|
"TERMINAL_TOKEN",
|
|
@@ -67,6 +67,8 @@ export default class YiniParser extends Parser {
|
|
|
67
67
|
static readonly RULE_string_literal = 16;
|
|
68
68
|
static readonly RULE_string_concat = 17;
|
|
69
69
|
static readonly RULE_boolean_literal = 18;
|
|
70
|
+
static readonly RULE_empty_object = 19;
|
|
71
|
+
static readonly RULE_empty_list = 20;
|
|
70
72
|
static readonly literalNames: (string | null)[];
|
|
71
73
|
static readonly symbolicNames: (string | null)[];
|
|
72
74
|
static readonly ruleNames: string[];
|
|
@@ -96,6 +98,8 @@ export default class YiniParser extends Parser {
|
|
|
96
98
|
string_literal(): String_literalContext;
|
|
97
99
|
string_concat(): String_concatContext;
|
|
98
100
|
boolean_literal(): Boolean_literalContext;
|
|
101
|
+
empty_object(): Empty_objectContext;
|
|
102
|
+
empty_list(): Empty_listContext;
|
|
99
103
|
static readonly _serializedATN: number[];
|
|
100
104
|
private static __ATN;
|
|
101
105
|
static get _ATN(): ATN;
|
|
@@ -183,7 +187,7 @@ export declare class Object_literalContext extends ParserRuleContext {
|
|
|
183
187
|
CC(): TerminalNode;
|
|
184
188
|
NL_list(): TerminalNode[];
|
|
185
189
|
NL(i: number): TerminalNode;
|
|
186
|
-
|
|
190
|
+
empty_object(): Empty_objectContext;
|
|
187
191
|
get ruleIndex(): number;
|
|
188
192
|
accept<Result>(visitor: YiniParserVisitor<Result>): Result;
|
|
189
193
|
}
|
|
@@ -195,14 +199,14 @@ export declare class ObjectMemberListContext extends ParserRuleContext {
|
|
|
195
199
|
COMMA(i: number): TerminalNode;
|
|
196
200
|
NL_list(): TerminalNode[];
|
|
197
201
|
NL(i: number): TerminalNode;
|
|
198
|
-
|
|
202
|
+
empty_object(): Empty_objectContext;
|
|
199
203
|
get ruleIndex(): number;
|
|
200
204
|
accept<Result>(visitor: YiniParserVisitor<Result>): Result;
|
|
201
205
|
}
|
|
202
206
|
export declare class ObjectMemberContext extends ParserRuleContext {
|
|
203
207
|
constructor(parser?: YiniParser, parent?: ParserRuleContext, invokingState?: number);
|
|
204
208
|
KEY(): TerminalNode;
|
|
205
|
-
|
|
209
|
+
COLON(): TerminalNode;
|
|
206
210
|
value(): ValueContext;
|
|
207
211
|
WS(): TerminalNode;
|
|
208
212
|
NL_list(): TerminalNode[];
|
|
@@ -224,7 +228,7 @@ export declare class List_in_bracketsContext extends ParserRuleContext {
|
|
|
224
228
|
CB(): TerminalNode;
|
|
225
229
|
NL_list(): TerminalNode[];
|
|
226
230
|
NL(i: number): TerminalNode;
|
|
227
|
-
|
|
231
|
+
empty_list(): Empty_listContext;
|
|
228
232
|
get ruleIndex(): number;
|
|
229
233
|
accept<Result>(visitor: YiniParserVisitor<Result>): Result;
|
|
230
234
|
}
|
|
@@ -281,3 +285,23 @@ export declare class Boolean_literalContext extends ParserRuleContext {
|
|
|
281
285
|
get ruleIndex(): number;
|
|
282
286
|
accept<Result>(visitor: YiniParserVisitor<Result>): Result;
|
|
283
287
|
}
|
|
288
|
+
export declare class Empty_objectContext extends ParserRuleContext {
|
|
289
|
+
constructor(parser?: YiniParser, parent?: ParserRuleContext, invokingState?: number);
|
|
290
|
+
EMPTY_OBJECT(): TerminalNode;
|
|
291
|
+
OC(): TerminalNode;
|
|
292
|
+
CC(): TerminalNode;
|
|
293
|
+
NL_list(): TerminalNode[];
|
|
294
|
+
NL(i: number): TerminalNode;
|
|
295
|
+
get ruleIndex(): number;
|
|
296
|
+
accept<Result>(visitor: YiniParserVisitor<Result>): Result;
|
|
297
|
+
}
|
|
298
|
+
export declare class Empty_listContext extends ParserRuleContext {
|
|
299
|
+
constructor(parser?: YiniParser, parent?: ParserRuleContext, invokingState?: number);
|
|
300
|
+
EMPTY_LIST(): TerminalNode;
|
|
301
|
+
OB(): TerminalNode;
|
|
302
|
+
CB(): TerminalNode;
|
|
303
|
+
NL_list(): TerminalNode[];
|
|
304
|
+
NL(i: number): TerminalNode;
|
|
305
|
+
get ruleIndex(): number;
|
|
306
|
+
accept<Result>(visitor: YiniParserVisitor<Result>): Result;
|
|
307
|
+
}
|