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
|
@@ -18,6 +18,8 @@ import { Null_literalContext } from "./YiniParser.js";
|
|
|
18
18
|
import { String_literalContext } from "./YiniParser.js";
|
|
19
19
|
import { String_concatContext } from "./YiniParser.js";
|
|
20
20
|
import { Boolean_literalContext } from "./YiniParser.js";
|
|
21
|
+
import { Empty_objectContext } from "./YiniParser.js";
|
|
22
|
+
import { Empty_listContext } from "./YiniParser.js";
|
|
21
23
|
/**
|
|
22
24
|
* This interface defines a complete generic visitor for a parse tree produced
|
|
23
25
|
* by `YiniParser`.
|
|
@@ -140,4 +142,16 @@ export default class YiniParserVisitor<Result> extends ParseTreeVisitor<Result>
|
|
|
140
142
|
* @return the visitor result
|
|
141
143
|
*/
|
|
142
144
|
visitBoolean_literal?: (ctx: Boolean_literalContext) => Result;
|
|
145
|
+
/**
|
|
146
|
+
* Visit a parse tree produced by `YiniParser.empty_object`.
|
|
147
|
+
* @param ctx the parse tree
|
|
148
|
+
* @return the visitor result
|
|
149
|
+
*/
|
|
150
|
+
visitEmpty_object?: (ctx: Empty_objectContext) => Result;
|
|
151
|
+
/**
|
|
152
|
+
* Visit a parse tree produced by `YiniParser.empty_list`.
|
|
153
|
+
* @param ctx the parse tree
|
|
154
|
+
* @return the visitor result
|
|
155
|
+
*/
|
|
156
|
+
visitEmpty_list?: (ctx: Empty_listContext) => Result;
|
|
143
157
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import YINI from './YINI';
|
|
2
|
+
export declare const parse: (yiniContent: string, strictMode?: boolean, bailSensitivity?: "auto" | 0 | 1 | 2, includeMetaData?: boolean) => import("./core/types").TJSObject;
|
|
3
|
+
export declare const parseFile: (filePath: string, strictMode?: boolean, bailSensitivity?: "auto" | 0 | 1 | 2, includeMetaData?: boolean) => import("./core/types").TJSObject;
|
|
4
|
+
export default YINI;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
var _a, _b, _c;
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
8
|
+
exports.parseFile = exports.parse = void 0;
|
|
9
9
|
/*
|
|
10
10
|
https://pauloe-me.medium.com/typescript-npm-package-publishing-a-beginners-guide-40b95908e69c
|
|
11
11
|
|
|
@@ -17,18 +17,20 @@ exports.default = void 0;
|
|
|
17
17
|
/END
|
|
18
18
|
*/
|
|
19
19
|
const env_1 = require("./config/env");
|
|
20
|
-
const
|
|
20
|
+
const print_1 = require("./utils/print");
|
|
21
21
|
const YINI_1 = __importDefault(require("./YINI"));
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(0,
|
|
22
|
+
// export { default } from './YINI'
|
|
23
|
+
exports.parse = YINI_1.default.parse;
|
|
24
|
+
exports.parseFile = YINI_1.default.parseFile;
|
|
25
|
+
exports.default = YINI_1.default;
|
|
26
|
+
(0, print_1.debugPrint)();
|
|
27
|
+
(0, print_1.debugPrint)('-> Entered index.ts');
|
|
28
|
+
(0, print_1.debugPrint)();
|
|
27
29
|
if ((0, env_1.isDev)() || (0, env_1.isDebug)()) {
|
|
28
30
|
console.log(`process.env?.NODE_ENV = '${(_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV}'`);
|
|
29
31
|
console.log(`process.env?.APP_ENV = '${(_b = process.env) === null || _b === void 0 ? void 0 : _b.APP_ENV}'`);
|
|
30
32
|
console.log(`process.env?.IS_DEBUG = '${(_c = process.env) === null || _c === void 0 ? void 0 : _c.IS_DEBUG}'`);
|
|
31
|
-
(0,
|
|
33
|
+
(0, print_1.debugPrint)();
|
|
32
34
|
console.log(`localNodeEnv = '${env_1.localNodeEnv}'`);
|
|
33
35
|
console.log(` localAppEnv = '${env_1.localAppEnv}'`);
|
|
34
36
|
console.log(' isProdEnv() = ' + (0, env_1.isProdEnv)());
|
|
@@ -43,9 +45,9 @@ const debugTestObj = {
|
|
|
43
45
|
name: 'e_test',
|
|
44
46
|
lang: 'TypeScript',
|
|
45
47
|
};
|
|
46
|
-
(0,
|
|
47
|
-
(0,
|
|
48
|
-
(0,
|
|
48
|
+
(0, print_1.debugPrint)('debugTestObj:');
|
|
49
|
+
(0, print_1.debugPrint)(debugTestObj);
|
|
50
|
+
(0, print_1.debugPrint)();
|
|
49
51
|
if ((0, env_1.isProdEnv)()) {
|
|
50
52
|
// Do nothing, and exit.
|
|
51
53
|
}
|
|
@@ -173,14 +175,11 @@ Expected JS output:
|
|
|
173
175
|
// id = 32403 # The correct app id.
|
|
174
176
|
// title = "My Program"
|
|
175
177
|
// `
|
|
176
|
-
const
|
|
177
|
-
^
|
|
178
|
-
|
|
179
|
-
items = 25
|
|
180
|
-
items = 90 // (!) Redefinition!
|
|
181
|
-
isDarkTheme = true
|
|
178
|
+
const yini = `
|
|
179
|
+
^ Database
|
|
180
|
+
pool = { max: 10, min: 2 }
|
|
182
181
|
`;
|
|
183
|
-
YINI_1.default.parse(
|
|
182
|
+
YINI_1.default.parse(yini);
|
|
184
183
|
// YINI.parse(`
|
|
185
184
|
// ^ Section1
|
|
186
185
|
// ^^ Section2
|
package/dist/parseEntry.js
CHANGED
|
@@ -11,14 +11,14 @@ const objectBuilder_1 = require("./core/objectBuilder");
|
|
|
11
11
|
const YINIVisitor_1 = __importDefault(require("./core/YINIVisitor"));
|
|
12
12
|
const YiniLexer_1 = __importDefault(require("./grammar/YiniLexer"));
|
|
13
13
|
const YiniParser_1 = __importDefault(require("./grammar/YiniParser"));
|
|
14
|
-
const
|
|
14
|
+
const print_1 = require("./utils/print");
|
|
15
15
|
class MyErrorListener {
|
|
16
16
|
constructor(errorHandler) {
|
|
17
17
|
this.errors = [];
|
|
18
18
|
this.errorHandler = errorHandler;
|
|
19
19
|
}
|
|
20
20
|
syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) {
|
|
21
|
-
(0,
|
|
21
|
+
(0, print_1.debugPrint)('ANTLR grammar cached an error');
|
|
22
22
|
this.errors.push(`Line ${line}:${charPositionInLine} ${msg}`);
|
|
23
23
|
const msgWhat = `Syntax error, at line: ${line}`;
|
|
24
24
|
const msgWhy = `At about column ${1 + charPositionInLine} ${msg}`;
|
|
@@ -36,10 +36,10 @@ const parseMain = (yiniContent, options = {
|
|
|
36
36
|
isWithDiagnostics: false,
|
|
37
37
|
isWithTiming: false,
|
|
38
38
|
}) => {
|
|
39
|
-
(0,
|
|
40
|
-
(0,
|
|
41
|
-
(0,
|
|
42
|
-
(0,
|
|
39
|
+
(0, print_1.debugPrint)();
|
|
40
|
+
(0, print_1.debugPrint)('-> Entered parseMain(..) in parseEntry');
|
|
41
|
+
(0, print_1.debugPrint)(' isStrict mode = ' + options.isStrict);
|
|
42
|
+
(0, print_1.debugPrint)('bailSensitivityLevel = ' + options.bailSensitivityLevel);
|
|
43
43
|
let persistThreshold;
|
|
44
44
|
switch (options.bailSensitivityLevel) {
|
|
45
45
|
case 0:
|
|
@@ -52,7 +52,7 @@ const parseMain = (yiniContent, options = {
|
|
|
52
52
|
persistThreshold = '2-Abort-Even-on-Warnings';
|
|
53
53
|
}
|
|
54
54
|
(0, env_1.isDebug)() && console.log();
|
|
55
|
-
(0,
|
|
55
|
+
(0, print_1.debugPrint)('=== Phase 1 ===================================================');
|
|
56
56
|
const inputStream = antlr4_1.CharStreams.fromString(yiniContent);
|
|
57
57
|
const lexer = new YiniLexer_1.default(inputStream);
|
|
58
58
|
const tokenStream = new antlr4_1.CommonTokenStream(lexer);
|
|
@@ -61,21 +61,21 @@ const parseMain = (yiniContent, options = {
|
|
|
61
61
|
const errorListener = new MyErrorListener(errorHandler);
|
|
62
62
|
parser.removeErrorListeners(); // Removes the default console error output.
|
|
63
63
|
parser.addErrorListener(errorListener);
|
|
64
|
-
(0,
|
|
65
|
-
(0,
|
|
64
|
+
(0, print_1.debugPrint)();
|
|
65
|
+
(0, print_1.debugPrint)('--- Starting parsing... ---');
|
|
66
66
|
const parseTree = parser.yini(); // The function yini() is the start rule.
|
|
67
67
|
if (errorListener.errors.length > 0) {
|
|
68
|
-
(0,
|
|
68
|
+
(0, print_1.debugPrint)('*** ERROR detected ***');
|
|
69
69
|
if ((0, env_1.isDebug)()) {
|
|
70
70
|
// Handle or display syntax errors
|
|
71
71
|
console.error('Syntax errors detected:', errorListener.errors);
|
|
72
72
|
//process.exit(1)
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
(0,
|
|
76
|
-
(0,
|
|
75
|
+
(0, print_1.debugPrint)('--- Parsing done. ---');
|
|
76
|
+
(0, print_1.debugPrint)('=== Ended phase 1 =============================================');
|
|
77
77
|
(0, env_1.isDebug)() && console.log();
|
|
78
|
-
(0,
|
|
78
|
+
(0, print_1.debugPrint)('=== Phase 2 ===================================================');
|
|
79
79
|
// const errorHandler = new ErrorDataHandler(persistThreshold)
|
|
80
80
|
const visitor = new YINIVisitor_1.default(errorHandler, options.isStrict);
|
|
81
81
|
const syntaxTreeC = visitor.visit(parseTree);
|
|
@@ -83,26 +83,26 @@ const parseMain = (yiniContent, options = {
|
|
|
83
83
|
console.log();
|
|
84
84
|
console.log('**************************************************************************');
|
|
85
85
|
console.log('*** syntaxTreeContainer: *************************************************');
|
|
86
|
-
(0,
|
|
86
|
+
(0, print_1.printObject)(syntaxTreeC);
|
|
87
87
|
console.log('**************************************************************************');
|
|
88
88
|
console.log('**************************************************************************');
|
|
89
89
|
console.log();
|
|
90
90
|
}
|
|
91
|
-
(0,
|
|
91
|
+
(0, print_1.debugPrint)('=== Ended phase 2 =============================================');
|
|
92
92
|
(0, env_1.isDebug)() && console.log();
|
|
93
|
-
(0,
|
|
93
|
+
(0, print_1.debugPrint)('=== Phase 3 ===================================================');
|
|
94
94
|
// Construct.
|
|
95
95
|
const finalJSResult = (0, objectBuilder_1.constructFinalObject)(syntaxTreeC, errorHandler);
|
|
96
|
-
(0,
|
|
97
|
-
(0,
|
|
96
|
+
(0, print_1.debugPrint)('=== Ended phase 3 =============================================');
|
|
97
|
+
(0, print_1.debugPrint)('visitor.visit(..): finalJSResult:');
|
|
98
98
|
(0, env_1.isDebug)() && console.debug(finalJSResult);
|
|
99
|
-
(0,
|
|
99
|
+
(0, print_1.debugPrint)();
|
|
100
100
|
if (options.isStrict) {
|
|
101
101
|
//throw Error('ERROR: Strict-mode not yet implemented')
|
|
102
102
|
errorHandler.pushOrBail(null, 'Syntax-Warning', 'WARNING: Strict-mode not yet fully implemented', '', '');
|
|
103
103
|
}
|
|
104
104
|
else {
|
|
105
|
-
(0,
|
|
105
|
+
(0, print_1.debugPrint)('visitor.visit(..): finalJSResult:');
|
|
106
106
|
(0, env_1.isDebug)() && console.debug(finalJSResult);
|
|
107
107
|
}
|
|
108
108
|
// Construct meta data.
|
|
@@ -148,7 +148,7 @@ const parseMain = (yiniContent, options = {
|
|
|
148
148
|
phase3Ms: null,
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
-
(0,
|
|
151
|
+
(0, print_1.debugPrint)('getNumOfErrors(): ' + errorHandler.getNumOfErrors());
|
|
152
152
|
if (errorHandler.getNumOfErrors()) {
|
|
153
153
|
console.log();
|
|
154
154
|
console.log('Parsing is complete, but some problems were detected. Please see the errors above for details.');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const print_1 = require("../utils/print");
|
|
4
4
|
const yiniHelpers_1 = require("../yiniHelpers");
|
|
5
5
|
const extractSignificantYiniLine_1 = require("./extractSignificantYiniLine");
|
|
6
6
|
/**
|
|
@@ -26,11 +26,11 @@ const extractSignificantYiniLine_1 = require("./extractSignificantYiniLine");
|
|
|
26
26
|
* @returns An object with the identified header parts: marker characters, parsed name, and parsed level string.
|
|
27
27
|
*/
|
|
28
28
|
const extractHeaderParts = (rawLine, errorHandler = null, ctx = null) => {
|
|
29
|
-
(0,
|
|
29
|
+
(0, print_1.debugPrint)('-> Entered extractHeaderParts(..)');
|
|
30
30
|
rawLine = rawLine.trim();
|
|
31
31
|
const str = (0, extractSignificantYiniLine_1.extractYiniLine)(rawLine);
|
|
32
|
-
(0,
|
|
33
|
-
(0,
|
|
32
|
+
(0, print_1.debugPrint)('rawLine: >>>' + rawLine + '<<<');
|
|
33
|
+
(0, print_1.debugPrint)(' str: >>>' + str + '<<<');
|
|
34
34
|
// Edge case: empty line.
|
|
35
35
|
if (!str) {
|
|
36
36
|
errorHandler.pushOrBail(ctx, 'Internal-Error', 'Received blank argument in extractHeaderParts(..)', 'Sorry, an unintended internal error happened.');
|
|
@@ -81,18 +81,18 @@ const extractHeaderParts = (rawLine, errorHandler = null, ctx = null) => {
|
|
|
81
81
|
// Optionally, strip trailing comments or newlines here if needed.
|
|
82
82
|
}
|
|
83
83
|
if (isBacktickedName) {
|
|
84
|
-
(0,
|
|
84
|
+
(0, print_1.debugPrint)('Backticed sectionNamePart: ' + sectionNamePart);
|
|
85
85
|
// sectionNamePart = trimBackticks(sectionNamePart)
|
|
86
86
|
}
|
|
87
|
-
(0,
|
|
88
|
-
(0,
|
|
89
|
-
(0,
|
|
90
|
-
(0,
|
|
91
|
-
(0,
|
|
92
|
-
(0,
|
|
93
|
-
(0,
|
|
94
|
-
(0,
|
|
95
|
-
(0,
|
|
87
|
+
(0, print_1.debugPrint)();
|
|
88
|
+
(0, print_1.debugPrint)('------');
|
|
89
|
+
(0, print_1.debugPrint)('<- About to leave extractHeaderParts(..)');
|
|
90
|
+
(0, print_1.debugPrint)();
|
|
91
|
+
(0, print_1.debugPrint)(' markerCharsPart: >>>' + markerCharsPart + '<<<');
|
|
92
|
+
(0, print_1.debugPrint)(' sectionNamePart: >>>' + sectionNamePart + '<<<');
|
|
93
|
+
(0, print_1.debugPrint)(' numberPart: >>>' + numberPart + '<<<');
|
|
94
|
+
(0, print_1.debugPrint)(' isBacktickedName: ' + isBacktickedName);
|
|
95
|
+
(0, print_1.debugPrint)();
|
|
96
96
|
return {
|
|
97
97
|
strMarkerChars: markerCharsPart,
|
|
98
98
|
strSectionName: sectionNamePart,
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractYiniLine = void 0;
|
|
4
4
|
const env_1 = require("../config/env");
|
|
5
|
+
const print_1 = require("../utils/print");
|
|
5
6
|
const string_1 = require("../utils/string");
|
|
6
|
-
const system_1 = require("../utils/system");
|
|
7
7
|
const yiniHelpers_1 = require("../yiniHelpers");
|
|
8
8
|
/**
|
|
9
9
|
* Extract significant YINI line from YINI content (that may be surrounded by comments.).
|
|
@@ -14,55 +14,57 @@ const yiniHelpers_1 = require("../yiniHelpers");
|
|
|
14
14
|
* @returns Will filter out any comments (before or after) and return only one single significant YINI line.
|
|
15
15
|
*/
|
|
16
16
|
const extractYiniLine = (rawYiniContent) => {
|
|
17
|
-
(0,
|
|
17
|
+
(0, print_1.debugPrint)('-> Entered extractSignificantYiniCode(..)');
|
|
18
18
|
const significantLines = [];
|
|
19
19
|
let resultLine = '';
|
|
20
|
-
(0,
|
|
20
|
+
(0, print_1.debugPrint)('rawYiniContent: >>>' + rawYiniContent + '<<<');
|
|
21
21
|
const contentLines = (0, string_1.splitLines)(rawYiniContent);
|
|
22
22
|
if ((0, env_1.isDebug)()) {
|
|
23
23
|
console.log(`contentLines: (len: ${contentLines.length})`);
|
|
24
|
-
(0,
|
|
24
|
+
(0, print_1.printObject)(contentLines);
|
|
25
25
|
}
|
|
26
26
|
// contentLines.forEach((row: string) => {
|
|
27
27
|
for (const line of contentLines) {
|
|
28
28
|
let row = line;
|
|
29
|
-
(0,
|
|
29
|
+
(0, print_1.debugPrint)('---');
|
|
30
30
|
// debugPrint('row (a): >>>' + row + '<<<')
|
|
31
31
|
// row = stripNLAndAfter(row)
|
|
32
|
-
(0,
|
|
32
|
+
(0, print_1.debugPrint)('row (b): >>>' + row + '<<<');
|
|
33
33
|
row = (0, yiniHelpers_1.stripCommentsAndAfter)(row);
|
|
34
|
-
(0,
|
|
34
|
+
(0, print_1.debugPrint)('row (c): >>>' + row + '<<<');
|
|
35
35
|
row = row.trim();
|
|
36
|
-
(0,
|
|
36
|
+
(0, print_1.debugPrint)('row (d): >>>' + row + '<<<');
|
|
37
37
|
if (row) {
|
|
38
|
-
(0,
|
|
39
|
-
(0,
|
|
38
|
+
(0, print_1.debugPrint)('Found some content in split row (non-comments).');
|
|
39
|
+
(0, print_1.debugPrint)('Split row: >>>' + row + '<<<');
|
|
40
40
|
// Use this as input in line.
|
|
41
41
|
// line = row
|
|
42
42
|
significantLines.push(row);
|
|
43
43
|
// break
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
(0,
|
|
47
|
-
(0,
|
|
46
|
+
(0, print_1.debugPrint)('--- End: parse line from section content-----------------');
|
|
47
|
+
(0, print_1.debugPrint)();
|
|
48
48
|
switch (significantLines.length) {
|
|
49
49
|
case 0:
|
|
50
50
|
resultLine = '';
|
|
51
51
|
break;
|
|
52
52
|
case 1:
|
|
53
|
-
(0,
|
|
53
|
+
(0, print_1.debugPrint)('Did only find one significant lines in rawYiniContent, OK');
|
|
54
54
|
resultLine = significantLines[0];
|
|
55
55
|
break;
|
|
56
56
|
default:
|
|
57
|
-
(0,
|
|
57
|
+
(0, print_1.debugPrint)('(!) Did find several significant lines in rawYiniContent! - Maybe internal error...');
|
|
58
|
+
(0, print_1.debugPrint)('significantLines[0] = >>>' + significantLines[0] + '<<<');
|
|
59
|
+
(0, print_1.debugPrint)('significantLines[1] = >>>' + significantLines[1] + '<<<');
|
|
58
60
|
// throw new Error(
|
|
59
61
|
// 'Internal error: Detected several row lines in rawYiniContent: >>>' +
|
|
60
62
|
// rawYiniContent +
|
|
61
63
|
// '<<<',
|
|
62
64
|
// )
|
|
63
65
|
}
|
|
64
|
-
(0,
|
|
65
|
-
(0,
|
|
66
|
+
(0, print_1.debugPrint)('<- About to leave extractSignificantYiniCode(..):');
|
|
67
|
+
(0, print_1.debugPrint)('resultLine: >>>' + resultLine + '<<<');
|
|
66
68
|
return resultLine;
|
|
67
69
|
};
|
|
68
70
|
exports.extractYiniLine = extractYiniLine;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const print_1 = require("../utils/print");
|
|
4
4
|
/**
|
|
5
5
|
* Extract boolean literal.
|
|
6
6
|
*/
|
|
7
7
|
const parseBooleanLiteral = (txt) => {
|
|
8
|
-
(0,
|
|
8
|
+
(0, print_1.debugPrint)('-> Entered parseBooleanLiteral(..)');
|
|
9
9
|
const value = !!(txt === 'true' || txt === 'yes' || txt === 'on');
|
|
10
10
|
return value;
|
|
11
11
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const print_1 = require("../utils/print");
|
|
4
4
|
const parseNullLiteral = (txt) => {
|
|
5
|
-
(0,
|
|
5
|
+
(0, print_1.debugPrint)('-> Entered parseNullLiteral(..)');
|
|
6
6
|
if (txt.toLowerCase() !== 'null') {
|
|
7
7
|
throw Error('Syntax Error: Unexpected token or character; expected `Null` literal (case-insensitive)');
|
|
8
8
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const print_1 = require("../utils/print");
|
|
4
4
|
const parseNumberLiteral = (txt) => {
|
|
5
|
-
(0,
|
|
5
|
+
(0, print_1.debugPrint)('-> Entered parseNumberLiteral(..), txt: ' + txt);
|
|
6
6
|
if (/^0[xX]|#/.test(txt)) {
|
|
7
7
|
// Prefix: 0x, 0X, #
|
|
8
|
-
(0,
|
|
8
|
+
(0, print_1.debugPrint)('* Identified as a hex number');
|
|
9
9
|
return {
|
|
10
10
|
type: 'Number-Integer',
|
|
11
11
|
// value: parseInt(txt.replace('#', '0x'), 16),
|
|
@@ -14,7 +14,7 @@ const parseNumberLiteral = (txt) => {
|
|
|
14
14
|
}
|
|
15
15
|
if (/^0[bB]|%/.test(txt)) {
|
|
16
16
|
// Prefix: 0b, 0B, %
|
|
17
|
-
(0,
|
|
17
|
+
(0, print_1.debugPrint)('* Identified as a bin number');
|
|
18
18
|
return {
|
|
19
19
|
type: 'Number-Integer',
|
|
20
20
|
value: parseInt(txt.replace(/^0[bB]|%/, ''), 2),
|
|
@@ -22,7 +22,7 @@ const parseNumberLiteral = (txt) => {
|
|
|
22
22
|
}
|
|
23
23
|
if (/^0[oO]/.test(txt)) {
|
|
24
24
|
// Prefix: 0o, 0O
|
|
25
|
-
(0,
|
|
25
|
+
(0, print_1.debugPrint)('* Identified as a ord number');
|
|
26
26
|
return {
|
|
27
27
|
type: 'Number-Integer',
|
|
28
28
|
value: parseInt(txt.replace(/^0[oO]/, ''), 8),
|
|
@@ -30,7 +30,7 @@ const parseNumberLiteral = (txt) => {
|
|
|
30
30
|
}
|
|
31
31
|
if (/^0[zZ]/.test(txt)) {
|
|
32
32
|
// Prefix: 0z, 0Z
|
|
33
|
-
(0,
|
|
33
|
+
(0, print_1.debugPrint)('* Identified as a duodecimal number');
|
|
34
34
|
return {
|
|
35
35
|
type: 'Number-Integer',
|
|
36
36
|
value: parseInt(txt.replace(/^0[zZ]/, ''), 12),
|
|
@@ -38,12 +38,12 @@ const parseNumberLiteral = (txt) => {
|
|
|
38
38
|
}
|
|
39
39
|
// In a regex literal the dot must be escaped (\.) to match a literal '.'
|
|
40
40
|
if (/\./.test(txt)) {
|
|
41
|
-
(0,
|
|
41
|
+
(0, print_1.debugPrint)('* Identified as a float number');
|
|
42
42
|
return { type: 'Number-Float', value: parseFloat(txt) };
|
|
43
43
|
}
|
|
44
44
|
// TODO: Depending, on mode, below continue or break on error
|
|
45
45
|
//console.error('Error: Failed to parse number value: ' + txt)
|
|
46
|
-
(0,
|
|
46
|
+
(0, print_1.debugPrint)('* Identified as a int number');
|
|
47
47
|
return { type: 'Number-Integer', value: parseInt(txt) };
|
|
48
48
|
};
|
|
49
49
|
exports.default = parseNumberLiteral;
|
|
@@ -5,25 +5,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const extractHeaderParts_1 = __importDefault(require("../parsers/extractHeaderParts"));
|
|
7
7
|
const extractSignificantYiniLine_1 = require("../parsers/extractSignificantYiniLine");
|
|
8
|
+
const print_1 = require("../utils/print");
|
|
8
9
|
const string_1 = require("../utils/string");
|
|
9
|
-
const system_1 = require("../utils/system");
|
|
10
10
|
const yiniHelpers_1 = require("../yiniHelpers");
|
|
11
11
|
/**
|
|
12
12
|
* Extract ...
|
|
13
13
|
* @param rawLine Raw line with the section header.
|
|
14
14
|
*/
|
|
15
15
|
const parseSectionHeader = (rawLine, errorHandler, ctx) => {
|
|
16
|
-
(0,
|
|
16
|
+
(0, print_1.debugPrint)('-> Entered parseSectionHeader(..)');
|
|
17
17
|
rawLine = rawLine.trim();
|
|
18
18
|
const line = (0, extractSignificantYiniLine_1.extractYiniLine)(rawLine);
|
|
19
|
-
(0,
|
|
20
|
-
(0,
|
|
19
|
+
(0, print_1.debugPrint)(' rawLine: >>>' + rawLine + '<<<');
|
|
20
|
+
(0, print_1.debugPrint)('extractYiniLine(..), line: >>>' + line + '<<<');
|
|
21
21
|
let { strMarkerChars, strSectionName, strNumberPart, isBacktickedName } = (0, extractHeaderParts_1.default)(rawLine, errorHandler, ctx);
|
|
22
|
-
(0,
|
|
23
|
-
(0,
|
|
24
|
-
(0,
|
|
25
|
-
(0,
|
|
26
|
-
(0,
|
|
22
|
+
(0, print_1.debugPrint)('In parseSectionHeader(..), after extractHeaderParts(..):');
|
|
23
|
+
(0, print_1.debugPrint)(' strMarkerChars: ' + strMarkerChars);
|
|
24
|
+
(0, print_1.debugPrint)(' strSectionName: ' + strSectionName);
|
|
25
|
+
(0, print_1.debugPrint)(' strNumberPart: ' + strNumberPart);
|
|
26
|
+
(0, print_1.debugPrint)('isBacktickedName: ' + isBacktickedName);
|
|
27
27
|
let headerMarkerType;
|
|
28
28
|
let level = 0;
|
|
29
29
|
if (strMarkerChars === '') {
|
|
@@ -76,7 +76,7 @@ const parseSectionHeader = (rawLine, errorHandler, ctx) => {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
|
-
(0,
|
|
79
|
+
(0, print_1.debugPrint)('Naming contraints: Is not a BacktickedName');
|
|
80
80
|
if (lenOfName <= 0) {
|
|
81
81
|
errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Invalid section name in repeating marker characters header, section name: "' +
|
|
82
82
|
strSectionName +
|
|
@@ -93,15 +93,15 @@ const parseSectionHeader = (rawLine, errorHandler, ctx) => {
|
|
|
93
93
|
}
|
|
94
94
|
// ---------------------------------------------------------------
|
|
95
95
|
// strSectionName = trimBackticks(strSectionName)
|
|
96
|
-
(0,
|
|
97
|
-
(0,
|
|
98
|
-
(0,
|
|
99
|
-
(0,
|
|
100
|
-
(0,
|
|
101
|
-
(0,
|
|
102
|
-
(0,
|
|
103
|
-
(0,
|
|
104
|
-
(0,
|
|
96
|
+
(0, print_1.debugPrint)(' --------------');
|
|
97
|
+
(0, print_1.debugPrint)('<- About to leave parseSectionHeader(..)');
|
|
98
|
+
(0, print_1.debugPrint)(` rawLine = >>>${rawLine}<<<`);
|
|
99
|
+
(0, print_1.debugPrint)(` line = >>>${line}<<<`);
|
|
100
|
+
(0, print_1.debugPrint)();
|
|
101
|
+
(0, print_1.debugPrint)('identified level: ' + level);
|
|
102
|
+
(0, print_1.debugPrint)(' SectionName: ' + strSectionName);
|
|
103
|
+
(0, print_1.debugPrint)('headerMarkerType: ' + headerMarkerType);
|
|
104
|
+
(0, print_1.debugPrint)(' --------------');
|
|
105
105
|
return {
|
|
106
106
|
markerType: headerMarkerType,
|
|
107
107
|
sectionName: strSectionName,
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const env_1 = require("../config/env");
|
|
4
|
-
const
|
|
4
|
+
const print_1 = require("../utils/print");
|
|
5
5
|
const parseStringLiteral = (raw) => {
|
|
6
6
|
var _a;
|
|
7
|
-
(0,
|
|
8
|
-
(0,
|
|
7
|
+
(0, print_1.debugPrint)('-> Entered parseStringLiteral(..)');
|
|
8
|
+
(0, print_1.debugPrint)('raw = >>>' + raw + '<<<');
|
|
9
9
|
/*
|
|
10
10
|
Extracts an optional prefix (C, c, H, or h) and identifies whether
|
|
11
11
|
the string is triple-quoted, double-quoted, or single-quoted.
|
|
12
12
|
*/
|
|
13
13
|
const prefixMatch = raw.match(/^(C|c|H|h|R|r)?("""|"|')/);
|
|
14
|
-
(0,
|
|
14
|
+
(0, print_1.debugPrint)('prefixMatch:');
|
|
15
15
|
if ((0, env_1.isDebug)()) {
|
|
16
16
|
console.debug(prefixMatch);
|
|
17
17
|
}
|
|
18
18
|
let prefix = prefixMatch ? (_a = prefixMatch[1]) === null || _a === void 0 ? void 0 : _a.toUpperCase() : '';
|
|
19
|
-
(0,
|
|
19
|
+
(0, print_1.debugPrint)(' prefix = ' + prefix);
|
|
20
20
|
let quoteType = prefixMatch ? prefixMatch[2] : '';
|
|
21
|
-
(0,
|
|
22
|
-
(0,
|
|
21
|
+
(0, print_1.debugPrint)(' quoteType = ' + quoteType);
|
|
22
|
+
(0, print_1.debugPrint)('quoteType.length = ' + quoteType.length);
|
|
23
23
|
// Extracts the substring after removing the initial prefix (if any)
|
|
24
24
|
// and quotes at the start (prefix.length + quoteType.length) and the
|
|
25
25
|
// quotes at the end (-quoteType.length).
|
|
26
26
|
let inner = raw.slice(((prefix === null || prefix === void 0 ? void 0 : prefix.length) || 0) + quoteType.length, -quoteType.length);
|
|
27
|
-
(0,
|
|
27
|
+
(0, print_1.debugPrint)('inner (raw) = ' + inner);
|
|
28
28
|
if (prefix === 'C') {
|
|
29
29
|
inner = inner
|
|
30
30
|
.replace(/\\n/g, '\n')
|
|
@@ -34,7 +34,7 @@ const parseStringLiteral = (raw) => {
|
|
|
34
34
|
else if (prefix === 'H') {
|
|
35
35
|
inner = inner.replace(/[\s\n\r]+/g, ' ').trim();
|
|
36
36
|
}
|
|
37
|
-
(0,
|
|
37
|
+
(0, print_1.debugPrint)('inner (reformat) = ' + inner);
|
|
38
38
|
return inner;
|
|
39
39
|
};
|
|
40
40
|
exports.default = parseStringLiteral;
|
package/dist/utils/string.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.stripNLAndAfter = exports.isDigit = exports.isAlpha = exports.isEnclosedInBackticks = exports.trimBackticks = void 0;
|
|
8
8
|
exports.splitLines = splitLines;
|
|
9
|
-
const
|
|
9
|
+
const print_1 = require("./print");
|
|
10
10
|
/**
|
|
11
11
|
* Splits a string into an array of lines, handling both LF and CRLF newlines.
|
|
12
12
|
* @param content The input string.
|
|
@@ -90,8 +90,8 @@ const stripNLAndAfter = (line) => {
|
|
|
90
90
|
// debugPrint('stripNLAndAfter(..): idx2 = ' + idx2)
|
|
91
91
|
const idx = Math.min(idx1, idx2);
|
|
92
92
|
const resultLine = idx === Number.MAX_SAFE_INTEGER ? line : line.substring(0, idx);
|
|
93
|
-
(0,
|
|
94
|
-
(0,
|
|
93
|
+
(0, print_1.debugPrint)('stripNLAndAfter(..), line: >>>' + line + '<<<');
|
|
94
|
+
(0, print_1.debugPrint)('stripNLAndAfter(..), resultLine: >>>' + resultLine + '<<<');
|
|
95
95
|
return resultLine;
|
|
96
96
|
};
|
|
97
97
|
exports.stripNLAndAfter = stripNLAndAfter;
|
package/dist/yiniHelpers.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.isValidBacktickedIdent = exports.isValidSimpleIdent = exports.stripCommentsAndAfter = exports.isMarkerCharacter = void 0;
|
|
8
|
+
const print_1 = require("./utils/print");
|
|
8
9
|
const string_1 = require("./utils/string");
|
|
9
|
-
const system_1 = require("./utils/system");
|
|
10
10
|
const SECTION_MARKER1 = '^';
|
|
11
11
|
const SECTION_MARKER2 = '<';
|
|
12
12
|
const SECTION_MARKER3 = '\u00A7'; // Section sign §.
|
|
@@ -64,8 +64,8 @@ const stripCommentsAndAfter = (line) => {
|
|
|
64
64
|
// debugPrint('stripCommentsAndAfter(..): idx5 = ' + idx5)
|
|
65
65
|
const idx = Math.min(idx1, idx2, idx3, idx4, idx5);
|
|
66
66
|
const resultLine = idx === Number.MAX_SAFE_INTEGER ? line : line.substring(0, idx);
|
|
67
|
-
(0,
|
|
68
|
-
(0,
|
|
67
|
+
(0, print_1.debugPrint)('stripCommentsAndAfter(..), line: >>>' + line + '<<<');
|
|
68
|
+
(0, print_1.debugPrint)('stripCommentsAndAfter(..), resultLine: >>>' + resultLine + '<<<');
|
|
69
69
|
return resultLine;
|
|
70
70
|
};
|
|
71
71
|
exports.stripCommentsAndAfter = stripCommentsAndAfter;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
basic-explained.yini
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@yini // Optional marker indicating this is a YINI config file.
|
|
6
|
+
|
|
7
|
+
^ App // Section header: defines the "App" section.
|
|
8
|
+
title = 'My App' // A string (single-quoted or double-quoted are both supported).
|
|
9
|
+
items = 10 // A number value.
|
|
10
|
+
debug = ON // Boolean true (ON/OFF are case-insensitive aliases for true/false).
|
|
11
|
+
|
|
12
|
+
^ Server // Another top-level section.
|
|
13
|
+
host = "localhost" // A string using double quotes.
|
|
14
|
+
port = 8080 // A number value.
|
|
15
|
+
useTLS = OFF // Boolean false.
|