mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-11 12:10:47 +08:00
1. 重新设计了 JSON门户类的实现
2. Script脚本添加了原始字符串的实现 3. 修复了Script中无法对 \" 双引号转义的问题 4. 新增了对于集合嵌套取值的支持(目前仅是集合取值) 5. 重新设计了FlowWorkManagement任务启动的逻辑,修复了触发器无法正常运行的问题 6. 在ScriptBaseFunc中新增了 json() 本地函数,支持将字符串转为IJsonToken进行取值。 7. EmitHelper对于集合取值时,反射获取“get_item”委托时存在看你多个MethodInfo,现在可以传入子项类型,帮助匹配目标重载方法
This commit is contained in:
@@ -42,6 +42,10 @@ namespace Serein.Script.Node
|
||||
case '\\': // 字面量反斜杠
|
||||
output.Append('\\');
|
||||
i++; // 跳过第二个 '\\'
|
||||
break;
|
||||
case '"': // 字符串反斜杠
|
||||
output.Append('"');
|
||||
i++; // 跳过第二个 '"'
|
||||
break;
|
||||
default:
|
||||
output.Append(input[i]); // 不是转义符,保留反斜杠
|
||||
|
||||
@@ -516,7 +516,7 @@ namespace Serein.Script
|
||||
/// <param name="indexValue"></param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private async Task<object?> GetCollectionValueAsync(ASTNode node, object collectionValue, object indexValue)
|
||||
private async Task<object?> GetCollectionValueAsync(CollectionIndexNode node, object collectionValue, object indexValue)
|
||||
{
|
||||
if (ASTDelegateDetails.TryGetValue(node, out DelegateDetails? delegateDetails))
|
||||
{
|
||||
@@ -530,8 +530,9 @@ namespace Serein.Script
|
||||
{
|
||||
return chars[index];
|
||||
}
|
||||
var itemType = symbolInfos[node.Index];
|
||||
var collectionType = collectionValue.GetType(); // 目标对象的类型
|
||||
delegateDetails = new DelegateDetails(collectionType, DelegateDetails.EmitType.CollectionGetter);
|
||||
delegateDetails = new DelegateDetails(collectionType, DelegateDetails.EmitType.CollectionGetter, itemType);
|
||||
ASTDelegateDetails[node] = delegateDetails; // 缓存委托
|
||||
var result = await delegateDetails.InvokeAsync(collectionValue, [indexValue]);
|
||||
return result;
|
||||
|
||||
@@ -214,6 +214,14 @@
|
||||
// 识别字符串字面量
|
||||
if (currentChar == '"')
|
||||
{
|
||||
if (_input[_index + 1] == '"'
|
||||
&& _input[_index + 2] == '"')
|
||||
{
|
||||
var value = _input.Slice(_index, 4).ToString();
|
||||
|
||||
// 原始字符串
|
||||
return ReadRawString();
|
||||
}
|
||||
return ReadString();
|
||||
}
|
||||
|
||||
@@ -440,6 +448,28 @@
|
||||
return token;
|
||||
}
|
||||
|
||||
private Token ReadRawString()
|
||||
{
|
||||
// skip opening triple quotes
|
||||
_index += 3;
|
||||
|
||||
var start = _index;
|
||||
while (_index + 2 < _input.Length)
|
||||
{
|
||||
if (_input[_index] == '"' && _input[_index + 1] == '"' && _input[_index + 2] == '"')
|
||||
{
|
||||
var value = _input.Slice(start, _index - start).ToString();
|
||||
_index += 3; // skip closing """
|
||||
return CreateToken(TokenType.String, value);
|
||||
}
|
||||
|
||||
_index++;
|
||||
}
|
||||
|
||||
throw new Exception("Unterminated raw string literal");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读取硬编码的文本
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Serein.Library.Utils;
|
||||
using Serein.Script.Node;
|
||||
using Serein.Script.Node.FlowControl;
|
||||
using System.Collections;
|
||||
|
||||
namespace Serein.Script
|
||||
{
|
||||
@@ -255,6 +256,7 @@ namespace Serein.Script
|
||||
if (JudgmentOperator(_currentToken, "=")) break; // 退出
|
||||
var peekToken = _currentToken; // _lexer.PeekToken(); // 获取下一个token开始判断
|
||||
source = nodes[^1]; // 重定向节点
|
||||
if (peekToken.Type == TokenType.Identifier) throw new Exception($"无法从对象获取成员,当前Token类型为 {peekToken.Type}。");
|
||||
if (peekToken.Type == TokenType.Dot) // 从对象获取
|
||||
{
|
||||
/*
|
||||
@@ -352,27 +354,51 @@ namespace Serein.Script
|
||||
public CollectionIndexNode ParseCollectionIndexNode(ASTNode sourceNode)
|
||||
{
|
||||
var collectionToken = _currentToken;
|
||||
string collectionName = _currentToken.Value; // 集合名称
|
||||
NextToken(TokenType.SquareBracketsLeft); // 消耗集合名称
|
||||
NextToken(); // 消耗 "[" 集合标识符的左中括号
|
||||
ASTNode indexNode = ParserExpression(); // 解析获取索引Node
|
||||
NextToken(); // 消耗 "]" 集合标识符的右中括号
|
||||
|
||||
if(sourceNode is IdentifierNode)
|
||||
if(_currentToken.Type == TokenType.SquareBracketsLeft)
|
||||
{
|
||||
var collectionIndexNode = new CollectionIndexNode(sourceNode, indexNode);
|
||||
collectionIndexNode.SetTokenInfo(collectionToken); // 表示获取集合第几个索引
|
||||
return collectionIndexNode;
|
||||
// 集合中获取集合
|
||||
NextToken(); // 消耗 "[" 集合标识符的左中括号
|
||||
ASTNode indexNode = ParserExpression(); // 解析获取索引Node
|
||||
NextToken(); // 消耗 "]" 集合标识符的右中括号
|
||||
|
||||
if (sourceNode is IdentifierNode)
|
||||
{
|
||||
var collectionIndexNode = new CollectionIndexNode(sourceNode, indexNode);
|
||||
collectionIndexNode.SetTokenInfo(collectionToken); // 表示获取集合第几个索引
|
||||
return collectionIndexNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
var collectionIndexNode = new CollectionIndexNode(sourceNode, indexNode);
|
||||
collectionIndexNode.SetTokenInfo(collectionToken); // 表示获取集合第几个索引
|
||||
return collectionIndexNode;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var memberAccessNode = new MemberAccessNode(sourceNode, collectionName).SetTokenInfo(_currentToken); // 表示集合从上一轮获取到的成员获取
|
||||
var collectionIndexNode = new CollectionIndexNode(memberAccessNode, indexNode);
|
||||
collectionIndexNode.SetTokenInfo(collectionToken); // 表示获取集合第几个索引
|
||||
return collectionIndexNode;
|
||||
string collectionName = _currentToken.Value; // 集合名称
|
||||
NextToken(TokenType.SquareBracketsLeft); // 消耗集合名称
|
||||
NextToken(); // 消耗 "[" 集合标识符的左中括号
|
||||
ASTNode indexNode = ParserExpression(); // 解析获取索引Node
|
||||
NextToken(); // 消耗 "]" 集合标识符的右中括号
|
||||
|
||||
if (sourceNode is IdentifierNode)
|
||||
{
|
||||
var collectionIndexNode = new CollectionIndexNode(sourceNode, indexNode);
|
||||
collectionIndexNode.SetTokenInfo(collectionToken); // 表示获取集合第几个索引
|
||||
return collectionIndexNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var memberAccessNode = new MemberAccessNode(sourceNode, collectionName).SetTokenInfo(_currentToken); // 表示集合从上一轮获取到的成员获取
|
||||
var collectionIndexNode = new CollectionIndexNode(memberAccessNode, indexNode);
|
||||
collectionIndexNode.SetTokenInfo(collectionToken); // 表示获取集合第几个索引
|
||||
return collectionIndexNode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -939,10 +965,6 @@ namespace Serein.Script
|
||||
{
|
||||
var peekToken = _currentToken; // _lexer.PeekToken(); // 获取下一个token开始判断
|
||||
source = nodes[^1]; // 重定向节点
|
||||
if(source.StartIndex == 501)
|
||||
{
|
||||
|
||||
}
|
||||
if (peekToken.Type == TokenType.Dot) // 从对象获取
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -674,7 +674,7 @@ namespace Serein.Script
|
||||
/// <param name="indexType">索引</param>
|
||||
/// <param name="resultType">获取到的类型</param>
|
||||
/// <returns></returns>
|
||||
public static bool TryGetIndexerType(Type collectionType, out Type indexType, out Type resultType)
|
||||
public static bool TryGetIndexerType(Type collectionType, out Type indexType, out Type resultType)
|
||||
{
|
||||
indexType = null!;
|
||||
resultType = null!;
|
||||
@@ -724,6 +724,7 @@ namespace Serein.Script
|
||||
|
||||
if (indexer != null)
|
||||
{
|
||||
var @params = indexer.GetIndexParameters();
|
||||
var param = indexer.GetIndexParameters()[0];
|
||||
indexType = param.ParameterType;
|
||||
resultType = indexer.PropertyType;
|
||||
|
||||
Reference in New Issue
Block a user