Skip to content

Commit 2fdea0b

Browse files
committed
SIFOSC の不具合を修正
1 parent 0277a3d commit 2fdea0b

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

FastChatProtocolInterface/SimpleFormulaScript/SifoscObject.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,30 @@
55
* distributed under the MIT License.
66
****/
77

8+
using System;
9+
using System.Text;
10+
811
namespace FastChatProtocolInterface.SimpleFormulaScript
912
{
1013
public record SifoscObject { }
1114

1215
public sealed record SifoscArray : SifoscObject
1316
{
14-
public SifoscObject?[]? Values { get; set; }
17+
public ReadOnlyMemory<SifoscObject?> Values { get; set; }
18+
19+
protected override bool PrintMembers(StringBuilder builder)
20+
{
21+
// 参考:https://qiita.com/muniel/items/fd843abc55a5626e5c45
22+
23+
var s = this.Values.Span;
24+
for (int i = 0; i < s.Length; ++i) {
25+
if (i != 0) {
26+
builder.Append(", ");
27+
}
28+
builder.Append(s[i]);
29+
}
30+
return s.Length > 0;
31+
}
1532
}
1633

1734
public sealed record SifoscNull : SifoscObject

FastChatProtocolInterface/SimpleFormulaScript/SifoscParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static bool TryParseArray(this SourceCode sc, [NotNullWhen(true)][MaybeNu
5252

5353
sc.SkipSpaces();
5454
if (sc.AdvanceIf(']')) {
55-
result = new() { Values = [ ..list ] };
55+
result = new() { Values = list.ToArray() };
5656
return true;
5757
}
5858
}

FastChatProtocolInterface/SimpleFormulaScript/SifoscServer.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ protected override string ReceiveMessageCore(FachpiCommunicationFlow flow)
2525

2626
public static string RunScriptLine(string s)
2727
{
28+
// SIFOSC の例:[ null, newobj, 123, +456, -789, [ ] ]
29+
2830
var sc = new SourceCode(s);
2931
if (sc.TryParseValue(out var result)) {
30-
return result.ToString();
31-
} else {
32-
return "(有効な SIFOSC ではありませんでした。)" + sc.Text;
32+
sc.SkipSpaces();
33+
if (sc.Index >= sc.Length) {
34+
return result.ToString();
35+
}
3336
}
37+
38+
return "(有効な SIFOSC ではありませんでした。)" + sc.Text;
3439
}
3540
}
3641
}

FastChatProtocolInterface/SimpleFormulaScript/SourceCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public bool TryReadChar(out char result)
7373
public bool TryPeekChar(out char result)
7474
{
7575
if (_idx < _src.Length) {
76-
result = _src[_idx++];
76+
result = _src[_idx];
7777
return true;
7878
} else {
7979
result = '\0';

0 commit comments

Comments
 (0)