Compare commits
No commits in common. "24042b3f88dbe3178508520001a5a96e31c6bb13" and "a7aefd33ade7331cfa88884275e07a74c1a9423f" have entirely different histories.
24042b3f88
...
a7aefd33ad
@ -5,9 +5,23 @@
|
|||||||
#include "syntax.h"
|
#include "syntax.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
|
|
||||||
bool replace(tSyntaxElement* tree, tProcessingData* pd) {
|
bool replace(tSyntaxElement* tree, tProcessingData* pdata) {
|
||||||
|
|
||||||
|
tProcessingData* pd = pdata;
|
||||||
|
|
||||||
|
bool didreplace = false;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
|
||||||
|
if (pd->data.replace.replacethis == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (tree->type == TOKEN)
|
||||||
|
|
||||||
if (strcmp(tree->content.string, pd->data.replace.replacethis) == 0) {
|
if (strcmp(tree->content.string, pd->data.replace.replacethis) == 0) {
|
||||||
|
|
||||||
|
didreplace = true;
|
||||||
|
|
||||||
free(tree->content.none);
|
free(tree->content.none);
|
||||||
|
|
||||||
tSyntaxElement* clone = se_clone_no_next(pd->data.replace.replacewiththis, tree);
|
tSyntaxElement* clone = se_clone_no_next(pd->data.replace.replacewiththis, tree);
|
||||||
@ -16,28 +30,6 @@ bool replace(tSyntaxElement* tree, tProcessingData* pd) {
|
|||||||
|
|
||||||
free(clone);
|
free(clone);
|
||||||
|
|
||||||
return true;
|
|
||||||
} else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void process_mod(tSyntaxElement* tree, tProcessingData* pdata) {
|
|
||||||
|
|
||||||
tProcessingData* pd = pdata;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
|
|
||||||
if (pd->data.replace.replacethis == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (tree->type == TOKEN) {
|
|
||||||
switch (pd->type) {
|
|
||||||
case REPLACE:
|
|
||||||
replace(tree,pd);
|
|
||||||
break;
|
|
||||||
case FUNCTION:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pd->prev != NULL)
|
if (pd->prev != NULL)
|
||||||
@ -47,6 +39,8 @@ void process_mod(tSyntaxElement* tree, tProcessingData* pdata) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return didreplace;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) {
|
bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) {
|
||||||
@ -80,41 +74,6 @@ bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) {
|
|||||||
|
|
||||||
deffound = true;
|
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -150,7 +109,16 @@ void process(tSyntaxElement* tree, tProcessingData* pdata) {
|
|||||||
if (se_istraversable(tree))
|
if (se_istraversable(tree))
|
||||||
process(tree->content.syntax, pd);
|
process(tree->content.syntax, pd);
|
||||||
|
|
||||||
process_mod(tree, pd);
|
switch (pd->type) {
|
||||||
|
|
||||||
|
case REPLACE:
|
||||||
|
replace(tree, pd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FUNCTION: // TODO
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
char* name;
|
char** args;
|
||||||
int argc;
|
|
||||||
char** argv;
|
|
||||||
tSyntaxElement* body;
|
tSyntaxElement* body;
|
||||||
|
|
||||||
} tProcessingFunction;
|
} tProcessingFunction;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user