jackfiled
89ce313b77
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/4 Co-authored-by: jackfiled <xcrenchangjun@outlook.com> Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System.Collections;
|
|
using CanonSharp.Benchmark.Canon.Core.Enums;
|
|
|
|
namespace CanonSharp.Benchmark.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();
|
|
}
|
|
}
|