yini-parser 1.0.0-beta.1 → 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 CHANGED
@@ -1,12 +1,25 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 1.0.0-beta.1
3
+ ## 1.0.2-beta - 2025 Aug
4
+ - Fixed issues with floats, including negative and exponential numbers with new test files here: `tests/fixed-issues/issue-32/*`
5
+ - Fixed an issue where parseFile(..) did not output a warning when parsing a file missing a newline at EOF. Plus added test cases to check that it is fixed (in `tests/fixed-issues/issue-30`).
6
+ - Fixed and improved number parsing to fully support negative values and edge cases for integers, floats, hex, bin, octal, duodecimal, and exponential numbers. Based on updated lexer and parser grammar files, and added extensive tests to ensure correct and robust handling. Here: `tests/integration/6-number-literals/*`
7
+
8
+ ## 1.0.1-beta - 2025 Aug
9
+ - Fixed catching lexer related errors correctly.
10
+ - Improves error and test handling for invalid YINI syntax.
11
+ - Grammar logic updated to catch bad systax specifically related to bad syntax for (key-value) members.
12
+ - Added another testing suite for reported and fixed tests.
13
+ - Added another testing suite for golden tests.
14
+ - Updated to the latest grammar (logic) version 1.0.0-rc.2.
15
+
16
+ ## 1.0.0-beta.1 - 2025-07-26
4
17
  - Package updated to **beta**. The core API is stabilizing, some more advanced features may still change.
5
18
  - Bugfix, fixed exports cleanly (so this lib can be imported in CJS and in full ESM).
6
19
  - 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
20
  - Optimized the top part of readme for npmjs Short Page.
8
21
  - 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.
22
+ - Updated to the latest grammar (logic) version 1.0.0-rc.1.
10
23
 
11
24
  ## 1.0.0-alpha.7
12
25
  - Fixed serious bug that on error did exit process.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # YINI Parser for Node.js
