using Canon.Core.Enums;
namespace Canon.Core.SyntaxNodes;
public class Parameter : NonTerminatedSyntaxNode
{
public override NonTerminatorType Type => NonTerminatorType.Parameter;
///
/// 是否为引用变量
///
public bool IsVar { get; private init; }
///
/// 声明的变量名称
///
public ValueParameter ValueParameter =>
IsVar ? Children[0].Convert().ValueParameter : Children[0].Convert();
public static Parameter Create(List children)
{
NonTerminatedSyntaxNode node = children[0].Convert();
bool isVar;
if (node.Type == NonTerminatorType.VarParameter)
{
isVar = true;
}
else if (node.Type == NonTerminatorType.ValueParameter)
{
isVar = false;
}
else
{
throw new InvalidOperationException();
}
return new Parameter { Children = children, IsVar = isVar };
}
}