yini-parser 1.0.2-beta → 1.2.0-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.
Files changed (103) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +83 -98
  3. package/dist/YINI.d.ts +162 -23
  4. package/dist/YINI.js +183 -99
  5. package/dist/YINI.js.map +1 -0
  6. package/dist/config/env.js +1 -0
  7. package/dist/config/env.js.map +1 -0
  8. package/dist/core/astBuilder.d.ts +191 -0
  9. package/dist/core/astBuilder.js +840 -0
  10. package/dist/core/astBuilder.js.map +1 -0
  11. package/dist/core/{ErrorDataHandler.d.ts → errorDataHandler.d.ts} +21 -19
  12. package/dist/core/errorDataHandler.js +271 -0
  13. package/dist/core/errorDataHandler.js.map +1 -0
  14. package/dist/core/internalTypes.d.ts +121 -0
  15. package/dist/core/internalTypes.js +16 -0
  16. package/dist/core/internalTypes.js.map +1 -0
  17. package/dist/core/objectBuilder.d.ts +10 -4
  18. package/dist/core/objectBuilder.js +127 -163
  19. package/dist/core/objectBuilder.js.map +1 -0
  20. package/dist/core/options/failLevel.d.ts +3 -0
  21. package/dist/core/options/failLevel.js +27 -0
  22. package/dist/core/options/failLevel.js.map +1 -0
  23. package/dist/core/options/normalizeOptions.d.ts +5 -0
  24. package/dist/core/options/normalizeOptions.js +53 -0
  25. package/dist/core/options/normalizeOptions.js.map +1 -0
  26. package/dist/core/options/parserOptionsConstants.d.ts +7 -0
  27. package/dist/core/options/parserOptionsConstants.js +37 -0
  28. package/dist/core/options/parserOptionsConstants.js.map +1 -0
  29. package/dist/core/pipeline.d.ts +18 -0
  30. package/dist/core/pipeline.js +323 -0
  31. package/dist/core/pipeline.js.map +1 -0
  32. package/dist/core/resultMetadataBuilder.d.ts +19 -0
  33. package/dist/core/resultMetadataBuilder.js +166 -0
  34. package/dist/core/resultMetadataBuilder.js.map +1 -0
  35. package/dist/core/runtime.d.ts +17 -0
  36. package/dist/core/runtime.js +189 -0
  37. package/dist/core/runtime.js.map +1 -0
  38. package/dist/dev/main.d.ts +1 -0
  39. package/dist/dev/main.js +374 -0
  40. package/dist/dev/main.js.map +1 -0
  41. package/dist/grammar/generated/YiniLexer.d.ts +74 -0
  42. package/dist/grammar/generated/YiniLexer.js +415 -0
  43. package/dist/grammar/generated/YiniLexer.js.map +1 -0
  44. package/dist/grammar/{YiniParser.d.ts → generated/YiniParser.d.ts} +167 -150
  45. package/dist/grammar/{YiniParser.js → generated/YiniParser.js} +1242 -1202
  46. package/dist/grammar/generated/YiniParser.js.map +1 -0
  47. package/dist/grammar/{YiniParserVisitor.d.ts → generated/YiniParserVisitor.d.ts} +59 -45
  48. package/dist/grammar/{YiniParserVisitor.js → generated/YiniParserVisitor.js} +2 -1
  49. package/dist/grammar/generated/YiniParserVisitor.js.map +1 -0
  50. package/dist/index.d.ts +43 -2
  51. package/dist/index.js +62 -101
  52. package/dist/index.js.map +1 -0
  53. package/dist/parsers/extractHeaderParts.d.ts +4 -3
  54. package/dist/parsers/extractHeaderParts.js +3 -1
  55. package/dist/parsers/extractHeaderParts.js.map +1 -0
  56. package/dist/parsers/extractSignificantYiniLine.js +2 -1
  57. package/dist/parsers/extractSignificantYiniLine.js.map +1 -0
  58. package/dist/parsers/parseBoolean.d.ts +1 -1
  59. package/dist/parsers/parseBoolean.js +3 -1
  60. package/dist/parsers/parseBoolean.js.map +1 -0
  61. package/dist/parsers/parseNull.js +1 -0
  62. package/dist/parsers/parseNull.js.map +1 -0
  63. package/dist/parsers/parseNumber.d.ts +8 -3
  64. package/dist/parsers/parseNumber.js +22 -7
  65. package/dist/parsers/parseNumber.js.map +1 -0
  66. package/dist/parsers/parseSectionHeader.d.ts +5 -4
  67. package/dist/parsers/parseSectionHeader.js +3 -1
  68. package/dist/parsers/parseSectionHeader.js.map +1 -0
  69. package/dist/parsers/parseString.js +3 -3
  70. package/dist/parsers/parseString.js.map +1 -0
  71. package/dist/types/index.d.ts +198 -0
  72. package/dist/types/index.js +4 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/utils/number.d.ts +3 -0
  75. package/dist/utils/number.js +19 -0
  76. package/dist/utils/number.js.map +1 -0
  77. package/dist/utils/object.d.ts +67 -0
  78. package/dist/utils/object.js +125 -0
  79. package/dist/utils/object.js.map +1 -0
  80. package/dist/utils/pathAndFileName.js +1 -0
  81. package/dist/utils/pathAndFileName.js.map +1 -0
  82. package/dist/utils/print.d.ts +2 -2
  83. package/dist/utils/print.js +11 -6
  84. package/dist/utils/print.js.map +1 -0
  85. package/dist/utils/string.d.ts +26 -1
  86. package/dist/utils/string.js +48 -4
  87. package/dist/utils/string.js.map +1 -0
  88. package/dist/utils/system.d.ts +15 -0
  89. package/dist/utils/system.js +22 -0
  90. package/dist/utils/system.js.map +1 -0
  91. package/dist/{yiniHelpers.d.ts → utils/yiniHelpers.d.ts} +3 -0
  92. package/dist/{yiniHelpers.js → utils/yiniHelpers.js} +46 -9
  93. package/dist/utils/yiniHelpers.js.map +1 -0
  94. package/package.json +7 -5
  95. package/dist/core/ErrorDataHandler.js +0 -203
  96. package/dist/core/YINIVisitor.d.ts +0 -158
  97. package/dist/core/YINIVisitor.js +0 -1008
  98. package/dist/core/types.d.ts +0 -59
  99. package/dist/core/types.js +0 -36
  100. package/dist/grammar/YiniLexer.d.ts +0 -68
  101. package/dist/grammar/YiniLexer.js +0 -379
  102. package/dist/parseEntry.d.ts +0 -2
  103. package/dist/parseEntry.js +0 -185
