From 2efe02624ba94618da722acd4e6ad49d9610afd8 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Sun, 30 Mar 2025 00:56:27 +0300 Subject: Simplify parser Don't call malloc when creating a command, but call cccl_parse function with no tokens as it will call malloc. --- parser.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'parser.c') diff --git a/parser.c b/parser.c index a2f5484..126d716 100644 --- a/parser.c +++ b/parser.c @@ -76,22 +76,21 @@ struct cccl_Node *cccl_parse(struct cccl_Token tokens[], size_t tokens_length, e { case cccl_Token_COMMAND: { - res->in[res->in_length - 1] = malloc(sizeof(struct cccl_Node)); - *res->in[res->in_length - 1] = (struct cccl_Node) - { - .type = get_nodetype(tokens[i].value), - }; + res->in[res->in_length - 1] = cccl_parse( + NULL, 0, + get_nodetype(tokens[i].value), + 0 + ); } break; case cccl_Token_COMMANDWITHARG: { assert(i + 1 != tokens_length); assert(tokens[i + 1].type == cccl_Token_IDENTIFIER); - res->in[res->in_length - 1] = malloc(sizeof(struct cccl_Node)); - *res->in[res->in_length - 1] = (struct cccl_Node) - { - .type = get_nodetype(tokens[i].value), - .value = tokens[i + 1].value, - }; + res->in[res->in_length - 1] = cccl_parse( + NULL, 0, + get_nodetype(tokens[i].value), + tokens[i + 1].value + ); } break; case cccl_Token_BLOCKSTART: { -- cgit 1.4.1