yini-parser 1.0.1-beta → 1.1.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 (43) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +131 -328
  3. package/dist/YINI.d.ts +34 -11
  4. package/dist/YINI.js +206 -121
  5. package/dist/core/ASTBuilder.d.ts +191 -0
  6. package/dist/core/ASTBuilder.js +827 -0
  7. package/dist/core/ErrorDataHandler.d.ts +19 -19
  8. package/dist/core/ErrorDataHandler.js +258 -150
  9. package/dist/core/objectBuilder.d.ts +9 -3
  10. package/dist/core/objectBuilder.js +126 -163
  11. package/dist/core/types.d.ts +234 -44
  12. package/dist/core/types.js +7 -33
  13. package/dist/grammar/YiniLexer.d.ts +54 -48
  14. package/dist/grammar/YiniLexer.js +330 -293
  15. package/dist/grammar/YiniParser.d.ts +167 -150
  16. package/dist/grammar/YiniParser.js +1241 -1202
  17. package/dist/grammar/YiniParserVisitor.d.ts +59 -45
  18. package/dist/grammar/YiniParserVisitor.js +1 -1
  19. package/dist/index.d.ts +4 -2
  20. package/dist/index.js +298 -120
  21. package/dist/parseEntry.d.ts +3 -2
  22. package/dist/parseEntry.js +352 -81
  23. package/dist/parsers/extractHeaderParts.d.ts +3 -2
  24. package/dist/parsers/extractHeaderParts.js +1 -0
  25. package/dist/parsers/parseBoolean.d.ts +1 -1
  26. package/dist/parsers/parseBoolean.js +2 -1
  27. package/dist/parsers/parseNumber.d.ts +8 -3
  28. package/dist/parsers/parseNumber.js +50 -16
  29. package/dist/parsers/parseSectionHeader.d.ts +3 -2
  30. package/dist/parsers/parseSectionHeader.js +1 -0
  31. package/dist/utils/number.d.ts +3 -0
  32. package/dist/utils/number.js +18 -0
  33. package/dist/utils/object.d.ts +55 -0
  34. package/dist/utils/object.js +85 -0
  35. package/dist/utils/string.d.ts +21 -1
  36. package/dist/utils/string.js +39 -4
  37. package/dist/utils/system.d.ts +15 -0
  38. package/dist/utils/system.js +21 -0
  39. package/dist/yiniHelpers.d.ts +3 -0
  40. package/dist/yiniHelpers.js +43 -7
  41. package/package.json +3 -3
  42. package/dist/core/YINIVisitor.d.ts +0 -158
  43. package/dist/core/YINIVisitor.js +0 -1010
@@ -1,21 +1,15 @@
1
- import { TIssueType, TPersistThreshold } from './types';
2
- interface IIssuePayload {
3
- type: TIssueType;
4
- msgWhat: string;
5
- start: {
6
- line: number;
7
- column: number;
8
- };
9
- end?: {
10
- line?: number;
11
- column?: number;
12
- };
13
- }
1
+ import { IIssuePayload, TIssueType, TPersistThreshold, TSubjectType } from './types';
14
2
  /**
15
3
  * This class handles all error/notice reporting and processes exit/throwing.
16
4
  */
