暂时实现了简陋的脚本AST分析解释,后面再绑定到控件上

This commit is contained in:
fengjiayi
2024-12-20 23:39:29 +08:00
parent 114e81424b
commit ef119e11e3
52 changed files with 3175 additions and 261 deletions

View File

@@ -1,7 +1,11 @@
using Newtonsoft.Json;
using Dm.parser;
using NetTaste;
using Newtonsoft.Json;
using Serein.Library;
using Serein.Library.Utils;
using Serein.Library.Utils.SereinExpression;
using Serein.NodeFlow.Model;
using Serein.Script;
using System.Diagnostics;
using System.IO;
using System.Linq.Expressions;
@@ -12,11 +16,7 @@ using System.Windows.Threading;
namespace Serein.Workbench
{
#if DEBUG
public class A
{
public string Data { get; set; } = "1234";
public bool Data2 { get; set; }
}
#endif
@@ -32,39 +32,9 @@ namespace Serein.Workbench
#if DEBUG
if (1 == 1)
{
//object Data = "false";
//var expression = "== false";
//var pass = Serein.Library.Utils.SereinExpression.SereinConditionParser.To(Data, expression);
//string[] objects = new string[]
//{
// "124",
// "true",
// "0.42"
//};
//Dictionary<string, object> keyValuePairs = new Dictionary<string, object>
//{
// {"value", objects }
//};
//var data = SerinExpressionEvaluator.Evaluate("@Get .[value].[0]<int>", keyValuePairs, out _);
//data = SerinExpressionEvaluator.Evaluate("@Get .[value].[1]<bool>", keyValuePairs, out _);
//data = SerinExpressionEvaluator.Evaluate("@Dtc <bool>", data, out _);
//var result = SereinConditionParser.To(data, "== True");
//SereinEnv.AddOrUpdateFlowGlobalData("My", A);
//var data = SerinExpressionEvaluator.Evaluate("@Get #My#",null,out _);
// 这里是我自己的测试代码,你可以删除
string filePath;
filePath = @"F:\临时\project\linux\project.dnf";
filePath = @"F:\临时\project\linux\http\project.dnf";
filePath = @"F:\临时\project\yolo flow\project.dnf";
filePath = @"F:\临时\project\data\project.dnf";
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\net8.0\PLCproject.dnf";
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\banyunqi\project.dnf";
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
@@ -132,104 +102,5 @@ namespace Serein.Workbench
}
}
#if DEBUG && false
public class TestObject
{
public NestedObject Data { get; set; }
public class NestedObject
{
public int Code { get; set; }
public int Code2 { get; set; }
public string Tips { get; set; }
}
public string ToUpper(string input)
{
return input.ToUpper();
}
}
//测试 操作表达式,条件表达式
private void TestExp()
{
#region
string expression = "";
var testObj = new TestObject
{
Data = new TestObject.NestedObject
{
Code = 15,
Code2 = 20,
Tips = "测试数据"
}
};
#endregion
#region
// 获取对象成员
var result = SerinExpressionEvaluator.Evaluate("get .Data.Code", testObj);
Debug.WriteLine(result); // 15
// 设置对象成员
SerinExpressionEvaluator.Evaluate("set .Data.Code = 20", testObj);
Debug.WriteLine(testObj.Data.Code); // 20
SerinExpressionEvaluator.Evaluate("set .Data.Tips = 123", testObj);
// 调用对象方法
result = SerinExpressionEvaluator.Evaluate($"call .ToUpper({SerinExpressionEvaluator.Evaluate("get .Data.Tips", testObj)})", testObj);
Debug.WriteLine(result); // HELLO
expression = "@number (@+1)/100";
result = SerinExpressionEvaluator.Evaluate(expression, 2);
Debug.WriteLine($"{expression} -> {result}"); // HELLO
#endregion
#region
expression = ".Data.Code == 15";
var pass = SerinConditionParser.To(testObj, expression);
Debug.WriteLine($"{expression} -> " + pass);
expression = ".Data.Code<int>[@*2] == 31";
//expression = ".Data.Tips<string> contains 数据";
pass = SerinConditionParser.To(testObj, expression);
Debug.WriteLine($"{expression} -> " + pass);
expression = ".Data.Code<int> < 20";
pass = SerinConditionParser.To(testObj, expression);
Debug.WriteLine($"{expression} -> " + pass);
int i = 43;
expression = "in 11-22";
pass = SerinConditionParser.To(i, expression);
Debug.WriteLine($"{i} {expression} -> " + pass);
expression = "== 43";
pass = SerinConditionParser.To(i, expression);
Debug.WriteLine($"{i} {expression} -> " + pass);
string str = "MY NAME IS COOOOL";
expression = "c NAME";
pass = SerinConditionParser.To(str, expression);
Debug.WriteLine($"{str} {expression} -> " + pass);
#endregion
}
#endif
}
}

