#include "parser/parser_functions.h" #include "parser/parser_utils.h" struct ast *parse_funcdec(struct lexer *lexer, enum parser_state *state, struct string *txt) { struct ast *function = ast_create(AST_FUNCTION); if (function == NULL) { QUICK_CLEANUP } struct token next = lexer_peek(lexer); if (txt == NULL && next.type != TOKEN_WORD) { cleanup(function, state); return NULL; } else if (txt == NULL) { ((struct ast_function *)function)->name = next.value; lexer_pop(lexer); next = lexer_peek(lexer); } else { // If we used the word in the txt variable, no need to peek ((struct ast_function *)function)->name = txt; } if (next.type != TOKEN_PAR_LEFT) { cleanup(function, state); return NULL; } lexer_pop(lexer); next = lexer_peek(lexer); if (next.type != TOKEN_PAR_RIGHT) { cleanup(function, state); return NULL; } lexer_pop(lexer); next = lexer_peek(lexer); clean_cons_tokens(TOKEN_NEWLINE, lexer); struct ast *body = parse_shell_command(lexer, state); next = lexer_peek(lexer); if (error_check(function, state, next)) { return NULL; } set_left(function, body); return function; }