yini-parser 1.0.0-beta.1 → 1.0.1-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.
@@ -20,6 +20,7 @@ import { String_concatContext } from "./YiniParser.js";
20
20
  import { Boolean_literalContext } from "./YiniParser.js";
21
21
  import { Empty_objectContext } from "./YiniParser.js";
22
22
  import { Empty_listContext } from "./YiniParser.js";
23
+ import { Bad_memberContext } from "./YiniParser.js";
23
24
  /**
24
25
  * This interface defines a complete generic visitor for a parse tree produced
25
26
  * by `YiniParser`.
@@ -154,4 +155,10 @@ export default class YiniParserVisitor<Result> extends ParseTreeVisitor<Result>
154
155
  * @return the visitor result
155
156
  */
156
157
  visitEmpty_list?: (ctx: Empty_listContext) => Result;
158
+ /**
159
+ * Visit a parse tree produced by `YiniParser.bad_member`.
160
+ * @param ctx the parse tree
161
+ * @return the visitor result
162
+ */
163
+ visitBad_member?: (ctx: Bad_memberContext) => Result;
157
164
  }
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Generated from grammar/v1.0.0-rc.1/YiniParser.g4 by ANTLR 4.13.2
2
+ // Generated from grammar/v1.0.0-rc.2/YiniParser.g4 by ANTLR 4.13.2
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const antlr4_1 = require("antlr4");
5
5
  /**
package/dist/index.js CHANGED
@@ -93,15 +93,15 @@ listItems = ["a", "b", "c"]
93
93
  // if (isDebug()) {
94
94
  // console.debug(input2)
95
95
  // }
96
- // YINI.parse(input2)
96
+ // parseUntilError(input2)
97
97
  // debugPrint('invalidInput1:')
98
98
  // if (isDebug()) {
99
99
  // console.debug(invalidInput1)
100
100
  // }
101
- // YINI.parse(invalidInput1)
101
+ // parseUntilError(invalidInput1)
102
102
  if (env_1.localAppEnv === 'local' && env_1.localNodeEnv !== 'test') {
103
103
  /*
104
- YINI.parse(`
104
+ parseUntilError(`
105
105
  --^ Section0
106
106
  --value = 0
107
107
  ^ Section1
@@ -120,7 +120,7 @@ listItems = ["a", "b", "c"]
120
120
  `)
121
121
  }
122
122
  */
123
- // YINI.parse(`number = 42`)
123
+ // parseUntilError(`number = 42`)
124
124
  /*
125
125
  Expected JS output:
126
126
  {
@@ -130,7 +130,7 @@ Expected JS output:
130
130
 
131
131
  */
132
132
  /*
133
- YINI.parse(
133
+ parseUntilError(
134
134
  `
135
135
  // Using numeric shorthand section markers.
136
136
 
@@ -145,7 +145,7 @@ Expected JS output:
145
145
  2,
146
146
  )
147
147
  */
148
- // YINI.parse(`^1 SectionName`, false, 2)
148
+ // parseUntilError(`^1 SectionName`, false, 2)
149
149
  // const validYini = `
150
150
  // < user
151
151
  // username = 'tester two'
@@ -169,18 +169,22 @@ Expected JS output:
169
169
  // notifications = ON
170
170
  // `
171
171
  // // Act.
172
- // const result = YINI.parse(validYini)
172
+ // const result = parseUntilError(validYini)
173
173
  // debugPrint(result)
174
174
  // const validYini = `^ App
175
175
  // id = 32403 # The correct app id.
176
176
  // title = "My Program"
177
177
  // `
178
+ // const yini = ` // corrupt yini
179
+ // ^ Section
180
+ // = "missing_key_name" // In strict should throw error, while lenient should pass
181
+ // `
178
182
  const yini = `
179
- ^ Database
180
- pool = { max: 10, min: 2 }
181
- `;
182
- YINI_1.default.parse(yini);
183
- // YINI.parse(`
183
+ // NOTE: Raw string doesn't support escapes, escape sequences will appear as-is!
184
+ `;
185
+ // YINI.parse(yini, false)
186
+ console.log((0, print_1.toPrettyJSON)(YINI_1.default.parse(yini, false)));
187
+ // parseUntilError(`
184
188
  // ^ Section1
185
189
  // ^^ Section2
186
190
  // ^^^ Section3
@@ -12,13 +12,13 @@ const YINIVisitor_1 = __importDefault(require("./core/YINIVisitor"));
12
12
  const YiniLexer_1 = __importDefault(require("./grammar/YiniLexer"));
13
13
  const YiniParser_1 = __importDefault(require("./grammar/YiniParser"));
14
14
  const print_1 = require("./utils/print");
