it sort of works now

This commit is contained in:
anon 2023-08-26 01:16:05 +02:00
parent f9953967e2
commit 6fc917b7b7
2 changed files with 32 additions and 21 deletions

View File

@ -42,6 +42,7 @@ int main(int argc,
//
#include "c.h"
//
render_string(buffer, "cterm");
putchar('\n');
fflush(stdout);

View File

@ -311,19 +311,6 @@ static int compile_range(const char * const range,
return ((s - range) + 1);
}
static bool catch_(const regex_t * const regex,
int * const state) {
for (size_t i = 0; i < regex->catch_table.element_count; i++){
const offshoot_t * const offshoot = *(offshoot_t**)vector_get(&regex->catch_table, i);
if (offshoot->in == *state) {
*state = offshoot->to;
return true;
}
}
return false;
}
#define HALT_AND_CATCH_FIRE -1
void HOOK_ALL(int from,
@ -343,7 +330,7 @@ void HOOK_ALL(int from,
vector_push(&cs->regex->delta_table,
&delta);
}
if (cs->do_catch || cs->is_negative) {
if (*cs->do_catch || *cs->is_negative) {
offshoot_t * offshoot = malloc(sizeof(offshoot_t));
offshoot->in = *cs->state + from;
offshoot->to = hook_to;
@ -383,6 +370,7 @@ regex_t * regex_compile(const char * const pattern) {
assert(!is_quantifier(*pattern) && "Pattern starts with quantifier.");
whitelist[0] = '\00';
do_catch = false;
is_negative = false;
width = 1;
switch (*s) {
@ -454,9 +442,23 @@ int regex_free(regex_t * const regex) {
// -----------------
// ### Searching ###
// -----------------
static bool regex_assert(const regex_t * const regex,
static bool catch_(const regex_t * const regex,
int * const state) {
for (size_t i = 0; i < regex->catch_table.element_count; i++){
const offshoot_t * const offshoot = *(offshoot_t**)vector_get(&regex->catch_table, i);
if (offshoot->in == *state) {
*state = offshoot->to;
return true;
}
}
return false;
}
static int regex_assert(const regex_t * const regex,
const char * const string,
int state) {
int state,
int * width) {
for (const char * s = string; *s != '\00'; s++) {
// delta
@ -474,13 +476,13 @@ static bool regex_assert(const regex_t * const regex,
continue;
}
return false;
}
return (state == regex->accepting_state);
}
bool regex_search( regex_t * regex,
return false;
}
int regex_match( regex_t * regex,
const char * const string) {
if (regex == NULL) {
@ -490,5 +492,13 @@ bool regex_search( regex_t * regex,
return true;
}
return regex_assert(regex, string, 0);
int r = 0;
return regex_assert(regex, string, 0, &r);
}
bool regex_search( regex_t * regex,
const char * const string) {
return (bool)regex_match(regex, string, 0);
}