yini-parser 1.0.0-alpha.7x → 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 +3 -1
- package/README.md +10 -0
- package/dist/YINI.js +15 -15
- package/dist/core/ErrorDataHandler.js +15 -15
- package/dist/core/YINIVisitor.js +175 -175
- package/dist/core/objectBuilder.js +39 -39
- package/dist/grammar/YiniLexer.js +1 -1
- package/dist/grammar/YiniParser.d.ts +1 -1
- package/dist/grammar/YiniParser.js +5 -5
- package/dist/grammar/YiniParserVisitor.js +1 -1
- package/dist/index.js +11 -35
- package/dist/parseEntry.js +21 -21
- 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 +1 -1
- /package/dist/utils/{system.d.ts → print.d.ts} +0 -0
- /package/dist/utils/{system.js → print.js} +0 -0
|
@@ -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,18 @@
|
|
|
1
|
+
// Parsed output in config from examples/nested.yini using YINI.parseFile(...)
|
|
2
|
+
|
|
3
|
+
config = {
|
|
4
|
+
App: {
|
|
5
|
+
name: 'Nested Demo App',
|
|
6
|
+
version: '1.2.3',
|
|
7
|
+
Theme: {
|
|
8
|
+
primaryColor: 3368601,
|
|
9
|
+
darkMode: true,
|
|
10
|
+
Overrides: { darkMode: false, fontSize: 14 },
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
Database: {
|
|
14
|
+
host: 'db.local',
|
|
15
|
+
port: 5432,
|
|
16
|
+
Credentials: { password: 'secret' },
|
|
17
|
+
},
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yini-parser",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "Simple and flexible config parser for Node.js. YINI: an enhanced, readable alternative to JSON, INI, and YAML—built for modern JavaScript and TypeScript projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yini",
|
|
File without changes
|
|
File without changes
|