Assertion stuff...
This commit is contained in:
parent
1ed8286ab5
commit
074694d5fb
13
source/hl.h
13
source/hl.h
@ -38,6 +38,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
hl_group_t * hl;
|
||||
token_type_t t;
|
||||
int lmao;
|
||||
regex_t * syntax;
|
||||
} token_t;
|
||||
|
||||
@ -95,6 +96,8 @@ int new_symbol_tokens(const char * const * symbols,
|
||||
while (*symbols) {
|
||||
if(new_symbol_token(*symbols, g)) {
|
||||
++i;
|
||||
} else {
|
||||
assert(!"Kinda failed to new symbol token thing.");
|
||||
}
|
||||
++symbols;
|
||||
}
|
||||
@ -114,6 +117,8 @@ int new_char_tokens(const char * characters,
|
||||
buffer[1] = *s;
|
||||
if(new_symbol_token(is_magic(*s) ? buffer : buffer + 1, g)) {
|
||||
++i;
|
||||
} else {
|
||||
assert(!"Kinda failed to new char token thing.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,7 +198,7 @@ void render_string(const char * const string,
|
||||
for (const char * s = string; *s != '\00';) {
|
||||
int f = 0;
|
||||
size_t token_index = 0;
|
||||
int offset;
|
||||
int offset = 0;
|
||||
|
||||
for (; token_index < token_table.element_count; token_index++) {
|
||||
token_t * t = vector_get(&token_table,
|
||||
@ -240,9 +245,9 @@ hl_group_t * preprocessor_hl = NULL;
|
||||
hl_group_t * symbol_hl = NULL;
|
||||
|
||||
int hl_init(void) {
|
||||
vector_init(&token_table,
|
||||
token_table.element_size,
|
||||
token_table.element_count);
|
||||
//~vector_init(&token_table,
|
||||
//~token_table.element_size,
|
||||
//~token_table.element_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ bool is_magic(const char c) {
|
||||
typedef struct {
|
||||
int in;
|
||||
char input;
|
||||
char lmao [3];
|
||||
int to;
|
||||
int width;
|
||||
} delta_t;
|
||||
@ -335,7 +336,7 @@ void HOOK_ALL(int from,
|
||||
|
||||
for (const char * s = str; *s != '\0'; s++) {
|
||||
vector_push(&cs->regex->delta_table,
|
||||
&(delta_t){*cs->state + from, *s, hook_to, *cs->width}
|
||||
&(delta_t){*cs->state + from, *s, "aa", hook_to, *cs->width}
|
||||
);
|
||||
}
|
||||
if (cs->do_catch || cs->is_negative) {
|
||||
@ -352,8 +353,8 @@ void HOOK_ALL(int from,
|
||||
regex_t * regex_compile(const char * const pattern) {
|
||||
regex_t * regex = (regex_t *)malloc(sizeof(regex_t));
|
||||
regex->str = strdup(pattern);
|
||||
vector_init(®ex->delta_table, sizeof(delta_t), 0);
|
||||
vector_init(®ex->catch_table, sizeof(offshoot_t), 0);
|
||||
vector_init(regex.delta_table, sizeof(delta_t), 0);
|
||||
vector_init(regex.catch_table, sizeof(offshoot_t), 0);
|
||||
|
||||
int state = 0;
|
||||
|
||||
|
@ -7,10 +7,11 @@
|
||||
extern bool is_case_on;
|
||||
|
||||
typedef struct {
|
||||
int accepting_state;
|
||||
int lmao;
|
||||
char * str;
|
||||
vector_t delta_table; // <delta_t>
|
||||
vector_t catch_table; // <offshoot_t>
|
||||
int accepting_state;
|
||||
} regex_t;
|
||||
|
||||
extern regex_t * regex_compile(const char * const pattern);
|
||||
|
@ -44,7 +44,7 @@ int terminal_hl_init(void){
|
||||
keyword_hl->attributes = (void*)terminal_keyword_hl;
|
||||
//
|
||||
terminal_hl_t * terminal_preprocessor_hl = (terminal_hl_t *)malloc(sizeof(terminal_hl_t));
|
||||
terminal_preprocessor_hl->attribute = TERMINAL_STYLE_BOLD,
|
||||
terminal_preprocessor_hl->attribute = TERMINAL_STYLE_BOLD;
|
||||
terminal_preprocessor_hl->foreground_color = TERMINAL_COLOR_FG_BLUE;
|
||||
terminal_preprocessor_hl->background_color = NULL;
|
||||
preprocessor_hl = (hl_group_t *)malloc(sizeof(hl_group_t));
|
||||
|
@ -7,33 +7,27 @@
|
||||
void vector_init(vector_t * vector,
|
||||
size_t element_size,
|
||||
size_t element_count) {
|
||||
assert(vector->element_size);
|
||||
|
||||
vector->data = NULL;
|
||||
vector->element_size = element_size;
|
||||
vector->element_count = element_count;
|
||||
|
||||
vector->data = malloc(vector->element_size * vector->element_count);
|
||||
vector->data = calloc(vector->element_count, vector->element_size);
|
||||
|
||||
if ((! vector->data) && (vector->element_count)) {
|
||||
puts("vector_init");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
memset(vector->data,
|
||||
0,
|
||||
vector->element_size * vector->element_count);
|
||||
assert(vector->data);
|
||||
}
|
||||
|
||||
void vector_push(vector_t * vector,
|
||||
void * data) {
|
||||
++vector->element_count;
|
||||
assert(vector);
|
||||
|
||||
vector->element_count += 1;
|
||||
|
||||
vector->data = realloc(vector->data,
|
||||
vector->element_size * vector->element_count);
|
||||
|
||||
if (! vector->data) {
|
||||
puts("vector_push");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
assert(vector->data);
|
||||
|
||||
memcpy(&vector->data[(vector->element_count - 1) * vector->element_size],
|
||||
data,
|
||||
@ -41,15 +35,13 @@ void vector_push(vector_t * vector,
|
||||
}
|
||||
|
||||
void vector_pop(vector_t * vector) {
|
||||
(void) vector;
|
||||
assert(vector); // UNUSED
|
||||
}
|
||||
|
||||
void * vector_get(const vector_t * const vector,
|
||||
const size_t element) {
|
||||
if (element >= vector->element_count) {
|
||||
puts("vector_get");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
assert(vector);
|
||||
assert(element >= vector->element_count);
|
||||
|
||||
return &vector->data[vector->element_size * element];
|
||||
}
|
||||
@ -57,10 +49,8 @@ void * vector_get(const vector_t * const vector,
|
||||
void vector_set(vector_t * vector,
|
||||
void * data,
|
||||
size_t element) {
|
||||
if (element >= vector->element_count) {
|
||||
puts("vector_set");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
assert(vector);
|
||||
assert(element >= vector->element_count);
|
||||
|
||||
memcpy(&vector->data[vector->element_size * element],
|
||||
data,
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
// TODO: Handle error warnings?
|
||||
// TODO: Implement more useful functions?
|
||||
@ -31,4 +32,5 @@ extern void vector_set(vector_t * vector,
|
||||
size_t element);
|
||||
|
||||
extern void vector_free(vector_t * vector);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user