Move some stuff around

This commit is contained in:
bʰedoh₂ swé 2024-06-10 20:24:57 +05:00
parent f0e6936008
commit 24042b3f88

View File

@ -5,32 +5,40 @@
#include "syntax.h" #include "syntax.h"
#include "process.h" #include "process.h"
bool replace(tSyntaxElement* tree, tProcessingData* pdata) { bool replace(tSyntaxElement* tree, tProcessingData* pd) {
if (strcmp(tree->content.string, pd->data.replace.replacethis) == 0) {
free(tree->content.none);
tSyntaxElement* clone = se_clone_no_next(pd->data.replace.replacewiththis, tree);
tree->content = clone->content;
tree->type = clone->type;
free(clone);
return true;
} else
return false;
}
void process_mod(tSyntaxElement* tree, tProcessingData* pdata) {
tProcessingData* pd = pdata; tProcessingData* pd = pdata;
bool didreplace = false;
while (1) { while (1) {
if (pd->data.replace.replacethis == NULL) if (pd->data.replace.replacethis == NULL)
break; break;
if (tree->type == TOKEN) if (tree->type == TOKEN) {
switch (pd->type) {
if (strcmp(tree->content.string, pd->data.replace.replacethis) == 0) { case REPLACE:
replace(tree,pd);
didreplace = true; break;
case FUNCTION:
free(tree->content.none); break;
tSyntaxElement* clone = se_clone_no_next(pd->data.replace.replacewiththis, tree);
tree->content = clone->content;
tree->type = clone->type;
free(clone);
} }
}
if (pd->prev != NULL) if (pd->prev != NULL)
pd = pd->prev; pd = pd->prev;
@ -39,8 +47,6 @@ bool replace(tSyntaxElement* tree, tProcessingData* pdata) {
} }
return didreplace;
} }
bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) { bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) {
@ -144,16 +150,7 @@ void process(tSyntaxElement* tree, tProcessingData* pdata) {
if (se_istraversable(tree)) if (se_istraversable(tree))
process(tree->content.syntax, pd); process(tree->content.syntax, pd);
switch (pd->type) { process_mod(tree, pd);
case REPLACE:
replace(tree, pd);
break;
case FUNCTION: // TODO
break;
}
} }