From: Patrick Date: Fri, 13 Oct 2023 22:10:18 +0000 (+0200) Subject: new node kinds X-Git-Url: https://gitweb.ps.run/iftint/commitdiff_plain/2acf9a06e0a4952223418d73c82bc11baf2b47f1 new node kinds --- diff --git a/main3.c b/main3.c index b2c1e9d..40e6966 100644 --- a/main3.c +++ b/main3.c @@ -1,6 +1,8 @@ -#include -#include -#include +#include +#include +#include +#include + // Global defines @@ -108,12 +110,16 @@ void vt100GetScreenSize(int * v, int * h) { // Node typedef enum NodeKind { + NK_Namespace, + NK_Struct, NK_Func, - NK_ArgList, + NK_VarList, NK_ExprList, NK_Var, + NK_Type, NK_Body, NK_If, + NK_While, NK_Num, NK_Str, NK_Call, @@ -123,12 +129,16 @@ typedef enum NodeKind { } NodeKind; const char *NK_STRINGS[NK_COUNT] = { + "NK_Namespace", + "NK_Struct", "NK_Func", - "NK_ArgList", + "NK_VarList", "NK_ExprList", "NK_Var", + "NK_Type", "NK_Body", "NK_If", + "NK_While", "NK_Num", "NK_Str", "NK_Call", @@ -219,16 +229,20 @@ void NodeDraw(Node *n, Node *selected) { if (n == selected) vt100EnableNegative(); switch (n->kind) { - case NK_Func: { printf("fn %s ", n->data); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break; } - case NK_ExprList: - case NK_ArgList: { printf("("); for (int i = 0; i < n->childCount; i++) { if (i != 0) printf(" "); NodeDraw(NodeGetChild(n, i), selected); } printf(")"); break; } - case NK_Var: { printf("var %s", n->data); break; } - case NK_Body: { printf("{\n"); indent++; for (int i = 0; i < n->childCount; i++) { INDENT NodeDraw(NodeGetChild(n, i), selected); printf("\n"); } indent--; INDENT printf("}\n"); break; } - case NK_If: { printf("if "); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break; } - case NK_Num: { printf("%s", n->data); break; } - case NK_Str: { printf("'%s'", n->data); break; } - case NK_Call: { printf("call %s ", n->data); NodeDraw(NodeGetChild(n, 0), selected); break; } - case NK_Op: { if (n->childCount <= 1) printf("%s ", n->data); for (int i = 0; i < n->childCount; i++) { if (i != 0) printf(" %s ", n->data); NodeDraw(NodeGetChild(n, i), selected); } break; } + case NK_Namespace: { break; } + case NK_Struct: { break; } + case NK_Func: { printf("fn %s ", n->data); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break; } + case NK_VarList: + case NK_ExprList: { printf("("); for (int i = 0; i < n->childCount; i++) { if (i != 0) printf(", "); NodeDraw(NodeGetChild(n, i), selected); } printf(")"); break; } + case NK_Var: { printf("[%s : ", n->data); NodeDraw(NodeGetChild(n, 0), selected); printf(); break; } + case NK_Type: { break; } + case NK_Body: { printf("{\n"); indent++; for (int i = 0; i < n->childCount; i++) { INDENT NodeDraw(NodeGetChild(n, i), selected); printf("\n"); } indent--; INDENT printf("}\n"); break; } + case NK_If: { printf("if "); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break; } + case NK_While: { printf("while "); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break; } + case NK_Num: { printf("%s", n->data); break; } + case NK_Str: { printf("'%s'", n->data); break; } + case NK_Call: { printf("call %s ", n->data); NodeDraw(NodeGetChild(n, 0), selected); break; } + case NK_Op: { if (n->childCount <= 1) printf("%s ", n->data); for (int i = 0; i < n->childCount; i++) { if (i != 0) printf(" %s ", n->data); NodeDraw(NodeGetChild(n, i), selected); } break; } } vt100DisableNegative(); @@ -427,7 +441,7 @@ Node *GetNode(InputAction actions[NK_COUNT][IN_COUNT]) { case IA_MoveUp: { if (n->parent != NULL) n = n->parent; break; } case IA_MoveRight: { if (n->next != NULL) n = n->next; break; } - case IA_AddFunc: { NS(n1, n, NK_Func) NA(n2, n1, NK_ArgList) NA(n3, n1, NK_Body) n = n1; mode = Mode_Editing; break; } + case IA_AddFunc: { NS(n1, n, NK_Func) NA(n2, n1, NK_VarList) NA(n3, n1, NK_Body) n = n1; mode = Mode_Editing; break; } case IA_AddVar: { NS(n1, n, NK_Var) n = n1; mode = Mode_Editing; break; } case IA_AddIf: { NA(n1, n, NK_If) NA(n2, n1, NK_ExprList) NA(n3, n1, NK_Body) n = n1; break; } case IA_AddNum: { NS(n1, n, NK_Num) n = n1; mode = Mode_Editing; break; } @@ -459,7 +473,7 @@ int main() { actions[NK_Func][IN_D] = IA_Delete; actions[NK_Func][IN_SPACE] = IA_StartEditing; - actions[NK_ArgList][IN_V] = IA_AddVar; + actions[NK_VarList][IN_V] = IA_AddVar; actions[NK_ExprList][IN_V] = IA_AddVar; actions[NK_ExprList][IN_I] = IA_AddIf;