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-04-28 22:02:29 +08:00
|
|
|
|
public class OnIndexGeneratorEventArgs : 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-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>
|
|
|
|
|
public event EventHandler<OnIndexGeneratorEventArgs>? 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-04-26 10:18:49 +08:00
|
|
|
|
return new IdentifierVarPart { Children = children };
|
|
|
|
|
}
|
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-04-28 22:02:29 +08:00
|
|
|
|
OnIndexGenerator?.Invoke(this, new OnIndexGeneratorEventArgs()
|
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
|
|
|
|
}
|
|
|
|
|
}
|