Assertion stuff...
This commit is contained in:
parent
1ed8286ab5
commit
074694d5fb
15
source/hl.h
15
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,9 +196,9 @@ int token_fits(const token_t * const token,
|
||||
void render_string(const char * const string,
|
||||
const char * const mode) {
|
||||
for (const char * s = string; *s != '\00';) {
|
||||
int f = 0;
|
||||
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;
|
||||
|
||||
@ -455,7 +456,7 @@ static bool regex_assert(const regex_t * const regex,
|
||||
// delta
|
||||
for (size_t i = 0; i < regex->delta_table.element_count; i++) {
|
||||
const delta_t * const delta = (delta_t *)(vector_get(®ex->delta_table, i));
|
||||
if ((delta->in == state)
|
||||
if ((delta->in == state)
|
||||
&& (delta->input == *s)) {
|
||||
if(regex_assert(regex, s + delta->width, delta->to)){
|
||||
return true;
|
||||
|
@ -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));
|
||||
|
@ -4,36 +4,30 @@
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
void vector_init(vector_t * vector,
|
||||
size_t element_size,
|
||||
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;
|
||||
void * data) {
|
||||
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,26 +35,22 @@ 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,
|
||||
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];
|
||||
}
|
||||
|
||||
void vector_set(vector_t * vector,
|
||||
void * data,
|
||||
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,31 +4,33 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
// TODO: Handle error warnings?
|
||||
// TODO: Implement more useful functions?
|
||||
|
||||
typedef struct {
|
||||
char * data;
|
||||
size_t element_size;
|
||||
char * data;
|
||||
size_t element_size;
|
||||
size_t element_count;
|
||||
} vector_t;
|
||||
|
||||
extern void vector_init(vector_t * vector,
|
||||
size_t element_size,
|
||||
extern void vector_init(vector_t * vector,
|
||||
size_t element_size,
|
||||
size_t element_count);
|
||||
|
||||
extern void vector_push(vector_t * vector,
|
||||
void * data);
|
||||
void * data);
|
||||
|
||||
extern void vector_pop(vector_t * vector);
|
||||
|
||||
extern void * vector_get(const vector_t * const vector,
|
||||
extern void * vector_get(const vector_t * const vector,
|
||||
const size_t element);
|
||||
|
||||
extern void vector_set(vector_t * vector,
|
||||
void * data,
|
||||
extern void vector_set(vector_t * vector,
|
||||
void * data,
|
||||
size_t element);
|
||||
|
||||
extern void vector_free(vector_t * vector);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user