mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
暂时实现了简陋的脚本AST分析解释,后面再绑定到控件上
This commit is contained in:
61
Serein.Script/Node/StringNode.cs
Normal file
61
Serein.Script/Node/StringNode.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Script.Node
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串字面量节点
|
||||
/// </summary>
|
||||
public class StringNode : ASTNode
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
public StringNode(string input)
|
||||
{
|
||||
// 使用 StringBuilder 来构建输出
|
||||
StringBuilder output = new StringBuilder(input.Length);
|
||||
|
||||
for (int i = 0; i < input.Length; i++)
|
||||
{
|
||||
if (i < input.Length - 1 && input[i] == '\\') // 找到反斜杠
|
||||
{
|
||||
char nextChar = input[i + 1];
|
||||
|
||||
// 处理转义符
|
||||
switch (nextChar)
|
||||
{
|
||||
case 'r':
|
||||
output.Append('\r');
|
||||
i++; // 跳过 'r'
|
||||
break;
|
||||
case 'n':
|
||||
output.Append('\n');
|
||||
i++; // 跳过 'n'
|
||||
break;
|
||||
case 't':
|
||||
output.Append('\t');
|
||||
i++; // 跳过 't'
|
||||
break;
|
||||
case '\\': // 字面量反斜杠
|
||||
output.Append('\\');
|
||||
i++; // 跳过第二个 '\\'
|
||||
break;
|
||||
default:
|
||||
output.Append(input[i]); // 不是转义符,保留反斜杠
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Append(input[i]); // 其他字符直接添加
|
||||
}
|
||||
}
|
||||
Value = output.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user