using Canon.Core.Enums;
namespace Canon.Core.SyntaxNodes;
public class IdentifierVarPart : NonTerminatedSyntaxNode
{
public override NonTerminatorType Type => NonTerminatorType.IdVarPart;
///
/// 是否声明了索引部分
///
public bool Exist { get; private init; }
///
/// 索引中的位置声明
///
public IEnumerable Positions => GetPositions();
private IEnumerable GetPositions()
{
if (!Exist)
{
yield break;
}
foreach (Expression expression in Children[1].Convert().Expressions)
{
yield return expression;
}
}
public static IdentifierVarPart Create(List children)
{
bool exist;
if (children.Count == 0)
{
exist = false;
}
else if (children.Count == 3)
{
exist = true;
}
else
{
throw new InvalidOperationException();
}
return new IdentifierVarPart { Children = children, Exist = exist };
}
}