View File

@@ -84,6 +84,7 @@
<!--暂时隐藏基础面板 Visibility="Collapsed" -->
<ScrollViewer Grid.Row="0" HorizontalScrollBarVisibility="Auto">
<StackPanel Orientation="Horizontal">
<nodeView:ScriptNodeControl x:Name="ScriptNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
<nodeView:GlobalDataControl x:Name="GlobalDataControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
<nodeView:ExpOpNodeControl x:Name="ExpOpNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
<nodeView:ConditionNodeControl x:Name="ConditionNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>

View File

@@ -177,6 +177,7 @@ namespace Serein.Workbench
NodeMVVMManagement.RegisterUI(NodeControlType.ExpCondition, typeof(ConditionNodeControl), typeof(ConditionNodeControlViewModel));
NodeMVVMManagement.RegisterUI(NodeControlType.ConditionRegion, typeof(ConditionRegionControl), typeof(ConditionRegionNodeControlViewModel));
NodeMVVMManagement.RegisterUI(NodeControlType.GlobalData, typeof(GlobalDataControl), typeof(GlobalDataNodeControlViewModel));
NodeMVVMManagement.RegisterUI(NodeControlType.Script, typeof(ScriptNodeControl), typeof(ScriptNodeControlViewModel));
#endregion
@@ -1406,6 +1407,7 @@ namespace Serein.Workbench
Type when typeof(ConditionNodeControl).IsAssignableFrom(droppedType) => NodeControlType.ExpCondition,
Type when typeof(ExpOpNodeControl).IsAssignableFrom(droppedType) => NodeControlType.ExpOp,
Type when typeof(GlobalDataControl).IsAssignableFrom(droppedType) => NodeControlType.GlobalData,
Type when typeof(ScriptNodeControl).IsAssignableFrom(droppedType) => NodeControlType.Script,
_ => NodeControlType.None,
};
if (nodeControlType != NodeControlType.None)
@@ -2913,7 +2915,7 @@ namespace Serein.Workbench
catch (Exception ex)
{
SereinEnv.WriteLine(InfoType.ERROR, $"粘贴节点时发生异常:{ex}");
//SereinEnv.WriteLine(InfoType.ERROR, $"粘贴节点时发生异常:{ex}");
}

View File

@@ -21,39 +21,6 @@ namespace Serein.Workbench.Node.ViewModel
}
//private NodeModelBase _nodeModelBase;
//public NodeModelBase NodeModel
//{
// get => _nodeModelBase; set
// {
// if (value != null)
// {
// _nodeModelBase = value;
// OnPropertyChanged();
// }
// }
//}
//private bool isSelect;
///// <summary>
///// 表示节点控件是否被选中
///// </summary>
//internal bool IsSelect
//{
// get => isSelect;
// set
// {
// isSelect = value;
// OnPropertyChanged();
// }
//}
private bool isInterrupt;
///// <summary>
///// 控制中断状态的视觉效果
@@ -68,45 +35,14 @@ namespace Serein.Workbench.Node.ViewModel
}
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
//Console.WriteLine(propertyName);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// 使节点获得中断能力(以及是否启用节点)
/// </summary>
//public NodeDebugSetting DebugSetting
//{
// get => Node.DebugSetting;
// set
// {
// if (value != null)
// {
// Node.DebugSetting = value;
// OnPropertyChanged();
// }
// }
//}
/// <summary>
/// 使节点能够表达方法信息
/// </summary>
//public MethodDetails MethodDetails
//{
// get => Node.MethodDetails;
// set
// {
// if(value != null)
// {
// Node.MethodDetails = value;
// OnPropertyChanged();
// }
// }
//}
}
}

View File

@@ -51,6 +51,7 @@
<ProjectReference Include="..\Library.Framework\Serein.Library.Framework.csproj" />
<ProjectReference Include="..\Library\Serein.Library.csproj" />
<ProjectReference Include="..\NodeFlow\Serein.NodeFlow.csproj" />
<ProjectReference Include="..\Serein.Script\Serein.Script.csproj" />
</ItemGroup>
<ItemGroup>