From 74bf888a84d82705803ed8fd0ea72eda92c79318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Tue, 11 Jun 2024 18:55:20 +0500 Subject: [PATCH] Add for loops --- src/compile.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/compile.c b/src/compile.c index b9e2ec4..40b6ff5 100644 --- a/src/compile.c +++ b/src/compile.c @@ -399,6 +399,50 @@ char* compile(tSyntaxElement* syntaxtree) { compile_exit_tag(&result); + } else if (strcmp(token->content.string, "for") == 0) { + + compile_enter_tag(&result); + + string_append(&result, "for "); + string_append_free(&result, compile_expression(token->next->content.syntax)); + string_append(&result, " in "); + string_append_free(&result, compile_expression(token->next->content.syntax->next)); + + compile_exit_tag(&result); + + + string_append_free(&result, compile(token->next->next)); + + + compile_enter_tag(&result); + + string_append(&result, "endfor"); + + compile_exit_tag(&result); + + } else if (strcmp(token->content.string, "formap") == 0) { + + compile_enter_tag(&result); + + string_append(&result, "for "); + string_append_free(&result, compile_expression(token->next->content.syntax)); + string_append(&result, ", "); + string_append_free(&result, compile_expression(token->next->content.syntax->next)); + string_append(&result, " in "); + string_append_free(&result, compile_expression(token->next->content.syntax->next->next)); + + compile_exit_tag(&result); + + + string_append_free(&result, compile(token->next->next)); + + + compile_enter_tag(&result); + + string_append(&result, "endfor"); + + compile_exit_tag(&result); + } else if (strcmp(token->content.string, "verbatim") == 0) { compile_enter_tag(&result);