-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.js
63 lines (63 loc) · 2.12 KB
/
error.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
module.exports = class AgateError {
constructor() {
this.count = 0;
this.log = true;
this.hint = "";
this.warnings = 0;
}
// Stops logging errors. Still counts
suspend() {
this.log = false;
}
// Resumes logging errors
resume() {
this.log = true;
}
generic(message, line, col, warning) {
if(warning) {
this.warnings++;
console.log(`Warning: ${message}`)
}
else{
this.count++;
console.log(message);
}
if(line && this.log){
console.log(`\tat line ${line} and column ${col}`);
}
if(this.hint) {
console.log(`Hint: ${this.hint}`);
this.hint = "";
}
return {
status: "error",
line: line,
column: col,
message: message
};
}
scanner(message, line, col) {
return this.generic(`Scanner Error: ${message}`, line, col);
}
parse(message, token) {
return this.generic(`Parse Error: ${message}`, token.line, token.column);
}
expected(message, token) {
if(message === "newline" && token.type === "equals"
|| message === "colon" && token.type === "closeSquare") {
this.hint = "Did you forget an @ symbol?";
}
if(message === "newline" && token.type === "dot") {
this.hint = "Did you mean @var[attr] or @var~func instead of @var.attr?";
}
if(message === "Expected some kind of expression"
&& ["colon", "equals"].indexOf(token.type) !== -1) {
this.hint = "Did you use parens instead of square brackets for attributes, like a(href='place.html') instead of a[href='place.html']?"
}
return this.parse(`Expected ${message}, got ${token.type}`, token);
}
undefined(type, name, token, warning) {
return this.generic(`Semantic ${warning ? "warning" : "error"}: ${type} '${name}' is not defined in this scope`, token.line, token.column, warning);
}
}