@@ -2,6 +2,7 @@
2
2
  * This file contains specific YINI helper functions (utils).
3
3
  * @note More general helper functions should go into the dir "src/utils/".
4
4
  */
5
+ import { TScalarValue, TValueLiteral } from '../core/internalTypes';
5
6
  /**
6
7
  * Check if the character is a section marker character.
7
8
  * @param character A character in a string.
@@ -42,3 +43,5 @@ export declare const isValidSimpleIdent: (str: string) => boolean;
42
43
  * @link https://github.com/YINI-lang/YINI-spec/blob/develop/YINI-Specification.md#34-identifiers
43
44
  */
44
45
  export declare const isValidBacktickedIdent: (str: string) => boolean;
46
+ export declare const printLiteral: (value: TValueLiteral) => void;
47
+ export declare const isScalar: (v: TValueLiteral) => v is TScalarValue;
@@ -4,9 +4,9 @@
4
4
  * @note More general helper functions should go into the dir "src/utils/".
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.isValidBacktickedIdent = exports.isValidSimpleIdent = exports.stripCommentsAndAfter = exports.isMarkerCharacter = void 0;
8
- const print_1 = require("./utils/print");
9
- const string_1 = require("./utils/string");
7
+ exports.isScalar = exports.printLiteral = exports.isValidBacktickedIdent = exports.isValidSimpleIdent = exports.stripCommentsAndAfter = exports.isMarkerCharacter = void 0;
8
+ const print_1 = require("./print");
9
+ const string_1 = require("./string");
10
10
  const SECTION_MARKER1 = '^';
11
11
  const SECTION_MARKER2 = '<';
12
12
  const SECTION_MARKER3 = '\u00A7'; // Section sign §.
@@ -37,11 +37,14 @@ exports.isMarkerCharacter = isMarkerCharacter;
37
37
  * @throws Will throw if consisting more than 1 lines.
38
38
  */
