2024-04-07 16:47:28 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2024-04-12 19:01:37 +08:00
|
|
|
|
else
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-12 19:01:37 +08:00
|
|
|
|
NonTerminatedSyntaxNode nonTerminatedNode = child.Convert<NonTerminatedSyntaxNode>();
|
|
|
|
|
|
|
|
|
|
foreach (SyntaxNodeBase node in nonTerminatedNode)
|
|
|
|
|
{
|
|
|
|
|
yield return node;
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
2024-04-19 14:59:45 +08:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return Type.ToString();
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|