-
Notifications
You must be signed in to change notification settings - Fork 2
/
ShellMode.cs
74 lines (66 loc) · 2.41 KB
/
ShellMode.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TASI.InternalLangCoreHandle;
using TASI.LangCoreHandleInterface;
using TASI.RuntimeObjects;
using TASI.RuntimeObjects.FunctionClasses;
using TASI.Token;
using static TASI.Command;
namespace TASI
{
public class ShellStatementHandler : ShellMode, IStatementHandler
{
public ShellStatementHandler(Global global) : base(global)
{
statementHandler = this;
}
public Value? HandleStatement(List<Command> inputStatement, AccessableObjects accessableObjects)
{
switch (inputStatement[0].commandText)
{
case "clear":
Console.Clear();
return null;
case "exit":
exitRequest = true;
return null;
default:
throw new InternalInterpreterException();
}
}
internal void InitShell(Global global)
{
global.AllNormalStatements.Add("clear", new("clear", new() { new() }, statementHandler));
global.AllNormalStatements.Add("exit", new("exit", new() { new() }, statementHandler));
}
}
public class ShellMode
{
protected IStatementHandler statementHandler = null!;
protected bool exitRequest = false;
public NamespaceInfo currentNamespace = null!;
protected Global global;
public ShellMode(Global global)
{
this.global = global;
}
public IEnumerable<Command> GetShell()
{
while (!exitRequest)
{
string input = Console.ReadLine() ?? "";
foreach (Command command in Tokeniser.CallTokeniseInput(input, global, -1))
{
global.CurrentLine = command.commandLine;
if (command.commandType == CommandTypes.FunctionCall) command.functionCall.SearchCallFunction(currentNamespace, global);
else if (command.commandType == CommandTypes.Calculation) command.calculation.InitFunctions(currentNamespace, global);
else if (command.commandType == CommandTypes.CodeContainer) command.initCodeContainerFunctions(currentNamespace, global);
yield return command;
}
}
}
}
}