yini-parser 1.0.0-alpha.5 → 1.0.0-alpha.7
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 +20 -0
- package/README.md +260 -28
- package/dist/YINI.d.ts +27 -5
- package/dist/YINI.js +27 -5
- package/dist/core/ErrorDataHandler.js +34 -38
- package/dist/core/YINIVisitor.d.ts +3 -0
- package/dist/core/YINIVisitor.js +55 -4
- package/dist/core/objectBuilder.js +21 -2
- package/dist/grammar/YiniLexer.d.ts +40 -41
- package/dist/grammar/YiniLexer.js +283 -287
- package/dist/grammar/YiniParser.d.ts +40 -41
- package/dist/grammar/YiniParser.js +138 -141
- package/dist/index.js +11 -13
- package/dist/parsers/extractHeaderParts.js +1 -1
- package/dist/utils/system.d.ts +10 -5
- package/dist/utils/system.js +21 -3
- package/dist/yiniHelpers.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 1.0.0-alpha.7
|
|
4
|
+
- Fixed serious bug that on error did exit process.
|
|
5
|
+
- Pached and updated JSDoc for remaing params for the functions parse(..) and parseFile(..).
|
|
6
|
+
- Changed the WIPs in the readme to "Planned – not yet implemented"-tag.
|
|
7
|
+
- Updated readme and especially "Intro to YINI Config Format".
|
|
8
|
+
|
|
9
|
+
## 1.0.0-alpha.6
|
|
10
|
+
- The YINI specificaiton discontinued alternative marker character `~` (visually ambiguous) in favor of `<`.
|
|
11
|
+
- The parser can now detect invalid . characters in identifiers (both keys and section names), allowing it to emit a clear error message to the user.
|
|
12
|
+
- Detect and emit error on defining already existing key or section name in a scope/section.
|
|
13
|
+
- Updated readme with "Intro to YINI Config Format" among other misc. updates.
|
|
14
|
+
|
|
15
|
+
## 1.0.0-alpha.5
|
|
16
|
+
- Readme updated with correct examples for CommonJS.
|
|
17
|
+
|
|
18
|
+
## 1.0.0-alpha.4 - 2025-07-20
|
|
19
|
+
|
|
20
|
+
First public release.
|
package/README.md
CHANGED
|
@@ -13,21 +13,43 @@ YINI is a simple, human-friendly configuration format inspired by INI and JSON.
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
A simple configuration:
|
|
19
|
+
```yini
|
|
20
|
+
^ App
|
|
21
|
+
name = 'My Title' // App display name.
|
|
22
|
+
items = 25
|
|
23
|
+
enabled = true
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
That's it!
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
16
30
|
## 💡 Why YINI?
|
|
17
|
-
- Easy to read and write
|
|
18
|
-
-
|
|
31
|
+
- **Easy to read and write**, minimal syntax, maximum clarity.
|
|
32
|
+
- **Clear section nesting** without painful indentation rules.
|
|
33
|
+
- **Supports strict/lenient modes**, and all major data types.
|
|
19
34
|
- A perfect alternative to messy JSON, legacy INI, or complex YAML.
|
|
20
|
-
- Built for both JavaScript and TypeScript
|
|
21
|
-
-
|
|
35
|
+
- Built for both **JavaScript and TypeScript**.
|
|
36
|
+
- Both **human-friendly**, and **machine-friendly**.
|
|
22
37
|
|
|
23
38
|
## ✨ Features
|
|
24
39
|
- Simple syntax (supports both strict and lenient modes).
|
|
25
|
-
- Familiar config file style (inspired by INI,
|
|
40
|
+
- Familiar config file style (inspired by INI, JSON, Python, and Markdown).
|
|
26
41
|
- Easy programmatic usage.
|
|
27
42
|
- Only the `YINI` class is exported; all internal details are private.
|
|
43
|
+
- 🚧 *(Planned – not yet implemented in parser)* Supports alternative list notation (colon‑style lists):
|
|
44
|
+
```yini
|
|
45
|
+
fruits:
|
|
46
|
+
'Pear',
|
|
47
|
+
'Cherry',
|
|
48
|
+
'Banana'
|
|
49
|
+
```
|
|
28
50
|
|
|
29
51
|
### Limitations
|
|
30
|
-
Not all features of the full YINI
|
|
52
|
+
Not all features of the full YINI are implemented yet.
|
|
31
53
|
|
|
32
54
|
See [FEATURE-CHECKLIST.md](https://github.com/YINI-lang/yini-parser-typescript/blob/main/FEATURE-CHECKLIST.md) for the current list of implemented YINI features.
|
|
33
55
|
|
|
@@ -57,9 +79,10 @@ pnpm add yini-parser
|
|
|
57
79
|
### Node.js (CommonJS)
|
|
58
80
|
**Note:** Only a default export (YINI) is provided. Named imports are not supported.
|
|
59
81
|
```js
|
|
60
|
-
const YINI = require('yini-parser');
|
|
61
|
-
// If you get undefined, try:
|
|
62
82
|
const YINI = require('yini-parser').default;
|
|
83
|
+
// (!) If you get undefined, try:
|
|
84
|
+
// (Some Node.js setups require the .default property, others don't, due to ESM/CommonJS interop quirks.)
|
|
85
|
+
const YINI = require('yini-parser');
|
|
63
86
|
|
|
64
87
|
// Parse from string.
|
|
65
88
|
const config = YINI.parse(`
|
|
@@ -125,8 +148,9 @@ Returns a JavaScript object representing the parsed YINI configuration file.
|
|
|
125
148
|
|
|
126
149
|
## Example Output
|
|
127
150
|
```js
|
|
151
|
+
// JS object
|
|
128
152
|
{
|
|
129
|
-
App:{
|
|
153
|
+
App: {
|
|
130
154
|
title: "My App Title",
|
|
131
155
|
items: 25,
|
|
132
156
|
isDarkTheme: false
|
|
@@ -135,12 +159,219 @@ Returns a JavaScript object representing the parsed YINI configuration file.
|
|
|
135
159
|
```
|
|
136
160
|
|
|
137
161
|
---
|
|
162
|
+
|
|
163
|
+
## Intro to YINI Config Format
|
|
164
|
+
|
|
165
|
+
### 1. Sections
|
|
166
|
+
Group settings under a named header. A section header name starts with `^`.
|
|
167
|
+
|
|
168
|
+
Start a section with `^`, e.g.:
|
|
169
|
+
```yini
|
|
170
|
+
^ App
|
|
171
|
+
title = "AppName"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
> Alternative section markers to `^` are also supported: `<`, `§`, `€` (e.g. `< Section`).
|
|
175
|
+
|
|
176
|
+
> See section 9 for more advanced marker and naming options.
|
|
177
|
+
|
|
178
|
+
### 2. Key = Value
|
|
179
|
+
Each line inside a section is a **key** (name) and **value**, separated by `=`.
|
|
180
|
+
|
|
181
|
+
Write settings as `key = value`:
|
|
182
|
+
```yini
|
|
183
|
+
maxConnections = 100
|
|
184
|
+
enableLogging = true
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
> See section 9 for more advanced marker and naming options.
|
|
188
|
+
|
|
189
|
+
#### 💡Tip
|
|
190
|
+
Use backticks (\`) to quote section or key names that contain spaces or special characters.
|
|
191
|
+
|
|
192
|
+
Key names with spaces/special characters can be backticked:
|
|
193
|
+
|
|
194
|
+
```yini
|
|
195
|
+
user id = 1 # Invalid ❌
|
|
196
|
+
`user id` = 1 # Valid ✅
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 3. Values
|
|
200
|
+
Values can be:
|
|
201
|
+
- **Strings** (always quoted): `"hello"` or `'world'` (either single or double quoted)
|
|
202
|
+
- **Numbers:** `42`, `3.14` or `-10`
|
|
203
|
+
- **Booleans:** `true`, `false`, `on`, `off`, `yes`, `no` (all case-insensitive)
|
|
204
|
+
- **Nulls:** Use `null` or leave the value blank after `=` (in lenient mode)
|
|
205
|
+
- *(Planned – not yet implemented in parser)* **Lists:**
|
|
206
|
+
* JSON‑style: `["red", "green", "blue"]`
|
|
207
|
+
* Colon‑style:
|
|
208
|
+
```yini
|
|
209
|
+
fruits:
|
|
210
|
+
"Pear",
|
|
211
|
+
"Cherry",
|
|
212
|
+
"Banana"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 4. Comments
|
|
216
|
+
Various commenting styles are supported:
|
|
217
|
+
```yini
|
|
218
|
+
// This is a line comment
|
|
219
|
+
timeout = 30 // inline comment
|
|
220
|
+
# This is also a line comment (must have a space after #)
|
|
221
|
+
interval = 30 # inline comment (must have a space after #)
|
|
222
|
+
/* Block comment spanning
|
|
223
|
+
multiple lines */
|
|
224
|
+
; Full line comment (must be whole line).
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
> **Tip:** You can add comments anywhere—above, beside, or below any setting or section.
|
|
228
|
+
>
|
|
229
|
+
👆 **Caveat:** If you use `#` for comments, always put a space after the `#`.
|
|
230
|
+
(Otherwise, the parser might misinterpret it as part of a value.)
|
|
231
|
+
|
|
232
|
+
💡**Tip:** You can use any comment style in your file.
|
|
233
|
+
For best readability, try to stick to one style per file.
|
|
234
|
+
|
|
235
|
+
### 5. Nested Sections
|
|
236
|
+
Use extra carets `^` for sub‑sections:
|
|
237
|
+
```yini
|
|
238
|
+
^ Parent
|
|
239
|
+
^^ Child
|
|
240
|
+
|
|
241
|
+
// Add another caret `^` and you get a sub-section
|
|
242
|
+
// of the previous section, and so...
|
|
243
|
+
^^^ SubChild
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
If you prefer, you can indent the nested section for visibility:
|
|
247
|
+
```yini
|
|
248
|
+
^ Main
|
|
249
|
+
^^ Sub
|
|
250
|
+
host = "db.example.com"
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
One can nest multiple sections:
|
|
254
|
+
```yini
|
|
255
|
+
^ Root
|
|
256
|
+
^^ Sub
|
|
257
|
+
^^^ SubSub
|
|
258
|
+
^ BackToRoot
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Example with indented sections:
|
|
262
|
+
```yini
|
|
263
|
+
^ Root
|
|
264
|
+
value = 'At level 1'
|
|
265
|
+
^^ Sub
|
|
266
|
+
value = 'At level 2'
|
|
267
|
+
^^^ SubSub
|
|
268
|
+
value = 'At level 3'
|
|
269
|
+
|
|
270
|
+
^ BackToRoot
|
|
271
|
+
value = 'Back at level 1'
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
The above Yini code will produce the following JavaScript object:
|
|
275
|
+
```js
|
|
276
|
+
// JS object
|
|
277
|
+
{
|
|
278
|
+
Root: {
|
|
279
|
+
value: 'At level 1',
|
|
280
|
+
Sub: { value: 'At level 2', SubSub: { value: 'At level 3' } }
|
|
281
|
+
},
|
|
282
|
+
BackToRoot: { value: 'Back at level 1' }
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
> See section 9 for more advanced marker and naming options.
|
|
287
|
+
|
|
288
|
+
### 6. Lists
|
|
289
|
+
👆 *List support is planned for an upcoming release.*
|
|
290
|
+
```yini
|
|
291
|
+
// JSON‑style list
|
|
292
|
+
colors = ["red", "green", "blue"]
|
|
293
|
+
|
|
294
|
+
// Colon‑style list
|
|
295
|
+
fruits:
|
|
296
|
+
"Pear",
|
|
297
|
+
"Cherry",
|
|
298
|
+
"Banana"
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
> You can use either single or double quotes for string values in YINI.
|
|
302
|
+
|
|
303
|
+
### 7. Document Terminator (strict mode)
|
|
304
|
+
The `/END` marker is required only in strict mode, and optional in lenient (default) mode.
|
|
305
|
+
|
|
306
|
+
End a file explicitly with:
|
|
307
|
+
```yini
|
|
308
|
+
^ App
|
|
309
|
+
title = "MyTitle"
|
|
310
|
+
|
|
311
|
+
/END // Must be included in strict mode.
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### 8. Disabled Lines
|
|
315
|
+
Prefix any valid line with `--` to skip it entirely:
|
|
316
|
+
```yini
|
|
317
|
+
--maxRetries = 5
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### 9. Advanced: Alternative Section Markers & Naming
|
|
321
|
+
In addition to the standard syntax, YINI supports several advanced options:
|
|
322
|
+
|
|
323
|
+
- (a.) **Alternative section markers:**
|
|
324
|
+
Besides `^`, you can use `<`, `§`, or `€` as section header markers.
|
|
325
|
+
|
|
326
|
+
```yini
|
|
327
|
+
< MySection
|
|
328
|
+
§ Settings
|
|
329
|
+
€ MyApp
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
- (b.) **Backticked section names and key names:**
|
|
333
|
+
Use backticks (`) to allow spaces or special characters in section or key names:
|
|
334
|
+
|
|
335
|
+
```yini
|
|
336
|
+
^ `Section name with spaces`
|
|
337
|
+
`user id` = 42
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
- (c.) **Numeric shorthand section markers:**
|
|
341
|
+
To create deeply nested sections (beyond 6 levels), use numeric shorthand:
|
|
342
|
+
|
|
343
|
+
```yini
|
|
344
|
+
^7 DeepSection # Equivalent to 7 carets: ^^^^^^^ DeepSection
|
|
345
|
+
<10 VeryDeep # Equivalent to <<<<<<<<<<< VeryDeep
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
👆 Though, can not mix standard/classic and numeric shorthand markers in the same section header.
|
|
349
|
+
|
|
350
|
+
### 10. Complete Example
|
|
351
|
+
|
|
352
|
+
```yini
|
|
353
|
+
@yini # Optional marker to identify YINI format.
|
|
354
|
+
|
|
355
|
+
^ App
|
|
356
|
+
name = "MyApp"
|
|
357
|
+
version = "1.0.0"
|
|
358
|
+
debug = off // Turn on for debugging.
|
|
359
|
+
|
|
360
|
+
^^ Database
|
|
361
|
+
host = "db.local"
|
|
362
|
+
port = 5432
|
|
363
|
+
--user = "secret" # This line is disabled due to --.
|
|
364
|
+
--userList = ["alice", "bob", "carol"]
|
|
365
|
+
|
|
366
|
+
/END
|
|
367
|
+
```
|
|
368
|
+
|
|
138
369
|
---
|
|
139
370
|
|
|
140
|
-
###
|
|
371
|
+
### Advanced Example
|
|
141
372
|
|
|
142
373
|
```js
|
|
143
|
-
const YINI = require('yini-parser'); // Or: import YINI from 'yini-parser';
|
|
374
|
+
const YINI = require('yini-parser').default; // Or: import YINI from 'yini-parser';
|
|
144
375
|
|
|
145
376
|
const config = YINI.parse(`
|
|
146
377
|
/*
|
|
@@ -183,26 +414,27 @@ console.log(config);
|
|
|
183
414
|
|
|
184
415
|
#### Output:
|
|
185
416
|
```js
|
|
417
|
+
// JS object
|
|
186
418
|
{
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
419
|
+
App: {
|
|
420
|
+
name: "Nested Example",
|
|
421
|
+
version: "1.0.0",
|
|
422
|
+
debug: false,
|
|
423
|
+
Database: {
|
|
424
|
+
host: "db.example.com",
|
|
425
|
+
port: 3306,
|
|
426
|
+
user: "appuser",
|
|
427
|
+
password: "dbpassword",
|
|
428
|
+
Pool: {
|
|
429
|
+
min: 2,
|
|
430
|
+
max: 10,
|
|
431
|
+
idleTimeout: 300
|
|
200
432
|
}
|
|
201
433
|
},
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
434
|
+
Logging: {
|
|
435
|
+
level: "info",
|
|
436
|
+
logToFile: true,
|
|
437
|
+
filePath: "./logs/app.log"
|
|
206
438
|
}
|
|
207
439
|
}
|
|
208
440
|
}
|
package/dist/YINI.d.ts
CHANGED
|
@@ -7,15 +7,37 @@ import { TJSObject } from './core/types';
|
|
|
7
7
|
export default class YINI {
|
|
8
8
|
static filePath: string;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
10
|
+
* Parse YINI content into a JavaScript object.
|
|
11
|
+
*
|
|
12
|
+
* @param yiniContent YINI code as a string (multi‑line content supported).
|
|
13
|
+
* @param strictMode If `true`, enforce strict parsing rules (e.g. require `/END`, disallow trailing commas).
|
|
14
|
+
* @param bailSensitivity Controls how errors and warnings are handled:
|
|
15
|
+
* - `'auto'` : Auto‑select level (strict→1, lenient→0)
|
|
16
|
+
* - `0` / `'Ignore-Errors'` : Continue parsing despite errors; log them and attempt recovery.
|
|
17
|
+
* - `1` / `'Abort-on-Errors'` : Stop parsing on the first error.
|
|
18
|
+
* - `2` / `'Abort-Even-on-Warnings'`: Stop parsing on the first warning **or** error.
|
|
19
|
+
* @param includeMetaData If `true`, return additional metadata (e.g. warnings, statistics) alongside the parsed object.
|
|
20
|
+
*
|
|
21
|
+
* @note The order of properties in each output object may differ from their order in the YINI source.
|
|
22
|
+
*
|
|
23
|
+
* @returns A JavaScript object representing the parsed YINI content.
|
|
13
24
|
*/
|
|
14
25
|
static parse: (yiniContent: string, strictMode?: boolean, bailSensitivity?: "auto" | 0 | 1 | 2, includeMetaData?: boolean) => TJSObject;
|
|
15
26
|
/**
|
|
27
|
+
* Parse a YINI file into a JavaScript object.
|
|
28
|
+
*
|
|
16
29
|
* @param yiniFile Path to the YINI file.
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
30
|
+
* @param strictMode If `true`, enforce strict parsing rules (e.g. require `/END`, disallow trailing commas).
|
|
31
|
+
* @param bailSensitivity Controls how errors and warnings are handled:
|
|
32
|
+
* - `'auto'` : Auto‑select level (strict→1, lenient→0)
|
|
33
|
+
* - `0` / `'Ignore-Errors'` : Continue parsing despite errors; log them and attempt recovery.
|
|
34
|
+
* - `1` / `'Abort-on-Errors'` : Stop parsing on the first error.
|
|
35
|
+
* - `2` / `'Abort-Even-on-Warnings'`: Stop parsing on the first warning **or** error.
|
|
36
|
+
* @param includeMetaData If `true`, return additional metadata (e.g. warnings, statistics) alongside the parsed object.
|
|
37
|
+
*
|
|
38
|
+
* @note The order of properties in each output object may differ from their order in the YINI source.
|
|
39
|
+
*
|
|
40
|
+
* @returns A JavaScript object representing the parsed YINI content.
|
|
19
41
|
*/
|
|
20
42
|
static parseFile: (filePath: string, strictMode?: boolean, bailSensitivity?: "auto" | 0 | 1 | 2, includeMetaData?: boolean) => TJSObject;
|
|
21
43
|
}
|
package/dist/YINI.js
CHANGED
|
@@ -17,9 +17,20 @@ class YINI {
|
|
|
17
17
|
}
|
|
18
18
|
YINI.filePath = ''; // Used in error reporting.
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
20
|
+
* Parse YINI content into a JavaScript object.
|
|
21
|
+
*
|
|
22
|
+
* @param yiniContent YINI code as a string (multi‑line content supported).
|
|
23
|
+
* @param strictMode If `true`, enforce strict parsing rules (e.g. require `/END`, disallow trailing commas).
|
|
24
|
+
* @param bailSensitivity Controls how errors and warnings are handled:
|
|
25
|
+
* - `'auto'` : Auto‑select level (strict→1, lenient→0)
|
|
26
|
+
* - `0` / `'Ignore-Errors'` : Continue parsing despite errors; log them and attempt recovery.
|
|
27
|
+
* - `1` / `'Abort-on-Errors'` : Stop parsing on the first error.
|
|
28
|
+
* - `2` / `'Abort-Even-on-Warnings'`: Stop parsing on the first warning **or** error.
|
|
29
|
+
* @param includeMetaData If `true`, return additional metadata (e.g. warnings, statistics) alongside the parsed object.
|
|
30
|
+
*
|
|
31
|
+
* @note The order of properties in each output object may differ from their order in the YINI source.
|
|
32
|
+
*
|
|
33
|
+
* @returns A JavaScript object representing the parsed YINI content.
|
|
23
34
|
*/
|
|
24
35
|
YINI.parse = (yiniContent, strictMode = false, bailSensitivity = 'auto', includeMetaData = false) => {
|
|
25
36
|
(0, system_1.debugPrint)('-> Entered static parse(..) in class YINI\n');
|
|
@@ -66,9 +77,20 @@ YINI.parse = (yiniContent, strictMode = false, bailSensitivity = 'auto', include
|
|
|
66
77
|
return result;
|
|
67
78
|
};
|
|
68
79
|
/**
|
|
80
|
+
* Parse a YINI file into a JavaScript object.
|
|
81
|
+
*
|
|
69
82
|
* @param yiniFile Path to the YINI file.
|
|
70
|
-
* @
|
|
71
|
-
* @
|
|
83
|
+
* @param strictMode If `true`, enforce strict parsing rules (e.g. require `/END`, disallow trailing commas).
|
|
84
|
+
* @param bailSensitivity Controls how errors and warnings are handled:
|
|
85
|
+
* - `'auto'` : Auto‑select level (strict→1, lenient→0)
|
|
86
|
+
* - `0` / `'Ignore-Errors'` : Continue parsing despite errors; log them and attempt recovery.
|
|
87
|
+
* - `1` / `'Abort-on-Errors'` : Stop parsing on the first error.
|
|
88
|
+
* - `2` / `'Abort-Even-on-Warnings'`: Stop parsing on the first warning **or** error.
|
|
89
|
+
* @param includeMetaData If `true`, return additional metadata (e.g. warnings, statistics) alongside the parsed object.
|
|
90
|
+
*
|
|
91
|
+
* @note The order of properties in each output object may differ from their order in the YINI source.
|
|
92
|
+
*
|
|
93
|
+
* @returns A JavaScript object representing the parsed YINI content.
|
|
72
94
|
*/
|
|
73
95
|
YINI.parseFile = (filePath, strictMode = false, bailSensitivity = 'auto', includeMetaData = false) => {
|
|
74
96
|
(0, system_1.debugPrint)('Current directory = ' + process.cwd());
|
|
@@ -95,13 +95,12 @@ class ErrorDataHandler {
|
|
|
95
95
|
this.emitInternalError(msgWhat, msgWhy, msgHint);
|
|
96
96
|
if (this.persistThreshold === '1-Abort-on-Errors' ||
|
|
97
97
|
this.persistThreshold === '2-Abort-Even-on-Warnings') {
|
|
98
|
-
if (process.env.NODE_ENV === 'test') {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
98
|
+
// if (process.env.NODE_ENV === 'test') {
|
|
99
|
+
// In test, throw an error instead of exiting.
|
|
100
|
+
throw new Error(`Internal-Error: ${msgWhat}`);
|
|
101
|
+
// } else {
|
|
102
|
+
// process.exit(2)
|
|
103
|
+
// }
|
|
105
104
|
}
|
|
106
105
|
break;
|
|
107
106
|
case 'Syntax-Error':
|
|
@@ -109,26 +108,24 @@ class ErrorDataHandler {
|
|
|
109
108
|
this.emitSyntaxError(msgWhat, msgWhy, msgHint);
|
|
110
109
|
if (this.persistThreshold === '1-Abort-on-Errors' ||
|
|
111
110
|
this.persistThreshold === '2-Abort-Even-on-Warnings') {
|
|
112
|
-
if (process.env.NODE_ENV === 'test') {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
111
|
+
// if (process.env.NODE_ENV === 'test') {
|
|
112
|
+
// In test, throw an error instead of exiting.
|
|
113
|
+
throw new Error(`Syntax-Error: ${'' + msgWhat}`);
|
|
114
|
+
// } else {
|
|
115
|
+
// process.exit(3)
|
|
116
|
+
// }
|
|
119
117
|
}
|
|
120
118
|
break;
|
|
121
119
|
case 'Syntax-Warning':
|
|
122
120
|
this.numSyntaxWarnings++;
|
|
123
121
|
this.emitSyntaxWarning(msgWhat, msgWhy, msgHint);
|
|
124
122
|
if (this.persistThreshold === '2-Abort-Even-on-Warnings') {
|
|
125
|
-
if (process.env.NODE_ENV === 'test') {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
123
|
+
// if (process.env.NODE_ENV === 'test') {
|
|
124
|
+
// In test, throw an error instead of exiting.
|
|
125
|
+
throw new Error(`Syntax-Warning: ${msgWhat}`);
|
|
126
|
+
// } else {
|
|
127
|
+
// process.exit(4)
|
|
128
|
+
// }
|
|
132
129
|
}
|
|
133
130
|
break;
|
|
134
131
|
case 'Notice':
|
|
@@ -143,53 +140,52 @@ class ErrorDataHandler {
|
|
|
143
140
|
this.numFatalErrors++;
|
|
144
141
|
this.emitFatalError(msgWhat, msgWhy, msgHint);
|
|
145
142
|
// CANNOT recover fatal errors, will lead to an exit!
|
|
146
|
-
if (process.env.NODE_ENV === 'test') {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
143
|
+
// if (process.env.NODE_ENV === 'test') {
|
|
144
|
+
// In test, throw an error instead of exiting.
|
|
145
|
+
throw new Error(`Internal-Error: ${msgWhat}`);
|
|
146
|
+
// } else {
|
|
147
|
+
// process.exit(1)
|
|
148
|
+
// (!) Not sure about the below yet, if it's preferable in this case...
|
|
149
|
+
// Use this instead of process.exit(1), this will
|
|
150
|
+
// lead to that the current thread(s) will exit as well.
|
|
151
|
+
// process.exitCode = 1
|
|
152
|
+
// }
|
|
157
153
|
}
|
|
158
154
|
};
|
|
159
155
|
this.emitFatalError = (msgWhat = 'Something went wrong!', msgWhy = '', msgHint = '') => {
|
|
160
156
|
console.error(issueTitle[0]); // Print the issue title.
|
|
161
157
|
msgWhat && console.error(msgWhat);
|
|
162
|
-
msgWhy && console.
|
|
158
|
+
msgWhy && console.log(msgWhy);
|
|
163
159
|
msgHint && console.log(msgHint);
|
|
164
160
|
};
|
|
165
161
|
this.emitInternalError = (msgWhat = 'Something went wrong!', msgWhy = '', msgHint = '') => {
|
|
166
162
|
console.error(issueTitle[1]); // Print the issue title.
|
|
167
163
|
msgWhat && console.error(msgWhat);
|
|
168
|
-
msgWhy && console.
|
|
164
|
+
msgWhy && console.log(msgWhy);
|
|
169
165
|
msgHint && console.log(msgHint);
|
|
170
166
|
};
|
|
171
167
|
this.emitSyntaxError = (msgWhat, msgWhy = '', msgHint = '') => {
|
|
172
168
|
console.error(issueTitle[2]); // Print the issue title.
|
|
173
169
|
msgWhat && console.error(msgWhat);
|
|
174
|
-
msgWhy && console.
|
|
170
|
+
msgWhy && console.log(msgWhy);
|
|
175
171
|
msgHint && console.log(msgHint);
|
|
176
172
|
};
|
|
177
173
|
this.emitSyntaxWarning = (msgWhat, msgWhy = '', msgHint = '') => {
|
|
178
174
|
console.warn(issueTitle[3]); // Print the issue title.
|
|
179
175
|
msgWhat && console.warn(msgWhat);
|
|
180
|
-
msgWhy && console.
|
|
176
|
+
msgWhy && console.log(msgWhy);
|
|
181
177
|
msgHint && console.log(msgHint);
|
|
182
178
|
};
|
|
183
179
|
this.emitNotice = (msgWhat, msgWhy = '', msgHint = '') => {
|
|
184
180
|
console.warn(issueTitle[4]); // Print the issue title.
|
|
185
181
|
msgWhat && console.warn(msgWhat);
|
|
186
|
-
msgWhy && console.
|
|
182
|
+
msgWhy && console.log(msgWhy);
|
|
187
183
|
msgHint && console.log(msgHint);
|
|
188
184
|
};
|
|
189
185
|
this.emitInfo = (msgWhat, msgWhy = '', msgHint = '') => {
|
|
190
186
|
console.info(issueTitle[5]); // Print the issue title.
|
|
191
187
|
msgWhat && console.info(msgWhat);
|
|
192
|
-
msgWhy && console.
|
|
188
|
+
msgWhy && console.log(msgWhy);
|
|
193
189
|
msgHint && console.log(msgHint);
|
|
194
190
|
};
|
|
195
191
|
this.persistThreshold = threshold;
|
|
@@ -23,6 +23,9 @@ export default class YINIVisitor<IResult> extends YiniParserVisitor<IResult> {
|
|
|
23
23
|
private meta_numOfMembers;
|
|
24
24
|
private meta_numOfChains;
|
|
25
25
|
private meta_maxLevelSection;
|
|
26
|
+
private existingSectionTitlesAtLevels;
|
|
27
|
+
private hasDefinedSectionTitle;
|
|
28
|
+
private setDefineSectionTitle;
|
|
26
29
|
constructor(errorHandler: ErrorDataHandler, isStrict: boolean);
|
|
27
30
|
private pushOnTree;
|
|
28
31
|
private getDepthOfLevels;
|