diff options
| author | Nakidai <nakidai@disroot.org> | 2025-03-30 00:56:27 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2025-03-30 00:56:27 +0300 |
| commit | 2efe02624ba94618da722acd4e6ad49d9610afd8 (patch) | |
| tree | d17198079a6bee7f1fa950bed496ee8e54712c8d | |
| parent | 4769f51d49134d7ef6e8ef81608f7759aa353394 (diff) | |
| download | 3cl-2efe02624ba94618da722acd4e6ad49d9610afd8.tar.gz 3cl-2efe02624ba94618da722acd4e6ad49d9610afd8.zip | |
Simplify parser
Don't call malloc when creating a command, but call cccl_parse function with no tokens as it will call malloc.
| -rw-r--r-- | parser.c | 21 |
1 files changed, 10 insertions, 11 deletions
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: { |