添加对while-do语句的支持 (#77)
Co-authored-by: jackfiled <xcrenchangjun@outlook.com> Reviewed-on: PostGuard/Canon#77 Co-authored-by: ichirinko <1621543655@qq.com> Co-committed-by: ichirinko <1621543655@qq.com>
This commit is contained in:
@@ -48,6 +48,11 @@ public class Expression : NonTerminatedSyntaxNode
|
||||
/// </summary>
|
||||
public bool IsIfCondition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为WHILE语句中的条件语句
|
||||
/// </summary>
|
||||
public bool IsWhileCondition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 直接赋值产生式的事件
|
||||
/// </summary>
|
||||
|
@@ -29,6 +29,17 @@ public class ForGeneratorEventArgs : EventArgs
|
||||
public required Expression End { get; init; }
|
||||
|
||||
public required Statement Sentence { get; init; }
|
||||
|
||||
public required TerminatedSyntaxNode Do { get; init; }
|
||||
}
|
||||
|
||||
public class WhileGeneratorEventArgs : EventArgs
|
||||
{
|
||||
public required Expression Condition { get; init; }
|
||||
|
||||
public required Statement Sentence { get; init; }
|
||||
|
||||
public required TerminatedSyntaxNode Do { get; init; }
|
||||
}
|
||||
|
||||
public class Statement : NonTerminatedSyntaxNode
|
||||
@@ -62,6 +73,11 @@ public class Statement : NonTerminatedSyntaxNode
|
||||
/// </summary>
|
||||
public event EventHandler<ForGeneratorEventArgs>? OnForGenerator;
|
||||
|
||||
/// <summary>
|
||||
/// 使用While产生式的事件
|
||||
/// </summary>
|
||||
public event EventHandler<WhileGeneratorEventArgs>? OnWhileGenerator;
|
||||
|
||||
public static Statement Create(List<SyntaxNodeBase> children)
|
||||
{
|
||||
return new Statement { Children = children };
|
||||
@@ -77,6 +93,16 @@ public class Statement : NonTerminatedSyntaxNode
|
||||
Variable = Children[0].Convert<Variable>(), Expression = Children[2].Convert<Expression>()
|
||||
});
|
||||
}
|
||||
else if (Children.Count == 4)
|
||||
{
|
||||
OnWhileGenerator?.Invoke(this,
|
||||
new WhileGeneratorEventArgs
|
||||
{
|
||||
Condition = Children[1].Convert<Expression>(),
|
||||
Do = Children[2].Convert<TerminatedSyntaxNode>(),
|
||||
Sentence = Children[3].Convert<Statement>(),
|
||||
});
|
||||
}
|
||||
else if (Children.Count == 5)
|
||||
{
|
||||
OnIfGenerator?.Invoke(this,
|
||||
@@ -95,6 +121,7 @@ public class Statement : NonTerminatedSyntaxNode
|
||||
Iterator = Children[1].Convert<TerminatedSyntaxNode>().Token.Convert<IdentifierSemanticToken>(),
|
||||
Begin = Children[3].Convert<Expression>(),
|
||||
End = Children[5].Convert<Expression>(),
|
||||
Do = Children[6].Convert<TerminatedSyntaxNode>(),
|
||||
Sentence = Children[7].Convert<Statement>()
|
||||
});
|
||||
}
|
||||
|
@@ -7,6 +7,16 @@ public class TerminatedSyntaxNode : SyntaxNodeBase
|
||||
{
|
||||
public override bool IsTerminated => true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否为For循环定义中的DO节点
|
||||
/// </summary>
|
||||
public bool IsForNode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为While循环定义中的DO节点
|
||||
/// </summary>
|
||||
public bool IsWhileNode { get; set; }
|
||||
|
||||
public override void PreVisit(SyntaxNodeVisitor visitor)
|
||||
{
|
||||
visitor.PreVisit(this);
|
||||
|
Reference in New Issue
Block a user