2024-04-26 10:18:49 +08:00
|
|
|
|
using Canon.Core.Abstractions;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
using Canon.Core.Enums;
|
2024-04-30 14:43:14 +08:00
|
|
|
|
using Canon.Core.SemanticParser;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
public class OnExpressionListEventArgs : EventArgs
|
|
|
|
|
{
|
|
|
|
|
public required ExpressionList ExpressionList { get; init; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public class ExpressionList : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.ExpressionList;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-26 10:18:49 +08:00
|
|
|
|
/// 子表达式列表
|
2024-04-07 16:47:28 +08:00
|
|
|
|
/// </summary>
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public List<Expression> Expressions { get; } = [];
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
2024-04-30 14:43:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否为传参列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsParamList;
|
|
|
|
|
|
|
|
|
|
public List<PascalParameterType> ParameterTypes { get; } = [];
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否为数组下标索引
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsIndex { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数组左边界列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<int> LeftBounds = new();
|
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前ExpressionList中的Expression定义
|
|
|
|
|
/// </summary>
|
|
|
|
|
public required Expression Expression { get; init; }
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PreVisit(SyntaxNodeVisitor visitor)
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
visitor.PreVisit(this);
|
2024-04-28 22:02:29 +08:00
|
|
|
|
RaiseEvent();
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PostVisit(SyntaxNodeVisitor visitor)
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
visitor.PostVisit(this);
|
2024-04-28 22:02:29 +08:00
|
|
|
|
RaiseEvent();
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 使用ExpressionList产生式的时间
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler<OnExpressionListEventArgs>? OnExpressionList;
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public static ExpressionList Create(List<SyntaxNodeBase> children)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-28 22:02:29 +08:00
|
|
|
|
ExpressionList result;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
if (children.Count == 1)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-28 22:02:29 +08:00
|
|
|
|
result = new ExpressionList { Expression = children[0].Convert<Expression>(), Children = children };
|
2024-04-26 10:18:49 +08:00
|
|
|
|
result.Expressions.Add(children[0].Convert<Expression>());
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-04-28 22:02:29 +08:00
|
|
|
|
else
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-28 22:02:29 +08:00
|
|
|
|
result = new ExpressionList { Expression = children[2].Convert<Expression>(), Children = children };
|
2024-04-26 10:18:49 +08:00
|
|
|
|
foreach (Expression expression in children[0].Convert<ExpressionList>().Expressions)
|
|
|
|
|
{
|
|
|
|
|
result.Expressions.Add(expression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Expressions.Add(children[2].Convert<Expression>());
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
return result;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-04-28 22:02:29 +08:00
|
|
|
|
|
|
|
|
|
private void RaiseEvent()
|
|
|
|
|
{
|
|
|
|
|
if (Children.Count == 3)
|
|
|
|
|
{
|
|
|
|
|
OnExpressionList?.Invoke(this,
|
|
|
|
|
new OnExpressionListEventArgs { ExpressionList = Children[0].Convert<ExpressionList>() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnExpressionList = null;
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|