using Canon.Core.Abstractions;
using Canon.Core.Enums;
using Canon.Core.LexicalParser;
namespace Canon.Core.SyntaxNodes;
public class Period : NonTerminatedSyntaxNode
{
public override NonTerminatorType Type => NonTerminatorType.Period;
///
/// 所有定义的Period
///
public List Periods { get; } = [];
///
/// 数组的开始下标和结束下标
///
public (NumberSemanticToken, NumberSemanticToken) Range
{
get
{
if (Children.Count == 3)
{
return (Children[0].Convert().Token.Convert(),
Children[2].Convert().Token.Convert());
}
else
{
return (Children[2].Convert().Token.Convert(),
Children[4].Convert().Token.Convert());
}
}
}
public override void PreVisit(SyntaxNodeVisitor visitor)
{
visitor.PreVisit(this);
}
public override void PostVisit(SyntaxNodeVisitor visitor)
{
visitor.PostVisit(this);
}
public static Period Create(List children)
{
Period result = new() { Children = children };
if (children.Count == 3)
{
result.Periods.Add(result);
}
else
{
Period child = children[0].Convert();
foreach (Period period in child.Periods)
{
result.Periods.Add(period);
}
result.Periods.Add(result);
}
return result;
}
}