2024-04-26 10:18:49 +08:00
|
|
|
|
using Canon.Core.Abstractions;
|
|
|
|
|
using Canon.Core.Enums;
|
|
|
|
|
using Canon.Core.LexicalParser;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
|
|
|
|
public class VarDeclaration : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.VarDeclaration;
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PreVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PreVisit(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PostVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PostVisit(this);
|
|
|
|
|
}
|
2024-04-25 11:42:36 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public required IdentifierSemanticToken Token { get; init; }
|
2024-04-25 11:42:36 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public required IdentifierList IdentifierList { get; init; }
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
public static VarDeclaration Create(List<SyntaxNodeBase> children)
|
|
|
|
|
{
|
2024-04-25 11:42:36 +08:00
|
|
|
|
if (children.Count == 2)
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
return new VarDeclaration
|
|
|
|
|
{
|
|
|
|
|
Children = children,
|
|
|
|
|
Token = children[0].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
|
|
|
|
|
IdentifierList = children[1].Convert<IdentifierList>()
|
|
|
|
|
};
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
return new VarDeclaration
|
|
|
|
|
{
|
|
|
|
|
Children = children,
|
|
|
|
|
Token = children[2].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
|
|
|
|
|
IdentifierList = children[3].Convert<IdentifierList>()
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|