From d30a715d066b604b61a3ccee85777133437e488c 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:26:23 +0500 Subject: [PATCH] Add "assert" and "fn" --- src/compile.c | 43 +++++++++++++++++++++++++++++++++++++++---- src/process.c | 2 +- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/compile.c b/src/compile.c index 3727db9..ad2d314 100644 --- a/src/compile.c +++ b/src/compile.c @@ -145,7 +145,7 @@ char* compile_gensplit(tSyntaxElement* se, char* operator) { if (token->next != NULL) { if (token->next->type == TOKEN) - string_append_free(&result,token->next->content.string); + string_append(&result,token->next->content.string); else string_append(&result,compile_expression_wrapped(token->next)); @@ -266,19 +266,23 @@ char* compile_expression(tSyntaxElement* syntaxelement) { } case STRING: + return NULL; case NONE: case NEWTREE: - return NULL; + string_append(&result, "()"); + break; } + } else { + string_append(&result, "()"); } break; case NEWTREE: case NONE: - free(result); - return NULL; + string_append(&result, "()"); + break; } @@ -367,6 +371,25 @@ char* compile(tSyntaxElement* syntaxtree) { } + } else if (strcmp(token->content.string, "fn") == 0) { + + compile_enter_tag(&result); + + string_append(&result, "macro "); + string_append_free(&result, compile_expression(token->next)); + + compile_exit_tag(&result); + + + string_append_free(&result, compile(token->next->next)); + + + compile_enter_tag(&result); + + string_append(&result, "endmacro"); + + compile_exit_tag(&result); + } else if (strcmp(token->content.string, "verbatim") == 0) { compile_enter_tag(&result); @@ -383,6 +406,18 @@ char* compile(tSyntaxElement* syntaxtree) { string_append(&result, " endverbatim"); compile_exit_tag(&result); + } else if (strcmp(token->content.string, "assert") == 0) { + + compile_enter_tag(&result); + string_append(&result, "require "); + + string_append_free(&result, compile_expression(token->next)); + + string_append(&result, " returning "); + + string_append_free(&result, compile_expression(token->next->next)); + compile_exit_tag(&result); + } else { string_append(&result, "{#"); diff --git a/src/process.c b/src/process.c index 68ceb99..77d72cd 100644 --- a/src/process.c +++ b/src/process.c @@ -85,7 +85,7 @@ bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) { deffound = true; - } else if (strcmp(token->content.string,"fn") == 0 && + } else if (strcmp(token->content.string,"#fn") == 0 && token->next != NULL && token->next->type == TOKEN && token->next->next != NULL && se_istraversable(token->next->next) && token->next->next->next != NULL) {