17
5
  export declare class ErrorDataHandler {
18
- private persistThreshold;
6
+ private readonly persistThreshold;
7
+ private readonly subjectType;
8
+ private readonly fileName;
9
+ private errors;
10
+ private warnings;
11
+ private notices;
12
+ private infos;
19
13
  private numFatalErrors;
20
14
  private numInternalErrors;
21
15
  private numSyntaxErrors;
@@ -31,8 +25,8 @@ export declare class ErrorDataHandler {
31
25
  - Level 1 = abort on errors only
32
26
  - Level 2 = abort even on warnings
33
27
  */
34
- constructor(threshold?: TPersistThreshold);
35
- makeIssuePayload: (type: TIssueType, msgWhat: string, lineNum: number, startCol: number, endCol: number) => IIssuePayload;
28
+ constructor(subjectType: TSubjectType, threshold?: TPersistThreshold, fileName?: string | undefined);
29
+ private makeIssue;
36
30
  /**
37
31
  * After pushing processing may continue or exit, depending on the error
38
32
  * and/or the bail threshold (that can be optionally set my the user).
@@ -46,15 +40,21 @@ export declare class ErrorDataHandler {
46
40
  * @param msgWhy More details and more specific info about the issue/error.
47
41
  * @param msgHint Hint or HUMBLE description on how to fix the issue.
48
42
  */
49
- pushOrBail: (ctx: any, type: TIssueType, msgWhat: string, msgWhy?: string, msgHint?: string) => void;
43
+ pushOrBail(ctx: any, type: TIssueType, msgWhat: string, msgWhy?: string, msgHint?: string): void;
44
+ private formatSignificantMessageLine;
50
45
  private emitFatalError;
51
46
  private emitInternalError;
52
47
  private emitSyntaxError;
53
48
  private emitSyntaxWarning;
54
49
  private emitNotice;
55
50
  private emitInfo;
51
+ getNumOfAllMessages(): number;
56
52
  getNumOfErrors(): number;
57
53
  getNumOfWarnings(): number;
58
- getNumOfInfoAndNotices(): number;
54
+ getNumOfNotices(): number;
55
+ getNumOfInfos(): number;
56
+ getErrors(): IIssuePayload[];
57
+ getWarnings(): IIssuePayload[];
58
+ getNotices(): IIssuePayload[];
59
+ getInfos(): IIssuePayload[];
59
60
  }
60
- export {};
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ErrorDataHandler = void 0;
4
4
  const env_1 = require("../config/env");
5
5
  const print_1 = require("../utils/print");
6
+ const string_1 = require("../utils/string");
6
7
  // All the issue titles are defined here to get a quick overview of all
7
8
  // titles, and to easier check that all titles match with relation to
8
9
  // the other titles.
@@ -27,168 +28,260 @@ class ErrorDataHandler {
27
28
  - Level 1 = abort on errors only
28
29
  - Level 2 = abort even on warnings
29
30
  */
30
- constructor(threshold = '1-Abort-on-Errors') {
31
+ constructor(subjectType, threshold = '1-Abort-on-Errors', fileName = undefined) {
32
+ this.errors = [];
33
+ this.warnings = [];
34
+ this.notices = [];
35
+ this.infos = [];
31
36
  this.numFatalErrors = 0;
32
37
  this.numInternalErrors = 0;
33
38
  this.numSyntaxErrors = 0;
34
39
  this.numSyntaxWarnings = 0;
35
40
  this.numNotices = 0;
36
41
  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;
42
+ this.subjectType = subjectType;
43
+ this.persistThreshold = threshold;
44
+ this.fileName = fileName;
45
+ }
46
+ makeIssue(line, column, type, message, advice = undefined, hint = undefined) {
47
+ const issue = {
48
+ line,
49
+ column: !column ? undefined : column,
50
+ typeKey: (0, string_1.toLowerSnakeCase)(type),
51
+ message,
52
+ advice: advice || undefined, // Note, this will render ''-values as undfined and omit these in console outputs.
53
+ hint: hint || undefined, // Note, this will render ''-values as undfined and omit these in console outputs.
54
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).
55
+ (0, print_1.debugPrint)('issue:');
56
+ (0, env_1.isDebug)() && console.log(issue);
57
+ return issue;
58
+ }
59
+ /**
60
+ * After pushing processing may continue or exit, depending on the error
61
+ * and/or the bail threshold (that can be optionally set my the user).
62
+ *
63
+ * @note This function MIGHT result in a return, throw, or exit depending
64
+ * on the bail policy (set my the user).
65
+ *
66
+ * @param ctx
67
+ * @param type
68
+ * @param msgWhat Name of the specific error or what failed. E.g. "Key already exists in this section scope".
69
+ * @param msgWhy More details and more specific info about the issue/error.
70
+ * @param msgHint Hint or HUMBLE description on how to fix the issue.
71
+ */
72
+ pushOrBail(ctx, type, msgWhat, msgWhy = '', msgHint = '') {
73
+ var _a, _b, _c, _d, _e, _f;
74
+ (0, print_1.debugPrint)('-> pushOrBail(..)');
75
+ (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));
76
+ (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));
77
+ (0, print_1.debugPrint)('exception?.offendingToken = ' + ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.exception) === null || _c === void 0 ? void 0 : _c.offendingToken));
78
+ (0, print_1.debugPrint)();
79
+ (0, print_1.debugPrint)('ctx.ruleIndex = ' + (ctx === null || ctx === void 0 ? void 0 : ctx.start.channel));
80
+ (0, print_1.debugPrint)('ctx.ruleIndex = ' + (ctx === null || ctx === void 0 ? void 0 : ctx.ruleIndex));
81
+ (0, print_1.debugPrint)('ctx.ruleContext = ' + (ctx === null || ctx === void 0 ? void 0 : ctx.ruleContext));
82
+ (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));
83
+ (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));
84
+ const lineNum = (ctx === null || ctx === void 0 ? void 0 : ctx.start.line) || undefined; // Line (1-based).
85
+ // const startCol = !ctx ? 0 : ++ctx.start.column // Column (0-based).
86
+ const startCol = !ctx
87
+ ? undefined
88
+ : ++ctx.start.column; // Column (0-based).
89
+ // const endCol = (ctx?.stop?.column || 0) + 1 // Column (0-based).
90
+ const endCol = !!((_f = ctx === null || ctx === void 0 ? void 0 : ctx.stop) === null || _f === void 0 ? void 0 : _f.column)
91
+ ? ++ctx.stop.column
92
+ : undefined; // Note: Column (0-based).
93
+ let colNum = startCol || endCol;
94
+ // if (colNum === 0) {
95
+ // colNum = undefined
96
+ // }
97
+ let msgWhatWithLineNum = msgWhat;
98
+ if (lineNum && lineNum > 0) {
99
+ //@todo func that removes possible . at end
100
+ //msgWhatWithLineNum =
83
101
  // Patch message with the offending line number.
84
- msgWhat += ', at line: ' + lineNum;
102
+ // msgWhatWithLineNum += ', at line: ' + lineNum
103
+ msgWhatWithLineNum += ' at line ' + lineNum;
104
+ if (colNum) {
105
+ msgWhatWithLineNum += ', column ' + colNum;
106
+ }
85
107
  if (process.env.NODE_ENV === 'test') {
86
- msgWhat += `\nAt line: ${lineNum}, column(s): ${startCol}-${endCol}`;
108
+ msgWhatWithLineNum += `\nAt line: ${lineNum}, column(s): ${startCol}-${endCol}`;
87
109
  }
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!
110
+ }
111
+ (0, print_1.debugPrint)('persistThreshold = ' + this.persistThreshold);
112
+ (0, print_1.debugPrint)(' lineNum = ' + lineNum);
113
+ (0, print_1.debugPrint)(' colNum = ' + colNum);
114
+ (0, print_1.debugPrint)('startCol = ' + startCol);
115
+ (0, print_1.debugPrint)(' endCol = ' + endCol);
116
+ (0, print_1.debugPrint)();
117
+ const loc = {
118
+ lineNum: lineNum || 0, // 1-based, if n/a use 0.
119
+ colNum: colNum || 0, // 1-based, if n/a use 0.
120
+ };
121
+ console.log(); // Print an empty line before outputting message.
122
+ switch (type) {
123
+ case 'Internal-Error':
124
+ this.numInternalErrors++;
125
+ this.errors.push(this.makeIssue(lineNum, colNum, type, msgWhat, msgWhy, msgHint));
126
+ this.emitInternalError(loc, msgWhatWithLineNum, msgWhy, msgHint);
127
+ console.log(); // Emit an empty line before outputting message.
128
+ if (this.persistThreshold === '1-Abort-on-Errors' ||
129
+ this.persistThreshold === '2-Abort-Even-on-Warnings') {
143
130
  // if (process.env.NODE_ENV === 'test') {
144
131
  // In test, throw an error instead of exiting.
145
132
  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
- // }
133
+ // } else {
134
+ // process.exit(2)
135
+ // }
136
+ }
137
+ break;
138
+ case 'Syntax-Error':
139
+ this.numSyntaxErrors++;
140
+ this.errors.push(this.makeIssue(lineNum, colNum, type, msgWhat, msgWhy, msgHint));
141
+ this.emitSyntaxError(loc, msgWhatWithLineNum, msgWhy, msgHint);
142
+ console.log(); // Emit an empty line before outputting message.
143
+ if (this.persistThreshold === '1-Abort-on-Errors' ||
144
+ this.persistThreshold === '2-Abort-Even-on-Warnings') {
145
+ // if (process.env.NODE_ENV === 'test') {
146
+ // In test, throw an error instead of exiting.
147
+ throw new Error(`Syntax-Error: ${'' + msgWhat}`);
148
+ // } else {
149
+ // process.exit(3)
150
+ // }
151
+ }
152
+ break;
153
+ case 'Syntax-Warning':
154
+ this.numSyntaxWarnings++;
155
+ this.warnings.push(this.makeIssue(lineNum, colNum, type, msgWhat, msgWhy, msgHint));
156
+ this.emitSyntaxWarning(loc, msgWhatWithLineNum, msgWhy, msgHint);
157
+ console.log(); // Emit an empty line before outputting message.
158
+ if (this.persistThreshold === '2-Abort-Even-on-Warnings') {
159
+ // if (process.env.NODE_ENV === 'test') {
160
+ // In test, throw an error instead of exiting.
161
+ throw new Error(`Syntax-Warning: ${msgWhat}`);
162
+ // } else {
163
+ // process.exit(4)
164
+ // }
165
+ }
166
+ break;
167
+ case 'Notice':
168
+ this.numNotices++;
169
+ this.notices.push(this.makeIssue(lineNum, colNum, type, msgWhat, msgWhy, msgHint));
170
+ this.emitNotice(loc, msgWhatWithLineNum, msgWhy, msgHint);
171
+ console.log(); // Emit an empty line before outputting message.
172
+ break;
173
+ case 'Info':
174
+ this.numInfos++;
175
+ this.infos.push(this.makeIssue(lineNum, colNum, type, msgWhat, msgWhy, msgHint));
176
+ this.emitInfo(loc, msgWhatWithLineNum, msgWhy, msgHint);
177
+ console.log(); // Emit an empty line before outputting message.
178
+ break;
179
+ default: // Including 'Internal-Error'.
180
+ this.numFatalErrors++;
181
+ this.errors.push(this.makeIssue(lineNum, colNum, type, msgWhat, msgWhy, msgHint));
182
+ this.emitFatalError(loc, msgWhatWithLineNum, msgWhy, msgHint);
183
+ console.log(); // Emit an empty line before outputting message.
184
+ // CANNOT recover fatal errors, will lead to an exit!
185
+ // if (process.env.NODE_ENV === 'test') {
186
+ // In test, throw an error instead of exiting.
187
+ throw new Error(`Internal-Error: ${msgWhat}`);
188
+ // } else {
189
+ // process.exit(1)
190
+ // (!) Not sure about the below yet, if it's preferable in this case...
191
+ // Use this instead of process.exit(1), this will
192
+ // lead to that the current thread(s) will exit as well.
193
+ // process.exitCode = 1
194
+ // }
195
+ }
196
+ }
197
+ formatSignificantMessageLine(loc, issueTitle) {
198
+ // if (this.subjectType === 'None/Ignore') {
199
+ // return issueTitle
200
+ // }
201
+ switch (this.subjectType) {
202
+ case 'None/Ignore':
203
+ return issueTitle;
204
+ case 'File':
205
+ case 'Inline': {
206
+ // Construct a full line from several parts.
207
+ const titlePart = (0, string_1.trimTrailingNonLetters)(issueTitle.trim());
208
+ let line = `${titlePart} in `;
209
+ if (this.subjectType === 'Inline') {
210
+ line += 'inline YINI content';
211
+ // if (loc?.lineNum) {
212
+ // line += `, ${loc.lineNum}`
213
+ // if (loc?.colNum) line += `:${loc.colNum}`
214
+ // }
215
+ }
216
+ else {
217
+ line += `in ${this.fileName}`;
218
+ // if (loc?.lineNum) {
219
+ // line += `:${loc.lineNum}`
220
+ // if (loc?.colNum) line += `:${loc.colNum}`
221
+ // }
222
+ }
223
+ if (loc === null || loc === void 0 ? void 0 : loc.lineNum) {
224
+ line += `:${loc.lineNum}`;
225
+ if (loc === null || loc === void 0 ? void 0 : loc.colNum)
226
+ line += `:${loc.colNum}`;
227
+ }
228
+ return line;
153
229
  }
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;
230
+ }
231
+ }
232
+ emitFatalError(loc, msgWhat = 'Something went wrong!', msgWhy = '', msgHint = '') {
233
+ // console.error(issueTitle[0]) // Print the issue title.
234
+ const messageHeader = this.formatSignificantMessageLine(loc, issueTitle[0]);
235
+ console.error(messageHeader); // Print the issue title.
236
+ msgWhat && console.log(msgWhat);
237
+ msgWhy && console.log(msgWhy);
238
+ msgHint && console.log(msgHint);
239
+ }
240
+ emitInternalError(loc, msgWhat = 'Something went wrong!', msgWhy = '', msgHint = '') {
241
+ // console.error(issueTitle[1]) // Print the issue title.
242
+ const messageHeader = this.formatSignificantMessageLine(loc, issueTitle[1]);
243
+ console.error(messageHeader); // Print the issue title.
244
+ msgWhat && console.log(msgWhat);
245
+ msgWhy && console.log(msgWhy);
246
+ msgHint && console.log(msgHint);
247
+ }
248
+ emitSyntaxError(loc, msgWhat, msgWhy = '', msgHint = '') {
249
+ // console.error(issueTitle[2]) // Print the issue title.
250
+ const messageHeader = this.formatSignificantMessageLine(loc, issueTitle[2]);
251
+ console.error(messageHeader); // Print the issue title.
252
+ msgWhat && console.log(msgWhat);
253
+ msgWhy && console.log(msgWhy);
254
+ msgHint && console.log(msgHint);
255
+ }
256
+ emitSyntaxWarning(loc, msgWhat, msgWhy = '', msgHint = '') {
257
+ // console.warn(issueTitle[3]) // Print the issue title.
258
+ const messageHeader = this.formatSignificantMessageLine(loc, issueTitle[3]);
259
+ console.warn(messageHeader); // Print the issue title.
260
+ msgWhat && console.log(msgWhat);
261
+ msgWhy && console.log(msgWhy);
262
+ msgHint && console.log(msgHint);
263
+ }
264
+ emitNotice(loc, msgWhat, msgWhy = '', msgHint = '') {
265
+ // console.warn(issueTitle[4]) // Print the issue title.
266
+ const messageHeader = this.formatSignificantMessageLine(loc, issueTitle[4]);
267
+ console.warn(messageHeader); // Print the issue title.
268
+ msgWhat && console.log(msgWhat);
269
+ msgWhy && console.log(msgWhy);
270
+ msgHint && console.log(msgHint);
271
+ }
272
+ emitInfo(loc, msgWhat, msgWhy = '', msgHint = '') {
273
+ // console.info(issueTitle[5]) // Print the issue title.
274
+ const messageHeader = this.formatSignificantMessageLine(loc, issueTitle[5]);
275
+ console.info(messageHeader); // Print the issue title.
276
+ msgWhat && console.log(msgWhat);
277
+ msgWhy && console.log(msgWhy);
278
+ msgHint && console.log(msgHint);
279
+ }
280
+ getNumOfAllMessages() {
281
+ return (this.getNumOfErrors() +
282
+ this.getNumOfWarnings() +
283
+ this.getNumOfNotices() +
284
+ this.getNumOfNotices());
192
285
  }