2
2
 
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.
3
+ A TypeScript/Node.js parser for YINI A type-safe, structured, and human-readable config format with nested sections, types, comments, and support for strict validation.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/yini-parser.svg)](https://www.npmjs.com/package/yini-parser) [![All Tests](https://github.com/YINI-lang/yini-parser-typescript/actions/workflows/run-all-tests.yml/badge.svg)](https://github.com/YINI-lang/yini-parser-typescript/actions/workflows/run-all-tests.yml)
6
6
 
@@ -13,7 +13,7 @@ import YINI from 'yini-parser'
13
13
  const config = YINI.parseFile('./config.yini')
14
14
  ```
15
15
 
16
- A clean, minimal, human-readable config formatdesigned as an alternative to INI, YAML, and JSON.
16
+ YINI (Yet another INI): YINI is a configuration format designed for readability and structure, inspired by INI and YAML.
17
17
 
18
18
  ➡️ See full [documentation or YINI format specification](https://github.com/YINI-lang/YINI-spec)
19
19
 
@@ -34,6 +34,28 @@ YINI is a simple, human-friendly configuration format inspired by INI and JSON.
34
34
 
35
35
  ---
36
36
 
37
+ ## 🙋‍♀️ Why YINI?
38
+ - **YINI is an alternative** to other great config formats like INI, JSON, YAML, XML, and TOML — Supports section nesting and explicit syntax for configuration files.
39
+ - **Started as a personal project and a research challenge:** Provides structure similar to INI, with features inspired by JSON and YAML.
40
+ - **Built for clarity:**
41
+ * Uses a concise syntax to minimize unnecessary characters.
42
+ * Supports commonly used configuration structures.
43
+ - *Developed to meet practical needs, driven by curiosity and a desire **for configuration clarity, simplicity, minimalism, and flexibility**.
44
+
45
+ ---
46
+
47
+ ## 💡 What is YINI?
48
+ - **Simple like INI** — but with strong typing, comments, and nested sections.
49
+ - **Provides concise, structured syntax** for configuration.
50
+ - Supports section nesting **without requiring indentation or dot-delimited keys**.
51
+ - This repo/parser is built for both **JavaScript and TypeScript**.
52
+ - **Supports strict and lenient modes**, and all major data types.
53
+ - Can be **edited manually** or **processed programmatically**.
54
+ - 👉 See [how YINI compares with JSON, YAML, INI, and TOML](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples/compare-formats.md).
55
+ - Want the full syntax reference? See the [YINI Specification](https://github.com/YINI-lang/YINI-spec).
56
+
57
+ ---
58
+
37
59
  ## Quick Start
38
60
 
39
61
  A minimal example using YINI in TypeScript:
@@ -71,239 +93,25 @@ false
71
93
  name: 'My Title',
72
94
  items: 25,
73
95
  darkMode: true,
74
- Special: { primaryColor: 3368601, isCaching: false }
96
+ Special: {
97
+ primaryColor: 3368601,
98
+ isCaching: false
99
+ }
75
100
  }
76
101
  }
77
102
  ```
78
103
 
79
104
  That's it!
80
105
 
81
- ▶️ Link to [examples/](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples) files.
106
+ - ▶️ Link to [examples/](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples) files.
107
+ - ▶️ Link to [Demo Apps](https://github.com/YINI-lang/yini-demo-apps/tree/main) with complete basic usage.
82
108
 
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
-
93
109
  ---
94
110
 
95
111
  ## Intro to YINI Config Format
112
+ **YINI** is a simple and readable configuration format. Sections are defined with `^ SectionName`, and values are assigned using `key = value`. The format supports common data types (same as those found in JSON), including strings, numbers, booleans, nulls, and lists.
96
113
 
97
- ### 1. Sections
98
- Group settings under a named header. A section header name starts with `^`.
99
-
100
- Start a section with `^`, e.g.:
101
- ```yini
102
- ^ App
103
- title = "AppName"
104
- ```
105
-
106
- > Alternative section markers to `^` are also supported: `<`, `§`, `€` (e.g. `< Section`).
107
-
108
- > See section 9 for more advanced marker and naming options.
109
-
110
- ### 2. Key = Value
111
- Each line inside a section is a **key** (name) and **value**, separated by `=`.
112
-
113
- Write settings as `key = value`:
114
- ```yini
115
- maxConnections = 100
116
- enableLogging = true
117
- ```
118
-
119
- > See section 9 for more advanced marker and naming options.
120
-
121
- #### 💡Tip
122
- Use backticks (\`) to quote section or key names that contain spaces or special characters.
123
-
124
- Key names with spaces/special characters can be backticked:
125
-
126
- ```yini
127
- user id = 1 # Invalid ❌
128
- `user id` = 1 # Valid ✅
129
- ```
130
-
131
- ### 3. Values
132
- Values can be:
133
- - **Strings** (always quoted): `'hello'` or `"world"` (either single or double quoted)
134
- - **Numbers:** `42`, `3.14` or `-10`
135
- - **Booleans:** `true`, `false`, `on`, `off`, `yes`, `no` (all case-insensitive)
136
- - **Nulls:** Use `null` or leave the value blank after `=` (in lenient mode)
137
- - **Lists:**
138
- * JSON‑style: `["red", "green", "blue"]`
139
- * Colon‑style: *(Planned – not yet implemented in parser)*
140
-
141
- ### 4. Comments
142
- Various commenting styles are supported:
143
- ```yini
144
- // This is a line comment
145
- timeout = 30 // inline comment
146
- # This is also a line comment (must have a space after #)
147
- interval = 30 # inline comment (must have a space after #)
148
- /* Block comment spanning
149
- multiple lines */
150
- ; Full line comment (must be whole line).
151
- ```
152
-
153
- > **Tip:** You can add comments anywhere—above, beside, or below any setting or section.
154
- >
155
- 👆 **Caveat 1:** If you use `#` for comments, always put a space after the `#`.
156
- (Otherwise, the parser might misinterpret it as part of a value.)
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
-
161
- 💡**Tip:** You can use any comment style in your file.
162
- For best readability, try to stick to one style per file.
163
-
164
- ### 5. Nested Sections
165
- Use extra carets `^` for sub‑sections:
166
- ```yini
167
- ^ Parent
168
- ^^ Child
169
-
170
- // Add another caret `^` and you get a sub-section
171
- // of the previous section, and so...
172
- ^^^ SubChild
173
- ```
174
-
175
- If you prefer, you can indent the nested section for visibility:
176
- ```yini
177
- ^ Main
178
- ^^ Sub
179
- host = "db.example.com"
180
- ```
181
-
182
- One can nest multiple sections:
183
- ```yini
184
- ^ Root
185
- ^^ Sub
186
- ^^^ SubSub
187
- ^ BackToRoot
188
- ```
189
-
190
- Example with indented sections:
191
- ```yini
192
- ^ Root
193
- value = 'At level 1'
194
- ^^ Sub
195
- value = 'At level 2'
196
- ^^^ SubSub
197
- value = 'At level 3'
198
-
199
- ^ BackToRoot
200
- value = 'Back at level 1'
201
- ```
202
-
203
- The above Yini code will produce the following JavaScript object:
204
- ```js
205
- // JS object
206
- {
207
- Root: {
208
- value: 'At level 1',
209
- Sub: { value: 'At level 2', SubSub: { value: 'At level 3' } }
210
- },
211
- BackToRoot: { value: 'Back at level 1' }
212
- }
213
- ```
214
-
215
- > See section 9 for more advanced marker and naming options.
216
-
217
- ### 6. Lists
218
- ```yini
219
- // JSON‑style lists
220
- colors = ["red", "green", "blue"]
221
-
222
- numberList = [
223
- 10,
224
- 20,
225
- 30
226
- ]
227
-
228
-
229
- // Colon‑style list
230
- // 👆 Colon‑style list support is planned for an upcoming release.
231
- fruits:
232
- "Pear",
233
- "Cherry",
234
- "Banana"
235
- ```
236
-
237
- > You can use either single or double quotes for string values in YINI.
238
-
239
- ### 7. Document Terminator (strict mode)
240
- The `/END` marker is required only in strict mode, and optional in lenient (default) mode.
241
-
242
- End a file explicitly with:
243
- ```yini
244
- ^ App
245
- title = "MyTitle"
246
-
247
- /END // Must be included in strict mode.
248
- ```
249
-
250
- ### 8. Disabled Lines
251
- Prefix any valid line with `--` to skip it entirely:
252
- ```yini
253
- --maxRetries = 5
254
- ```
255
-
256
- ### 9. Advanced: Alternative Section Markers & Naming
257
- In addition to the standard syntax, YINI supports several advanced options:
258
-
259
- - (a.) **Alternative section markers:**
260
- Besides `^`, you can use `<`, `§`, or `€` as section header markers.
261
-
262
- ```yini
263
- < MySection
264
- § Settings
265
- € MyApp
266
- ```
267
-
268
- - (b.) **Backticked section names and key names:**
269
- Use backticks (`) to allow spaces or special characters in section or key names:
270
-
271
- ```yini
272
- ^ `Section name with spaces`
273
- `user id` = 42
274
- ```
275
-
276
- - (c.) **Numeric shorthand section markers:**
277
- To create deeply nested sections (beyond 6 levels), use numeric shorthand:
278
-
279
- ```yini
280
- ^7 DeepSection # Equivalent to 7 carets: ^^^^^^^ DeepSection
281
- <10 VeryDeep # Equivalent to <<<<<<<<<<< VeryDeep
282
- ```
283
-
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).
288
-
289
- ### 10. Complete Example
290
-
291
- ```yini
292
- @yini # Optional marker to identify YINI format.
293
-
294
- ^ App
295
- name = "MyApp"
296
- version = "1.0.0"
297
- debug = off // Turn on for debugging.
298
-
299
- ^^ Database
300
- host = "db.local"
301
- port = 5432
302
- --user = "secret" # This line is disabled due to --.
303
- userList = ["alice", "bob", "carol"]
304
-
305
- /END
306
- ```
114
+ To learn more, see the [Getting Started: Intro to YINI Config Format](https://github.com/YINI-lang/YINI-spec/blob/develop/Docs/Intro-to-YINI-Config-Format.md) tutorial.
307
115
 
308
116
  ---
309
117
 
@@ -541,12 +349,26 @@ We welcome feedback, bug reports, feature requests, and code contributions!
541
349
  ---
542
350
 
543
351
  ## 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)
352
+ - ➡️ [Getting Started: Intro to YINI Config Format](https://github.com/YINI-lang/YINI-spec/blob/develop/Docs/Intro-to-YINI-Config-Format.md)
353
+ *Beginner-friendly walkthrough and basic usage examples.*
354
+
355
+ - ➡️ [YINI Parser on npm](https://www.npmjs.com/package/yini-parser)
356
+ *Install and view package details.*
357
+
358
+ - ➡️ [Read the YINI Specification](https://github.com/YINI-lang/YINI-spec/blob/release/YINI-Specification.md#table-of-contents)
359
+ *Full formal spec for the YINI format, including syntax and features.*
360
+
361
+ - ➡️ [YINI CLI on GitHub](https://github.com/YINI-lang/yini-cli)
362
+ *TypeScript source code, issue tracker, and contributing guide.*
363
+
364
+ - ➡️ [YINI vs Other Formats](https://github.com/YINI-lang/YINI-spec/tree/release#-summary-difference-with-other-formats)
365
+ *How does YINI differ: comparison with INI, YAML, and JSON.*
366
+
367
+ - ➡️ [Why YINI? (Project Rationale)](https://github.com/YINI-lang/YINI-spec/blob/release/RATIONALE.md)
368
+ *Learn about the motivations and design decisions behind YINI.*
369
+
370
+ - ➡️ [YINI Project](https://github.com/YINI-lang)
371
+ *YINI home.*
550
372
 
551
373
  ---
552
374
 
package/dist/YINI.js CHANGED
@@ -2,6 +2,7 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
+ var _a;
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
7
  const fs_1 = __importDefault(require("fs"));
7
8
  const env_1 = require("./config/env");
@@ -15,6 +16,7 @@ const print_1 = require("./utils/print");
15
16
  */
16
17
  class YINI {
17
18
  }
19
+ _a = YINI;
18
20
  YINI.filePath = ''; // Used in error reporting.
19
21
  /**
20
22
  * Parse YINI content into a JavaScript object.
@@ -43,15 +45,11 @@ YINI.parse = (yiniContent, strictMode = false, bailSensitivity = 'auto', include
43
45
  yiniContent += '\n';
44
46
  }
45
47
  let level = 0;
46
- // if (bailSensitivity === 'auto' && !strictMode) level = 0
47
- // if (bailSensitivity === 'auto' && strictMode) level = 1
48
48
  if (bailSensitivity === 'auto') {
49
49
  if (!strictMode)
50
50
  level = 0;
51
51
  if (strictMode)
52
52
  level = 1;
53
- if (process.env.NODE_ENV === 'test')
54
- level = 1;
55
53
  }
56
54
  else {
57
55
  level = bailSensitivity;
@@ -106,38 +104,10 @@ YINI.parseFile = (filePath, strictMode = false, bailSensitivity = 'auto', includ
106
104
  content += '\n';
107
105
  hasNoNewlineAtEOF = true;
108
106
  }
109
- YINI.filePath = filePath;
110
- let level = 0;
111
- // if (bailSensitivity === 'auto' && !strictMode) level = 0
112
- // if (bailSensitivity === 'auto' && strictMode) level = 1
113
- if (bailSensitivity === 'auto') {
114
- if (!strictMode)
115
- level = 0;
116
- if (strictMode)
117
- level = 1;
118
- if (process.env.NODE_ENV === 'test')
119
- level = 1;
120
- }
121
- else {
122
- level = bailSensitivity;
123
- }
124
- const options = {
125
- isStrict: strictMode,
126
- bailSensitivityLevel: level,
127
- isIncludeMeta: includeMetaData,
128
- isWithDiagnostics: (0, env_1.isDev)() || (0, env_1.isDebug)(),
129
- isWithTiming: (0, env_1.isDebug)(),
130
- };
131
- (0, print_1.debugPrint)();
132
- (0, print_1.debugPrint)('==== Call parse ==========================');
133
- const result = (0, parseEntry_1.parseMain)(content, options);
134
- (0, print_1.debugPrint)('==== End call parse ==========================\n');
135
- if ((0, env_1.isDev)()) {
136
- console.log();
137
- (0, print_1.devPrint)('YINI.parse(..): result:');
138
- console.log(result);
139
- (0, print_1.devPrint)('Complete result:');
140
- (0, print_1.printObject)(result);
107
+ _a.filePath = filePath;
108
+ const result = _a.parse(content, strictMode, bailSensitivity, includeMetaData);
109
+ if (hasNoNewlineAtEOF) {
110
+ console.warn(`No newline at end of file, it's recommended to end a file with a newline. File:\n"${filePath}"`);
141
111
  }
142
112
  return result;
143
113
  };
@@ -1,4 +1,4 @@
1
- import { Boolean_literalContext, ElementContext, ElementsContext, List_in_bracketsContext, ListContext, Member_colon_listContext, MemberContext, Null_literalContext, Number_literalContext, Object_literalContext, ObjectMemberContext, ObjectMemberListContext, Section_membersContext, SectionContext, String_concatContext, String_literalContext, Terminal_lineContext, ValueContext, YiniContext } from '../grammar/YiniParser.js';
1
+ import { Bad_memberContext, Boolean_literalContext, ElementContext, ElementsContext, List_in_bracketsContext, ListContext, Member_colon_listContext, MemberContext, Null_literalContext, Number_literalContext, Object_literalContext, ObjectMemberContext, ObjectMemberListContext, Section_membersContext, SectionContext, String_concatContext, String_literalContext, Terminal_lineContext, ValueContext, YiniContext } from '../grammar/YiniParser.js';
2
2
  import YiniParserVisitor from '../grammar/YiniParserVisitor';
3
3
  import { ErrorDataHandler } from './ErrorDataHandler';
4
4
  export type TDataType = undefined | 'String' | 'Number-Integer' | 'Number-Float' | 'Boolean' | 'Null' | 'Object' | 'List';
@@ -42,6 +42,12 @@ export default class YINIVisitor<IResult> extends YiniParserVisitor<IResult> {
42
42
  * @returns { [sectionName]: sectionObj }
43
43
  */
44
44
  visitSection: (ctx: SectionContext) => any;
45
+ /**
46
+ * Visit a parse tree produced by `YiniParser.bad_member`.
47
+ * @param ctx the parse tree
48
+ * @return the visitor result
49
+ */
50
+ visitBad_member: (ctx: Bad_memberContext) => any;
45
51
  /**
46
52
  * Visit a parse tree produced by `YiniParser.terminal_line`.
47
53
  * @param ctx the parse tree
@@ -496,6 +496,15 @@ class YINIVisitor extends YiniParserVisitor_1.default {
496
496
  members: members,
497
497
  };
498
498
  };
499
+ /**
500
+ * Visit a parse tree produced by `YiniParser.bad_member`.
501
+ * @param ctx the parse tree
502
+ * @return the visitor result
503
+ */
504
+ this.visitBad_member = (ctx) => {
505
+ ctx.REST;
506
+ this.errorHandler.pushOrBail(ctx, 'Syntax-Error', 'Invalid or malformed member found.', `Offending text: ${ctx.getText()}`);
507
+ };
499
508
  /**
500
509
  * Visit a parse tree produced by `YiniParser.section_members`.
501
510
  * In here will mount object onto members object.
@@ -767,8 +776,6 @@ class YINIVisitor extends YiniParserVisitor_1.default {
767
776
  this.visitValue = (ctx) => {
768
777
  (0, env_1.isDebug)() && console.log();
769
778
  (0, print_1.debugPrint)('-> Entered visitValue(..)');
770
- (0, print_1.debugPrint)('ctx.number_literal(): ' + ctx.number_literal());
771
- (0, print_1.debugPrint)('ctx.boolean_literal(): ' + ctx.boolean_literal());
772
779
  if (ctx.string_literal())
773
780
  return this.visit(ctx.string_literal());
774
781
  if (ctx.number_literal())
@@ -46,6 +46,7 @@ export default class YiniLexer extends Lexer {
46
46
  static readonly LINE_COMMENT = 44;
47
47
  static readonly INLINE_COMMENT = 45;
48
48
  static readonly IDENT_INVALID = 46;
49
+ static readonly REST = 47;
49
50
  static readonly EOF: number;
50
51
  static readonly channelNames: string[];
51
52
  static readonly literalNames: (string | null)[];