-
Notifications
You must be signed in to change notification settings - Fork 39
/
error_reporting.ts
38 lines (31 loc) · 1.38 KB
/
error_reporting.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { SourceLocation } from "./ast";
import { stackTrace } from "./runtime_error";
export class CompileTimeError extends Error {
__proto__: Error
constructor(message: string) {
const trueProto = new.target.prototype;
super(message);
// Alternatively use Object.setPrototypeOf if you have an ES6 environment.
this.__proto__ = trueProto;
}
}
// I ❤️ TypeScript: https://github.com/microsoft/TypeScript/issues/13965
export class TypeCheckError extends CompileTimeError {
constructor(message: string, location: SourceLocation) {
super("TYPE ERROR: " + message + " in line " + location.line.toString()+" at column " + location.column.toString() + "\n\t" + location.srcCode.trim() + "\n\t" + '^'.repeat(location.srcCode.trim().length));
}
}
export class ParseError extends CompileTimeError {
constructor(message: string, location: SourceLocation) {
super("PARSE ERROR: " + message + " in line " + location.line.toString()+" at column " + location.column.toString() + "\n\t" + location.srcCode.trim() + "\n\t" + ' '.repeat(location.column-1) + "^^^");
}
}
export class RunTimeError extends Error {
__proto__: Error
constructor(message: string) {
const trueProto = new.target.prototype;
super(message);
// Alternatively use Object.setPrototypeOf if you have an ES6 environment.
this.__proto__ = trueProto;
}
}