dbbab1c761
尽管里面有点粪,但还是生成了漂亮的树,就当给树施肥了 剩下一个小问题:未考虑节点的宽度(因为名称不一样长),但目前未发现对图生成的明显影响 Co-authored-by: jackfiled <xcrenchangjun@outlook.com> Reviewed-on: PostGuard/Canon#33 Co-authored-by: Ichirinko <1621543655@qq.com> Co-committed-by: Ichirinko <1621543655@qq.com>
43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using System.Collections;
|
|
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();
|
|
}
|
|
}
|