19 module->file = fopen(filepath, "r");
26 module->filepath[MODULE_MAX_FILEPATH_SIZE] = '\0';
30 module->tokens = malloc(sizeof(token_t) * MODULE_INITIAL_TOKENS_LENGTH);
31 module->tokens_count = 0;
32 module->_tokens_length = MODULE_INITIAL_TOKENS_LENGTH;
34 module->errors = malloc(sizeof(module_error_t) * MODULE_INITIAL_ERRORS_LENGTH);
35 module->errors_count = 0;
36 module->_errors_length = MODULE_INITIAL_ERRORS_LENGTH;
47 module->_tokens_length += MODULE_TOKENS_LENGTH_INCREMENT;
48 module->tokens = realloc(module->tokens, sizeof(token_t) * module->_tokens_length);
51 return &
module->tokens[module->tokens_count++];
57 _module_fill_queue(
module);
65 _module_fill_queue(
module);
77 module->tokens = NULL;
86 module->errors = NULL;
95 module->_errors_length += MODULE_ERRORS_LENGTH_INCREMENT;
96 module->errors = realloc(module->errors, sizeof(module_error_t) * module->_errors_length);
117 error = &
module->errors[i];
133 for (
int i = 0, ch = 0; i < size && ch != EOF; i++) {
void ast_node_init(ast_node_t *node, ast_node_t *parent, node_type_t type, token_t *token)
Initializes an AST node.
void ast_close(ast_node_t *root)
Closes the given AST root node and all children.
#define DPRINTF1(fmt,...)
void dstring_init(dstring_t *string, unsigned int buffer_size)
Initializes a dynamic string (dstring).
void dstring_copy(dstring_t *string, const char *source)
Copies the content of source to the dstring.
void dstring_close(dstring_t *string)
Closes the dynamic string.
enum error_code error_code_t
Enumeration of error codes.
#define ERROR_BREAK(expr)
void error_module_ctx(module_t *module, unsigned int line, unsigned int column, unsigned int length, const char *message)
Print a error message formated to show the code context inside the module.
void module_add_error(module_t *module, unsigned int line, unsigned int column, unsigned int length, const char *message)
Add error for the given module.
token_t * module_add_token(module_t *module)
Add a new token to module.
error_code_t module_init(module_t *module, const char *filepath)
Initialize a module struct.
void module_print_errors(module_t *module)
Print all errors on the module.
error_code_t module_lookup(module_t *module, int *chret, unsigned int seek)
Get a character on module's file, without removing it from the queue.
void module_close(module_t *module)
Close the given module.
error_code_t module_getc(module_t *module, int *chret)
Get next character on module's file, removing it from the queue.
void cqueue_close(cqueue_t *queue)
Close the given circular queue.
error_code_t cqueue_add(cqueue_t *queue, int item)
Add a value to the circular queue.
error_code_t cqueue_get(cqueue_t *queue, int *item)
Get the current value from the circular queue, removing it from the queue.
error_code_t cqueue_lookup(const cqueue_t *queue, int *item, unsigned int seek)
Get a value from the circular queue, without removing it from the queue.
void cqueue_init(cqueue_t *queue, unsigned int max_length)
Initializes a circular queue.
unsigned int length
The current number of items on the queue.
char * data
Pointer for the raw string content (a normal C string).
dstring_t message
The error message to print.
unsigned int line
The module's line where the error is.
unsigned int length
The length of the part where has an error in the line.
unsigned int column
The line's column where the error starts.
Struct that represents a Mya module.
ast_node_t ast
AST of the module.
module_error_t * errors
List of errors inside the module.
cqueue_t _queue
Internal queue to read file character by character.
char filepath[MODULE_MAX_FILEPATH_SIZE+1]
Module's filepath.
unsigned int _tokens_length
Internal field with the size of tokens allocated memory.
unsigned int _errors_length
Internal field with the size of errors allocated memory.
unsigned int errors_count
Number of errors on errors list.
token_t * tokens
List of tokens inside the module.
FILE * file
Module's file handler.
unsigned int tokens_count
Number of tokens on tokens list.
#define MODULE_MAX_FILEPATH_SIZE
struct module module_t
Struct that represents a Mya module.
#define MODULE_MIN_QUEUE_LENGTH
struct module_error module_error_t
Struct that represents a error inside a Mya module.
#define MODULE_MAX_QUEUE_LENGTH
struct token token_t
Struct for a Mya token.