yini-parser 1.0.0-alpha.7 → 1.0.0-alpha.7x
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 +6 -0
- package/README.md +244 -151
- package/dist/core/YINIVisitor.d.ts +2 -2
- package/dist/core/YINIVisitor.js +99 -5
- package/dist/grammar/YiniLexer.js +4 -1
- package/dist/grammar/YiniParser.d.ts +27 -3
- package/dist/grammar/YiniParser.js +544 -294
- package/dist/grammar/YiniParserVisitor.d.ts +14 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +34 -11
- package/dist/parsers/extractSignificantYiniLine.js +2 -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.yini +26 -0
- package/examples/parse-example.ts +22 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## --Upcoming-- -beta
|
|
4
|
+
- Package updated to **beta**. The core API is stabilizing, some more advanced features may still change.
|
|
5
|
+
- 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.
|
|
6
|
+
- Optimized the top part of readme for npmjs Short Page.
|
|
7
|
+
- Added a dir `examples/` with a few example Yini files, `compare-formats.md` and TS file.
|
|
8
|
+
|
|
3
9
|
## 1.0.0-alpha.7
|
|
4
10
|
- Fixed serious bug that on error did exit process.
|
|
5
11
|
- 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
|
-
---
|
|
29
|
-
|
|
30
|
-
## 💡 Why YINI?
|
|
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
|
-
---
|
|
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.
|
|
57
4
|
|
|
58
|
-
|
|
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
|
-
##
|
|
24
|
+
## YINI Parser – TypeScript
|
|
118
25
|
|
|
119
|
-
|
|
26
|
+
> 🚧 This package is in **beta**. The core API is stabilizing, some more advanced features may still change. Feedback and bug reports are welcome!
|
|
120
27
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Parses YINI code from a string.
|
|
124
|
-
|
|
125
|
-
**Params:**
|
|
126
|
-
- `yiniContent`: The YINI configuration as a string.
|
|
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,51 @@ 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.
|
|
447
540
|
|
|
448
541
|
---
|
|
449
542
|
|
|
@@ -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
|
package/dist/core/YINIVisitor.js
CHANGED
|
@@ -779,7 +779,8 @@ class YINIVisitor extends YiniParserVisitor_1.default {
|
|
|
779
779
|
return this.visit(ctx.null_literal());
|
|
780
780
|
if (ctx.object_literal())
|
|
781
781
|
return this.visit(ctx.object_literal());
|
|
782
|
-
|
|
782
|
+
if (ctx.list_in_brackets())
|
|
783
|
+
return this.visit(ctx.list_in_brackets());
|
|
783
784
|
// if (ctx.string_concat()) return this.visit(ctx.string_concat())
|
|
784
785
|
return null;
|
|
785
786
|
};
|
|
@@ -883,8 +884,80 @@ class YINIVisitor extends YiniParserVisitor_1.default {
|
|
|
883
884
|
*/
|
|
884
885
|
// visitList_in_brackets?: (ctx: List_in_bracketsContext) => IResult
|
|
885
886
|
this.visitList_in_brackets = (ctx) => {
|
|
886
|
-
|
|
887
|
-
|
|
887
|
+
(0, system_1.debugPrint)('-> Entered visitList_in_brackets(..)');
|
|
888
|
+
let elements = [];
|
|
889
|
+
if (!ctx.elements()) {
|
|
890
|
+
(0, system_1.debugPrint)('Detected elements() is [], in list brackets');
|
|
891
|
+
// elements = []
|
|
892
|
+
return { type: 'List', value: [] };
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
(0, system_1.debugPrint)('Detected elements() has items, in list brackets');
|
|
896
|
+
elements = this.visit(ctx.elements());
|
|
897
|
+
}
|
|
898
|
+
(0, system_1.debugPrint)('<- Leaving visitList_in_brackets(..)');
|
|
899
|
+
if ((0, env_1.isDebug)()) {
|
|
900
|
+
console.log('returning:');
|
|
901
|
+
console.log({ type: 'List', value: elements.value });
|
|
902
|
+
console.log();
|
|
903
|
+
}
|
|
904
|
+
return { type: 'List', value: elements.value };
|
|
905
|
+
};
|
|
906
|
+
/**
|
|
907
|
+
* Visit a parse tree produced by `YiniParser.elements`.
|
|
908
|
+
* @param ctx the parse tree
|
|
909
|
+
* @return the visitor result
|
|
910
|
+
*/
|
|
911
|
+
this.visitElements = (ctx) => {
|
|
912
|
+
(0, system_1.debugPrint)('-> Entered visitElements(..)');
|
|
913
|
+
const firstElem = ctx.element();
|
|
914
|
+
let elements = [];
|
|
915
|
+
(0, system_1.debugPrint)(' element = ' + firstElem);
|
|
916
|
+
(0, system_1.debugPrint)(' element.getText() = ' + firstElem.getText());
|
|
917
|
+
(0, system_1.debugPrint)(' elements = ' + !!ctx.elements());
|
|
918
|
+
const resultElem = ctx.element()
|
|
919
|
+
? this.visitElement(ctx.element())
|
|
920
|
+
: null;
|
|
921
|
+
const resultTypeElem = resultElem === null || resultElem === void 0 ? void 0 : resultElem.type;
|
|
922
|
+
const resultValueElem = resultElem === null || resultElem === void 0 ? void 0 : resultElem.value;
|
|
923
|
+
(0, system_1.debugPrint)(' elem type = ' + resultTypeElem + ' @visitElements(..)');
|
|
924
|
+
(0, system_1.debugPrint)(' elem value = ' + resultValueElem + ' @visitElements(..)');
|
|
925
|
+
const resultElems = ctx.elements()
|
|
926
|
+
? this.visitElements(ctx.elements())
|
|
927
|
+
: null;
|
|
928
|
+
const resultTypeElems = resultElems === null || resultElems === void 0 ? void 0 : resultElems.type;
|
|
929
|
+
const resultValueElems = resultElems === null || resultElems === void 0 ? void 0 : resultElems.value;
|
|
930
|
+
(0, system_1.debugPrint)(' elems type = ' +
|
|
931
|
+
resultTypeElems +
|
|
932
|
+
' @visitElements(..)');
|
|
933
|
+
(0, system_1.debugPrint)(' elems value = ' +
|
|
934
|
+
resultValueElems +
|
|
935
|
+
' @visitElements(..)');
|
|
936
|
+
if (!ctx.elements()) {
|
|
937
|
+
(0, system_1.debugPrint)('In visitElements(..) detected that elements() has no elements');
|
|
938
|
+
elements = undefined;
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
(0, system_1.debugPrint)('In visitElements(..) detected elements in elements()');
|
|
942
|
+
elements = this.visit(ctx.elements());
|
|
943
|
+
if ((0, env_1.isDebug)()) {
|
|
944
|
+
console.log('result of visited elements:');
|
|
945
|
+
(0, system_1.printObject)(elements);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
const returnValues = elements
|
|
949
|
+
? [resultElem].concat(elements.value)
|
|
950
|
+
: [resultElem];
|
|
951
|
+
(0, system_1.debugPrint)('<- Leaving visitElements(..)');
|
|
952
|
+
if ((0, env_1.isDebug)()) {
|
|
953
|
+
console.log('returnValues:');
|
|
954
|
+
(0, system_1.printObject)(returnValues);
|
|
955
|
+
}
|
|
956
|
+
return {
|
|
957
|
+
type: 'List',
|
|
958
|
+
// value: [resultElem].concat(elements.value),
|
|
959
|
+
value: returnValues,
|
|
960
|
+
};
|
|
888
961
|
};
|
|
889
962
|
/**
|
|
890
963
|
* Visit a parse tree produced by `YiniParser.element`.
|
|
@@ -892,12 +965,33 @@ class YINIVisitor extends YiniParserVisitor_1.default {
|
|
|
892
965
|
* @return the visitor result
|
|
893
966
|
*/
|
|
894
967
|
// visitElement?: (ctx: ElementContext) => IResult
|
|
968
|
+
// visitElement = (ctx: ElementContext): IResult => {
|
|
895
969
|
this.visitElement = (ctx) => {
|
|
970
|
+
(0, system_1.debugPrint)('-> Entered visitElement(..)');
|
|
971
|
+
// if (ctx.value()) {
|
|
972
|
+
// return this.visit(ctx.value())
|
|
973
|
+
// } else {
|
|
974
|
+
// return { type: 'Null', value: null } as IResult
|
|
975
|
+
// }
|
|
976
|
+
let result;
|
|
896
977
|
if (ctx.value()) {
|
|
897
|
-
|
|
978
|
+
result = this.visit(ctx.value());
|
|
898
979
|
}
|
|
899
980
|
else {
|
|
900
|
-
|
|
981
|
+
result = { type: 'Null', value: null };
|
|
982
|
+
}
|
|
983
|
+
(0, system_1.debugPrint)('<- Leaving visitElement(..)');
|
|
984
|
+
if ((0, env_1.isDebug)()) {
|
|
985
|
+
console.log('returning:');
|
|
986
|
+
(0, system_1.printObject)(result);
|
|
987
|
+
console.log();
|
|
988
|
+
}
|
|
989
|
+
//return 'value'
|
|
990
|
+
switch (result.type) {
|
|
991
|
+
case 'String':
|
|
992
|
+
return `${result.value}`;
|
|
993
|
+
default:
|
|
994
|
+
return result.value;
|
|
901
995
|
}
|
|
902
996
|
};
|
|
903
997
|
this.errorHandler = errorHandler;
|
|
@@ -81,7 +81,10 @@ YiniLexer.literalNames = [null, null,
|
|
|
81
81
|
"']'", "'{'",
|
|
82
82
|
"'}'", "'+'",
|
|
83
83
|
"'$'", "'%'",
|
|
84
|
-
"'@'", "';'"
|
|
84
|
+
"'@'", "';'",
|
|
85
|
+
null, null,
|
|
86
|
+
null, "'{}'",
|
|
87
|
+
"'[]'"];
|
|
85
88
|
YiniLexer.symbolicNames = [null, "YINI_MARKER",
|
|
86
89
|
"SECTION_HEAD",
|
|
87
90
|
"TERMINAL_TOKEN",
|