yini-parser 1.1.0-beta → 1.3.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.
- package/CHANGELOG.md +50 -2
- package/README.md +2 -2
- package/dist/YINI.d.ts +155 -27
- package/dist/YINI.js +145 -174
- package/dist/YINI.js.map +1 -0
- package/dist/config/env.js +1 -0
- package/dist/config/env.js.map +1 -0
- package/dist/core/{ASTBuilder.d.ts → astBuilder.d.ts} +4 -4
- package/dist/core/{ASTBuilder.js → astBuilder.js} +82 -69
- package/dist/core/astBuilder.js.map +1 -0
- package/dist/core/{ErrorDataHandler.d.ts → errorDataHandler.d.ts} +16 -10
- package/dist/core/{ErrorDataHandler.js → errorDataHandler.js} +115 -109
- package/dist/core/errorDataHandler.js.map +1 -0
- package/dist/core/internalTypes.d.ts +127 -0
- package/dist/core/{types.js → internalTypes.js} +6 -0
- package/dist/core/internalTypes.js.map +1 -0
- package/dist/core/objectBuilder.d.ts +2 -2
- package/dist/core/objectBuilder.js +1 -0
- package/dist/core/objectBuilder.js.map +1 -0
- package/dist/core/options/defaultParserOptions.d.ts +17 -0
- package/dist/core/options/defaultParserOptions.js +46 -0
- package/dist/core/options/defaultParserOptions.js.map +1 -0
- package/dist/core/options/failLevel.d.ts +3 -0
- package/dist/core/options/failLevel.js +27 -0
- package/dist/core/options/failLevel.js.map +1 -0
- package/dist/core/options/optionsFunctions.d.ts +8 -0
- package/dist/core/options/optionsFunctions.js +62 -0
- package/dist/core/options/optionsFunctions.js.map +1 -0
- package/dist/core/parsingRules/modeFromRulesMatcher.d.ts +8 -0
- package/dist/core/parsingRules/modeFromRulesMatcher.js +114 -0
- package/dist/core/parsingRules/modeFromRulesMatcher.js.map +1 -0
- package/dist/core/parsingRules/rulesConstAndGuards.d.ts +7 -0
- package/dist/core/parsingRules/rulesConstAndGuards.js +35 -0
- package/dist/core/parsingRules/rulesConstAndGuards.js.map +1 -0
- package/dist/core/pipeline/errorListeners.d.ts +18 -0
- package/dist/core/pipeline/errorListeners.js +107 -0
- package/dist/core/pipeline/errorListeners.js.map +1 -0
- package/dist/core/pipeline/pipeline.d.ts +18 -0
- package/dist/core/pipeline/pipeline.js +244 -0
- package/dist/core/pipeline/pipeline.js.map +1 -0
- package/dist/core/resultMetadataBuilder.d.ts +19 -0
- package/dist/core/resultMetadataBuilder.js +187 -0
- package/dist/core/resultMetadataBuilder.js.map +1 -0
- package/dist/core/runtime.d.ts +21 -0
- package/dist/core/runtime.js +201 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/dev/main.d.ts +1 -0
- package/dist/dev/main.js +305 -0
- package/dist/dev/main.js.map +1 -0
- package/dist/grammar/{YiniLexer.js → generated/YiniLexer.js} +2 -1
- package/dist/grammar/generated/YiniLexer.js.map +1 -0
- package/dist/grammar/{YiniParser.js → generated/YiniParser.js} +2 -1
- package/dist/grammar/generated/YiniParser.js.map +1 -0
- package/dist/grammar/{YiniParserVisitor.js → generated/YiniParserVisitor.js} +2 -1
- package/dist/grammar/generated/YiniParserVisitor.js.map +1 -0
- package/dist/index.d.ts +40 -1
- package/dist/index.js +60 -359
- package/dist/index.js.map +1 -0
- package/dist/parsers/extractHeaderParts.d.ts +2 -2
- package/dist/parsers/extractHeaderParts.js +2 -1
- package/dist/parsers/extractHeaderParts.js.map +1 -0
- package/dist/parsers/extractSignificantYiniLine.js +2 -1
- package/dist/parsers/extractSignificantYiniLine.js.map +1 -0
- package/dist/parsers/parseBoolean.js +1 -0
- package/dist/parsers/parseBoolean.js.map +1 -0
- package/dist/parsers/parseNull.js +1 -0
- package/dist/parsers/parseNull.js.map +1 -0
- package/dist/parsers/parseNumber.js +1 -0
- package/dist/parsers/parseNumber.js.map +1 -0
- package/dist/parsers/parseSectionHeader.d.ts +3 -3
- package/dist/parsers/parseSectionHeader.js +2 -1
- package/dist/parsers/parseSectionHeader.js.map +1 -0
- package/dist/parsers/parseString.js +3 -3
- package/dist/parsers/parseString.js.map +1 -0
- package/dist/types/index.d.ts +219 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/number.js +1 -0
- package/dist/utils/number.js.map +1 -0
- package/dist/utils/object.d.ts +12 -0
- package/dist/utils/object.js +41 -1
- package/dist/utils/object.js.map +1 -0
- package/dist/utils/pathAndFileName.js +1 -0
- package/dist/utils/pathAndFileName.js.map +1 -0
- package/dist/utils/print.d.ts +2 -2
- package/dist/utils/print.js +11 -6
- package/dist/utils/print.js.map +1 -0
- package/dist/utils/string.d.ts +5 -0
- package/dist/utils/string.js +10 -1
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/system.js +1 -0
- package/dist/utils/system.js.map +1 -0
- package/dist/{yiniHelpers.d.ts → utils/yiniHelpers.d.ts} +1 -1
- package/dist/{yiniHelpers.js → utils/yiniHelpers.js} +3 -2
- package/dist/utils/yiniHelpers.js.map +1 -0
- package/examples/basic-output.js +12 -12
- package/package.json +11 -6
- package/dist/core/types.d.ts +0 -249
- package/dist/parseEntry.d.ts +0 -3
- package/dist/parseEntry.js +0 -456
- /package/dist/grammar/{YiniLexer.d.ts → generated/YiniLexer.d.ts} +0 -0
- /package/dist/grammar/{YiniParser.d.ts → generated/YiniParser.d.ts} +0 -0
- /package/dist/grammar/{YiniParserVisitor.d.ts → generated/YiniParserVisitor.d.ts} +0 -0
package/dist/parseEntry.js
DELETED
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports._parseMain = void 0;
|
|
40
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
41
|
-
const antlr4_1 = require("antlr4");
|
|
42
|
-
const env_1 = require("./config/env");
|
|
43
|
-
const ASTBuilder_1 = __importDefault(require("./core/ASTBuilder"));
|
|
44
|
-
const ErrorDataHandler_1 = require("./core/ErrorDataHandler");
|
|
45
|
-
const objectBuilder_1 = require("./core/objectBuilder");
|
|
46
|
-
const YiniLexer_1 = __importDefault(require("./grammar/YiniLexer"));
|
|
47
|
-
const YiniParser_1 = __importStar(require("./grammar/YiniParser"));
|
|
48
|
-
const object_1 = require("./utils/object");
|
|
49
|
-
const print_1 = require("./utils/print");
|
|
50
|
-
const string_1 = require("./utils/string");
|
|
51
|
-
const system_1 = require("./utils/system");
|
|
52
|
-
const pkg = require('../package.json');
|
|
53
|
-
/**
|
|
54
|
-
* @param line Line number as 1-based.
|
|
55
|
-
* @param col Column number as 0-based.
|
|
56
|
-
*/
|
|
57
|
-
const createGeneralCtx = (line, endColumn, startColumn = undefined) => {
|
|
58
|
-
const startToken = new antlr4_1.Token();
|
|
59
|
-
const stopToken = new antlr4_1.Token();
|
|
60
|
-
const ctx = new YiniParser_1.YiniContext();
|
|
61
|
-
ctx.start = startToken;
|
|
62
|
-
ctx.stop = stopToken;
|
|
63
|
-
ctx.start.line = line; // Note: Line num is 1-based.
|
|
64
|
-
if (startColumn && startColumn >= 0) {
|
|
65
|
-
ctx.start.column = startColumn; // Note: Column num is 0-based.
|
|
66
|
-
}
|
|
67
|
-
ctx.stop.column = endColumn; // Note: Column num is 0-based.
|
|
68
|
-
return ctx;
|
|
69
|
-
};
|
|
70
|
-
const parsePossibleStartCol = (errorHandler, recognizer) => {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
let possibleStartCol = undefined;
|
|
73
|
-
try {
|
|
74
|
-
possibleStartCol = ((_a = recognizer === null || recognizer === void 0 ? void 0 : recognizer._ctx.start) === null || _a === void 0 ? void 0 : _a.column)
|
|
75
|
-
? ((_b = recognizer === null || recognizer === void 0 ? void 0 : recognizer._ctx.start) === null || _b === void 0 ? void 0 : _b.column) + 1
|
|
76
|
-
: undefined;
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
let msgHint = '';
|
|
80
|
-
if ((0, system_1.isError)(err)) {
|
|
81
|
-
msgHint = 'Error: ' + err.message;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
msgHint = 'Thrown value:' + JSON.stringify(err);
|
|
85
|
-
}
|
|
86
|
-
errorHandler.pushOrBail(null, 'Internal-Error', 'Catched error of possibleStartCol in parser grammar listener.', msgHint);
|
|
87
|
-
}
|
|
88
|
-
return possibleStartCol;
|
|
89
|
-
};
|
|
90
|
-
class MyParserErrorListener {
|
|
91
|
-
constructor(errorHandler) {
|
|
92
|
-
this.errors = [];
|
|
93
|
-
this.errorHandler = errorHandler;
|
|
94
|
-
}
|
|
95
|
-
syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) {
|
|
96
|
-
(0, print_1.debugPrint)('ANTLR parser cached an error');
|
|
97
|
-
const col = charPositionInLine + 1;
|
|
98
|
-
const possibleStartCol = parsePossibleStartCol(this.errorHandler, recognizer);
|
|
99
|
-
const msgWhat = `Syntax error`;
|
|
100
|
-
// Try to map message:
|
|
101
|
-
// From: "mismatched input '/END' expecting <EOF>"
|
|
102
|
-
// To: "Found '/END', but expected the end of the document."
|
|
103
|
-
// const msgWhy = `${capitalizeFirst(msg)}`
|
|
104
|
-
const msgWhy = `Details: ${msg}`;
|
|
105
|
-
const ctx = createGeneralCtx(line, charPositionInLine, possibleStartCol); // So we can show line/col in error message.
|
|
106
|
-
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
107
|
-
this.errorHandler.pushOrBail(ctx, 'Syntax-Error', msgWhat, msgWhy);
|
|
108
|
-
}
|
|
109
|
-
// The following are required for the interface, but can be left empty.
|
|
110
|
-
reportAmbiguity(...args) { }
|
|
111
|
-
reportAttemptingFullContext(...args) { }
|
|
112
|
-
reportContextSensitivity(...args) { }
|
|
113
|
-
}
|
|
114
|
-
class MyLexerErrorListener {
|
|
115
|
-
constructor(errorHandler) {
|
|
116
|
-
this.errors = [];
|
|
117
|
-
this.errorHandler = errorHandler;
|
|
118
|
-
}
|
|
119
|
-
syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) {
|
|
120
|
-
// Handle the error as you want:
|
|
121
|
-
(0, print_1.debugPrint)('ANTLR lexer cached an error');
|
|
122
|
-
const col = charPositionInLine + 1;
|
|
123
|
-
const possibleStartCol = parsePossibleStartCol(this.errorHandler, recognizer);
|
|
124
|
-
// const msgWhat = `Syntax error at line ${line}, column ${col}:`
|
|
125
|
-
const msgWhat = `Syntax error`;
|
|
126
|
-
// Try to map message:
|
|
127
|
-
// From: "mismatched input '/END' expecting <EOF>"
|
|
128
|
-
// To: "Found '/END', but expected the end of the document."
|
|
129
|
-
// const msgWhy = `${capitalizeFirst(msg)}`
|
|
130
|
-
const msgWhy = `Details: ${msg}`;
|
|
131
|
-
// const msgHint = ``
|
|
132
|
-
const ctx = createGeneralCtx(line, charPositionInLine, possibleStartCol); // So we can show line/col in error message.
|
|
133
|
-
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
134
|
-
this.errorHandler.pushOrBail(ctx, 'Syntax-Error', msgWhat, msgWhy);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/** Single source of truth. */
|
|
138
|
-
const _parseMain = (yiniContent,
|
|
139
|
-
// options: IParseMainOptions = {
|
|
140
|
-
options = {
|
|
141
|
-
isStrict: false,
|
|
142
|
-
bailSensitivity: 0,
|
|
143
|
-
isIncludeMeta: false,
|
|
144
|
-
isWithDiagnostics: false,
|
|
145
|
-
isWithTiming: false,
|
|
146
|
-
isKeepUndefinedInMeta: false,
|
|
147
|
-
isRequireDocTerminator: false,
|
|
148
|
-
}, runtimeInfo) => {
|
|
149
|
-
(0, print_1.debugPrint)();
|
|
150
|
-
(0, print_1.debugPrint)('-> Entered parseMain(..) in parseEntry');
|
|
151
|
-
(0, print_1.debugPrint)(' isStrict mode = ' + options.isStrict);
|
|
152
|
-
(0, print_1.debugPrint)(' bailSensitivity = ' + options.bailSensitivity);
|
|
153
|
-
(0, print_1.debugPrint)(' isIncludeMeta = ' + options.isIncludeMeta);
|
|
154
|
-
(0, print_1.debugPrint)(' isWithDiagnostics = ' + options.isWithDiagnostics);
|
|
155
|
-
(0, print_1.debugPrint)(' isWithTiming = ' + options.isWithTiming);
|
|
156
|
-
(0, print_1.debugPrint)(' requireDocTerminator = ' + options.isRequireDocTerminator);
|
|
157
|
-
(0, print_1.debugPrint)('runtimeInfo.sourceType = ' + runtimeInfo.sourceType);
|
|
158
|
-
(0, print_1.debugPrint)(' runtimeInfo.fileName = ' + runtimeInfo.fileName);
|
|
159
|
-
let persistThreshold;
|
|
160
|
-
switch (options.bailSensitivity) {
|
|
161
|
-
case 0:
|
|
162
|
-
persistThreshold = '0-Ignore-Errors';
|
|
163
|
-
break;
|
|
164
|
-
case 1:
|
|
165
|
-
persistThreshold = '1-Abort-on-Errors';
|
|
166
|
-
break;
|
|
167
|
-
default:
|
|
168
|
-
persistThreshold = '2-Abort-Even-on-Warnings';
|
|
169
|
-
}
|
|
170
|
-
const errorHandler = new ErrorDataHandler_1.ErrorDataHandler(runtimeInfo.sourceType, persistThreshold, runtimeInfo.fileName);
|
|
171
|
-
if (yiniContent.trim() === '') {
|
|
172
|
-
const isFileSourceType = (runtimeInfo === null || runtimeInfo === void 0 ? void 0 : runtimeInfo.sourceType) === 'File';
|
|
173
|
-
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
174
|
-
errorHandler.pushOrBail(null, 'Syntax-Error', 'Empty YINI document.', `The input is blank or contains only whitespace in the ${isFileSourceType ? 'YINI file' : 'YINI inline content'}.`, `Tip: Add at least one section '^ SectionName' or a key-value pair 'key = value' to make it a valid YINI file.`);
|
|
175
|
-
}
|
|
176
|
-
//---------------------------------------------
|
|
177
|
-
// Note: Only computed when isWithTiming.
|
|
178
|
-
let timeStartMs = 0;
|
|
179
|
-
let timeEnd1Ms = 0;
|
|
180
|
-
let timeEnd2Ms = 0;
|
|
181
|
-
let timeEnd3Ms = 0;
|
|
182
|
-
let timeEnd4Ms = 0;
|
|
183
|
-
//---------------------------------------------
|
|
184
|
-
//---------------------------------------------
|
|
185
|
-
// Note: Should ALWAYS be computed.
|
|
186
|
-
let runStartedAt = '';
|
|
187
|
-
let runFinishedAt = '';
|
|
188
|
-
let durationMs = 0;
|
|
189
|
-
//---------------------------------------------
|
|
190
|
-
(0, env_1.isDebug)() && console.log();
|
|
191
|
-
(0, print_1.debugPrint)('=== Phase 1 - Lexing ===================================================');
|
|
192
|
-
// -----------------------------
|
|
193
|
-
// Below block should always be done despite isWithTiming to compute
|
|
194
|
-
// total time and runStartedAt that should always be computed.
|
|
195
|
-
{
|
|
196
|
-
timeStartMs = perf_hooks_1.performance.now();
|
|
197
|
-
runStartedAt = new Date().toISOString();
|
|
198
|
-
}
|
|
199
|
-
// -----------------------------
|
|
200
|
-
const inputStream = antlr4_1.CharStreams.fromString(yiniContent);
|
|
201
|
-
const lexer = new YiniLexer_1.default(inputStream);
|
|
202
|
-
// Remove the default ConsoleErrorListener
|
|
203
|
-
lexer.removeErrorListeners(); // Removes the default lexer console error output.
|
|
204
|
-
const lexerErrorListener = new MyLexerErrorListener(errorHandler);
|
|
205
|
-
lexer.addErrorListener(lexerErrorListener);
|
|
206
|
-
const tokenStream = new antlr4_1.CommonTokenStream(lexer);
|
|
207
|
-
// Important: force tokenization here so lexing is measured separately.
|
|
208
|
-
tokenStream.fill();
|
|
209
|
-
(0, print_1.debugPrint)('--- Parsing done. ---');
|
|
210
|
-
(0, print_1.debugPrint)('=== Ended phase 1 =============================================');
|
|
211
|
-
(0, env_1.isDebug)() && console.log();
|
|
212
|
-
(0, print_1.debugPrint)('=== Phase 2 - Parsing ===================================================');
|
|
213
|
-
if (options.isWithTiming) {
|
|
214
|
-
timeEnd1Ms = perf_hooks_1.performance.now();
|
|
215
|
-
}
|
|
216
|
-
const parser = new YiniParser_1.default(tokenStream);
|
|
217
|
-
// const errorListener = new MyParserErrorListener(errorHandler)
|
|
218
|
-
parser.removeErrorListeners(); // Removes the default parser console error output.
|
|
219
|
-
const parserErrorListener = new MyParserErrorListener(errorHandler);
|
|
220
|
-
parser.addErrorListener(parserErrorListener);
|
|
221
|
-
const parseTree = parser.yini(); // The function yini() is the start rule.
|
|
222
|
-
if (parserErrorListener.errors.length > 0 ||
|
|
223
|
-
lexerErrorListener.errors.length > 0) {
|
|
224
|
-
(0, print_1.debugPrint)('*** ERROR detected ***');
|
|
225
|
-
if ((0, env_1.isDebug)()) {
|
|
226
|
-
// Handle or display syntax errors
|
|
227
|
-
console.error('Syntax errors detected:', parserErrorListener.errors, lexerErrorListener.errors);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
(0, print_1.debugPrint)('=== Ended phase 2 =============================================');
|
|
231
|
-
(0, env_1.isDebug)() && console.log();
|
|
232
|
-
(0, print_1.debugPrint)('=== Phase 3 - AST Model build & validation ===================================================');
|
|
233
|
-
if (options.isWithTiming) {
|
|
234
|
-
timeEnd2Ms = perf_hooks_1.performance.now();
|
|
235
|
-
}
|
|
236
|
-
const builder = new ASTBuilder_1.default(errorHandler, options, runtimeInfo.sourceType, runtimeInfo.fileName || null);
|
|
237
|
-
const ast = builder.buildAST(parseTree);
|
|
238
|
-
if (ast.numOfMembers === 0 && ast.numOfSections === 0) {
|
|
239
|
-
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
240
|
-
errorHandler.pushOrBail(null, 'Syntax-Error', 'No meaningful content.', `No sections or members found in the ${ast.sourceType === 'File' ? 'YINI file' : 'YINI inline content'}.`, `${ast.sourceType === 'File' ? 'A valid YINI file' : 'Any valid YINI inline content'} must contain at least one section '^ SectionName' or a key–value pair 'key = value' to make it a valid YINI file.`);
|
|
241
|
-
}
|
|
242
|
-
if ((0, env_1.isDebug)()) {
|
|
243
|
-
console.log();
|
|
244
|
-
console.log('**************************************************************************');
|
|
245
|
-
console.log('*** AST *************************************************');
|
|
246
|
-
(0, print_1.printObject)(ast);
|
|
247
|
-
console.log('**************************************************************************');
|
|
248
|
-
console.log('**************************************************************************');
|
|
249
|
-
console.log();
|
|
250
|
-
}
|
|
251
|
-
(0, print_1.debugPrint)('=== Ended phase 3 =============================================');
|
|
252
|
-
(0, env_1.isDebug)() && console.log();
|
|
253
|
-
(0, print_1.debugPrint)('=== Phase 4 - Object Building Construction / Binding / Evaluation) ===================================================');
|
|
254
|
-
if (options.isWithTiming) {
|
|
255
|
-
timeEnd3Ms = perf_hooks_1.performance.now();
|
|
256
|
-
}
|
|
257
|
-
// Construct.
|
|
258
|
-
// const finalJSResult = constructFinalObject(syntaxTreeC, errorHandler)
|
|
259
|
-
// const finalJSResult = builder.build(parseTree)
|
|
260
|
-
// const finalJSResult = ast //NOTE: ONLY TEMP so code runs
|
|
261
|
-
const finalJSResult = (0, objectBuilder_1.astToObject)(ast, errorHandler);
|
|
262
|
-
(0, print_1.debugPrint)('=== Ended phase 4 =============================================');
|
|
263
|
-
// -----------------------------
|
|
264
|
-
// Below block should always be done despite isWithTiming to compute
|
|
265
|
-
// total time and runStartedAt that should always be computed.
|
|
266
|
-
{
|
|
267
|
-
timeEnd4Ms = perf_hooks_1.performance.now();
|
|
268
|
-
durationMs = timeEnd4Ms - timeStartMs;
|
|
269
|
-
runFinishedAt = new Date().toISOString();
|
|
270
|
-
}
|
|
271
|
-
// -----------------------------
|
|
272
|
-
(0, print_1.debugPrint)('visitor.visit(..): finalJSResult:');
|
|
273
|
-
(0, env_1.isDebug)() && console.debug(finalJSResult);
|
|
274
|
-
(0, print_1.debugPrint)();
|
|
275
|
-
if (options.isStrict) {
|
|
276
|
-
// Note, after pushing processing may continue or exit, depending on the error and/or the bail threshold.
|
|
277
|
-
errorHandler.pushOrBail(null, 'Syntax-Warning', 'Warning: Strict mode is not yet fully implemented.', 'Some validation rules may still be missing or incomplete.');
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
(0, print_1.debugPrint)('visitor.visit(..): finalJSResult:');
|
|
281
|
-
(0, env_1.isDebug)() && console.debug(finalJSResult);
|
|
282
|
-
}
|
|
283
|
-
const constructResultMetaData = () => {
|
|
284
|
-
// --- Construct meta information -------------------------------------
|
|
285
|
-
const to3 = (n) => Number.parseFloat(n.toFixed(3));
|
|
286
|
-
// Construct meta data.
|
|
287
|
-
const metaData = {
|
|
288
|
-
parserVersion: pkg.version,
|
|
289
|
-
mode: options.isStrict ? 'strict' : 'lenient',
|
|
290
|
-
orderPreserved: true,
|
|
291
|
-
totalErrors: errorHandler.getNumOfErrors(),
|
|
292
|
-
totalWarnings: errorHandler.getNumOfWarnings(),
|
|
293
|
-
totalMessages: errorHandler.getNumOfAllMessages(),
|
|
294
|
-
runStartedAt,
|
|
295
|
-
runFinishedAt,
|
|
296
|
-
durationMs: to3(durationMs),
|
|
297
|
-
source: {
|
|
298
|
-
sourceType: (0, string_1.toLowerSnakeCase)(ast.sourceType),
|
|
299
|
-
fileName: ast.fileName,
|
|
300
|
-
hasDocumentTerminator: ast.terminatorSeen,
|
|
301
|
-
hasYiniMarker: ast.yiniMarkerSeen,
|
|
302
|
-
lineCount: runtimeInfo.lineCount,
|
|
303
|
-
byteSize: runtimeInfo.fileByteSize,
|
|
304
|
-
sha256: runtimeInfo.sha256,
|
|
305
|
-
},
|
|
306
|
-
structure: {
|
|
307
|
-
maxDepth: ast.maxDepth,
|
|
308
|
-
sectionCount: ast.numOfSections,
|
|
309
|
-
memberCount: ast.numOfMembers,
|
|
310
|
-
keysParsedCount: null,
|
|
311
|
-
// objectCount: null,
|
|
312
|
-
// listCount: null,
|
|
313
|
-
sectionNamePaths: ast.sectionNamePaths,
|
|
314
|
-
},
|
|
315
|
-
metaSchemaVersion: '1.0.0',
|
|
316
|
-
};
|
|
317
|
-
// Attach optional diagnostics.
|
|
318
|
-
if (options.isWithDiagnostics) {
|
|
319
|
-
const mapLevelKey = (level) => {
|
|
320
|
-
switch (level) {
|
|
321
|
-
case 0:
|
|
322
|
-
return 'ignore_errors';
|
|
323
|
-
case 1:
|
|
324
|
-
return 'abort_on_errors';
|
|
325
|
-
case 2:
|
|
326
|
-
return 'abort_on_warnings';
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
const mapLevelLabel = (level) => {
|
|
330
|
-
switch (level) {
|
|
331
|
-
case 0:
|
|
332
|
-
return '0-Ignore-Errors';
|
|
333
|
-
case 1:
|
|
334
|
-
return '1-Abort-on-Errors';
|
|
335
|
-
case 2:
|
|
336
|
-
return '2-Abort-Even-on-Warnings';
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
const mapLevelDescription = (level) => {
|
|
340
|
-
switch (level) {
|
|
341
|
-
case 0:
|
|
342
|
-
return 'Continue despite errors.';
|
|
343
|
-
case 1:
|
|
344
|
-
return 'Abort when errors occur.';
|
|
345
|
-
case 2:
|
|
346
|
-
return 'Abort when errors or warnings occur.';
|
|
347
|
-
}
|
|
348
|
-
return null;
|
|
349
|
-
};
|
|
350
|
-
metaData.diagnostics = {
|
|
351
|
-
failLevel: {
|
|
352
|
-
preferredLevel: runtimeInfo.preferredBailSensitivity,
|
|
353
|
-
levelUsed: options.bailSensitivity,
|
|
354
|
-
levelKey: mapLevelKey(options.bailSensitivity),
|
|
355
|
-
levelLabel: mapLevelLabel(options.bailSensitivity),
|
|
356
|
-
levelDescription: (mapLevelDescription(options.bailSensitivity)),
|
|
357
|
-
},
|
|
358
|
-
errors: {
|
|
359
|
-
errorCount: errorHandler.getNumOfErrors(),
|
|
360
|
-
payload: errorHandler.getErrors(),
|
|
361
|
-
},
|
|
362
|
-
warnings: {
|
|
363
|
-
warningCount: errorHandler.getNumOfWarnings(),
|
|
364
|
-
payload: errorHandler.getWarnings(),
|
|
365
|
-
},
|
|
366
|
-
notices: {
|
|
367
|
-
noticeCount: errorHandler.getNumOfNotices(),
|
|
368
|
-
payload: errorHandler.getNotices(),
|
|
369
|
-
},
|
|
370
|
-
infos: {
|
|
371
|
-
infoCount: errorHandler.getNumOfInfos(),
|
|
372
|
-
payload: errorHandler.getInfos(),
|
|
373
|
-
},
|
|
374
|
-
environment: {
|
|
375
|
-
NODE_ENV: process.env.NODE_ENV,
|
|
376
|
-
APP_ENV: process.env.APP_ENV,
|
|
377
|
-
lib: {
|
|
378
|
-
nodeEnv: env_1.localNodeEnv,
|
|
379
|
-
appEnv: env_1.localAppEnv,
|
|
380
|
-
flags: { isDev: (0, env_1.isDev)(), isDebug: (0, env_1.isDebug)() },
|
|
381
|
-
},
|
|
382
|
-
},
|
|
383
|
-
optionsUsed: {
|
|
384
|
-
// NOTE: (!) These MUST user options.
|
|
385
|
-
strictMode: options.isStrict,
|
|
386
|
-
failLevel: options.bailSensitivity,
|
|
387
|
-
includeMetaData: options.isIncludeMeta,
|
|
388
|
-
includeDiagnostics: options.isWithDiagnostics,
|
|
389
|
-
includeTiming: options.isWithTiming,
|
|
390
|
-
preserveUndefinedInMeta: options.isKeepUndefinedInMeta,
|
|
391
|
-
requireDocTerminator: options.isRequireDocTerminator,
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
// Attach optional durations timing data.
|
|
396
|
-
if (options.isWithTiming) {
|
|
397
|
-
metaData.timing = {
|
|
398
|
-
total: !options.isWithTiming
|
|
399
|
-
? null
|
|
400
|
-
: {
|
|
401
|
-
timeMs: to3(durationMs), // durationMs = timeEnd4Ms - timeStartMs
|
|
402
|
-
name: runtimeInfo.sourceType === 'Inline'
|
|
403
|
-
? 'Total'
|
|
404
|
-
: 'Total (excluding phase0 (I/O))',
|
|
405
|
-
},
|
|
406
|
-
phase0: !options.isWithTiming || runtimeInfo.sourceType === 'Inline'
|
|
407
|
-
? undefined
|
|
408
|
-
: {
|
|
409
|
-
timeMs: to3(runtimeInfo.timeIoMs),
|
|
410
|
-
name: 'I/O',
|
|
411
|
-
},
|
|
412
|
-
phase1: !options.isWithTiming
|
|
413
|
-
? null
|
|
414
|
-
: {
|
|
415
|
-
timeMs: to3(timeEnd1Ms - timeStartMs),
|
|
416
|
-
name: 'Lexing',
|
|
417
|
-
},
|
|
418
|
-
phase2: !options.isWithTiming
|
|
419
|
-
? null
|
|
420
|
-
: {
|
|
421
|
-
timeMs: to3(timeEnd2Ms - timeEnd1Ms),
|
|
422
|
-
name: 'Parsing',
|
|
423
|
-
},
|
|
424
|
-
phase3: !options.isWithTiming
|
|
425
|
-
? null
|
|
426
|
-
: {
|
|
427
|
-
timeMs: to3(timeEnd3Ms - timeEnd2Ms),
|
|
428
|
-
name: 'AST Building',
|
|
429
|
-
},
|
|
430
|
-
phase4: !options.isWithTiming
|
|
431
|
-
? null
|
|
432
|
-
: {
|
|
433
|
-
timeMs: to3(timeEnd4Ms - timeEnd3Ms),
|
|
434
|
-
name: 'Object Building',
|
|
435
|
-
},
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
return metaData;
|
|
439
|
-
};
|
|
440
|
-
(0, print_1.debugPrint)('getNumOfErrors(): ' + errorHandler.getNumOfErrors());
|
|
441
|
-
if (errorHandler.getNumOfErrors()) {
|
|
442
|
-
console.log();
|
|
443
|
-
console.log('Parsing is complete, but some problems were detected. Please see the errors above for details.');
|
|
444
|
-
console.log('Number of errors found: ' + errorHandler.getNumOfErrors());
|
|
445
|
-
}
|
|
446
|
-
if (options.isIncludeMeta) {
|
|
447
|
-
return {
|
|
448
|
-
result: finalJSResult,
|
|
449
|
-
meta: !options.isKeepUndefinedInMeta
|
|
450
|
-
? (0, object_1.removeUndefinedDeep)(constructResultMetaData())
|
|
451
|
-
: constructResultMetaData(),
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
return finalJSResult;
|
|
455
|
-
};
|
|
456
|
-
exports._parseMain = _parseMain;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|