using Canon.Core.Abstractions; using Canon.Core.Enums; using Canon.Core.LexicalParser; using Canon.Core.SemanticParser; namespace 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(); } private PascalType? _definitionType; /// /// IdentifierList中定义的类型 /// /// 尚未确定定义的类型 public PascalType DefinitionType { get { if (_definitionType is null) { throw new InvalidOperationException(); } return _definitionType; } set { _definitionType = value; } } /// /// 是否为参数中的引用参数 /// public bool IsReference { get; set; } /// /// 是否在过程定义中使用 /// public bool IsProcedure { 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; } }