Canon/Canon.Core/SyntaxNodes/NonTerminatedSyntaxNode.cs
ichirinko 03852ed2bf feat:完成语法树结点的类型检查 (#59)
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Reviewed-on: PostGuard/Canon#59
Co-authored-by: ichirinko <1621543655@qq.com>
Co-committed-by: ichirinko <1621543655@qq.com>
2024-04-28 22:02:29 +08:00

44 lines
1.1 KiB
C#

using System.Collections;
using Canon.Core.Abstractions;
using Canon.Core.Enums;
namespace Canon.Core.SyntaxNodes;
public abstract class NonTerminatedSyntaxNode : SyntaxNodeBase, IEnumerable<SyntaxNodeBase>
{
public override bool IsTerminated => false;
public abstract NonTerminatorType Type { get; }
public required List<SyntaxNodeBase> Children { get; init; }
public IEnumerator<SyntaxNodeBase> GetEnumerator()
{
yield return this;
foreach (SyntaxNodeBase child in Children)
{
if (child.IsTerminated)
{
yield return child;
}
else
{
NonTerminatedSyntaxNode nonTerminatedNode = child.Convert<NonTerminatedSyntaxNode>();
foreach (SyntaxNodeBase node in nonTerminatedNode)
{
yield return node;
}
}
}
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public override string ToString()
{
return Type.ToString();
}
}