@halleyassist/rule-parser 1.0.13 → 1.0.15
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/index.d.ts +213 -0
- package/package.json +9 -4
- package/src/RuleParser.ebnf.js +3 -3
- package/src/RuleParser.js +81 -4
- package/src/RuleParser.production.ebnf.js +1 -1
- package/src/RuleParser.production.js +81 -4
- package/src/errors/ErrorAnalyzer.js +924 -0
- package/src/errors/RuleParseError.js +64 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a user-friendly rule parsing error with error codes
|
|
3
|
+
*/
|
|
4
|
+
class RuleParseError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Create a RuleParseError
|
|
7
|
+
* @param {string} code - Error code for programmatic handling
|
|
8
|
+
* @param {string} message - Human-readable error message
|
|
9
|
+
* @param {string} hint - Helpful suggestion for fixing the error
|
|
10
|
+
* @param {Object} position - Position information with line, column, and offset
|
|
11
|
+
* @param {string} found - What was found at error position
|
|
12
|
+
* @param {Array<string>} expected - What was expected
|
|
13
|
+
* @param {string} snippet - Code snippet showing error location
|
|
14
|
+
*/
|
|
15
|
+
constructor(code, message, hint, position, found, expected, snippet) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'RuleParseError';
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.hint = hint;
|
|
20
|
+
this.line = position.line;
|
|
21
|
+
this.column = position.column;
|
|
22
|
+
this.offset = position.offset;
|
|
23
|
+
this.found = found;
|
|
24
|
+
this.expected = expected;
|
|
25
|
+
this.snippet = snippet;
|
|
26
|
+
|
|
27
|
+
// Maintain proper prototype chain for instanceof checks
|
|
28
|
+
Object.setPrototypeOf(this, RuleParseError.prototype);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
toString() {
|
|
32
|
+
let msg = `${this.name} [${this.code}]: ${this.message}\n`;
|
|
33
|
+
msg += ` at line ${this.line}, column ${this.column} (offset ${this.offset})\n`;
|
|
34
|
+
if (this.snippet) {
|
|
35
|
+
msg += ` ${this.snippet}\n`;
|
|
36
|
+
}
|
|
37
|
+
if (this.hint) {
|
|
38
|
+
msg += ` Hint: ${this.hint}\n`;
|
|
39
|
+
}
|
|
40
|
+
if (this.found) {
|
|
41
|
+
msg += ` Found: ${this.found}\n`;
|
|
42
|
+
}
|
|
43
|
+
if (this.expected && this.expected.length) {
|
|
44
|
+
msg += ` Expected: ${this.expected.join(', ')}`;
|
|
45
|
+
}
|
|
46
|
+
return msg;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toJSON() {
|
|
50
|
+
return {
|
|
51
|
+
code: this.code,
|
|
52
|
+
message: this.message,
|
|
53
|
+
hint: this.hint,
|
|
54
|
+
line: this.line,
|
|
55
|
+
column: this.column,
|
|
56
|
+
offset: this.offset,
|
|
57
|
+
found: this.found,
|
|
58
|
+
expected: this.expected,
|
|
59
|
+
snippet: this.snippet
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { RuleParseError };
|