This repository was archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsole.ts
66 lines (55 loc) · 2.18 KB
/
Console.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
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
64
65
66
// deno-lint-ignore-file no-explicit-any
import { RunInterpreter } from "./run.ts";
import Enviornment from "./runtime/enviornment.ts";
import { NullValue } from "./runtime/values.ts";
export function RunFromConsole(C: string, enviornment:Enviornment){
console.log("\nSoup v0.0.6");
RunInterpreter(C, enviornment)
while (true) {
const filecontents = prompt("> ") || " ";
if (!filecontents || filecontents.includes("exit")) { Deno.exit(1); }
console.log((RunInterpreter(filecontents, enviornment) as NullValue).value)
}
}
export function ProcessFlags(args: string[]): Record<string, any>{
const Flags: Record<string, any> = {
"file": "",
".soup": false,
"-tr": false,
"-tk": false,
"-v": false,
"-ig_lexer":false,
"-help":false,
"help":false,
"-ig_fn":false,
"-ig_parser":false,
"-unsafe": false,
"-constants":false,
"-constants:":""
}
const CLI_FLAGS: Record<string, boolean> = {
".soup": false,
"-tr": false,
"-tk": false,
"-v": true,
"-constants":true,
"-constants:":true,
"-help":true,
"help":true,
}
const lastFlag: Map<string, string> = new Map();
for (let i = 0; i < args.length; i++) {
const Flag = args[i];
if (!Flag.includes(".soup") && Flags[Flag] == undefined && !Flag.includes("-constants")){ throw `Flag "${Flag}" Does Not Exist` }
if (Flag.includes(".soup")){ Flags[".soup"] = true, Flags["file"] = Flag }
if (Flags[Flag] != undefined){ Flags[Flag] = true }
if (lastFlag.get(Flag) == Flag){ throw `Flag "${Flag}" had been used twice or more`}
lastFlag.set(Flag, Flag)
if (Flag.includes("-constants")){ Flags["-constants"] = true; Flags["-constants:"] = Flag.replaceAll("-constants:", "").replaceAll("_", " ").replaceAll("!", "\n"); }
}
for (let i = 0; i < args.length; i++) {
const Flag = args[i];
if (!Flags[".soup"] && !Flag.includes(".soup") && !CLI_FLAGS[Flag] && !Flag.includes("-constants")) { throw `Flags may be used if a file is provided` }
}
return Flags
}