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-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public class IndexGeneratorEventArgs : EventArgs
|
2024-04-26 10:18:49 +08:00
|
|
|
|
{
|
2024-04-28 22:02:29 +08:00
|
|
|
|
public required ExpressionList IndexParameters { get; init; }
|
2024-04-26 10:18:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public class IdentifierVarPart : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.IdVarPart;
|
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数组索引的个数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int IndexCount { get; set; }
|
|
|
|
|
|
2024-05-04 11:56:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 索引中的表达式
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<Expression> Expressions { get; } = [];
|
|
|
|
|
|
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);
|
|
|
|
|
RaiseEvent();
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PostVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PostVisit(this);
|
|
|
|
|
RaiseEvent();
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 使用了索引产生式的事件
|
|
|
|
|
/// </summary>
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public event EventHandler<IndexGeneratorEventArgs>? OnIndexGenerator;
|
2024-04-26 10:18:49 +08:00
|
|
|
|
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public static IdentifierVarPart Create(List<SyntaxNodeBase> children)
|
|
|
|
|
{
|
2024-05-04 11:56:06 +08:00
|
|
|
|
IdentifierVarPart result = new() { Children = children };
|
|
|
|
|
|
|
|
|
|
if (children.Count == 3)
|
|
|
|
|
{
|
|
|
|
|
ExpressionList expressionList = children[1].Convert<ExpressionList>();
|
|
|
|
|
|
|
|
|
|
result.Expressions.AddRange(expressionList.Expressions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2024-04-26 10:18:49 +08:00
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
private void RaiseEvent()
|
|
|
|
|
{
|
|
|
|
|
if (Children.Count == 3)
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-05-01 21:06:27 +08:00
|
|
|
|
OnIndexGenerator?.Invoke(this, new IndexGeneratorEventArgs()
|
2024-04-26 10:18:49 +08:00
|
|
|
|
{
|
2024-04-28 22:02:29 +08:00
|
|
|
|
IndexParameters = Children[1].Convert<ExpressionList>()
|
2024-04-26 10:18:49 +08:00
|
|
|
|
});
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 22:02:29 +08:00
|
|
|
|
OnIndexGenerator = null;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|