39
39
  const stripCommentsAndAfter = (line) => {
40
- if ((0, string_1.splitLines)(line).length > 1) {
41
- throw new Error('Internal error: Detected several row lines in line: >>>' +
42
- line +
43
- '<<<');
44
- }
40
+ // if (splitLines(line).length > 1) {
41
+ // throw new Error(
42
+ // 'Internal error: Detected several row lines in line: >>>' +
43
+ // line +
44
+ // '<<<',
45
+ // )
46
+ // }
47
+ line = line.split('\n', 1)[0];
45
48
  let idx1 = line.indexOf('//');
46
49
  let idx2 = line.indexOf('# '); // NOTE: (!) Hash comments requires a WS after the hash!
47
50
  let idx3 = line.indexOf('#\t'); // NOTE: (!) Hash comments requires a WS after the hash!
@@ -66,7 +69,7 @@ const stripCommentsAndAfter = (line) => {
66
69
  const resultLine = idx === Number.MAX_SAFE_INTEGER ? line : line.substring(0, idx);
67
70
  (0, print_1.debugPrint)('stripCommentsAndAfter(..), line: >>>' + line + '<<<');
68
71
  (0, print_1.debugPrint)('stripCommentsAndAfter(..), resultLine: >>>' + resultLine + '<<<');
69
- return resultLine;
72
+ return resultLine.trim();
70
73
  };
71
74
  exports.stripCommentsAndAfter = stripCommentsAndAfter;
72
75
  /**
@@ -139,3 +142,37 @@ const isValidBacktickedIdent = (str) => {
139
142
  return true;
140
143
  };
141
144
  exports.isValidBacktickedIdent = isValidBacktickedIdent;
145
+ const assertNever = (x) => {
146
+ throw new Error(`Unhandled: ${JSON.stringify(x)}`);
147
+ };
148
+ const printLiteral = (value) => {
149
+ switch (value.type) {
150
+ case 'String':
151
+ case 'Number':
152
+ case 'Boolean':
153
+ case 'Null':
154
+ console.log('' + value.value);
155
+ break;
156
+ case 'Undefined':
157
+ console.log('' + value.value);
158
+ break;
159
+ case 'List':
160
+ (0, print_1.printObject)(value.elems);
161
+ break;
162
+ case 'Object':
163
+ (0, print_1.printObject)(value.entries);
164
+ break;
165
+ default:
166
+ return assertNever(value); // ensures exhaustiveness
167
+ }
168
+ };
169
+ exports.printLiteral = printLiteral;
170
+ const isScalar = (v) => v.type === 'String' ||
171
+ v.type === 'Number' ||
172
+ v.type === 'Boolean' ||
173
+ v.type === 'Null';
174
+ exports.isScalar = isScalar;
175
+ // export const isList = (v: TValueLiteral): v is TListValue => v.type === 'List'
176
+ // export const isObject = (v: TValueLiteral): v is TObjectValue =>
177
+ // v.type === 'Object'
178
+ //# sourceMappingURL=yiniHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yiniHelpers.js","sourceRoot":"","sources":["../../src/utils/yiniHelpers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,mCAAiD;AACjD,qCAA4D;AAE5D,MAAM,eAAe,GAAG,GAAG,CAAA;AAC3B,MAAM,eAAe,GAAG,GAAG,CAAA;AAC3B,MAAM,eAAe,GAAG,QAAQ,CAAA,CAAC,kBAAkB;AACnD,MAAM,eAAe,GAAG,QAAQ,CAAA,CAAC,eAAe;AAEhD;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAW,EAAE;IAC5D,I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AAC,CAAA;AACtD,CAAC,CAAA;AAEM,MAAM,YAAY,GAAG,CAAC,KAAoB,EAAQ,EAAE;IACvD,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS,CAAC;QACf,KAAK,MAAM;YACP,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;YAC7B,MAAK;QACT,KAAK,WAAW;YACZ,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;YAC7B,MAAK;QACT,KAAK,MAAM;YACP,IAAA,mBAAW,EAAE,KAAoB,CAAC,KAAK,CAAC,CAAA;YACxC,MAAK;QACT,KAAK,QAAQ;YACT,IAAA,mBAAW,EAAE,KAAsB,CAAC,OAAO,CAAC,CAAA;YAC5C,MAAK;QACT;YACI,OAAO,WAAW,CAAC,KAAK,CAAC,CAAA,CAAC,yBAAyB;IAC3D,CAAC;AACL,CAAC,CAAA;AApBY,QAAA,YAAY,gBAoBxB;AAEM,MAAM,QAAQ,GAAG,CAAC,CAAgB,EAAqB,EAAE,CAC5D,CAAC,CAAC,IAAI,KAAK,QAAQ;IACnB,CAAC,CAAC,IAAI,KAAK,QAAQ;IACnB,CAAC,CAAC,IAAI,KAAK,SAAS;IACpB,CAAC,CAAC,IAAI,KAAK,MAAM,CAAA;AAJR,QAAA,QAAQ,YAIA;AAErB,iFAAiF;AACjF,mEAAmE;AACnE,0BAA0B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yini-parser",
3
- "version": "1.0.2-beta",
3
+ "version": "1.2.0-beta",
4
4
  "description": "Node.js parser for YINI — a clean, structured INI alternative with types, simple section nesting, comments, and strict mode.",
5
5
  "keywords": [
6
6
  "yini",
@@ -23,6 +23,7 @@
23
23
  "license": "Apache-2.0",
24
24
  "files": [
25
25
  "dist/",
26
+ "!dist/**/*.test.*",
26
27
  "package.json",
27
28
  "README.md",
28
29
  "LICENSE",
@@ -40,19 +41,19 @@
40
41
  },
