2024-04-26 10:18:49 +08:00
|
|
|
|
using Canon.Core.Abstractions;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
using Canon.Core.Enums;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
|
|
|
|
public class ExpressionList : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.ExpressionList;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-26 10:18:49 +08:00
|
|
|
|
/// 子表达式列表
|
2024-04-07 16:47:28 +08:00
|
|
|
|
/// </summary>
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public List<Expression> Expressions { get; } = [];
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PreVisit(SyntaxNodeVisitor visitor)
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
visitor.PreVisit(this);
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PostVisit(SyntaxNodeVisitor visitor)
|
2024-04-07 16:47:28 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
visitor.PostVisit(this);
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public static ExpressionList Create(List<SyntaxNodeBase> children)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
ExpressionList result = new() { Children = children };
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
if (children.Count == 1)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
result.Expressions.Add(children[0].Convert<Expression>());
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-04-26 10:18:49 +08:00
|
|
|
|
else if (children.Count == 3)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-26 10:18:49 +08:00
|
|
|
|
foreach (Expression expression in children[0].Convert<ExpressionList>().Expressions)
|
|
|
|
|
{
|
|
|
|
|
result.Expressions.Add(expression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Expressions.Add(children[2].Convert<Expression>());
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
return result;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|