diff --git a/src/compile.c b/src/compile.c index 3b3defd..6abb7f9 100644 --- a/src/compile.c +++ b/src/compile.c @@ -13,6 +13,11 @@ void string_append(char** string, char* append) { } +void string_append_free(char** string, char* append) { + string_append(string, append); + free(append); +} + void compile_enter_tag(char** string) { int len = strlen(*string); @@ -106,6 +111,30 @@ void compile_genexec(char** result, tSyntaxElement* se){ string_append(result,")"); } +char* compile_gensplit(tSyntaxElement* se, char* operator) { + tSyntaxElement* token = se; + char* result = malloc(sizeof(char)); + result[0] = '\0'; + while (1) { + + if (token->next != NULL) { + + if (token->next->type == TOKEN) + string_append(&result,token->next->content.string); + else + string_append(&result,compile_expression_wrapped(token->next)); + + if (token->next->next != NULL) + string_append(&result,operator); + + token = token->next; + + } else break; + + } + return result; +} + char* compile_expression(tSyntaxElement* syntaxelement) { char* result = calloc(1,sizeof(char)); @@ -139,23 +168,7 @@ char* compile_expression(tSyntaxElement* syntaxelement) { char* operator = token->content.string; - while (1) { - - if (token->next != NULL) { - - if (token->next->type == TOKEN) - string_append(&result,token->next->content.string); - else - string_append(&result,compile_expression_wrapped(token->next)); - - if (token->next->next != NULL) - string_append(&result,operator); - - token = token->next; - - } else break; - - } + string_append_free(&result, compile_gensplit(token, operator)); } else { @@ -186,6 +199,12 @@ char* compile_expression(tSyntaxElement* syntaxelement) { string_append(&result,"not"); string_append(&result,compile_expression_wrapped(token->next)); + } else if (strcmp(token->content.string, "list") == 0) { + + string_append(&result,"["); + string_append_free(&result,compile_gensplit(token->next, ",")); + string_append(&result,"]"); + } else { string_append(&result,token->content.string);