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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.1
|
|
4
|
+
- Package updated to **beta**. The core API is stabilizing, some more advanced features may still change.
|
|
5
|
+
- Bugfix, fixed exports cleanly (so this lib can be imported in CJS and in full ESM).
|
|
6
|
+
- Implemented support for colon lists, both empty and with elements, including nested lists. Also updated to the latest grammar, which fixes handling of empty lists with or without spaces or tabs between the brackets.
|
|
7
|
+
- Optimized the top part of readme for npmjs Short Page.
|
|
8
|
+
- Added a dir `examples/` with a few example Yini files, `compare-formats.md` and TS file.
|
|
9
|
+
- Updated to the latest grammar (logic) to the spec 1.0.0-rc.1.
|
|
10
|
+
|
|
3
11
|
## 1.0.0-alpha.7
|
|
4
12
|
- Fixed serious bug that on error did exit process.
|
|
5
13
|
- Pached and updated JSDoc for remaing params for the functions parse(..) and parseFile(..).
|
package/README.md
CHANGED
|
@@ -1,163 +1,95 @@
|
|
|
1
|
-
# YINI Parser
|
|
1
|
+
# YINI Parser for Node.js
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
> ⚠️ This package is in **alpha**. The API and features may change. Not all parts of the YINI specification are implemented yet.
|
|
6
|
-
|
|
7
|
-
**YINI Parser in TypeScript** — a runtime library for Node.js.
|
|
8
|
-
A parser / reader for the [YINI configuration file format](https://github.com/YINI-lang/YINI-spec).
|
|
9
|
-
|
|
10
|
-
This library implements the official YINI specification using TypeScript + ANTLR4.
|
|
11
|
-
|
|
12
|
-
YINI is a simple, human-friendly configuration format inspired by INI and JSON.
|
|
13
|
-
|
|
14
|
-
---
|
|
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
|
-
---
|
|
3
|
+
YINI is a clean, minimal, and human-readable config format for structured configuration. This parser implements the YINI spec in TypeScript for Node.js, with support for nested sections, strict/lenient modes, and typed values.
|
|
29
4
|
|
|
30
|
-
|
|
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.
|
|
34
|
-
- A perfect alternative to messy JSON, legacy INI, or complex YAML.
|
|
35
|
-
- Built for both **JavaScript and TypeScript**.
|
|
36
|
-
- Both **human-friendly**, and **machine-friendly**.
|
|
37
|
-
|
|
38
|
-
## ✨ Features
|
|
39
|
-
- Simple syntax (supports both strict and lenient modes).
|
|
40
|
-
- Familiar config file style (inspired by INI, JSON, Python, and Markdown).
|
|
41
|
-
- Easy programmatic usage.
|
|
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
|
-
```
|
|
50
|
-
|
|
51
|
-
### Limitations
|
|
52
|
-
Not all features of the full YINI are implemented yet.
|
|
53
|
-
|
|
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.
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## 🚀 Installation
|
|
5
|
+
[](https://www.npmjs.com/package/yini-parser) [](https://github.com/YINI-lang/yini-parser-typescript/actions/workflows/run-all-tests.yml)
|
|
59
6
|
|
|
60
|
-
With **npm**:
|
|
61
7
|
```sh
|
|
62
8
|
npm install yini-parser
|
|
63
9
|
```
|
|
64
10
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
With **pnpm**:
|
|
71
|
-
```sh
|
|
72
|
-
pnpm add yini-parser
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## Usage
|
|
78
|
-
|
|
79
|
-
### Node.js (CommonJS)
|
|
80
|
-
**Note:** Only a default export (YINI) is provided. Named imports are not supported.
|
|
81
|
-
```js
|
|
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');
|
|
86
|
-
|
|
87
|
-
// Parse from string.
|
|
88
|
-
const config = YINI.parse(`
|
|
89
|
-
^ App
|
|
90
|
-
title = 'My App Title'
|
|
91
|
-
items = 25
|
|
92
|
-
isDarkTheme = true
|
|
93
|
-
`);
|
|
94
|
-
|
|
95
|
-
// Parse from file.
|
|
96
|
-
const configFromFile = YINI.parseFile('./config.yini');
|
|
11
|
+
```ts
|
|
12
|
+
import YINI from 'yini-parser'
|
|
13
|
+
const config = YINI.parseFile('./config.yini')
|
|
97
14
|
```
|
|
98
15
|
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
import YINI from 'yini-parser';
|
|
16
|
+
A clean, minimal, human-readable config format—designed as an alternative to INI, YAML, and JSON.
|
|
102
17
|
|
|
103
|
-
|
|
104
|
-
const config = YINI.parse(`
|
|
105
|
-
^ App
|
|
106
|
-
title = "My App Title"
|
|
107
|
-
items = 25
|
|
108
|
-
isDarkTheme = OFF
|
|
109
|
-
`);
|
|
18
|
+
➡️ See full [documentation or YINI format specification](https://github.com/YINI-lang/YINI-spec)
|
|
110
19
|
|
|
111
|
-
|
|
112
|
-
const configFromFile = YINI.parseFile('./config.yini');
|
|
113
|
-
```
|
|
20
|
+
⭐ **Enjoying YINI?** If you find this project useful, please consider [starring it on GitHub](https://github.com/YINI-lang/yini-parser-typescript) — it helps others discover it!
|
|
114
21
|
|
|
115
22
|
---
|
|
116
23
|
|
|
117
|
-
##
|
|
118
|
-
|
|
119
|
-
Only the `YINI` class is exposed in the public API, with two static methods: `parse` and `parseFile`.
|
|
120
|
-
|
|
121
|
-
### `YINI.parse(yiniContent: string, strictMode?: boolean, bailSensitivity: 'auto' | 0 | 1 | 2 = "auto", includeMetaData = false): object`
|
|
24
|
+
## YINI Parser – TypeScript
|
|
122
25
|
|
|
123
|
-
|
|
26
|
+
> 🚧 This package is in **beta**. The core API is stabilizing, some more advanced features may still change. Feedback and bug reports are welcome!
|
|
124
27
|
|
|
125
|
-
**
|
|
126
|
-
|
|
127
|
-
- `strictMode`: (optional, default `false`) Parse in strict mode.
|
|
128
|
-
- `bailSensitivity`: (optional, default `"auto"`) Error tolerance level.
|
|
129
|
-
* If `bailSensitivity` is `"auto"` then bail sensitivity level will be set to 0 if in non-strict mode, if in strict mode then level 1 will be used automatically.
|
|
130
|
-
- `includeMetaData`: If true then additional meta data will be returned along the object.
|
|
28
|
+
**YINI Parser in TypeScript** — a runtime library for Node.js.
|
|
29
|
+
A parser / reader for the [YINI configuration file format](https://github.com/YINI-lang/YINI-spec).
|
|
131
30
|
|
|
132
|
-
|
|
133
|
-
- 0 = 'Ignore-Errors' // Don't bail on errors, persist and try to recover.
|
|
134
|
-
- 1 = 'Abort-on-Errors'
|
|
135
|
-
- 2 = 'Abort-Even-on-Warnings'
|
|
31
|
+
This library implements the official YINI specification using TypeScript + ANTLR4.
|
|
136
32
|
|
|
137
|
-
|
|
33
|
+
YINI is a simple, human-friendly configuration format inspired by INI and JSON.
|
|
138
34
|
|
|
139
|
-
|
|
35
|
+
---
|
|
140
36
|
|
|
141
|
-
|
|
142
|
-
- `filePath`: Path to the `.yini` file.
|
|
143
|
-
- Other parameters are the same as `parse(..)`.
|
|
37
|
+
## Quick Start
|
|
144
38
|
|
|
145
|
-
|
|
39
|
+
A minimal example using YINI in TypeScript:
|
|
40
|
+
```ts
|
|
41
|
+
import YINI from 'yini-parser'
|
|
146
42
|
|
|
147
|
-
|
|
43
|
+
const config = YINI.parse(`
|
|
44
|
+
^ App
|
|
45
|
+
name = 'My Title' // App display name.
|
|
46
|
+
items = 25
|
|
47
|
+
darkMode = true
|
|
48
|
+
|
|
49
|
+
// Sub-section of App.
|
|
50
|
+
^^ Special
|
|
51
|
+
primaryColor = #336699
|
|
52
|
+
isCaching = false
|
|
53
|
+
`)
|
|
54
|
+
|
|
55
|
+
// To parse from a file instead:
|
|
56
|
+
// const config = YINI.parseFile('./config.yini')
|
|
57
|
+
|
|
58
|
+
console.log(config.App.name) // My Title
|
|
59
|
+
console.log(config.App.Special.isCaching) // false
|
|
60
|
+
console.log()
|
|
61
|
+
console.log(config)
|
|
62
|
+
```
|
|
148
63
|
|
|
149
|
-
|
|
64
|
+
**Output:**
|
|
150
65
|
```js
|
|
151
|
-
|
|
66
|
+
My Title
|
|
67
|
+
false
|
|
68
|
+
|
|
152
69
|
{
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
70
|
+
App: {
|
|
71
|
+
name: 'My Title',
|
|
72
|
+
items: 25,
|
|
73
|
+
darkMode: true,
|
|
74
|
+
Special: { primaryColor: 3368601, isCaching: false }
|
|
75
|
+
}
|
|
158
76
|
}
|
|
159
77
|
```
|
|
160
78
|
|
|
79
|
+
That's it!
|
|
80
|
+
|
|
81
|
+
▶️ Link to [examples/](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples) files.
|
|
82
|
+
|
|
83
|
+
## 💡 Why YINI?
|
|
84
|
+
- **Easy to read and write**, minimal syntax noise, maximum clarity.
|
|
85
|
+
- **Clear and minimal section nesting** without painful indentation rules or long dot nested strings, etc.
|
|
86
|
+
- A perfect alternative to messy JSON, legacy INI, or complex YAML.
|
|
87
|
+
- Built for both **JavaScript and TypeScript**.
|
|
88
|
+
- **Supports strict/lenient modes**, and all major data types.
|
|
89
|
+
- Both **human-friendly**, and **machine-friendly**.
|
|
90
|
+
- 👉 See [how YINI compares to JSON, YAML, INI, and TOML](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples/compare-formats.md).
|
|
91
|
+
- Want the full syntax reference? See the [YINI Specification](https://github.com/YINI-lang/YINI-spec).
|
|
92
|
+
|
|
161
93
|
---
|
|
162
94
|
|
|
163
95
|
## Intro to YINI Config Format
|
|
@@ -198,19 +130,13 @@ Key names with spaces/special characters can be backticked:
|
|
|
198
130
|
|
|
199
131
|
### 3. Values
|
|
200
132
|
Values can be:
|
|
201
|
-
- **Strings** (always quoted): `
|
|
133
|
+
- **Strings** (always quoted): `'hello'` or `"world"` (either single or double quoted)
|
|
202
134
|
- **Numbers:** `42`, `3.14` or `-10`
|
|
203
135
|
- **Booleans:** `true`, `false`, `on`, `off`, `yes`, `no` (all case-insensitive)
|
|
204
136
|
- **Nulls:** Use `null` or leave the value blank after `=` (in lenient mode)
|
|
205
|
-
-
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
```yini
|
|
209
|
-
fruits:
|
|
210
|
-
"Pear",
|
|
211
|
-
"Cherry",
|
|
212
|
-
"Banana"
|
|
213
|
-
```
|
|
137
|
+
- **Lists:**
|
|
138
|
+
* JSON‑style: `["red", "green", "blue"]`
|
|
139
|
+
* Colon‑style: *(Planned – not yet implemented in parser)*
|
|
214
140
|
|
|
215
141
|
### 4. Comments
|
|
216
142
|
Various commenting styles are supported:
|
|
@@ -226,9 +152,12 @@ interval = 30 # inline comment (must have a space after #)
|
|
|
226
152
|
|
|
227
153
|
> **Tip:** You can add comments anywhere—above, beside, or below any setting or section.
|
|
228
154
|
>
|
|
229
|
-
👆 **Caveat:** If you use `#` for comments, always put a space after the `#`.
|
|
155
|
+
👆 **Caveat 1:** If you use `#` for comments, always put a space after the `#`.
|
|
230
156
|
(Otherwise, the parser might misinterpret it as part of a value.)
|
|
231
157
|
|
|
158
|
+
👆 **Caveat 2:** `;` is used only for full-line comments. The `;` must be the first non-whitespace character on a line (only spaces or tabs are allowed before it).
|
|
159
|
+
(If `;` appears later in the line, the parser may treat it as part of a value or as a line delimiter, not as a comment.)
|
|
160
|
+
|
|
232
161
|
💡**Tip:** You can use any comment style in your file.
|
|
233
162
|
For best readability, try to stick to one style per file.
|
|
234
163
|
|
|
@@ -286,12 +215,19 @@ The above Yini code will produce the following JavaScript object:
|
|
|
286
215
|
> See section 9 for more advanced marker and naming options.
|
|
287
216
|
|
|
288
217
|
### 6. Lists
|
|
289
|
-
👆 *List support is planned for an upcoming release.*
|
|
290
218
|
```yini
|
|
291
|
-
// JSON‑style
|
|
219
|
+
// JSON‑style lists
|
|
292
220
|
colors = ["red", "green", "blue"]
|
|
293
221
|
|
|
222
|
+
numberList = [
|
|
223
|
+
10,
|
|
224
|
+
20,
|
|
225
|
+
30
|
|
226
|
+
]
|
|
227
|
+
|
|
228
|
+
|
|
294
229
|
// Colon‑style list
|
|
230
|
+
// 👆 Colon‑style list support is planned for an upcoming release.
|
|
295
231
|
fruits:
|
|
296
232
|
"Pear",
|
|
297
233
|
"Cherry",
|
|
@@ -345,7 +281,10 @@ In addition to the standard syntax, YINI supports several advanced options:
|
|
|
345
281
|
<10 VeryDeep # Equivalent to <<<<<<<<<<< VeryDeep
|
|
346
282
|
```
|
|
347
283
|
|
|
348
|
-
👆 Though, can not mix standard/classic and numeric shorthand markers in the same section header.
|
|
284
|
+
👆 Though, can not mix standard/classic and numeric shorthand markers in the same section header.
|
|
285
|
+
|
|
286
|
+
- (d.) **More features:**
|
|
287
|
+
The YINI format supports even more features than listed here, such as additional number notations, string types, and advanced escaping. For full details, see the [latest release of the YINI specification](https://github.com/YINI-lang/YINI-spec/blob/release/YINI-Specification.md).
|
|
349
288
|
|
|
350
289
|
### 10. Complete Example
|
|
351
290
|
|
|
@@ -361,14 +300,128 @@ debug = off // Turn on for debugging.
|
|
|
361
300
|
host = "db.local"
|
|
362
301
|
port = 5432
|
|
363
302
|
--user = "secret" # This line is disabled due to --.
|
|
364
|
-
|
|
303
|
+
userList = ["alice", "bob", "carol"]
|
|
365
304
|
|
|
366
305
|
/END
|
|
367
306
|
```
|
|
368
307
|
|
|
369
308
|
---
|
|
370
309
|
|
|
371
|
-
|
|
310
|
+
## Usage
|
|
311
|
+
|
|
312
|
+
### Installation
|
|
313
|
+
|
|
314
|
+
With **npm**:
|
|
315
|
+
```sh
|
|
316
|
+
npm install yini-parser
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
With **yarn**:
|
|
320
|
+
```sh
|
|
321
|
+
yarn add yini-parser
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
With **pnpm**:
|
|
325
|
+
```sh
|
|
326
|
+
pnpm add yini-parser
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Node.js (CommonJS)
|
|
330
|
+
**Note:** Only a default export (YINI) is provided. Named imports are not supported.
|
|
331
|
+
```js
|
|
332
|
+
const YINI = require('yini-parser').default;
|
|
333
|
+
// (!) If you get undefined, try:
|
|
334
|
+
// (Some Node.js setups require the .default property, others don't, due to ESM/CommonJS interop quirks.)
|
|
335
|
+
const YINI = require('yini-parser');
|
|
336
|
+
|
|
337
|
+
// Parse from string.
|
|
338
|
+
const config = YINI.parse(`
|
|
339
|
+
^ App
|
|
340
|
+
title = 'My App Title'
|
|
341
|
+
items = 25
|
|
342
|
+
isDarkTheme = true
|
|
343
|
+
`);
|
|
344
|
+
|
|
345
|
+
// Parse from file.
|
|
346
|
+
const configFromFile = YINI.parseFile('./config.yini');
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### TypeScript (with `"esModuleInterop": true`)
|
|
350
|
+
```ts
|
|
351
|
+
import YINI from 'yini-parser';
|
|
352
|
+
|
|
353
|
+
// Parse from string.
|
|
354
|
+
const config = YINI.parse(`
|
|
355
|
+
^ App
|
|
356
|
+
title = "My App Title"
|
|
357
|
+
items = 25
|
|
358
|
+
isDarkTheme = OFF
|
|
359
|
+
`);
|
|
360
|
+
|
|
361
|
+
// Parse from file.
|
|
362
|
+
const configFromFile = YINI.parseFile('./config.yini');
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Example Output
|
|
366
|
+
```js
|
|
367
|
+
// JS object
|
|
368
|
+
{
|
|
369
|
+
App: {
|
|
370
|
+
title: "My App Title",
|
|
371
|
+
items: 25,
|
|
372
|
+
isDarkTheme: false
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## ✨ Features
|
|
380
|
+
- Simple syntax (supports both strict and lenient modes).
|
|
381
|
+
- Familiar config file style (inspired by INI, JSON, Python, and Markdown).
|
|
382
|
+
- Easy programmatic usage.
|
|
383
|
+
- Only the `YINI` class is exported; all internal details are private.
|
|
384
|
+
- Lists (bracketed): `list = [10, 20, 30]`
|
|
385
|
+
- 🚧 *(Planned – not yet implemented in parser)* Supports alternative list notation (colon‑style lists):
|
|
386
|
+
```yini
|
|
387
|
+
fruits:
|
|
388
|
+
'Pear',
|
|
389
|
+
'Cherry',
|
|
390
|
+
'Banana'
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Limitations
|
|
394
|
+
Not all features of the full YINI are implemented yet.
|
|
395
|
+
|
|
396
|
+
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.
|
|
397
|
+
|
|
398
|
+
## 🚧 Missing or Upcoming Features
|
|
399
|
+
|
|
400
|
+
This parser currently supports all core YINI syntax for values, comments, section headers, and basic nesting.
|
|
401
|
+
|
|
402
|
+
The following features from the [YINI specification](https://github.com/YINI-lang/YINI-spec) are **planned but not yet fully implemented**:
|
|
403
|
+
|
|
404
|
+
- Object literals
|
|
405
|
+
- Advanced escape sequences
|
|
406
|
+
- String types and triple-quoted strings
|
|
407
|
+
- All number format literals
|
|
408
|
+
- Full strict mode validation
|
|
409
|
+
|
|
410
|
+
You can follow progress in the [YINI parser GitHub repo-FEATURE-CHECKLIST](https://github.com/YINI-lang/yini-parser-typescript/blob/main/FEATURE-CHECKLIST.md). Contributions and feature requests are welcome!
|
|
411
|
+
|
|
412
|
+
## 📂 Examples
|
|
413
|
+
|
|
414
|
+
See the [examples/](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples) folder for:
|
|
415
|
+
|
|
416
|
+
- Basic YINI file with common types and comments
|
|
417
|
+
- Nested sections example
|
|
418
|
+
- Comparison with JSON/YAML config
|
|
419
|
+
|
|
420
|
+
These examples are also included in the npm package.
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## Advanced Example
|
|
372
425
|
|
|
373
426
|
```js
|
|
374
427
|
const YINI = require('yini-parser').default; // Or: import YINI from 'yini-parser';
|
|
@@ -412,7 +465,7 @@ const config = YINI.parse(`
|
|
|
412
465
|
console.log(config);
|
|
413
466
|
```
|
|
414
467
|
|
|
415
|
-
|
|
468
|
+
### Output:
|
|
416
469
|
```js
|
|
417
470
|
// JS object
|
|
418
471
|
{
|
|
@@ -439,11 +492,61 @@ console.log(config);
|
|
|
439
492
|
}
|
|
440
493
|
}
|
|
441
494
|
```
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## API
|
|
499
|
+
|
|
500
|
+
Only the `YINI` class is exposed in the public API, with two static methods: `parse` and `parseFile`.
|
|
501
|
+
|
|
502
|
+
### `YINI.parse(yiniContent: string, strictMode?: boolean, bailSensitivity: 'auto' | 0 | 1 | 2 = "auto", includeMetaData = false): object`
|
|
503
|
+
|
|
504
|
+
Parses YINI code from a string.
|
|
505
|
+
|
|
506
|
+
**Params:**
|
|
507
|
+
- `yiniContent`: The YINI configuration as a string.
|
|
508
|
+
- `strictMode`: (optional, default `false`) Parse in strict mode.
|
|
509
|
+
- `bailSensitivity`: (optional, default `"auto"`) Error tolerance level.
|
|
510
|
+
* If `bailSensitivity` is `"auto"` then bail sensitivity level will be set to 0 if in non-strict mode, if in strict mode then level 1 will be used automatically.
|
|
511
|
+
- `includeMetaData`: If true then additional meta data will be returned along the object.
|
|
512
|
+
|
|
513
|
+
**Bail sensitivity levels:**
|
|
514
|
+
- 0 = 'Ignore-Errors' // Don't bail on errors, persist and try to recover.
|
|
515
|
+
- 1 = 'Abort-on-Errors'
|
|
516
|
+
- 2 = 'Abort-Even-on-Warnings'
|
|
517
|
+
|
|
518
|
+
Returns a JavaScript object representing the parsed configuration (YINI content).
|
|
519
|
+
|
|
520
|
+
### `YINI.parseFile(filePath: string, strictMode?: boolean, bailSensitivity: 'auto' | 0 | 1 | 2 = "auto", includeMetaData = false): object`
|
|
521
|
+
|
|
522
|
+
Parses YINI code from a file.
|
|
523
|
+
- `filePath`: Path to the `.yini` file.
|
|
524
|
+
- Other parameters are the same as `parse(..)`.
|
|
525
|
+
|
|
526
|
+
Returns a JavaScript object representing the parsed YINI configuration file.
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
## 🤝 Contributing
|
|
531
|
+
We welcome feedback, bug reports, feature requests, and code contributions!
|
|
532
|
+
- [Open an Issue](https://github.com/YINI-lang/yini-parser-typescript/issues)
|
|
533
|
+
- [Start a Discussion](https://github.com/YINI-lang/yini-parser-typescript/discussions)
|
|
534
|
+
|
|
442
535
|
---
|
|
443
536
|
|
|
444
537
|
## 📚 Documentation
|
|
445
|
-
- [Development Setup](
|
|
446
|
-
- [Conventions](
|
|
538
|
+
- [Development Setup](https://github.com/YINI-lang/yini-parser-typescript/blob/main/docs/Development-Setup.md) — How to run, test, and build the project, etc.
|
|
539
|
+
- [Conventions](https://github.com/YINI-lang/yini-parser-typescript/blob/main/docs/Conventions.md) — Project conventions, naming patterns, etc.
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
## Links
|
|
544
|
+
- ➡️ [Why YINI? Why another format!?](./RATIONALE.md) (rationale)
|
|
545
|
+
- ➡️ [Intro to YINI Config Format](https://github.com/YINI-lang/yini-parser-typescript?tab=readme-ov-file#intro-to-yini-config-format) (learn YINI)
|
|
546
|
+
- ➡️ [Read the YINI Specification](./YINI-Specification.md#table-of-contents) (spec)
|
|
547
|
+
- ➡️ [Official YINI Parser on npm](https://www.npmjs.com/package/yini-parser) (npm)
|
|
548
|
+
- ➡️ [YINI Parser GitHub Repo](https://github.com/YINI-lang/yini-parser-typescript) (GitHub)
|
|
549
|
+
- ➡️ [YINI vs Other Formats](https://github.com/YINI-lang/YINI-spec/blob/develop/Docs/Examples%20of%20YINI%20vs%20Other%20Formats.md)
|
|
447
550
|
|
|
448
551
|
---
|
|
449
552
|
|
package/dist/YINI.js
CHANGED
|
@@ -7,7 +7,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
7
7
|
const env_1 = require("./config/env");
|
|
8
8
|
const parseEntry_1 = require("./parseEntry");
|
|
9
9
|
const pathAndFileName_1 = require("./utils/pathAndFileName");
|
|
10
|
-
const
|
|
10
|
+
const print_1 = require("./utils/print");
|
|
11
11
|
/**
|
|
12
12
|
* This class is the public API, which exposes only parse(..) and
|
|
13
13
|
* parseFile(..), rest of the implementation details are hidden.
|
|
@@ -33,7 +33,7 @@ YINI.filePath = ''; // Used in error reporting.
|
|
|
33
33
|
* @returns A JavaScript object representing the parsed YINI content.
|
|
34
34
|
*/
|
|
35
35
|
YINI.parse = (yiniContent, strictMode = false, bailSensitivity = 'auto', includeMetaData = false) => {
|
|
36
|
-
(0,
|
|
36
|
+
(0, print_1.debugPrint)('-> Entered static parse(..) in class YINI\n');
|
|
37
37
|
// Important: First, before anything, trim beginning and trailing whitespaces!
|
|
38
38
|
yiniContent = yiniContent.trim();
|
|
39
39
|
if (!yiniContent) {
|
|
@@ -63,16 +63,16 @@ YINI.parse = (yiniContent, strictMode = false, bailSensitivity = 'auto', include
|
|
|
63
63
|
isWithDiagnostics: (0, env_1.isDev)() || (0, env_1.isDebug)(),
|
|
64
64
|
isWithTiming: (0, env_1.isDebug)(),
|
|
65
65
|
};
|
|
66
|
-
(0,
|
|
67
|
-
(0,
|
|
66
|
+
(0, print_1.debugPrint)();
|
|
67
|
+
(0, print_1.debugPrint)('==== Call parse ==========================');
|
|
68
68
|
const result = (0, parseEntry_1.parseMain)(yiniContent, options);
|
|
69
|
-
(0,
|
|
69
|
+
(0, print_1.debugPrint)('==== End call parse ==========================\n');
|
|
70
70
|
if ((0, env_1.isDev)()) {
|
|
71
71
|
console.log();
|
|
72
|
-
(0,
|
|
72
|
+
(0, print_1.devPrint)('YINI.parse(..): result:');
|
|
73
73
|
console.log(result);
|
|
74
|
-
(0,
|
|
75
|
-
(0,
|
|
74
|
+
(0, print_1.devPrint)('Complete result:');
|
|
75
|
+
(0, print_1.printObject)(result);
|
|
76
76
|
}
|
|
77
77
|
return result;
|
|
78
78
|
};
|
|
@@ -93,7 +93,7 @@ YINI.parse = (yiniContent, strictMode = false, bailSensitivity = 'auto', include
|
|
|
93
93
|
* @returns A JavaScript object representing the parsed YINI content.
|
|
94
94
|
*/
|
|
95
95
|
YINI.parseFile = (filePath, strictMode = false, bailSensitivity = 'auto', includeMetaData = false) => {
|
|
96
|
-
(0,
|
|
96
|
+
(0, print_1.debugPrint)('Current directory = ' + process.cwd());
|
|
97
97
|
if ((0, pathAndFileName_1.getFileNameExtension)(filePath).toLowerCase() !== '.yini') {
|
|
98
98
|
console.error('Invalid file extension for YINI file:');
|
|
99
99
|
console.error(`"${filePath}"`);
|
|
@@ -128,16 +128,16 @@ YINI.parseFile = (filePath, strictMode = false, bailSensitivity = 'auto', includ
|
|
|
128
128
|
isWithDiagnostics: (0, env_1.isDev)() || (0, env_1.isDebug)(),
|
|
129
129
|
isWithTiming: (0, env_1.isDebug)(),
|
|
130
130
|
};
|
|
131
|
-
(0,
|
|
132
|
-
(0,
|
|
131
|
+
(0, print_1.debugPrint)();
|
|
132
|
+
(0, print_1.debugPrint)('==== Call parse ==========================');
|
|
133
133
|
const result = (0, parseEntry_1.parseMain)(content, options);
|
|
134
|
-
(0,
|
|
134
|
+
(0, print_1.debugPrint)('==== End call parse ==========================\n');
|
|
135
135
|
if ((0, env_1.isDev)()) {
|
|
136
136
|
console.log();
|
|
137
|
-
(0,
|
|
137
|
+
(0, print_1.devPrint)('YINI.parse(..): result:');
|
|
138
138
|
console.log(result);
|
|
139
|
-
(0,
|
|
140
|
-
(0,
|
|
139
|
+
(0, print_1.devPrint)('Complete result:');
|
|
140
|
+
(0, print_1.printObject)(result);
|
|
141
141
|
}
|
|
142
142
|
return result;
|
|
143
143
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ErrorDataHandler = void 0;
|
|
4
4
|
const env_1 = require("../config/env");
|
|
5
|
-
const
|
|
5
|
+
const print_1 = require("../utils/print");
|
|
6
6
|
// All the issue titles are defined here to get a quick overview of all
|
|
7
7
|
// titles, and to easier check that all titles match with relation to
|
|
8
8
|
// the other titles.
|
|
@@ -48,7 +48,7 @@ class ErrorDataHandler {
|
|
|
48
48
|
column: endCol,
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
|
-
(0,
|
|
51
|
+
(0, print_1.debugPrint)('issue:');
|
|
52
52
|
(0, env_1.isDebug)() && console.log(issue);
|
|
53
53
|
return issue;
|
|
54
54
|
};
|
|
@@ -67,16 +67,16 @@ class ErrorDataHandler {
|
|
|
67
67
|
*/
|
|
68
68
|
this.pushOrBail = (ctx, type, msgWhat, msgWhy = '', msgHint = '') => {
|
|
69
69
|
var _a, _b, _c, _d, _e, _f;
|
|
70
|
-
(0,
|
|
71
|
-
(0,
|
|
72
|
-
(0,
|
|
73
|
-
(0,
|
|
74
|
-
(0,
|
|
75
|
-
(0,
|
|
76
|
-
(0,
|
|
77
|
-
(0,
|
|
78
|
-
(0,
|
|
79
|
-
(0,
|
|
70
|
+
(0, print_1.debugPrint)('-> pushOrBail(..)');
|
|
71
|
+
(0, print_1.debugPrint)('ctx.exception?.name =' + ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.exception) === null || _a === void 0 ? void 0 : _a.name));
|
|
72
|
+
(0, print_1.debugPrint)('ctx.exception?.message = ' + ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.exception) === null || _b === void 0 ? void 0 : _b.message));
|
|
73
|
+
(0, print_1.debugPrint)('exception?.offendingToken = ' + ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.exception) === null || _c === void 0 ? void 0 : _c.offendingToken));
|
|
74
|
+
(0, print_1.debugPrint)();
|
|
75
|
+
(0, print_1.debugPrint)('ctx.ruleIndex = ' + (ctx === null || ctx === void 0 ? void 0 : ctx.start.channel));
|
|
76
|
+
(0, print_1.debugPrint)('ctx.ruleIndex = ' + (ctx === null || ctx === void 0 ? void 0 : ctx.ruleIndex));
|
|
77
|
+
(0, print_1.debugPrint)('ctx.ruleContext = ' + (ctx === null || ctx === void 0 ? void 0 : ctx.ruleContext));
|
|
78
|
+
(0, print_1.debugPrint)('ctx.stop?.line = ' + ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.stop) === null || _d === void 0 ? void 0 : _d.line));
|
|
79
|
+
(0, print_1.debugPrint)('ctx.stop?.column = ' + ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.stop) === null || _e === void 0 ? void 0 : _e.column));
|
|
80
80
|
const lineNum = (ctx === null || ctx === void 0 ? void 0 : ctx.start.line) || 0; // Column (1-based).
|
|
81
81
|
const startCol = !ctx ? 0 : ++ctx.start.column; // Column (0-based).
|
|
82
82
|
const endCol = (((_f = ctx === null || ctx === void 0 ? void 0 : ctx.stop) === null || _f === void 0 ? void 0 : _f.column) || 0) + 1; // Column (0-based).
|
|
@@ -85,9 +85,9 @@ class ErrorDataHandler {
|
|
|
85
85
|
if (process.env.NODE_ENV === 'test') {
|
|
86
86
|
msgWhat += `\nAt line: ${lineNum}, column(s): ${startCol}-${endCol}`;
|
|
87
87
|
}
|
|
88
|
-
(0,
|
|
89
|
-
(0,
|
|
90
|
-
(0,
|
|
88
|
+
(0, print_1.debugPrint)('persistThreshold = ' + this.persistThreshold);
|
|
89
|
+
(0, print_1.debugPrint)('lineNum = ' + lineNum);
|
|
90
|
+
(0, print_1.debugPrint)();
|
|
91
91
|
const issue = this.makeIssuePayload(type, msgWhat, lineNum, startCol, endCol);
|
|
92
92
|
switch (type) {
|
|
93
93
|
case 'Internal-Error':
|
|
@@ -136,13 +136,13 @@ export default class YINIVisitor<IResult> extends YiniParserVisitor<IResult> {
|
|
|
136
136
|
* @param ctx the parse tree
|
|
137
137
|
* @return the visitor result
|
|
138
138
|
*/
|
|
139
|
-
visitElements
|
|
139
|
+
visitElements: (ctx: ElementsContext) => IResult;
|
|
140
140
|
/**
|
|
141
141
|
* Visit a parse tree produced by `YiniParser.element`.
|
|
142
142
|
* @param ctx the parse tree
|
|
143
143
|
* @return the visitor result
|
|
144
144
|
*/
|
|
145
|
-
visitElement: (ctx: ElementContext) =>
|
|
145
|
+
visitElement: (ctx: ElementContext) => any;
|
|
146
146
|
/**
|
|
147
147
|
* Visit a parse tree produced by `YiniParser.string_concat`.
|
|
148
148
|
* @param ctx the parse tree
|