Skip to content

Commit 0277a3d

Browse files
committed
SIFOSC の REPL 機能を実装。
1 parent ce58629 commit 0277a3d

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

FastChatProtocolInterface/CommandLineArguments.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ private static void PrintHelp()
177177
Console.WriteLine("fachpi 通常のサーバーを起動する。如何なる拡張機能も使用しない事を強制する。");
178178
Console.WriteLine("sifosc SIFOSC 機能を有効にしてサーバーを起動する。");
179179
Console.WriteLine("client クライアントを起動する。");
180+
Console.WriteLine("repl サーバーを起動せずに SIFOSC を実行する。");
180181
Console.WriteLine();
181182
Console.WriteLine("注意:幾つかのオプションにはこの説明書に記載されていない別表記があります。");
182183
Console.WriteLine();

FastChatProtocolInterface/ExecutionMode.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* distributed under the MIT License.
66
****/
77

8+
using System;
89
using System.Collections.Concurrent;
910
using System.Net;
1011
using System.Threading;
@@ -26,6 +27,7 @@ static ExecutionMode()
2627
_modes.TryAdd("fachpi", ServerImpl._inst_fachpi);
2728
_modes.TryAdd("sifosc", ServerImpl._inst_sifosc);
2829
_modes.TryAdd("client", ClientImpl._inst);
30+
_modes.TryAdd("repl", ReplImpl ._inst);
2931
}
3032

3133
public static ExecutionMode? GetMode(string name)
@@ -79,5 +81,29 @@ public override void Run(in CommandLineArguments args)
7981
client.Connect(args.HostName, args.Port);
8082
}
8183
}
84+
85+
private sealed class ReplImpl : ExecutionMode
86+
{
87+
internal static readonly ReplImpl _inst = new();
88+
89+
private ReplImpl() { }
90+
91+
public override void Run(in CommandLineArguments args)
92+
{
93+
Console.WriteLine("SIFOSC を実行できます。");
94+
95+
while (true) {
96+
Console.Write("> ");
97+
98+
string? input = Console.ReadLine();
99+
if (!string.IsNullOrEmpty(input)) {
100+
string output = SifoscServer.RunScriptLine(input);
101+
102+
Console.WriteLine(output);
103+
Console.WriteLine();
104+
}
105+
}
106+
}
107+
}
82108
}
83109
}

FastChatProtocolInterface/SimpleFormulaScript/SifoscServer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ public override void OnConnected()
2121
}
2222

2323
protected override string ReceiveMessageCore(FachpiCommunicationFlow flow)
24+
=> RunScriptLine(flow.Reader.ReadString());
25+
26+
public static string RunScriptLine(string s)
2427
{
25-
var sc = new SourceCode(flow.Reader.ReadString());
28+
var sc = new SourceCode(s);
2629
if (sc.TryParseValue(out var result)) {
2730
return result.ToString();
2831
} else {

0 commit comments

Comments
 (0)