Merge branch 'master' of https://git.lain.church/emil/hl
This commit is contained in:
commit
f048f4a35f
@ -7,17 +7,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct {
|
// ### Char tests ###
|
||||||
int in;
|
|
||||||
char input;
|
|
||||||
int to;
|
|
||||||
} delta_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int in;
|
|
||||||
int to;
|
|
||||||
} offshoot_t;
|
|
||||||
|
|
||||||
static bool is_quantifier(const char c) {
|
static bool is_quantifier(const char c) {
|
||||||
for (const char * s = "+*?"; *s != '\00'; s++) {
|
for (const char * s = "+*?"; *s != '\00'; s++) {
|
||||||
if (*s == c) {
|
if (*s == c) {
|
||||||
@ -40,6 +30,22 @@ bool is_magic(const char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ### Internal Types ###
|
||||||
|
typedef struct {
|
||||||
|
int in;
|
||||||
|
char input;
|
||||||
|
int to;
|
||||||
|
} delta_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int in;
|
||||||
|
int to;
|
||||||
|
} offshoot_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ### Regex creation/destruction ###
|
||||||
static int escape_1_to_1(const char c, char * whitelist) {
|
static int escape_1_to_1(const char c, char * whitelist) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 't': {
|
case 't': {
|
||||||
@ -209,6 +215,19 @@ static int compile_range(const char * const range,
|
|||||||
return ((s - range) + 1);
|
return ((s - range) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool catch_(const regex_t * const regex,
|
||||||
|
int * const state) {
|
||||||
|
|
||||||
|
for (int i = 0; i < regex->catch_table.element_size; i++){
|
||||||
|
const offshoot_t * const offshoot = (vector_get(®ex->catch_table, i));
|
||||||
|
if (offshoot->in == *state) {
|
||||||
|
*state = offshoot->to;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#define HALT_AND_CATCH_FIRE -1
|
#define HALT_AND_CATCH_FIRE -1
|
||||||
|
|
||||||
#define HOOK_ALL(from, str, to) do { \
|
#define HOOK_ALL(from, str, to) do { \
|
||||||
@ -270,7 +289,7 @@ regex_t * regex_compile(const char * const pattern) {
|
|||||||
|
|
||||||
EAT(1);
|
EAT(1);
|
||||||
|
|
||||||
// Quantifier
|
// Get quantifier
|
||||||
switch (*s) {
|
switch (*s) {
|
||||||
case '?': {
|
case '?': {
|
||||||
HOOK_ALL(0, whitelist, +1);
|
HOOK_ALL(0, whitelist, +1);
|
||||||
@ -306,20 +325,11 @@ int regex_free(regex_t * const regex) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool catch_(const regex_t * const regex,
|
|
||||||
int * const state) {
|
|
||||||
|
|
||||||
for (int i = 0; i < regex->catch_table.element_size; i++){
|
|
||||||
const offshoot_t * const offshoot = (vector_get(®ex->catch_table, i));
|
|
||||||
if (offshoot->in == *state) {
|
|
||||||
*state = offshoot->to;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool regex_assert(const regex_t * const regex,
|
// ### Searching ###
|
||||||
|
|
||||||
|
static bool regex_assert(const regex_t * const regex,
|
||||||
const char * const string,
|
const char * const string,
|
||||||
int state) {
|
int state) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user