using CanonSharp.Benchmark.Canon.Core.Abstractions; using CanonSharp.Benchmark.Canon.Core.Enums; using CanonSharp.Benchmark.Canon.Core.LexicalParser; namespace CanonSharp.Benchmark.Canon.Core.SyntaxNodes; public class IdentifierGeneratorEventArgs : EventArgs { public required IdentifierSemanticToken IdentifierToken { get; init; } public required IdentifierList IdentifierList { get; init; } } public class TypeGeneratorEventArgs : EventArgs { public required TypeSyntaxNode TypeSyntaxNode { get; init; } } public class IdentifierList : NonTerminatedSyntaxNode { public override NonTerminatorType Type => NonTerminatorType.IdentifierList; public override void PreVisit(SyntaxNodeVisitor visitor) { visitor.PreVisit(this); RaiseEvent(); } public override void PostVisit(SyntaxNodeVisitor visitor) { visitor.PostVisit(this); RaiseEvent(); } /// /// 是否为参数中的引用参数 /// public bool IsReference { get; set; } /// /// 是否在过程定义中使用 /// public bool IsProcedure { get; set; } /// /// 是否为变量定义中使用 /// public bool IsVariableDefinition { get; set; } public event EventHandler? OnIdentifierGenerator; public event EventHandler? OnTypeGenerator; public static IdentifierList Create(List children) { return new IdentifierList { Children = children }; } private void RaiseEvent() { if (Children.Count == 2) { OnTypeGenerator?.Invoke(this, new TypeGeneratorEventArgs { TypeSyntaxNode = Children[1].Convert() }); } else { OnIdentifierGenerator?.Invoke(this, new IdentifierGeneratorEventArgs { IdentifierToken = Children[1].Convert().Token.Convert(), IdentifierList = Children[2].Convert() }); } OnTypeGenerator = null; OnIdentifierGenerator = null; } }