-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezrShell.cs
82 lines (72 loc) · 2.7 KB
/
ezrShell.cs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using ezrSquared.Main;
using ezrSquared.Errors;
using ezrSquared.Values;
using ezrSquared.General;
using static ezrSquared.Constants.constants;
using System;
namespace ezrSquared.Shell
{
public class ezrShell
{
public static void Main(string[] args)
{
string filepath = string.Empty;
if (args.Length > 0)
filepath = args[0].Replace("\\", "\\\\");
Console.WriteLine($"ezr² biShell version- ({VERSION}) release- [{VERSION_DATE}]");
bool isScript = false;
string script = string.Empty;
int scriptLine = 1;
context runtimeContext = new context("<main>", ezr.globalPredefinedContext, new position(0, 0, 0, "<main>", ""), false);
runtimeContext.symbolTable = new symbolTable(ezr.globalPredefinedContext.symbolTable);
while (true)
{
if (string.IsNullOrEmpty(filepath))
{
if (isScript)
Console.Write($"({scriptLine}) > ");
else
Console.Write($"> ");
string? input = Console.ReadLine();
if (string.IsNullOrWhiteSpace(input)) continue;
if (input == "switch mode")
{
isScript = !isScript;
scriptLine = 1;
script = "";
continue;
}
else if (input == "run code")
isScript = false;
else if (input == "quit shell")
break;
else
script += input;
if (isScript)
{
script += '\n';
scriptLine++;
continue;
}
}
else
{
script = $"run(\"{filepath}\")";
filepath = string.Empty;
}
if (!string.IsNullOrEmpty(script))
{
error? error = ezr.easyRun("<ezr² biShell>", script, runtimeContext, out item? result);
if (error != null) Console.WriteLine(error.asString());
else if (result != null)
{
item[] results = ((array)result).storedValue;
if (results.Length == 1) Console.WriteLine(results[0].ToString());
else Console.WriteLine(result.ToString());
}
}
script = "";
}
}
}
}