-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
56 lines (43 loc) · 1.54 KB
/
main.ts
File metadata and controls
56 lines (43 loc) · 1.54 KB
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
import { parseArgs } from "@std/cli/parse-args";
import { parse } from "./src/parser.ts";
import { ErrorTypes, type Error as BSError } from "./types/errors.ts";
import { adv } from "./src/console.ts";
import { printErrorContext } from "./src/printError.ts";
const flags = parseArgs(Deno.args, {
boolean: ["debug", "help"],
string: ["file"],
});
if (flags.help || !flags.file) {
console.log("Specify file path with --file");
Deno.exit(1);
}
const content = Deno.readTextFileSync(flags.file);
try {
const result = parse(content);
if (flags.debug) {
console.log(
adv`§8[§r§lDebug§n§8]§r Writing compiler output to result.json`
);
Deno.writeTextFileSync("result.json", JSON.stringify(result));
}
console.log(result);
// deno-lint-ignore no-explicit-any
} catch (e: any) {
if (e.start !== undefined && e.stop !== undefined && e.message) {
// Handle compiler errors
const error = e as BSError;
console.log(adv`§u§lException occured while compiling:§r`);
printErrorContext(content, flags.file, error.start, error.stop);
console.log(adv`§l§5${ErrorTypes[error.type]}: §r§d${error.message}`);
} else {
// Handle all other erros
const error = e as Error;
console.log(adv`§e§u§l:( The BlockScript compiler has crashed:§r`);
console.log("Please note, that this is not a problem with your code!\n");
console.log(adv`§l§uFurther information:§r\n`);
console.log(adv`§lType: §r${error.name}`);
console.log(adv`§lMessage: §r${error.message}`);
console.log(adv`§lStack: §r${error.stack}`);
}
Deno.exit(1);
}