41
42
  "repository": {
42
43
  "type": "git",
43
- "url": "https://github.com/YINI-lang/yini-parser-typescript.git"
44
+ "url": "git+https://github.com/YINI-lang/yini-parser-typescript.git"
44
45
  },
45
46
  "private": false,
46
47
  "scripts": {
47
48
  "start": "npm run build && node dist/index.js",
48
49
  "start:debug": "npm run start -- isDebug=1",
49
- "start:dev": "cross-env NODE_ENV=development APP_ENV=local ts-node src/index.ts isDev=1",
50
+ "start:dev": "cross-env NODE_ENV=development APP_ENV=local ts-node src/dev/main.ts isDev=1",
50
51
  "start:dev:debug": "cross-env npm run start:dev -- isDebug=1",
51
52
  "start-w-clean": "npm run tsc && npm run clean:ts-js && npm run start:dev",
52
53
  "test": "cross-env NODE_ENV=test APP_ENV=local jest --bail --verbose --runInBand",
53
54
  "test:debug": "cross-env npm run test -- --isDebug=1",
54
55
  "test:smoke": "cross-env NODE_ENV=test APP_ENV=local jest tests/smoke --bail --verbose --runInBand",
55
- "test:unit": "cross-env NODE_ENV=test APP_ENV=local jest tests/unit --bail --verbose --runInBand",
56
+ "test:unit": "cross-env NODE_ENV=test APP_ENV=local jest src/ --bail --verbose --runInBand",
56
57
  "test:integr": "cross-env NODE_ENV=test APP_ENV=local jest tests/integration --bail --verbose --runInBand",
57
58
  "test:issues": "cross-env NODE_ENV=test APP_ENV=local jest tests/fixed-issues --bail --verbose --runInBand",
58
59
  "test:gold": "cross-env NODE_ENV=test APP_ENV=local jest tests/golden --bail --verbose --runInBand",
@@ -100,7 +101,8 @@
100
101
  ]
101
102
  },
102
103
  "engines": {
103
- "node": ">=16"
104
+ "node": ">=20"
104
105
  },
106
+ "sideEffects": false,
105
107
  "type": "commonjs"
106
108
  }
