Add "assert" and "fn"

This commit is contained in:
bʰedoh₂ swé 2024-06-11 18:26:23 +05:00
parent c8189f5ec1
commit d30a715d06
2 changed files with 40 additions and 5 deletions

View File

@ -145,7 +145,7 @@ char* compile_gensplit(tSyntaxElement* se, char* operator) {
if (token->next != NULL) { if (token->next != NULL) {
if (token->next->type == TOKEN) if (token->next->type == TOKEN)
string_append_free(&result,token->next->content.string); string_append(&result,token->next->content.string);
else else
string_append(&result,compile_expression_wrapped(token->next)); string_append(&result,compile_expression_wrapped(token->next));
@ -266,19 +266,23 @@ char* compile_expression(tSyntaxElement* syntaxelement) {
} }
case STRING: case STRING:
return NULL;
case NONE: case NONE:
case NEWTREE: case NEWTREE:
return NULL; string_append(&result, "()");
break;
} }
} else {
string_append(&result, "()");
} }
break; break;
case NEWTREE: case NEWTREE:
case NONE: case NONE:
free(result); string_append(&result, "()");
return NULL; 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) { } else if (strcmp(token->content.string, "verbatim") == 0) {
compile_enter_tag(&result); compile_enter_tag(&result);
@ -383,6 +406,18 @@ char* compile(tSyntaxElement* syntaxtree) {
string_append(&result, " endverbatim"); string_append(&result, " endverbatim");
compile_exit_tag(&result); 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 { } else {
string_append(&result, "{#"); string_append(&result, "{#");

View File

@ -85,7 +85,7 @@ bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) {
deffound = true; 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 != NULL && token->next->type == TOKEN &&
token->next->next != NULL && se_istraversable(token->next->next) && token->next->next != NULL && se_istraversable(token->next->next) &&
token->next->next->next != NULL) { token->next->next->next != NULL) {