This commit is contained in:
2026-02-08 16:10:39 +01:00
parent 1a5742fc4f
commit 38f55d8e7c
4 changed files with 63 additions and 1 deletions

View File

@@ -71,6 +71,9 @@ public sealed class Generator(List<NodeDefinition> nodes)
case NodeStatementAssignment statement:
EmitStatementAssignment(statement);
break;
case NodeStatementIf statement:
EmitStatementIf(statement);
break;
default:
throw new ArgumentOutOfRangeException(nameof(node), node, null);
}
@@ -114,6 +117,36 @@ public sealed class Generator(List<NodeDefinition> nodes)
writer.WriteLine($"{target} = {value};");
}
private void EmitStatementIf(NodeStatementIf statement)
{
var condition = EmitExpression(statement.Condition);
writer.WriteLine($"if ({condition})");
writer.WriteLine("{");
using (writer.Indent())
{
EmitStatement(statement.ThenBlock);
}
writer.WriteLine("}");
if (statement.ElseBlock != null)
{
writer.Write("else");
if (statement.ElseBlock is NodeStatementIf)
writer.Write(" ");
else
writer.WriteLine();
writer.WriteLine("{");
using (writer.Indent())
{
EmitStatement(statement.ElseBlock);
}
writer.WriteLine("}");
}
}
private string EmitExpression(NodeExpression node)
{
return node switch