@@ -1,203 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorDataHandler = void 0;
4
- const env_1 = require("../config/env");
5
- const print_1 = require("../utils/print");
6
- // All the issue titles are defined here to get a quick overview of all
7
- // titles, and to easier check that all titles match with relation to
8
- // the other titles.
9
- const issueTitle = [
10
- 'FATAL ERROR!',
11
- 'Internal error!', // 'Internal-Error'.
12
- 'Syntax error.', // 'Syntax-Error'.
13
- 'Syntax warning.',
14
- 'Notice:',
15
- 'Info:',
16
- ];
17
- /**
18
- * This class handles all error/notice reporting and processes exit/throwing.
19
- */
20
- class ErrorDataHandler {
21
- /** '1-Abort-on-Errors' is the default.
22
-
23
- Below is from the YINI spec:
24
- **Abort Sensitivity Levels** while parsing a YINI document:
25
- (AKA severity threshold)
26
- - Level 0 = ignore errors and try parse anyway (may remap falty key/section names)
27
- - Level 1 = abort on errors only
28
- - Level 2 = abort even on warnings
29
- */
30
- constructor(threshold = '1-Abort-on-Errors') {
31
- this.numFatalErrors = 0;
32
- this.numInternalErrors = 0;
33
- this.numSyntaxErrors = 0;
34
- this.numSyntaxWarnings = 0;
35
- this.numNotices = 0;
36
- this.numInfos = 0;
37
- this.makeIssuePayload = (type, msgWhat, lineNum, startCol, endCol) => {
38
- const issue = {
39
- type,
40
- msgWhat,
41
- // msgHintOrFix: string = '', // Hint or wow to fix.
42
- start: {
43
- line: lineNum,
44
- column: startCol,
45
- },
46
- end: {
47
- line: lineNum,
48
- column: endCol,
49
- },
50
- };
51
- (0, print_1.debugPrint)('issue:');
52
- (0, env_1.isDebug)() && console.log(issue);
53
- return issue;
54
- };
55
- /**
56
- * After pushing processing may continue or exit, depending on the error
57
- * and/or the bail threshold (that can be optionally set my the user).
58
- *
59
- * @note This function MIGHT result in a return, throw, or exit depending
60
- * on the bail policy (set my the user).
61
- *
62
- * @param ctx
63
- * @param type
64
- * @param msgWhat Name of the specific error or what failed. E.g. "Key already exists in this section scope".
65
- * @param msgWhy More details and more specific info about the issue/error.
66
- * @param msgHint Hint or HUMBLE description on how to fix the issue.
67
- */
68
- this.pushOrBail = (ctx, type, msgWhat, msgWhy = '', msgHint = '') => {
69
- var _a, _b, _c, _d, _e, _f;
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
- const lineNum = (ctx === null || ctx === void 0 ? void 0 : ctx.start.line) || 0; // Column (1-based).
81
- const startCol = !ctx ? 0 : ++ctx.start.column; // Column (0-based).
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).
83
- // Patch message with the offending line number.
84
- msgWhat += ', at line: ' + lineNum;
85
- if (process.env.NODE_ENV === 'test') {
86
- msgWhat += `\nAt line: ${lineNum}, column(s): ${startCol}-${endCol}`;
87
- }
88
- (0, print_1.debugPrint)('persistThreshold = ' + this.persistThreshold);
89
- (0, print_1.debugPrint)('lineNum = ' + lineNum);
90
- (0, print_1.debugPrint)();
91
- const issue = this.makeIssuePayload(type, msgWhat, lineNum, startCol, endCol);
92
- switch (type) {
93
- case 'Internal-Error':
94
- this.numInternalErrors++;
95
- this.emitInternalError(msgWhat, msgWhy, msgHint);
96
- if (this.persistThreshold === '1-Abort-on-Errors' ||
97
- this.persistThreshold === '2-Abort-Even-on-Warnings') {
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
- // }
104
- }
105
- break;
106
- case 'Syntax-Error':
107
- this.numSyntaxErrors++;
108
- this.emitSyntaxError(msgWhat, msgWhy, msgHint);
109
- if (this.persistThreshold === '1-Abort-on-Errors' ||
110
- this.persistThreshold === '2-Abort-Even-on-Warnings') {
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
- // }
117
- }
118
- break;
119
- case 'Syntax-Warning':
120
- this.numSyntaxWarnings++;
121
- this.emitSyntaxWarning(msgWhat, msgWhy, msgHint);
122
- if (this.persistThreshold === '2-Abort-Even-on-Warnings') {
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
- // }
129
- }
130
- break;
131
- case 'Notice':
132
- this.numNotices++;
133
- this.emitNotice(msgWhat, msgWhy, msgHint);
134
- break;
135
- case 'Info':
136
- this.numInfos++;
137
- this.emitInfo(msgWhat, msgWhy, msgHint);
138
- break;
139
- default: // Including 'Internal-Error'.
140
- this.numFatalErrors++;
141
- this.emitFatalError(msgWhat, msgWhy, msgHint);
142
- // CANNOT recover fatal errors, will lead to an exit!
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
- // }
153
- }
154
- };
155
- this.emitFatalError = (msgWhat = 'Something went wrong!', msgWhy = '', msgHint = '') => {
156
- console.error(issueTitle[0]); // Print the issue title.
157
- msgWhat && console.error(msgWhat);
158
- msgWhy && console.log(msgWhy);
159
- msgHint && console.log(msgHint);
160
- };
161
- this.emitInternalError = (msgWhat = 'Something went wrong!', msgWhy = '', msgHint = '') => {
162
- console.error(issueTitle[1]); // Print the issue title.
163
- msgWhat && console.error(msgWhat);
164
- msgWhy && console.log(msgWhy);
165
- msgHint && console.log(msgHint);
166
- };
167
- this.emitSyntaxError = (msgWhat, msgWhy = '', msgHint = '') => {
168
- console.error(issueTitle[2]); // Print the issue title.
169
- msgWhat && console.error(msgWhat);
170
- msgWhy && console.log(msgWhy);
171
- msgHint && console.log(msgHint);
172
- };
173
- this.emitSyntaxWarning = (msgWhat, msgWhy = '', msgHint = '') => {
174
- console.warn(issueTitle[3]); // Print the issue title.
175
- msgWhat && console.warn(msgWhat);
176
- msgWhy && console.log(msgWhy);
177
- msgHint && console.log(msgHint);
178
- };
179
- this.emitNotice = (msgWhat, msgWhy = '', msgHint = '') => {
180
- console.warn(issueTitle[4]); // Print the issue title.
181
- msgWhat && console.warn(msgWhat);
182
- msgWhy && console.log(msgWhy);
183
- msgHint && console.log(msgHint);
184
- };
185
- this.emitInfo = (msgWhat, msgWhy = '', msgHint = '') => {
186
- console.info(issueTitle[5]); // Print the issue title.
187
- msgWhat && console.info(msgWhat);
188
- msgWhy && console.log(msgWhy);
189
- msgHint && console.log(msgHint);
190
- };
191
- this.persistThreshold = threshold;
192
- }
193
- getNumOfErrors() {
194
- return (this.numFatalErrors + this.numInternalErrors + this.numSyntaxErrors);
195
- }
196
- getNumOfWarnings() {
197
- return this.numSyntaxWarnings;
198
- }
199
- getNumOfInfoAndNotices() {
200
- return this.numNotices + this.numInfos;
201
- }
202
- }
203
- exports.ErrorDataHandler = ErrorDataHandler;
@@ -1,158 +0,0 @@
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
- import YiniParserVisitor from '../grammar/YiniParserVisitor';
3
- import { ErrorDataHandler } from './ErrorDataHandler';
4
- export type TDataType = undefined | 'String' | 'Number-Integer' | 'Number-Float' | 'Boolean' | 'Null' | 'Object' | 'List';
5
- /**
6
- * This interface defines a complete generic visitor for a parse tree produced
7
- * by `YiniParser`.
8
- *
9
- * @param <IResult> The return type of the visit operation. Use `void` for
10
- * operations with no return type.
11
- */
12
- export default class YINIVisitor<IResult> extends YiniParserVisitor<IResult> {
13
- private reversedTree;
14
- private errorHandler;
15
- private isStrict;
16
- private lastActiveSectionAtLevels;
17
- private lastActiveSectionNameAtLevels;
18
- private numOfLevelOnes;
19
- private level;
20
- private prevLevel;
21
- private prevSectionName;
22
- private meta_numOfSections;
23
- private meta_numOfMembers;
24
- private meta_numOfChains;
25
- private meta_maxLevelSection;
26
- private existingSectionTitlesAtLevels;
27
- private hasDefinedSectionTitle;
28
- private setDefineSectionTitle;
29
- constructor(errorHandler: ErrorDataHandler, isStrict: boolean);
30
- private pushOnTree;
31
- private getDepthOfLevels;
32
- private setLastActiveSection;
33
- /**
34
- * Visit a parse tree produced by `YiniParser.yini`.
35
- * @param ctx the parse tree
36
- * @return the visitor result
37
- */
38
- visitYini: (ctx: YiniContext, isStrict?: boolean) => any;
39
- /**
40
- * Will visit here on EVERY section.
41
- * @param ctx the parse tree
42
- * @returns { [sectionName]: sectionObj }
43
- */
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;
51
- /**
52
- * Visit a parse tree produced by `YiniParser.terminal_line`.
53
- * @param ctx the parse tree
54
- * @return the visitor result
55
- */
56
- visitTerminal_line?: (ctx: Terminal_lineContext) => IResult;
57
- /**
58
- * Visit a parse tree produced by `YiniParser.section_members`.
59
- * In here will mount object onto members object.
60
- * @param ctx the parse tree
61
- * @returns { key: value, ... }
62
- */
63
- visitSection_members: (ctx: Section_membersContext) => any;
64
- /**
65
- * Visit every single section or member (any key-value pair such as
66
- * key=value or key=[...] etc.).
67
- * @returns {
68
- type: resultType,
69
- key: resultKey,
70
- value: resultValue,
71
- }: IResult
72
- */
73
- visitMember: (ctx: MemberContext) => IResult;
74
- /**
75
- * Visit a parse tree produced by `YiniParser.member_colon_list`.
76
- * @param ctx the parse tree
77
- * @return the visitor result
78
- */
79
- visitMember_colon_list: (ctx: Member_colon_listContext) => IResult;
80
- /**
81
- * Visit a parse tree produced by `YiniParser.value`.
82
- * @param ctx the parse tree
83
- * @return the visitor result
84
- */
85
- visitValue: (ctx: ValueContext) => any;
86
- /**
87
- * Visit a parse tree produced by `YiniParser.string_literal`.
88
- * @param ctx the parse tree
89
- * @return the visitor result
90
- */
91
- visitString_literal: (ctx: String_literalContext) => IResult;
92
- /**
93
- * Visit a parse tree produced by `YiniParser.number_literal`.
94
- * @param ctx the parse tree
95
- * @return the visitor result
96
- */
97
- visitNumber_literal: (ctx: Number_literalContext) => IResult;
98
- /**
99
- * Visit a parse tree produced by `YiniParser.boolean_literal`.
100
- * @param ctx the parse tree
101
- * @return the visitor result
102
- */
103
- visitBoolean_literal: (ctx: Boolean_literalContext) => IResult;
104
- /**
105
- * Visit a parse tree produced by `YiniParser.null_literal`.
106
- * @param ctx the parse tree
107
- * @return the visitor result
108
- */
109
- visitNull_literal: (ctx: Null_literalContext) => IResult;
110
- /**
111
- * Visit a parse tree produced by `YiniParser.object_literal`.
112
- * @param ctx the parse tree
113
- * @return the visitor result
114
- */
115
- visitObject_literal: (ctx: Object_literalContext) => IResult;
116
- /**
117
- * Visit a parse tree produced by `YiniParser.objectMemberList`.
118
- * @param ctx the parse tree
119
- * @return the visitor result
120
- */
121
- visitObjectMemberList: (ctx: ObjectMemberListContext) => IResult;
122
- /**
123
- * Visit a parse tree produced by `YiniParser.objectMember`.
124
- * @param ctx the parse tree
125
- * @return the visitor result
126
- */
127
- visitObjectMember: (ctx: ObjectMemberContext) => IResult;
128
- /**
129
- * Visit a parse tree produced by `YiniParser.list`.
130
- * @param ctx the parse tree
131
- * @return the visitor result
132
- */
133
- visitList: (ctx: ListContext) => IResult;
134
- /**
135
- * Visit a parse tree produced by `YiniParser.list_in_brackets`.
136
- * @param ctx the parse tree
137
- * @return the visitor result
138
- */
139
- visitList_in_brackets: (ctx: List_in_bracketsContext) => IResult;
140
- /**
141
- * Visit a parse tree produced by `YiniParser.elements`.
142
- * @param ctx the parse tree
143
- * @return the visitor result
144
- */
145
- visitElements: (ctx: ElementsContext) => IResult;
146
- /**
147
- * Visit a parse tree produced by `YiniParser.element`.
148
- * @param ctx the parse tree
149
- * @return the visitor result
150
- */
151
- visitElement: (ctx: ElementContext) => any;
152
- /**
153
- * Visit a parse tree produced by `YiniParser.string_concat`.
154
- * @param ctx the parse tree
155
- * @return the visitor result
156
- */
157
- visitString_concat?: (ctx: String_concatContext) => IResult;
158
- }