15
- class MyErrorListener {
15
+ class MyParserErrorListener {
16
16
  constructor(errorHandler) {
17
17
  this.errors = [];
18
18
  this.errorHandler = errorHandler;
19
19
  }
20
20
  syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) {
21
- (0, print_1.debugPrint)('ANTLR grammar cached an error');
21
+ (0, print_1.debugPrint)('ANTLR parser cached an error');
22
22
  this.errors.push(`Line ${line}:${charPositionInLine} ${msg}`);
23
23
  const msgWhat = `Syntax error, at line: ${line}`;
24
24
  const msgWhy = `At about column ${1 + charPositionInLine} ${msg}`;
@@ -29,6 +29,20 @@ class MyErrorListener {
29
29
  reportAttemptingFullContext(...args) { }
30
30
  reportContextSensitivity(...args) { }
31
31
  }
32
+ class MyLexerErrorListener {
33
+ constructor(errorHandler) {
34
+ this.errors = [];
35
+ this.errorHandler = errorHandler;
36
+ }
37
+ syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) {
38
+ // Handle the error as you want:
39
+ (0, print_1.debugPrint)('ANTLR parser cached an error');
40
+ this.errors.push(`Line ${line}:${charPositionInLine} ${msg}`);
41
+ const msgWhat = `Syntax error, at line: ${line}`;
42
+ const msgWhy = `At about column ${1 + charPositionInLine} ${msg}`;
43
+ this.errorHandler.pushOrBail(null, 'Syntax-Error', msgWhat, msgWhy);
44
+ }
45
+ }
32
46
  const parseMain = (yiniContent, options = {
33
47
  isStrict: false,
34
48
  bailSensitivityLevel: 0,
@@ -58,17 +72,23 @@ const parseMain = (yiniContent, options = {
58
72
  const tokenStream = new antlr4_1.CommonTokenStream(lexer);
59
73
  const parser = new YiniParser_1.default(tokenStream);
60
74
  const errorHandler = new ErrorDataHandler_1.ErrorDataHandler(persistThreshold);
61
- const errorListener = new MyErrorListener(errorHandler);
62
- parser.removeErrorListeners(); // Removes the default console error output.
63
- parser.addErrorListener(errorListener);
75
+ // Remove the default ConsoleErrorListener
76
+ lexer.removeErrorListeners(); // Removes the default lexer console error output.
77
+ const lexerErrorListener = new MyLexerErrorListener(errorHandler);
78
+ lexer.addErrorListener(lexerErrorListener);
79
+ // const errorListener = new MyParserErrorListener(errorHandler)
80
+ parser.removeErrorListeners(); // Removes the default parser console error output.
81
+ const parserErrorListener = new MyParserErrorListener(errorHandler);
82
+ parser.addErrorListener(parserErrorListener);
64
83
  (0, print_1.debugPrint)();
65
84
  (0, print_1.debugPrint)('--- Starting parsing... ---');
66
85
  const parseTree = parser.yini(); // The function yini() is the start rule.
67
- if (errorListener.errors.length > 0) {
86
+ if (parserErrorListener.errors.length > 0 ||
87
+ lexerErrorListener.errors.length > 0) {
68
88
  (0, print_1.debugPrint)('*** ERROR detected ***');
69
89
  if ((0, env_1.isDebug)()) {
70
90
  // Handle or display syntax errors
71
- console.error('Syntax errors detected:', errorListener.errors);
91
+ console.error('Syntax errors detected:', parserErrorListener.errors, lexerErrorListener.errors);
72
92
  //process.exit(1)
73
93
  }
74
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yini-parser",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.1-beta",
4
4
  "description": "Simple and flexible config parser for Node.js. YINI: an enhanced, readable alternative to JSON, INI, and YAML—built for modern JavaScript and TypeScript projects.",
5
5
  "keywords": [
6
6
  "yini",
@@ -54,9 +54,13 @@
54
54
  "test:smoke": "cross-env NODE_ENV=test APP_ENV=local jest tests/smoke --bail --verbose --runInBand",
55
55
  "test:unit": "cross-env NODE_ENV=test APP_ENV=local jest tests/unit --bail --verbose --runInBand",
56
56
  "test:integr": "cross-env NODE_ENV=test APP_ENV=local jest tests/integration --bail --verbose --runInBand",
57
+ "test:issues": "cross-env NODE_ENV=test APP_ENV=local jest tests/fixed-issues --bail --verbose --runInBand",
58
+ "test:gold": "cross-env NODE_ENV=test APP_ENV=local jest tests/golden --bail --verbose --runInBand",
57
59
  "test:smoke:debug": "cross-env npm run test:smoke -- --isDebug=1",
58
60
  "test:unit:debug": "cross-env npm run test:unit -- --isDebug=1",
59
61
  "test:integr:debug": "cross-env npm run test:integr -- --isDebug=1",
62
+ "test:issues:debug": "cross-env npm run test:issues -- --isDebug=1",
63
+ "test:gold:debug": "cross-env npm run test:gold -- --isDebug=1",
60
64
  "test:esm": "node ./tests/fixtures/test-src-files/esm-smoke.js",
61
65
  "ci:test": "cross-env NODE_ENV=test APP_ENV=ci jest --verbose --runInBand",
62
66
  "ci:test:smoke": "cross-env NODE_ENV=test APP_ENV=ci jest tests/smoke --verbose --runInBand",