Improve #def

This commit is contained in:
bʰedoh₂ swé 2024-06-11 19:58:09 +05:00
parent 74d20d9f37
commit b98579699d

View File

@ -26,9 +26,10 @@ bool replace(tSyntaxElement* tree, tProcessingData* pd) {
return false;
}
void process_mod(tSyntaxElement* tree, tProcessingData* pdata) {
bool process_mod(tSyntaxElement* tree, tProcessingData* pdata) {
tProcessingData* pd = pdata;
bool b = false;
while (1) {
@ -38,7 +39,8 @@ void process_mod(tSyntaxElement* tree, tProcessingData* pdata) {
if (tree->type == TOKEN) {
switch (pd->type) {
case REPLACE:
replace(tree,pd);
if (replace(tree,pd))
b = true;
break;
case FUNCTION:
break;
@ -51,6 +53,8 @@ void process_mod(tSyntaxElement* tree, tProcessingData* pdata) {
else break;
}
return b;
}
@ -129,11 +133,12 @@ bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) {
}
void process(tSyntaxElement* tree, tProcessingData* pdata) {
bool process(tSyntaxElement* tree, tProcessingData* pdata) {
tProcessingData* pd = pdata;
bool deffound = false;
bool didreplace = false;
tProcessingData* firstpd = NULL;
@ -147,22 +152,29 @@ void process(tSyntaxElement* tree, tProcessingData* pdata) {
deffound = process_find(tree, &pd);
if (tree->next != NULL) {
process(tree->next, pd);
if (process(tree->next, pd))
didreplace = true;
}
if (!deffound) {
if (se_istraversable(tree))
process(tree->content.syntax, pd);
if (process(tree->content.syntax, pd))
didreplace = true;
process_mod(tree, pd);
if (process_mod(tree, pd))
didreplace = true;
}
if (pd != pdata)
free(pd);
if (firstpd != pd && firstpd != NULL)
if (firstpd != pd && firstpd != NULL) {
free(firstpd);
if (didreplace)
process(tree, NULL);
}
return didreplace;
}