193
286
  getNumOfErrors() {
194
287
  return (this.numFatalErrors + this.numInternalErrors + this.numSyntaxErrors);
@@ -196,8 +289,23 @@ class ErrorDataHandler {
196
289
  getNumOfWarnings() {
197
290
  return this.numSyntaxWarnings;
198
291
  }
199
- getNumOfInfoAndNotices() {
200
- return this.numNotices + this.numInfos;
292
+ getNumOfNotices() {
293
+ return this.numNotices;
294
+ }
295
+ getNumOfInfos() {
296
+ return this.numInfos;
297
+ }
298
+ getErrors() {
299
+ return this.errors;
300
+ }
301
+ getWarnings() {
302
+ return this.warnings;
303
+ }
304
+ getNotices() {
305
+ return this.notices;
306
+ }
307
+ getInfos() {
308
+ return this.infos;
201
309
  }
202
310
  }
203
311
  exports.ErrorDataHandler = ErrorDataHandler;
@@ -1,6 +1,12 @@
1
- import { TJSObject, TSyntaxTreeContainer } from '../core/types';
1
+ import { IYiniAST } from '../core/types';
2
2
  import { ErrorDataHandler } from './ErrorDataHandler';
3
3
  /**
4
- * Construct the final result of a JavaScript Object.
4
+ * Construct the final JavaScript Object.
5
+ * Transforms the AST to the plain JS object.
6
+ *
7
+ * - Keys are used exactly as-is.
8
+ * - Order of properties matches the AST traversal order.
9
+ *
10
+ * @note All `tag` fields MUST be ignored.
5
11
  */
6
- export declare const constructFinalObject: (syntaxTreeC: TSyntaxTreeContainer, errorHandler: ErrorDataHandler) => TJSObject;
12
+ export declare const astToObject: (ast: IYiniAST, errorHandler: ErrorDataHandler) => Record<string, unknown>;