yini-parser 1.0.1-beta → 1.0.2-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 +5 -0
- package/README.md +48 -230
- package/dist/YINI.js +6 -34
- package/dist/core/YINIVisitor.js +0 -2
- package/dist/grammar/YiniLexer.js +221 -219
- package/dist/grammar/YiniParser.js +1 -1
- package/dist/grammar/YiniParserVisitor.js +1 -1
- package/dist/index.js +28 -110
- package/dist/parsers/parseNumber.js +30 -10
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Generated from grammar/v1.0.0-rc.
|
|
2
|
+
// Generated from grammar/v1.0.0-rc.2x/YiniParser.g4 by ANTLR 4.13.2
|
|
3
3
|
// noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.Bad_memberContext = exports.Empty_listContext = exports.Empty_objectContext = exports.Boolean_literalContext = exports.String_concatContext = exports.String_literalContext = exports.Null_literalContext = exports.Number_literalContext = exports.ElementContext = exports.ElementsContext = exports.List_in_bracketsContext = exports.ListContext = exports.ObjectMemberContext = exports.ObjectMemberListContext = exports.Object_literalContext = exports.ValueContext = exports.Member_colon_listContext = exports.MemberContext = exports.Section_membersContext = exports.Terminal_lineContext = exports.SectionContext = exports.YiniContext = void 0;
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// import { isDebug&&console.log } from './utils/general'
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
var _a, _b, _c;
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.parseFile = exports.parse = void 0;
|
|
9
2
|
/*
|
|
10
|
-
https://
|
|
3
|
+
https://github.com/YINI-lang/yini-parser-typescript/blob/main/docs/Project-Setup.md
|
|
11
4
|
|
|
12
5
|
Run the code with the following command:
|
|
13
|
-
npx ts-node index
|
|
14
|
-
or
|
|
15
6
|
npm start
|
|
7
|
+
or
|
|
8
|
+
npm run start:dev
|
|
9
|
+
or
|
|
10
|
+
npm run start:dev:debug
|
|
16
11
|
|
|
17
12
|
/END
|
|
18
13
|
*/
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.parseFile = exports.parse = void 0;
|
|
19
20
|
const env_1 = require("./config/env");
|
|
20
21
|
const print_1 = require("./utils/print");
|
|
21
22
|
const YINI_1 = __importDefault(require("./YINI"));
|
|
22
|
-
// export { default } from './YINI'
|
|
23
23
|
exports.parse = YINI_1.default.parse;
|
|
24
24
|
exports.parseFile = YINI_1.default.parseFile;
|
|
25
25
|
exports.default = YINI_1.default;
|
|
@@ -52,99 +52,7 @@ if ((0, env_1.isProdEnv)()) {
|
|
|
52
52
|
// Do nothing, and exit.
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
|
-
const invalidInput1 = `
|
|
56
|
-
^ Settings
|
|
57
|
-
fruit = "Pear"
|
|
58
|
-
number = 5
|
|
59
|
-
value q= "something"
|
|
60
|
-
`;
|
|
61
|
-
const invalidInput2 = `
|
|
62
|
-
^ Config
|
|
63
|
-
varAge = 30
|
|
64
|
-
varName = abcd
|
|
65
|
-
varNull = NULL
|
|
66
|
-
`;
|
|
67
|
-
const input1 = `
|
|
68
|
-
^ SectionName
|
|
69
|
-
varBool = true
|
|
70
|
-
varBool2 = off
|
|
71
|
-
varInt = 30
|
|
72
|
-
varFloat = 12.34
|
|
73
|
-
varStr = "Alice"
|
|
74
|
-
listItems = ["a", "b", "c"]
|
|
75
|
-
varE1 = 1e4
|
|
76
|
-
varE2 = 1.23e4
|
|
77
|
-
varE3 = 6.5E23
|
|
78
|
-
/END
|
|
79
|
-
`;
|
|
80
|
-
const input2 = `
|
|
81
|
-
^ Config
|
|
82
|
-
varAge = 30
|
|
83
|
-
varName = "Alice"
|
|
84
|
-
varNull = NULL
|
|
85
|
-
listItems = ["a", "b", "c"]
|
|
86
|
-
^^Extra
|
|
87
|
-
isExtra = true
|
|
88
|
-
/END
|
|
89
|
-
`;
|
|
90
|
-
// const input = `
|
|
91
|
-
// # Config`;
|
|
92
|
-
// debugPrint('input2:')
|
|
93
|
-
// if (isDebug()) {
|
|
94
|
-
// console.debug(input2)
|
|
95
|
-
// }
|
|
96
|
-
// parseUntilError(input2)
|
|
97
|
-
// debugPrint('invalidInput1:')
|
|
98
|
-
// if (isDebug()) {
|
|
99
|
-
// console.debug(invalidInput1)
|
|
100
|
-
// }
|
|
101
|
-
// parseUntilError(invalidInput1)
|
|
102
55
|
if (env_1.localAppEnv === 'local' && env_1.localNodeEnv !== 'test') {
|
|
103
|
-
/*
|
|
104
|
-
parseUntilError(`
|
|
105
|
-
--^ Section0
|
|
106
|
-
--value = 0
|
|
107
|
-
^ Section1
|
|
108
|
-
value = 1
|
|
109
|
-
|
|
110
|
-
^^ Section11
|
|
111
|
-
value = 11
|
|
112
|
-
|
|
113
|
-
^^^ Section111
|
|
114
|
-
value = 111
|
|
115
|
-
//^^^^ Section2104
|
|
116
|
-
value = 24
|
|
117
|
-
|
|
118
|
-
^ Section2
|
|
119
|
-
value = 2
|
|
120
|
-
`)
|
|
121
|
-
}
|
|
122
|
-
*/
|
|
123
|
-
// parseUntilError(`number = 42`)
|
|
124
|
-
/*
|
|
125
|
-
Expected JS output:
|
|
126
|
-
{
|
|
127
|
-
Section1: { value: 1, Section2: { value: 11 }},
|
|
128
|
-
Section2: { value: 2 }
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
*/
|
|
132
|
-
/*
|
|
133
|
-
parseUntilError(
|
|
134
|
-
`
|
|
135
|
-
// Using numeric shorthand section markers.
|
|
136
|
-
|
|
137
|
-
@yini
|
|
138
|
-
|
|
139
|
-
// This whole line is a comment.
|
|
140
|
-
^SectionName# This part is a comment.
|
|
141
|
-
// This whole line is a comment.
|
|
142
|
-
--x=1
|
|
143
|
-
`,
|
|
144
|
-
false,
|
|
145
|
-
2,
|
|
146
|
-
)
|
|
147
|
-
*/
|
|
148
56
|
// parseUntilError(`^1 SectionName`, false, 2)
|
|
149
57
|
// const validYini = `
|
|
150
58
|
// < user
|
|
@@ -175,15 +83,25 @@ Expected JS output:
|
|
|
175
83
|
// id = 32403 # The correct app id.
|
|
176
84
|
// title = "My Program"
|
|
177
85
|
// `
|
|
178
|
-
// const yini = ` // corrupt yini
|
|
179
|
-
// ^ Section
|
|
180
|
-
// = "missing_key_name" // In strict should throw error, while lenient should pass
|
|
181
|
-
// `
|
|
182
86
|
const yini = `
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
87
|
+
^ DozNumbers
|
|
88
|
+
^^ WithXE
|
|
89
|
+
doz1 = 0z00
|
|
90
|
+
doz2 = 0z01 // One with leading zeros
|
|
91
|
+
doz3 = 0z100 // Decimal 144 (X/A is digit for 10 in base-12)
|
|
92
|
+
doz4 = 0z7EE // Decimal 1151
|
|
93
|
+
doz5 = 0zX00 // Decimal 1440 (E/B is digit for 11 in base-12)
|
|
94
|
+
|
|
95
|
+
^^ WithAB
|
|
96
|
+
doz6 = 0z7BB // Decimal 1151
|
|
97
|
+
doz7 = 0zA00 // Decimal 1440 (E/B is digit for 11 in base-12)
|
|
98
|
+
`;
|
|
186
99
|
console.log((0, print_1.toPrettyJSON)(YINI_1.default.parse(yini, false)));
|
|
100
|
+
// console.log(
|
|
101
|
+
// toPrettyJSON(YINI.parseFile('comprehensive-example.yini', true)),
|
|
102
|
+
// )
|
|
103
|
+
// const fileName = './tests/fixtures/valid/common/common-config-2.yini'
|
|
104
|
+
// YINI.parseFile(fileName, false)
|
|
187
105
|
// parseUntilError(`
|
|
188
106
|
// ^ Section1
|
|
189
107
|
// ^^ Section2
|
|
@@ -3,37 +3,57 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const print_1 = require("../utils/print");
|
|
4
4
|
const parseNumberLiteral = (txt) => {
|
|
5
5
|
(0, print_1.debugPrint)('-> Entered parseNumberLiteral(..), txt: ' + txt);
|
|
6
|
-
if (/^
|
|
6
|
+
if (/^[+-]?(?:\d+\.\d*|\d*\.?\d+)e[+-]?\d+$/i.test(txt)) {
|
|
7
|
+
// Exp. numbers
|
|
8
|
+
(0, print_1.debugPrint)('* Identified as an exp number');
|
|
9
|
+
return {
|
|
10
|
+
type: 'Number-Float',
|
|
11
|
+
// value: parseInt(txt.replace('#', '0x'), 16),
|
|
12
|
+
value: parseFloat(txt),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
// --- Hexadecimal ---------
|
|
16
|
+
if (/^[+-]?(0[xX]|#)/.test(txt)) {
|
|
7
17
|
// Prefix: 0x, 0X, #
|
|
8
18
|
(0, print_1.debugPrint)('* Identified as a hex number');
|
|
19
|
+
(0, print_1.debugPrint)('parsed out HEX: ' + txt.replace(/0[xX]|#/, ''));
|
|
9
20
|
return {
|
|
10
21
|
type: 'Number-Integer',
|
|
11
22
|
// value: parseInt(txt.replace('#', '0x'), 16),
|
|
12
|
-
value: parseInt(txt.replace(
|
|
23
|
+
value: parseInt(txt.replace(/0[xX]|#/, ''), 16),
|
|
13
24
|
};
|
|
14
25
|
}
|
|
15
|
-
|
|
26
|
+
// --- Binary ---------
|
|
27
|
+
if (/^[+-]?(0[bB]|%)/.test(txt)) {
|
|
16
28
|
// Prefix: 0b, 0B, %
|
|
17
29
|
(0, print_1.debugPrint)('* Identified as a bin number');
|
|
30
|
+
(0, print_1.debugPrint)('parsed out BIN: ' + txt.replace(/0[bB]|%/, ''));
|
|
18
31
|
return {
|
|
19
32
|
type: 'Number-Integer',
|
|
20
|
-
value: parseInt(txt.replace(
|
|
33
|
+
value: parseInt(txt.replace(/0[bB]|%/, ''), 2),
|
|
21
34
|
};
|
|
22
35
|
}
|
|
23
|
-
|
|
36
|
+
// --- Octal ---------
|
|
37
|
+
if (/^[+-]?0[oO]/.test(txt)) {
|
|
24
38
|
// Prefix: 0o, 0O
|
|
25
|
-
(0, print_1.debugPrint)('* Identified as a
|
|
39
|
+
(0, print_1.debugPrint)('* Identified as a oct number');
|
|
40
|
+
(0, print_1.debugPrint)('parsed out OCT: ' + txt.replace(/0[oO]/, ''));
|
|
26
41
|
return {
|
|
27
42
|
type: 'Number-Integer',
|
|
28
|
-
value: parseInt(txt.replace(
|
|
43
|
+
value: parseInt(txt.replace(/0[oO]/, ''), 8),
|
|
29
44
|
};
|
|
30
45
|
}
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
// --- Duodecimal ---------
|
|
47
|
+
if (/^[+-]?0[zZ]/.test(txt)) {
|
|
48
|
+
// Prefix: 0z, 0Z, x = A = 10, e = B = 11.
|
|
33
49
|
(0, print_1.debugPrint)('* Identified as a duodecimal number');
|
|
50
|
+
(0, print_1.debugPrint)('parsed out DOZ: ' + txt.replace(/0[zZ]/, ''));
|
|
51
|
+
txt = txt.replace(/[xX]/g, 'A');
|
|
52
|
+
txt = txt.replace(/[eE]/g, 'B');
|
|
53
|
+
(0, print_1.debugPrint)('Converter to AB form: ' + txt.replace(/0[zZ]/, ''));
|
|
34
54
|
return {
|
|
35
55
|
type: 'Number-Integer',
|
|
36
|
-
value: parseInt(txt.replace(
|
|
56
|
+
value: parseInt(txt.replace(/0[zZ]/, ''), 12),
|
|
37
57
|
};
|
|
38
58
|
}
|
|
39
59
|
// In a regex literal the dot must be escaped (\.) to match a literal '.'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yini-parser",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.2-beta",
|
|
4
|
+
"description": "Node.js parser for YINI — a clean, structured INI alternative with types, simple section nesting, comments, and strict mode.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yini",
|
|
7
7
|
"yini-parser",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"nodejs",
|
|
20
20
|
"javascript"
|
|
21
21
|
],
|
|
22
|
-
"homepage": "https://
|
|
22
|
+
"homepage": "https://github.com/YINI-lang/yini-parser-typescript",
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"files": [
|
|
25
25
|
"dist/",
|