diff --git a/src/process.c b/src/process.c index 16c62ae..993e815 100644 --- a/src/process.c +++ b/src/process.c @@ -74,6 +74,41 @@ bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) { deffound = true; + } 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) { + + tProcessingData* npd = malloc(sizeof(tSyntaxElement)); + + npd->type = FUNCTION; + + npd->data.function.name = malloc(strlen(token->next->content.string)); + strcpy(npd->data.function.name, token->next->content.string); + + npd->data.function.body = se_clone(token->next->next->next, NULL); + + // TODO: Check if all function's arguments are TOKENs + int size = 0; + for (tSyntaxElement* i = token->next->next->content.syntax; i != NULL; i = i->next) + size++; + + // TODO: Fix memory leak + char** argv = calloc(size, sizeof(char*)); // This time there's actually should be an asterisk inside sizeof... + tSyntaxElement* ptr = token->next->next->content.syntax; + for (int i = 0; i < size; i++) { + argv[i] = malloc(strlen(ptr->content.string)); + strcpy(argv[i], ptr->content.string); + ptr = ptr->next; + } + + npd->data.function.argc = size; + npd->data.function.argv = argv; + + *p_pdata = npd; + + deffound = true; + } } diff --git a/src/process.h b/src/process.h index 66e10ff..e254c11 100644 --- a/src/process.h +++ b/src/process.h @@ -19,7 +19,9 @@ typedef struct { typedef struct { - char** args; + char* name; + int argc; + char** argv; tSyntaxElement* body; } tProcessingFunction;