2026-01-07 20:18:11 +01:00
|
|
|
#ifndef PARSER_H
|
|
|
|
|
#define PARSER_H
|
|
|
|
|
|
2026-01-23 17:01:26 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
2026-01-20 22:16:46 +01:00
|
|
|
#include "../lexer/lexer.h"
|
|
|
|
|
#include "../utils/ast/ast.h"
|
2026-01-09 16:32:15 +01:00
|
|
|
|
2026-01-23 17:01:26 +01:00
|
|
|
enum parser_state {
|
|
|
|
|
PARSER_STATE_NOT_INITIALIZED = 0,
|
|
|
|
|
PARSER_STATE_READY,
|
|
|
|
|
PARSER_STATE_CLOSED
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* @brief Initializes the parser module
|
|
|
|
|
* @warning parser needs to be closed after use with parser_close()
|
|
|
|
|
*
|
|
|
|
|
* @return Returns false on error and true on success
|
|
|
|
|
*/
|
|
|
|
|
bool parser_init(void);
|
|
|
|
|
|
|
|
|
|
/* @brief Closes the parser module after use
|
|
|
|
|
*/
|
|
|
|
|
void parser_close(void);
|
|
|
|
|
|
2026-01-09 16:32:15 +01:00
|
|
|
/* @brief Builds the AST representation of the next command to execute.
|
|
|
|
|
*
|
|
|
|
|
* @return Returns the AST representation of the next command to execute.
|
|
|
|
|
* If there is no command left to execute, retuns an AST_END node.
|
2026-01-10 19:16:36 +01:00
|
|
|
*
|
|
|
|
|
* @warning NOT IMPLEMENTED
|
2026-01-09 16:32:15 +01:00
|
|
|
*/
|
2026-01-20 20:32:59 +01:00
|
|
|
struct ast *get_ast(struct lexer_context *ctx);
|
2026-01-09 16:32:15 +01:00
|
|
|
|
|
|
|
|
/* @brief Builds the AST representation of the given command string.
|
|
|
|
|
*
|
|
|
|
|
* @return Returns the AST representation of the given command string.
|
|
|
|
|
* Returns an AST_END node if the given command is empty.
|
2026-01-10 19:16:36 +01:00
|
|
|
*
|
|
|
|
|
* @warning NOT IMPLEMENTED
|
2026-01-09 16:32:15 +01:00
|
|
|
*/
|
2026-01-12 21:48:11 +01:00
|
|
|
struct ast *get_ast_str(char *command);
|
2026-01-09 16:32:15 +01:00
|
|
|
|
2026-01-07 20:18:11 +01:00
|
|
|
#endif /* ! PARSER_H */
|