using Canon.Core.Enums;
namespace Canon.Core.SyntaxNodes;
public class VarDeclarations : NonTerminatedSyntaxNode
{
public override NonTerminatorType Type => NonTerminatorType.VarDeclarations;
///
/// 声明的变量列表
///
public IEnumerable<(IdentifierList, TypeSyntaxNode)> Variables => EnumerateVariables();
public static VarDeclarations Create(List children)
{
return new VarDeclarations { Children = children };
}
private IEnumerable<(IdentifierList, TypeSyntaxNode)> EnumerateVariables()
{
if (Children.Count == 0)
{
yield break;
}
VarDeclaration declaration = Children[1].Convert();
while (true)
{
yield return declaration.Variable;
if (declaration.IsRecursive)
{
declaration = declaration.Children[0].Convert();
}
else
{
break;
}
}
}
}